40
def update_or_install_ini(mongo_url=None):
42
if mongo_url is not None:
43
config.set('app:main', 'mongo.url', mongo_url)
34
def install_ini(mongo_url):
35
config = ConfigParser()
36
path = os.path.join(PROJECT_DIR, INI_TEMPLATE)
37
if not os.path.exists(path):
40
config.set('app:main', 'mongo.url', mongo_url)
44
41
config.write(open(get_ini_path(), 'w'))
86
83
call_script('scripts/run')
90
config = hookenv.config()
91
if config['source'] == '':
92
raise IncompleteConfig('source not specified.')
93
if re.match('(lp:|.*://bazaar.launchpad.net/)', config['source']):
94
if config['lp-key'] == '':
95
raise IncompleteConfig('lp-key not specified.')
99
class IncompleteConfig(ValueError):
100
"""Error class indicating that ssh is not set to a valid value."""
104
def update_source(source_url, revno, ssh_key):
106
fd = os.open('/root/.ssh/lp_rsa', os.O_WRONLY | os.O_TRUNC |
109
os.write(fd, ssh_key)
113
subprocess.check_call(['bzr', 'lp-login', 'juju-qa-bot'])
86
def open_secret(path, uid=None, gid=None):
87
fd = os.open(path, os.O_WRONLY | os.O_TRUNC | os.O_CREAT, 0600)
89
os.fchown(fd, uid, gid)
90
return os.fdopen(fd, 'w')
93
def configure_lp(ssh_key):
96
with open_secret('/root/.ssh/lp_rsa') as key_file:
97
key_file.write(ssh_key)
98
pwd = getpwnam('ubuntu')
99
ubuntu_path = os.path.join(HOME, '.ssh/lp_rsa')
100
with open_secret(ubuntu_path, pwd.pw_uid, pwd.pw_gid) as key_file:
101
key_file.write(ssh_key)
103
subprocess.check_call(['bzr', 'lp-login', 'juju-qa-bot'])
106
def update_source(source_url, revno):
116
108
revno = 'revno:%s' % revno
117
109
bzr_cmd = ['bzr', 'pull', '--overwrite', source_url, '-r', revno, '-d',
110
PROJECT_DIR, '--remember']
119
111
subprocess.check_call(bzr_cmd)
121
# Remove the unnecessary INI files--if something tries to use them we need
123
for ini in ['test.ini', 'development.ini']:
125
os.unlink(os.path.join(PROJECT_DIR, ini))
127
if e.errno != errno.ENOENT:
112
# Restore the templates if they are missing/altered.
113
subprocess.check_call(['bzr', 'revert',
114
os.path.join(PROJECT_DIR, 'resources')])
132
117
def install_production(dist_clean):
133
subprocess.check_call(['make', 'deploydeps'])
118
subprocess.check_call(['make', 'deploydeps'], cwd=PROJECT_DIR)
135
subprocess.check_call(['make', 'distclean'])
136
subprocess.check_call(['make', 'prodinstall'])
120
subprocess.check_call(['make', 'distclean'], cwd=PROJECT_DIR)
121
subprocess.check_call(['make', 'prodinstall'], cwd=PROJECT_DIR)
137
122
subprocess.check_call(['apt-get', 'autoremove', '--yes'])
193
178
def update_from_config():
197
mongo_url = get_mongo_url()
199
raise IncompleteConfig('No mongodb set up.')
200
config = get_config()
205
except IncompleteConfig as e:
206
subprocess.call(['juju-log', 'Incomplete config: %s' % e])
180
mongo_url = get_mongo_url()
181
config = hookenv.config()
208
182
set_port(ini, False)
210
update_source(config['source'], config['revno'], config['lp-key'])
211
# ini may be updated by update_source
184
configure_lp(config['lp-key'])
185
if config['source'] == '':
186
hookenv.log('Incomplete config: source')
188
update_source(config['source'], config['revno'])
213
189
install_production(config['dist-clean'])
214
ini = update_or_install_ini(mongo_url)
215
install_cronjob(config['cron-interval'], config['error-email'])
191
hookenv.log('No mongodb set up.')
193
ini = install_ini(mongo_url)
194
if config['lp-key'] == '':
195
hookenv.log('Not setting up cron because lp-key not set.')
197
install_cronjob(config['cron-interval'], config['error-email'])
217
199
set_port(ini, True)
218
200
update_website(ini)