Add test case for distro->folsom remap, add execd preinstall hooks

This commit is contained in:
James Page 2013-09-27 17:26:48 +01:00
parent 85273685eb
commit 996ddcd564
5 changed files with 66 additions and 1 deletions

View File

@ -6,3 +6,4 @@ include:
- contrib.openstack
- contrib.hahelpers
- contrib.network.ovs
- payload.execd

View File

@ -0,0 +1 @@
"Tools for working with files injected into a charm just before deployment."

View File

@ -0,0 +1,50 @@
#!/usr/bin/env python
import os
import sys
import subprocess
from charmhelpers.core import hookenv
def default_execd_dir():
return os.path.join(os.environ['CHARM_DIR'], 'exec.d')
def execd_module_paths(execd_dir=None):
"""Generate a list of full paths to modules within execd_dir."""
if not execd_dir:
execd_dir = default_execd_dir()
if not os.path.exists(execd_dir):
return
for subpath in os.listdir(execd_dir):
module = os.path.join(execd_dir, subpath)
if os.path.isdir(module):
yield module
def execd_submodule_paths(command, execd_dir=None):
"""Generate a list of full paths to the specified command within exec_dir.
"""
for module_path in execd_module_paths(execd_dir):
path = os.path.join(module_path, command)
if os.access(path, os.X_OK) and os.path.isfile(path):
yield path
def execd_run(command, execd_dir=None, die_on_error=False, stderr=None):
"""Run command for each module within execd_dir which defines it."""
for submodule_path in execd_submodule_paths(command, execd_dir):
try:
subprocess.check_call(submodule_path, shell=True, stderr=stderr)
except subprocess.CalledProcessError as e:
hookenv.log("Error ({}) running {}. Output: {}".format(
e.returncode, e.cmd, e.output))
if die_on_error:
sys.exit(e.returncode)
def execd_preinstall(execd_dir=None):
"""Run charm-pre-install for each module within execd_dir."""
execd_run('charm-pre-install', execd_dir=execd_dir)

View File

@ -27,6 +27,7 @@ from charmhelpers.contrib.openstack.utils import (
configure_installation_source,
openstack_upgrade_available
)
from charmhelpers.payload.execd import execd_preinstall
import sys
from quantum_utils import (
@ -51,6 +52,7 @@ CONFIGS = register_configs()
@hooks.hook('install')
def install():
execd_preinstall()
src = config('openstack-origin')
if (lsb_release()['DISTRIB_CODENAME'] == 'precise' and
src == 'distro'):

View File

@ -31,7 +31,9 @@ TO_PATCH = [
'install_ca_cert',
'eligible_leader',
'reassign_agent_resources',
'get_common_package'
'get_common_package',
'execd_preinstall',
'lsb_release'
]
@ -42,6 +44,7 @@ class TestQuantumHooks(CharmTestCase):
self.config.side_effect = self.test_config.get
self.test_config.set('openstack-origin', 'cloud:precise-havana')
self.test_config.set('plugin', 'ovs')
self.lsb_release.return_value = {'DISTRIB_CODENAME': 'precise'}
def _call_hook(self, hookname):
hooks.hooks.execute([
@ -62,6 +65,14 @@ class TestQuantumHooks(CharmTestCase):
])
self.get_early_packages.assert_called()
self.get_packages.assert_called()
self.execd_preinstall.assert_called()
def test_install_hook_precise_nocloudarchive(self):
self.test_config.set('openstack-origin', 'distro')
self._call_hook('install')
self.configure_installation_source.assert_called_with(
'cloud:precise-folsom'
)
@patch('sys.exit')
def test_install_hook_invalid_plugin(self, _exit):