Add support for deployment from git.

This commit is contained in:
James Page 2015-06-10 15:01:05 +01:00
commit 0433af560a
3 changed files with 50 additions and 3 deletions

View File

@ -16,9 +16,15 @@ from charmhelpers.contrib.openstack.utils import (
git_install_requested, git_install_requested,
git_clone_and_install, git_clone_and_install,
git_src_dir, git_src_dir,
git_pip_venv_dir,
git_yaml_value,
configure_installation_source, configure_installation_source,
) )
from charmhelpers.contrib.python.packages import (
pip_install,
)
from charmhelpers.core.hookenv import ( from charmhelpers.core.hookenv import (
config, config,
log, log,
@ -67,8 +73,12 @@ KILO_PACKAGES = [
] ]
BASE_GIT_PACKAGES = [ BASE_GIT_PACKAGES = [
'libffi-dev',
'libmysqlclient-dev',
'libssl-dev',
'libxml2-dev', 'libxml2-dev',
'libxslt1-dev', 'libxslt1-dev',
'libyaml-dev',
'python-dev', 'python-dev',
'python-pip', 'python-pip',
'python-setuptools', 'python-setuptools',
@ -420,6 +430,14 @@ def git_pre_install():
def git_post_install(projects_yaml): def git_post_install(projects_yaml):
"""Perform post-install setup.""" """Perform post-install setup."""
http_proxy = git_yaml_value(projects_yaml, 'http_proxy')
if http_proxy:
pip_install('mysql-python', proxy=http_proxy,
venv=git_pip_venv_dir(projects_yaml))
else:
pip_install('mysql-python',
venv=git_pip_venv_dir(projects_yaml))
src_etc = os.path.join(git_src_dir(projects_yaml, 'neutron'), 'etc') src_etc = os.path.join(git_src_dir(projects_yaml, 'neutron'), 'etc')
configs = [ configs = [
{'src': src_etc, {'src': src_etc,
@ -435,13 +453,30 @@ def git_post_install(projects_yaml):
shutil.rmtree(c['dest']) shutil.rmtree(c['dest'])
shutil.copytree(c['src'], c['dest']) shutil.copytree(c['src'], c['dest'])
# NOTE(coreycb): Need to find better solution than bin symlinks.
symlinks = [
{'src': os.path.join(git_pip_venv_dir(projects_yaml),
'bin/neutron-rootwrap'),
'link': '/usr/local/bin/neutron-rootwrap'},
{'src': os.path.join(git_pip_venv_dir(projects_yaml),
'bin/neutron-db-manage'),
'link': '/usr/local/bin/neutron-db-manage'},
]
for s in symlinks:
if os.path.lexists(s['link']):
os.remove(s['link'])
os.symlink(s['src'], s['link'])
render('git/neutron_sudoers', '/etc/sudoers.d/neutron_sudoers', {}, render('git/neutron_sudoers', '/etc/sudoers.d/neutron_sudoers', {},
perms=0o440) perms=0o440)
bin_dir = os.path.join(git_pip_venv_dir(projects_yaml), 'bin')
neutron_api_context = { neutron_api_context = {
'service_description': 'Neutron API server', 'service_description': 'Neutron API server',
'charm_name': 'neutron-api', 'charm_name': 'neutron-api',
'process_name': 'neutron-server', 'process_name': 'neutron-server',
'executable_name': os.path.join(bin_dir, 'neutron-server'),
} }
# NOTE(coreycb): Needs systemd support # NOTE(coreycb): Needs systemd support

View File

@ -16,7 +16,7 @@ end script
script script
[ -r /etc/default/{{ process_name }} ] && . /etc/default/{{ process_name }} [ -r /etc/default/{{ process_name }} ] && . /etc/default/{{ process_name }}
[ -r "$NEUTRON_PLUGIN_CONFIG" ] && CONF_ARG="--config-file $NEUTRON_PLUGIN_CONFIG" [ -r "$NEUTRON_PLUGIN_CONFIG" ] && CONF_ARG="--config-file $NEUTRON_PLUGIN_CONFIG"
exec start-stop-daemon --start --chuid neutron --exec /usr/local/bin/neutron-server -- \ exec start-stop-daemon --start --chuid neutron --exec {{ executable_name }} -- \
--config-file /etc/neutron/neutron.conf \ --config-file /etc/neutron/neutron.conf \
--log-file /var/log/neutron/server.log $CONF_ARG --log-file /var/log/neutron/server.log $CONF_ARG
end script end script

View File

@ -31,6 +31,7 @@ TO_PATCH = [
'log', 'log',
'neutron_plugin_attribute', 'neutron_plugin_attribute',
'os_release', 'os_release',
'pip_install',
'subprocess', 'subprocess',
] ]
@ -415,14 +416,19 @@ class TestNeutronAPIUtils(CharmTestCase):
@patch.object(nutils, 'git_src_dir') @patch.object(nutils, 'git_src_dir')
@patch.object(nutils, 'service_restart') @patch.object(nutils, 'service_restart')
@patch.object(nutils, 'render') @patch.object(nutils, 'render')
@patch.object(nutils, 'git_pip_venv_dir')
@patch('os.path.join') @patch('os.path.join')
@patch('os.path.exists') @patch('os.path.exists')
@patch('os.symlink')
@patch('shutil.copytree') @patch('shutil.copytree')
@patch('shutil.rmtree') @patch('shutil.rmtree')
def test_git_post_install(self, rmtree, copytree, exists, join, render, @patch('subprocess.check_call')
service_restart, git_src_dir): def test_git_post_install(self, check_call, rmtree, copytree, symlink,
exists, join, venv, render, service_restart,
git_src_dir):
projects_yaml = openstack_origin_git projects_yaml = openstack_origin_git
join.return_value = 'joined-string' join.return_value = 'joined-string'
venv.return_value = '/mnt/openstack-git/venv'
nutils.git_post_install(projects_yaml) nutils.git_post_install(projects_yaml)
expected = [ expected = [
call('joined-string', '/etc/neutron'), call('joined-string', '/etc/neutron'),
@ -430,10 +436,16 @@ class TestNeutronAPIUtils(CharmTestCase):
call('joined-string', '/etc/neutron/rootwrap.d'), call('joined-string', '/etc/neutron/rootwrap.d'),
] ]
copytree.assert_has_calls(expected) copytree.assert_has_calls(expected)
expected = [
call('joined-string', '/usr/local/bin/neutron-rootwrap'),
call('joined-string', '/usr/local/bin/neutron-db-manage'),
]
symlink.assert_has_calls(expected, any_order=True)
neutron_api_context = { neutron_api_context = {
'service_description': 'Neutron API server', 'service_description': 'Neutron API server',
'charm_name': 'neutron-api', 'charm_name': 'neutron-api',
'process_name': 'neutron-server', 'process_name': 'neutron-server',
'executable_name': 'joined-string',
} }
expected = [ expected = [
call('git/neutron_sudoers', '/etc/sudoers.d/neutron_sudoers', {}, call('git/neutron_sudoers', '/etc/sudoers.d/neutron_sudoers', {},