[xtrusia,r=hopem]
Adds more unit tests Closes-Bug: 1375395
This commit is contained in:
commit
b4380504f2
@ -11,6 +11,7 @@ TO_PATCH = [
|
||||
'relation_get',
|
||||
'relation_ids',
|
||||
'unit_private_ip',
|
||||
'get_ipv6_addr',
|
||||
]
|
||||
|
||||
|
||||
@ -46,6 +47,15 @@ class SwiftStorageContextTests(CharmTestCase):
|
||||
self.assertEquals({'local_ip': '10.0.0.5'}, ctxt())
|
||||
self.assertTrue(ctxt.enable_rsyncd.called)
|
||||
|
||||
def test_rsync_context_ipv6(self):
|
||||
self.test_config.set('prefer-ipv6', True)
|
||||
self.get_ipv6_addr.return_value = ['2001:db8:1::1']
|
||||
ctxt = swift_context.RsyncContext()
|
||||
ctxt.enable_rsyncd = MagicMock()
|
||||
ctxt.enable_rsyncd.return_value = True
|
||||
self.assertEquals({'local_ip': '2001:db8:1::1'}, ctxt())
|
||||
self.assertTrue(ctxt.enable_rsyncd.called)
|
||||
|
||||
def test_rsync_enable_rsync(self):
|
||||
with patch_open() as (_open, _file):
|
||||
ctxt = swift_context.RsyncContext()
|
||||
|
@ -39,7 +39,8 @@ TO_PATCH = [
|
||||
'setup_rsync',
|
||||
'setup_storage',
|
||||
'register_configs',
|
||||
'update_nrpe_config'
|
||||
'update_nrpe_config',
|
||||
'get_ipv6_addr',
|
||||
]
|
||||
|
||||
|
||||
@ -82,20 +83,56 @@ class SwiftStorageRelationsTests(CharmTestCase):
|
||||
self.assertTrue(self.do_openstack_upgrade.called)
|
||||
self.assertTrue(self.CONFIGS.write_all.called)
|
||||
|
||||
def test_config_changed_nrpe_master(self):
|
||||
self.openstack_upgrade_available.return_value = False
|
||||
self.relations_of_type.return_value = True
|
||||
with patch_open() as (_open, _file):
|
||||
_file.read.return_value = "foo"
|
||||
hooks.config_changed()
|
||||
self.assertTrue(self.CONFIGS.write_all.called)
|
||||
self.assertTrue(self.setup_rsync.called)
|
||||
self.assertTrue(self.update_nrpe_config.called)
|
||||
|
||||
@patch.object(hooks, 'assert_charm_supports_ipv6')
|
||||
def test_config_changed_ipv6(self, mock_assert_charm_supports_ipv6):
|
||||
self.test_config.set('prefer-ipv6', True)
|
||||
self.openstack_upgrade_available.return_value = False
|
||||
self.relations_of_type.return_value = False
|
||||
with patch_open() as (_open, _file):
|
||||
_file.read.return_value = "foo"
|
||||
hooks.config_changed()
|
||||
self.assertTrue(self.CONFIGS.write_all.called)
|
||||
self.assertTrue(self.setup_rsync.called)
|
||||
|
||||
def test_upgrade_charm(self):
|
||||
self.filter_installed_packages.return_value = ['python-psutil']
|
||||
self.filter_installed_packages.return_value = [
|
||||
'python-psutil']
|
||||
hooks.upgrade_charm()
|
||||
self.apt_install.assert_called_with(['python-psutil'], fatal=True)
|
||||
self.apt_install.assert_called_with([
|
||||
'python-psutil'], fatal=True)
|
||||
self.assertTrue(self.update_nrpe_config.called)
|
||||
|
||||
def test_storage_joined_single_device(self):
|
||||
self.determine_block_devices.return_value = ['/dev/vdb']
|
||||
self.determine_block_devices.return_value = [
|
||||
'/dev/vdb']
|
||||
hooks.swift_storage_relation_joined()
|
||||
self.relation_set.assert_called_with(
|
||||
device='vdb', object_port=6000, account_port=6002,
|
||||
zone=1, container_port=6001
|
||||
)
|
||||
|
||||
def test_storage_joined_ipv6(self):
|
||||
self.determine_block_devices.return_value = ['/dev/vdb']
|
||||
self.test_config.set('prefer-ipv6', True)
|
||||
self.get_ipv6_addr.return_value = ['2001:db8:1::1']
|
||||
hooks.swift_storage_relation_joined()
|
||||
args = {
|
||||
'device': 'vdb', 'object_port': 6000,
|
||||
'account_port': 6002, 'zone': 1, 'container_port': 6001,
|
||||
'private-address': '2001:db8:1::1',
|
||||
}
|
||||
self.relation_set.assert_called_with(**args)
|
||||
|
||||
def test_storage_joined_multi_device(self):
|
||||
self.determine_block_devices.return_value = ['/dev/vdb', '/dev/vdc',
|
||||
'/dev/vdd']
|
||||
|
@ -26,6 +26,7 @@ TO_PATCH = [
|
||||
'unit_private_ip',
|
||||
'service_restart',
|
||||
'_save_script_rc',
|
||||
'lsb_release',
|
||||
]
|
||||
|
||||
|
||||
@ -223,6 +224,20 @@ class SwiftStorageUtilsTests(CharmTestCase):
|
||||
swift_utils.save_script_rc()
|
||||
self._save_script_rc.assert_called_with(**SCRIPT_RC_ENV)
|
||||
|
||||
def test_assert_charm_not_supports_ipv6(self):
|
||||
self.lsb_release.return_value = {'DISTRIB_ID': 'Ubuntu',
|
||||
'DISTRIB_RELEASE': '12.04',
|
||||
'DISTRIB_CODENAME': 'precise',
|
||||
'DISTRIB_DESCRIPTION': 'Ubuntu 12.04'}
|
||||
self.assertRaises(Exception, swift_utils.assert_charm_supports_ipv6)
|
||||
|
||||
def test_assert_charm_supports_ipv6(self):
|
||||
self.lsb_release.return_value = {'DISTRIB_ID': 'Ubuntu',
|
||||
'DISTRIB_RELEASE': '14.04',
|
||||
'DISTRIB_CODENAME': 'trusty',
|
||||
'DISTRIB_DESCRIPTION': 'Ubuntu 14.04'}
|
||||
swift_utils.assert_charm_supports_ipv6()
|
||||
|
||||
@patch('charmhelpers.contrib.openstack.templating.OSConfigRenderer')
|
||||
def test_register_configs_pre_install(self, renderer):
|
||||
self.get_os_codename_package.return_value = None
|
||||
|
Loading…
x
Reference in New Issue
Block a user