Add test case for distro->folsom remap, add execd preinstall hooks
This commit is contained in:
parent
85273685eb
commit
996ddcd564
@ -6,3 +6,4 @@ include:
|
|||||||
- contrib.openstack
|
- contrib.openstack
|
||||||
- contrib.hahelpers
|
- contrib.hahelpers
|
||||||
- contrib.network.ovs
|
- contrib.network.ovs
|
||||||
|
- payload.execd
|
||||||
|
1
hooks/charmhelpers/payload/__init__.py
Normal file
1
hooks/charmhelpers/payload/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
"Tools for working with files injected into a charm just before deployment."
|
50
hooks/charmhelpers/payload/execd.py
Normal file
50
hooks/charmhelpers/payload/execd.py
Normal 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)
|
@ -27,6 +27,7 @@ from charmhelpers.contrib.openstack.utils import (
|
|||||||
configure_installation_source,
|
configure_installation_source,
|
||||||
openstack_upgrade_available
|
openstack_upgrade_available
|
||||||
)
|
)
|
||||||
|
from charmhelpers.payload.execd import execd_preinstall
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from quantum_utils import (
|
from quantum_utils import (
|
||||||
@ -51,6 +52,7 @@ CONFIGS = register_configs()
|
|||||||
|
|
||||||
@hooks.hook('install')
|
@hooks.hook('install')
|
||||||
def install():
|
def install():
|
||||||
|
execd_preinstall()
|
||||||
src = config('openstack-origin')
|
src = config('openstack-origin')
|
||||||
if (lsb_release()['DISTRIB_CODENAME'] == 'precise' and
|
if (lsb_release()['DISTRIB_CODENAME'] == 'precise' and
|
||||||
src == 'distro'):
|
src == 'distro'):
|
||||||
|
@ -31,7 +31,9 @@ TO_PATCH = [
|
|||||||
'install_ca_cert',
|
'install_ca_cert',
|
||||||
'eligible_leader',
|
'eligible_leader',
|
||||||
'reassign_agent_resources',
|
'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.config.side_effect = self.test_config.get
|
||||||
self.test_config.set('openstack-origin', 'cloud:precise-havana')
|
self.test_config.set('openstack-origin', 'cloud:precise-havana')
|
||||||
self.test_config.set('plugin', 'ovs')
|
self.test_config.set('plugin', 'ovs')
|
||||||
|
self.lsb_release.return_value = {'DISTRIB_CODENAME': 'precise'}
|
||||||
|
|
||||||
def _call_hook(self, hookname):
|
def _call_hook(self, hookname):
|
||||||
hooks.hooks.execute([
|
hooks.hooks.execute([
|
||||||
@ -62,6 +65,14 @@ class TestQuantumHooks(CharmTestCase):
|
|||||||
])
|
])
|
||||||
self.get_early_packages.assert_called()
|
self.get_early_packages.assert_called()
|
||||||
self.get_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')
|
@patch('sys.exit')
|
||||||
def test_install_hook_invalid_plugin(self, _exit):
|
def test_install_hook_invalid_plugin(self, _exit):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user