141 lines
5.8 KiB
Python
Raw Normal View History

2017-04-10 09:00:27 +01:00
import mock
import os
import shutil
import tempfile
import yaml
from hooks import hooks
from test_utils import CharmTestCase
TO_PATCH = [
'apt_update',
'apt_install',
'get_release',
]
class TestConfigChanged(CharmTestCase):
def setUp(self):
CharmTestCase.setUp(self, hooks, TO_PATCH)
self.tmpdir = tempfile.mkdtemp()
mirrors_fname = os.path.basename(hooks.MIRRORS_CONF_FILE_NAME)
self.mirrors_conf_fpath = os.path.join(self.tmpdir, mirrors_fname)
hooks.MIRRORS_CONF_FILE_NAME = self.mirrors_conf_fpath
hooks.CRON_POLL_FILEPATH = os.path.join(self.tmpdir,
hooks.CRON_POLL_FILENAME)
self.tmpcrond = tempfile.mkdtemp(prefix='cron.d')
hooks.CRON_D = self.tmpcrond
self.sharedir = tempfile.mkdtemp(prefix='share')
hooks.USR_SHARE_DIR = self.sharedir
setattr(self.test_config, "save", lambda: None)
hooks.CRON_POLL_FILEPATH = os.path.join(self.tmpcrond,
hooks.CRON_POLL_FILENAME)
self.get_release.return_value = 'icehouse'
def tearDown(self):
CharmTestCase.tearDown(self)
shutil.rmtree(self.tmpdir)
shutil.rmtree(self.tmpcrond)
shutil.rmtree(self.sharedir)
@mock.patch.object(hooks, 'update_nrpe_config')
2017-04-10 09:00:27 +01:00
@mock.patch('os.symlink')
@mock.patch('charmhelpers.core.hookenv.config')
@mock.patch('charmhelpers.core.hookenv.relations_of_type')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.get_nagios_hostname')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.config')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.local_unit')
2017-04-10 09:00:27 +01:00
def test_default_config(self, local_unit, nrpe_config, nag_host,
relations_of_type, config, symlink,
update_nrpe_config):
2017-04-10 09:00:27 +01:00
local_unit.return_value = 'juju/0'
nag_host.return_value = "nagios_hostname"
nrpe_config.return_value = self.test_config
setattr(self.test_config, "changed", lambda x: False)
config.return_value = self.test_config
Switch to using snap for simplestreams tools Switch over to using the new simplestreams snap instead of using the largely unmaintained packaging in distro (and various PPA's). This drops direct integration with the simplestreams codebase in preference to just calling the sstream-mirror-glance command with the correct parameters. This commit includes refactoring of 'custom_properties' handling which was actually broken - there was no loading of the yaml formatted list, which was probably overkill, so the option now takes a space separated list of key=value pairs, for example: custom_properties="hw_firmware_type=uefi hw_vif_multiqueue_enabled=true" Fix version comparison in script wrapper. Drop Trusty support - snaps on Trusty are awkward requiring new kernel versions and trusty support was only retained for upgrade purposes anyway. Drop unsupported Xenial OpenStack versions. Fixup CA cert handling to use any charm installed CA cert (including that provided via the certificates relation) and install cert to snap compatible location for simplestreams to use. Add basic action to perform image sync on demand an refactor the glance simplestreams sync wrapper to work within a hook context to support the action. Disable automatic scheduling of image syncs by default as this tends to be racey during deployment resulting in images being synced to glance unit local storage. Add bionic-ussuri bundle and make it the default smoke test. Deprecate source and key options - no longer required for deployment with snap. Change-Id: I730df6b7f5955ddfeea5b8de15490ac083823f5a Func-Test-PR: https://github.com/openstack-charmers/zaza-openstack-tests/pull/321
2020-06-03 11:45:52 +01:00
self.test_config.set('run', True)
2017-04-10 09:00:27 +01:00
hooks.config_changed()
symlink.assert_any_call(os.path.join(self.sharedir,
hooks.SCRIPT_WRAPPER_NAME),
'/etc/cron.%s/%s'
% (self.test_config['frequency'],
hooks.CRON_JOB_FILENAME))
self.assertTrue(os.path.isfile(os.path.join(self.tmpcrond,
hooks.CRON_POLL_FILENAME)))
self.assertTrue(os.path.isfile(self.mirrors_conf_fpath))
with open(self.mirrors_conf_fpath, 'r') as f:
mirrors = yaml.safe_load(f)
for k in ['cloud_name', 'region', 'use_swift']:
self.assertEqual(self.test_config[k], mirrors[k])
mirror_list = yaml.safe_load(self.test_config['mirror_list'])
self.assertEqual(mirrors['mirror_list'], mirror_list)
update_nrpe_config.assert_called()
2017-04-10 09:00:27 +01:00
@mock.patch.object(hooks, 'update_nrpe_config')
@mock.patch('os.symlink')
@mock.patch('charmhelpers.core.hookenv.config')
@mock.patch('charmhelpers.core.hookenv.relations_of_type')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.get_nagios_hostname')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.config')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.local_unit')
def test_custom_properties_config(self, local_unit, nrpe_config, nag_host,
relations_of_type, config, symlink,
update_nrpe_config):
local_unit.return_value = 'juju/0'
nag_host.return_value = "nagios_hostname"
nrpe_config.return_value = self.test_config
setattr(self.test_config, "changed", lambda x: False)
Switch to using snap for simplestreams tools Switch over to using the new simplestreams snap instead of using the largely unmaintained packaging in distro (and various PPA's). This drops direct integration with the simplestreams codebase in preference to just calling the sstream-mirror-glance command with the correct parameters. This commit includes refactoring of 'custom_properties' handling which was actually broken - there was no loading of the yaml formatted list, which was probably overkill, so the option now takes a space separated list of key=value pairs, for example: custom_properties="hw_firmware_type=uefi hw_vif_multiqueue_enabled=true" Fix version comparison in script wrapper. Drop Trusty support - snaps on Trusty are awkward requiring new kernel versions and trusty support was only retained for upgrade purposes anyway. Drop unsupported Xenial OpenStack versions. Fixup CA cert handling to use any charm installed CA cert (including that provided via the certificates relation) and install cert to snap compatible location for simplestreams to use. Add basic action to perform image sync on demand an refactor the glance simplestreams sync wrapper to work within a hook context to support the action. Disable automatic scheduling of image syncs by default as this tends to be racey during deployment resulting in images being synced to glance unit local storage. Add bionic-ussuri bundle and make it the default smoke test. Deprecate source and key options - no longer required for deployment with snap. Change-Id: I730df6b7f5955ddfeea5b8de15490ac083823f5a Func-Test-PR: https://github.com/openstack-charmers/zaza-openstack-tests/pull/321
2020-06-03 11:45:52 +01:00
self.test_config.config["custom_properties"] = (
"hypervisor_type=kvm hw_firmware_type=uefi"
)
config.return_value = self.test_config
hooks.config_changed()
self.assertTrue(os.path.isfile(self.mirrors_conf_fpath))
with open(self.mirrors_conf_fpath, 'r') as f:
mirrors = yaml.safe_load(f)
self.assertEqual(
self.test_config.config['custom_properties'],
mirrors['custom_properties']
)
update_nrpe_config.assert_called()
@mock.patch.object(hooks, 'update_nrpe_config')
2017-04-10 09:00:27 +01:00
@mock.patch('os.path.exists')
@mock.patch('os.remove')
@mock.patch('glob.glob')
@mock.patch('charmhelpers.core.hookenv.config')
@mock.patch('charmhelpers.core.hookenv.relations_of_type')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.get_nagios_hostname')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.config')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.local_unit')
2017-04-10 09:00:27 +01:00
def test_uninstall_cron(self, local_unit, nrpe_config, nag_host,
relations_of_type, config, glob, remove, exists,
update_nrpe_config):
2017-04-10 09:00:27 +01:00
local_unit.return_value = 'juju/0'
nag_host.return_value = "nagios_hostname"
nrpe_config.return_value = self.test_config
self.test_config.set('run', False)
setattr(self.test_config, "changed", lambda x: True)
config.return_value = self.test_config
glob.return_value = [os.path.join('/etc/cron.daily/',
hooks.CRON_JOB_FILENAME)]
exists.return_value = True
hooks.config_changed()
remove.assert_any_call(os.path.join('/etc/cron.daily/',
hooks.CRON_JOB_FILENAME))
remove.assert_any_call(hooks.CRON_POLL_FILEPATH)
update_nrpe_config.assert_called()