9
from subprocess import CalledProcessError
3
12
from helpers import (
7
17
install_extra_repository,
12
from subprocess import CalledProcessError
18
# config_file is changed via juju like:
19
# juju set buildbot-master config-file=`uuencode master.cfg`
21
28
CONFIG_PICKLE = "config.pkl"
85
92
log("{} is an unsupported transport".format(config_transport))
95
master_cfg_path = os.path.join(buildbot_dir, 'master.cfg')
88
97
# Write the buildbot config to disk (fetching it if necessary).
89
if config_file and 'config-file' not in diff.unchanged:
90
if not os.path.exists(buildbot_dir):
91
os.makedirs(buildbot_dir)
92
with open(os.path.join(buildbot_dir, 'master.cfg', 'w')) as f:
93
f.write(base64.decode(config_file))
98
if config_file and 'config-file' in diff.added_or_changed:
99
if not os.path.exists(os.path.join(buildbot_dir, 'buildbot.tac')):
100
run('buildbot', 'create-master', buildbot_dir)
101
# This file will be moved to master.cfg.original below.
102
with open(master_cfg_path, 'w') as f:
103
base64.decode(StringIO.StringIO(config_file), f)
94
104
log('config_file decoded and written.')
95
105
restart_required = True
96
106
elif (config_transport == 'bzr' and config_url and
112
122
with open(os.path.join(ssh_dir, 'lp_key', w)) as f:
113
123
f.write(base64.decode(private_key))
114
124
bzr('branch', '--use-existing-dir', config_url, buildbot_dir)
115
run('chown', '-R', 'ubuntu:ubuntu', buildbot_dir)
116
125
log('configuration fetched from {}'.format(config_url))
117
126
restart_required = True
119
128
# Configuration file specifiers are unchanged or unrecognized.
122
# Restart buildbot if it is running.
124
pidfile = os.path.join(buildbot_dir, 'twistd.pid')
125
if os.path.exists(pidfile):
126
buildbot_pid = open(pidfile).read().strip()
128
# Is buildbot running?
129
run('kill', '-0', buildbot_pid)
130
except CalledProcessError:
131
# Buildbot isn't running, so no need to reconfigure it.
134
# Buildbot is running, reconfigure it.
135
log('Reconfiguring buildbot')
136
run('buildbot', 'reconfig', buildbot_dir)
137
log('Buildbot reconfigured')
139
# Buildbot isn't running so start afresh but only if properly
141
if os.path.exists(os.path.join(buildbot_dir, 'master.cfg')):
142
run('buildbot', 'start', buildbot_dir)
131
# Initialize the buildbot directory and (re)start buildbot.
132
if restart_required and os.path.exists(master_cfg_path):
133
shutil.move(master_cfg_path, master_cfg_path + '.original')
135
os.path.join(os.path.dirname(__file__), 'master.cfg'), master_cfg_path)
136
if not os.path.exists(get_slave_info_path()):
138
placeholder_path = os.path.join(buildbot_dir, 'placeholder.json')
139
if not os.path.exists(placeholder_path):
140
with open(placeholder_path, 'w') as f:
141
json.dump(generate_string("temporary-placeholder-"), f)
142
run('chown', '-R', 'ubuntu:ubuntu', buildbot_dir)
144
145
log("Configuration changed but didn't require restarting.")