Add systemd init support for deploy from source
systemd is used instead of upstart by default since Ubuntu 15.10 (Wily). This adds systemd init file support for glance services that are deployed from source. Change-Id: I4117e9cbe5a30ed19ef2976d4e7160b82c09d4d3
This commit is contained in:
parent
c4c2293c5e
commit
8b49c92fc2
@ -54,11 +54,12 @@ from charmhelpers.contrib.hahelpers.cluster import (
|
||||
from charmhelpers.contrib.openstack.alternatives import install_alternative
|
||||
from charmhelpers.contrib.openstack.utils import (
|
||||
get_os_codename_install_source,
|
||||
git_install_requested,
|
||||
git_clone_and_install,
|
||||
git_generate_systemd_init_files,
|
||||
git_install_requested,
|
||||
git_pip_venv_dir,
|
||||
git_src_dir,
|
||||
git_yaml_value,
|
||||
git_pip_venv_dir,
|
||||
configure_installation_source,
|
||||
os_release,
|
||||
set_os_workload_status,
|
||||
@ -90,6 +91,7 @@ BASE_GIT_PACKAGES = [
|
||||
'libxslt1-dev',
|
||||
'libssl-dev',
|
||||
'libyaml-dev',
|
||||
'openstack-pkg-tools',
|
||||
'python-dev',
|
||||
'python-pip',
|
||||
'python-setuptools',
|
||||
@ -259,7 +261,7 @@ def migrate_database():
|
||||
|
||||
|
||||
def do_openstack_upgrade(configs):
|
||||
"""Perform an uprade of cinder. Takes care of upgrading
|
||||
"""Perform an upgrade of glance. Takes care of upgrading
|
||||
packages, rewriting configs + database migration and potentially
|
||||
any other post-upgrade actions.
|
||||
|
||||
@ -406,35 +408,50 @@ def git_post_install(projects_yaml):
|
||||
os.symlink(s['src'], s['link'])
|
||||
|
||||
bin_dir = os.path.join(git_pip_venv_dir(projects_yaml), 'bin')
|
||||
glance_api_context = {
|
||||
'service_description': 'Glance API server',
|
||||
'service_name': 'Glance',
|
||||
'user_name': 'glance',
|
||||
'start_dir': '/var/lib/glance',
|
||||
'process_name': 'glance-api',
|
||||
'executable_name': os.path.join(bin_dir, 'glance-api'),
|
||||
'config_files': ['/etc/glance/glance-api.conf'],
|
||||
'log_file': '/var/log/glance/api.log',
|
||||
}
|
||||
# Use systemd init units/scripts from ubuntu wily onward
|
||||
if lsb_release()['DISTRIB_RELEASE'] >= '15.10':
|
||||
templates_dir = os.path.join(charm_dir(), 'templates/git')
|
||||
daemons = ['glance-api', 'glance-glare', 'glance-registry']
|
||||
for daemon in daemons:
|
||||
glance_context = {
|
||||
'daemon_path': os.path.join(bin_dir, daemon),
|
||||
}
|
||||
template_file = 'git/{}.init.in.template'.format(daemon)
|
||||
init_in_file = '{}.init.in'.format(daemon)
|
||||
render(template_file, os.path.join(templates_dir, init_in_file),
|
||||
glance_context, perms=0o644)
|
||||
git_generate_systemd_init_files(templates_dir)
|
||||
else:
|
||||
glance_api_context = {
|
||||
'service_description': 'Glance API server',
|
||||
'service_name': 'Glance',
|
||||
'user_name': 'glance',
|
||||
'start_dir': '/var/lib/glance',
|
||||
'process_name': 'glance-api',
|
||||
'executable_name': os.path.join(bin_dir, 'glance-api'),
|
||||
'config_files': ['/etc/glance/glance-api.conf'],
|
||||
'log_file': '/var/log/glance/api.log',
|
||||
}
|
||||
|
||||
glance_registry_context = {
|
||||
'service_description': 'Glance registry server',
|
||||
'service_name': 'Glance',
|
||||
'user_name': 'glance',
|
||||
'start_dir': '/var/lib/glance',
|
||||
'process_name': 'glance-registry',
|
||||
'executable_name': os.path.join(bin_dir, 'glance-registry'),
|
||||
'config_files': ['/etc/glance/glance-registry.conf'],
|
||||
'log_file': '/var/log/glance/registry.log',
|
||||
}
|
||||
glance_registry_context = {
|
||||
'service_description': 'Glance registry server',
|
||||
'service_name': 'Glance',
|
||||
'user_name': 'glance',
|
||||
'start_dir': '/var/lib/glance',
|
||||
'process_name': 'glance-registry',
|
||||
'executable_name': os.path.join(bin_dir, 'glance-registry'),
|
||||
'config_files': ['/etc/glance/glance-registry.conf'],
|
||||
'log_file': '/var/log/glance/registry.log',
|
||||
}
|
||||
|
||||
# NOTE(coreycb): Needs systemd support
|
||||
templates_dir = 'hooks/charmhelpers/contrib/openstack/templates'
|
||||
templates_dir = os.path.join(charm_dir(), templates_dir)
|
||||
render('git.upstart', '/etc/init/glance-api.conf',
|
||||
glance_api_context, perms=0o644, templates_dir=templates_dir)
|
||||
render('git.upstart', '/etc/init/glance-registry.conf',
|
||||
glance_registry_context, perms=0o644, templates_dir=templates_dir)
|
||||
templates_dir = 'hooks/charmhelpers/contrib/openstack/templates'
|
||||
templates_dir = os.path.join(charm_dir(), templates_dir)
|
||||
render('git.upstart', '/etc/init/glance-api.conf',
|
||||
glance_api_context, perms=0o644,
|
||||
templates_dir=templates_dir)
|
||||
render('git.upstart', '/etc/init/glance-registry.conf',
|
||||
glance_registry_context, perms=0o644,
|
||||
templates_dir=templates_dir)
|
||||
|
||||
# Don't restart services if the unit is supposed to be paused.
|
||||
if not is_unit_paused_set():
|
||||
|
21
templates/git/glance-api.init.in.template
Normal file
21
templates/git/glance-api.init.in.template
Normal file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: glance-api
|
||||
# Required-Start: $network $local_fs $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs
|
||||
# Should-Start: postgresql mysql keystone ntp rabbitmq-server
|
||||
# Should-Stop: postgresql mysql keystone ntp rabbitmq-server
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Glance API server
|
||||
# Description: Frontend Glance API server
|
||||
### END INIT INFO
|
||||
|
||||
# Author: Julien Danjou <acid@debian.org>
|
||||
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
||||
DESC="OpenStack Image Service API"
|
||||
PROJECT_NAME=glance
|
||||
NAME=${PROJECT_NAME}-api
|
||||
CONFIG_FILE=/etc/${PROJECT_NAME}/${NAME}.conf
|
||||
DAEMON={{ daemon_path }}
|
21
templates/git/glance-glare.init.in.template
Normal file
21
templates/git/glance-glare.init.in.template
Normal file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: glance-glare
|
||||
# Required-Start: $network $local_fs $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs
|
||||
# Should-Start: postgresql mysql keystone ntp rabbitmq-server
|
||||
# Should-Stop: postgresql mysql keystone ntp rabbitmq-server
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Glance Artifact Repository API
|
||||
# Description: Frontend Glance Artifact Repository API
|
||||
### END INIT INFO
|
||||
|
||||
# Author: Corey Bryant <corey.bryant@canonical.com>
|
||||
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
||||
DESC="OpenStack Glance Artifact Repository API"
|
||||
PROJECT_NAME=glance
|
||||
NAME=${PROJECT_NAME}-glare
|
||||
CONFIG_FILE=/etc/${PROJECT_NAME}/${NAME}.conf
|
||||
DAEMON={{ daemon_path }}
|
21
templates/git/glance-registry.init.in.template
Normal file
21
templates/git/glance-registry.init.in.template
Normal file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: glance-registry
|
||||
# Required-Start: $network $local_fs $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs
|
||||
# Should-Start: postgresql mysql keystone ntp rabbitmq-server
|
||||
# Should-Stop: postgresql mysql keystone ntp rabbitmq-server
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Glance registry server
|
||||
# Description: Frontend Glance registry server
|
||||
### END INIT INFO
|
||||
|
||||
# Author: Julien Danjou <acid@debian.org>
|
||||
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
||||
DESC="OpenStack Image Service Registry"
|
||||
PROJECT_NAME=glance
|
||||
NAME=${PROJECT_NAME}-registry
|
||||
CONFIG_FILE=/etc/${PROJECT_NAME}/${NAME}.conf
|
||||
DAEMON={{ daemon_path }}
|
@ -142,9 +142,9 @@ class GlanceRelationTests(CharmTestCase):
|
||||
self.apt_install.assert_called_with(
|
||||
['apache2', 'haproxy', 'libffi-dev', 'libmysqlclient-dev',
|
||||
'libssl-dev', 'libxml2-dev', 'libxslt1-dev', 'libyaml-dev',
|
||||
'python-dev', 'python-mysqldb', 'python-pip', 'python-psycopg2',
|
||||
'python-setuptools', 'python-six', 'uuid', 'zlib1g-dev'],
|
||||
fatal=True)
|
||||
'openstack-pkg-tools', 'python-dev', 'python-mysqldb',
|
||||
'python-pip', 'python-psycopg2', 'python-setuptools',
|
||||
'python-six', 'uuid', 'zlib1g-dev'], fatal=True)
|
||||
self.git_install.assert_called_with(projects_yaml)
|
||||
|
||||
def test_db_joined(self):
|
||||
|
@ -22,13 +22,18 @@ TO_PATCH = [
|
||||
'apt_update',
|
||||
'apt_upgrade',
|
||||
'apt_install',
|
||||
'git_pip_venv_dir',
|
||||
'git_src_dir',
|
||||
'mkdir',
|
||||
'os_release',
|
||||
'pip_install',
|
||||
'render',
|
||||
'service_restart',
|
||||
'service_start',
|
||||
'service_stop',
|
||||
'service_name',
|
||||
'install_alternative'
|
||||
'install_alternative',
|
||||
'lsb_release',
|
||||
]
|
||||
|
||||
DPKG_OPTS = [
|
||||
@ -227,22 +232,18 @@ class TestGlanceUtils(CharmTestCase):
|
||||
]
|
||||
self.assertEquals(write_file.call_args_list, expected)
|
||||
|
||||
@patch.object(utils, 'git_src_dir')
|
||||
@patch.object(utils, 'service_restart')
|
||||
@patch.object(utils, 'render')
|
||||
@patch.object(utils, 'git_pip_venv_dir')
|
||||
@patch('os.path.join')
|
||||
@patch('os.path.exists')
|
||||
@patch('os.symlink')
|
||||
@patch('shutil.copytree')
|
||||
@patch('shutil.rmtree')
|
||||
@patch('subprocess.check_call')
|
||||
def test_git_post_install(self, check_call, rmtree, copytree, symlink,
|
||||
exists, join, venv, render, service_restart,
|
||||
git_src_dir):
|
||||
def test_git_post_install_upstart(self, check_call, rmtree, copytree,
|
||||
symlink, exists, join):
|
||||
projects_yaml = openstack_origin_git
|
||||
join.return_value = 'joined-string'
|
||||
venv.return_value = '/mnt/openstack-git/venv'
|
||||
self.git_pip_venv_dir.return_value = '/mnt/openstack-git/venv'
|
||||
self.lsb_release.return_value = {'DISTRIB_RELEASE': '15.04'}
|
||||
utils.git_post_install(projects_yaml)
|
||||
expected = [
|
||||
call('joined-string', '/etc/glance'),
|
||||
@ -280,12 +281,38 @@ class TestGlanceUtils(CharmTestCase):
|
||||
glance_registry_context, perms=0o644,
|
||||
templates_dir='joined-string'),
|
||||
]
|
||||
self.assertEquals(render.call_args_list, expected)
|
||||
self.assertEquals(self.render.call_args_list, expected)
|
||||
expected = [
|
||||
call('glance-api'),
|
||||
call('glance-registry'),
|
||||
]
|
||||
self.assertEquals(service_restart.call_args_list, expected)
|
||||
self.assertEquals(self.service_restart.call_args_list, expected)
|
||||
|
||||
@patch.object(utils, 'services')
|
||||
@patch('os.listdir')
|
||||
@patch('os.path.join')
|
||||
@patch('os.path.exists')
|
||||
@patch('os.symlink')
|
||||
@patch('shutil.copytree')
|
||||
@patch('shutil.rmtree')
|
||||
@patch('subprocess.check_call')
|
||||
def test_git_post_install_systemd(self, check_call, rmtree, copytree,
|
||||
symlink, exists, join, listdir,
|
||||
services):
|
||||
projects_yaml = openstack_origin_git
|
||||
join.return_value = 'joined-string'
|
||||
self.lsb_release.return_value = {'DISTRIB_RELEASE': '15.10'}
|
||||
utils.git_post_install(projects_yaml)
|
||||
|
||||
expected = [
|
||||
call('git/glance-api.init.in.template', 'joined-string',
|
||||
{'daemon_path': 'joined-string'}, perms=420),
|
||||
call('git/glance-glare.init.in.template', 'joined-string',
|
||||
{'daemon_path': 'joined-string'}, perms=420),
|
||||
call('git/glance-registry.init.in.template', 'joined-string',
|
||||
{'daemon_path': 'joined-string'}, perms=420),
|
||||
]
|
||||
self.assertEquals(self.render.call_args_list, expected)
|
||||
|
||||
def test_assess_status(self):
|
||||
with patch.object(utils, 'assess_status_func') as asf:
|
||||
|
Loading…
Reference in New Issue
Block a user