6
from charmhelpers import fetch
7
from charmhelpers.core import hookenv
8
from charmhelpers.core.host import adduser
9
from charmhelpers.payload import (archive, execd)
11
SERVICE_NAME = 'core-image-publisher'
12
SERVICE_CONFIGNAME = 'core-service.conf'
14
'autopkgtest', 'python-novaclient', 'python-neutronclient',
15
'python-virtualenv', 'python3-dev']
17
config = hookenv.config()
21
template = '/srv/{}/{}'
22
return template.format(config['environment'], SERVICE_NAME)
25
def basenode(service_name):
26
hookenv.log('Executing basenode')
27
execd.execd_preinstall()
30
def log_start(service_name):
31
hookenv.log('%s starting', SERVICE_NAME)
34
def install_packages(service_name):
35
hookenv.log('Installing dependencies...')
36
fetch.add_source('ppa:canonical-ci-engineering/ci-airline-phase-0')
37
fetch.configure_sources(update=True)
38
fetch.apt_install(REQUIRED_PACKAGES, fatal=True)
41
def install_service_tarball(service_name):
42
files_dir = os.path.join(hookenv.charm_dir(), 'files')
43
tarball = os.path.join(files_dir, '{}.tgz'.format(SERVICE_NAME))
44
if not os.path.exists(_service_dir()):
45
hookenv.log('Installing the code for the first time from tarball')
46
archive.extract_tarfile(tarball, os.path.dirname(_service_dir()))
49
def update_config_file(service_name):
51
'Updating service configuration file: %s', SERVICE_CONFIGNAME)
52
config_content = base64.b64decode(config['config-file'])
53
config_path = os.path.join(_service_dir(), SERVICE_CONFIGNAME)
54
with open(config_path, 'w') as f:
55
f.write(config_content)
58
def create_user(service_name):
59
username = 'core-worker'
60
hookenv.log('Creating service user: %s', username)
64
def install_python_packages(service_name):
65
env_dir = os.path.join(_service_dir(), 've')
66
if os.path.exists(env_dir):
67
hookenv.log('Service venv already exists, nothing to do ...')
70
hookenv.log('Installing python packages into the venv ...')
71
subprocess.check_call(['virtualenv', '-p', 'python3', env_dir])
73
pip_cache = os.path.join(hookenv.charm_dir(), 'files', 'pip-cache')
74
requirements = os.path.join(_service_dir(), 'requirements.txt')
76
hookenv.log('Installing from download cache.')
77
subprocess.check_call(['%s/bin/pip' % env_dir,
80
'--find-links={}'.format(pip_cache),
83
subprocess.check_call(['%s/bin/pip' % env_dir,
84
'install', '--no-deps', '-e', _service_dir()])