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 nova services
that are deployed from source.

Change-Id: I45757fcd52426369b42916ad2195d2fe2f6a4c15
This commit is contained in:
Corey Bryant 2016-06-30 18:57:52 +00:00 committed by James Page
parent 425f7c675a
commit 731ca45e07
3 changed files with 78 additions and 22 deletions

View File

@ -28,11 +28,12 @@ from charmhelpers.contrib.openstack.neutron import (
from charmhelpers.contrib.openstack.utils import (
os_release,
get_os_codename_install_source,
git_install_requested,
git_clone_and_install,
git_default_repos,
git_src_dir,
git_generate_systemd_init_files,
git_install_requested,
git_pip_venv_dir,
git_src_dir,
git_yaml_value,
configure_installation_source,
incomplete_relation_data,
@ -110,6 +111,7 @@ BASE_GIT_PACKAGES = [
'libxml2-dev',
'libxslt1-dev',
'libyaml-dev',
'openstack-pkg-tools',
'python-dev',
'python-neutronclient', # required for get_neutron_client() import
'python-pip',
@ -655,17 +657,29 @@ def git_post_install(projects_yaml):
perms=0o440)
bin_dir = os.path.join(git_pip_venv_dir(projects_yaml), 'bin')
neutron_api_context = {
'service_description': 'Neutron API server',
'charm_name': 'neutron-api',
'process_name': 'neutron-server',
'executable_name': os.path.join(bin_dir, 'neutron-server'),
}
# 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')
daemon = 'neutron-server'
neutron_api_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),
neutron_api_context, perms=0o644)
git_generate_systemd_init_files(templates_dir)
else:
neutron_api_context = {
'service_description': 'Neutron API server',
'charm_name': 'neutron-api',
'process_name': 'neutron-server',
'executable_name': os.path.join(bin_dir, 'neutron-server'),
}
# NOTE(coreycb): Needs systemd support
render('git/upstart/neutron-server.upstart',
'/etc/init/neutron-server.conf',
neutron_api_context, perms=0o644)
render('git/upstart/neutron-server.upstart',
'/etc/init/neutron-server.conf',
neutron_api_context, perms=0o644)
if not is_unit_paused_set():
service_restart('neutron-server')

View File

@ -0,0 +1,19 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: neutron-server
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: mysql postgresql rabbitmq-server keystone
# Should-Stop: mysql postgresql rabbitmq-server keystone
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: neutron-server
# Description: Provides the Neutron networking service
### END INIT INFO
DESC="OpenStack Neutron Server"
PROJECT_NAME=neutron
NAME=${PROJECT_NAME}-server
DAEMON={{ daemon_path }}
[ -r /etc/default/neutron-server ] && . /etc/default/neutron-server
[ -n "$NEUTRON_PLUGIN_CONFIG" ] && DAEMON_ARGS="--config-file=$NEUTRON_PLUGIN_CONFIG"

View File

@ -42,10 +42,15 @@ TO_PATCH = [
'config',
'configure_installation_source',
'get_os_codename_install_source',
'git_pip_venv_dir',
'git_src_dir',
'log',
'lsb_release',
'neutron_plugin_attribute',
'os_release',
'pip_install',
'render',
'service_restart',
'subprocess',
'is_elected_leader',
'service_stop',
@ -522,22 +527,18 @@ class TestNeutronAPIUtils(CharmTestCase):
]
self.assertEquals(write_file.call_args_list, expected)
@patch.object(nutils, 'git_src_dir')
@patch.object(nutils, 'service_restart')
@patch.object(nutils, 'render')
@patch.object(nutils, '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'}
nutils.git_post_install(projects_yaml)
expected = [
call('joined-string', '/etc/neutron'),
@ -563,11 +564,33 @@ class TestNeutronAPIUtils(CharmTestCase):
'/etc/init/neutron-server.conf',
neutron_api_context, perms=0o644),
]
self.assertEquals(render.call_args_list, expected)
self.assertEquals(self.render.call_args_list, expected)
expected = [
call('neutron-server'),
]
self.assertEquals(service_restart.call_args_list, expected)
self.assertEquals(self.service_restart.call_args_list, expected)
@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):
projects_yaml = openstack_origin_git
join.return_value = 'joined-string'
self.git_pip_venv_dir.return_value = '/mnt/openstack-git/venv'
self.lsb_release.return_value = {'DISTRIB_RELEASE': '15.10'}
nutils.git_post_install(projects_yaml)
expected = [
call('git/neutron_sudoers', '/etc/sudoers.d/neutron_sudoers',
{}, perms=288),
call('git/neutron-server.init.in.template', 'joined-string',
{'daemon_path': 'joined-string'}, perms=420)
]
self.assertEquals(self.render.call_args_list, expected)
def test_stamp_neutron_database(self):
nutils.stamp_neutron_database('icehouse')