Create config test base class
Using TestConfigChecks as a base class introduced problems with test runtime - the unittest library will execute every `test_` method in a class, resulting in multiple execution of the same test. This change puts all the utility functions that aren't actually tests into a base class that can be used for any test classes without duplicating tests (and also increasing execution time). In the future, this will be helpful for setting up config check functional tests, too. Change-Id: Ib76cb5eab0f8b8f394335acc6724d0743b28d40b
This commit is contained in:
parent
1a797e42ec
commit
49c303ac4c
@ -363,7 +363,7 @@ class TestIps(unittest.TestCase):
|
||||
di.USED_IPS = set()
|
||||
|
||||
|
||||
class TestConfigChecks(unittest.TestCase):
|
||||
class TestConfigCheckBase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.config_changed = False
|
||||
self.user_defined_config = dict()
|
||||
@ -407,6 +407,25 @@ class TestConfigChecks(unittest.TestCase):
|
||||
os.rename(USER_CONFIG_FILE + ".tmp", USER_CONFIG_FILE)
|
||||
self.config_changed = False
|
||||
|
||||
def set_new_hostname(self, user_defined_config, group,
|
||||
old_hostname, new_hostname):
|
||||
self.config_changed = True
|
||||
# set a new name for the specified hostname
|
||||
old_hostname_settings = user_defined_config[group].pop(old_hostname)
|
||||
user_defined_config[group][new_hostname] = old_hostname_settings
|
||||
self.write_config()
|
||||
|
||||
def set_new_ip(self, user_defined_config, group, hostname, ip):
|
||||
# Sets an IP address for a specified host.
|
||||
user_defined_config[group][hostname]['ip'] = ip
|
||||
self.write_config()
|
||||
|
||||
def tearDown(self):
|
||||
if self.config_changed:
|
||||
self.restore_config()
|
||||
|
||||
|
||||
class TestConfigChecks(TestConfigCheckBase):
|
||||
def test_missing_container_cidr_network(self):
|
||||
self.delete_provider_network('container')
|
||||
with self.assertRaises(SystemExit) as context:
|
||||
@ -443,19 +462,6 @@ class TestConfigChecks(unittest.TestCase):
|
||||
expectedLog = "No container CIDR specified in user config"
|
||||
self.assertEqual(context.exception.message, expectedLog)
|
||||
|
||||
def set_new_hostname(self, user_defined_config, group,
|
||||
old_hostname, new_hostname):
|
||||
self.config_changed = True
|
||||
# set a new name for the specified hostname
|
||||
old_hostname_settings = user_defined_config[group].pop(old_hostname)
|
||||
user_defined_config[group][new_hostname] = old_hostname_settings
|
||||
self.write_config()
|
||||
|
||||
def set_new_ip(self, user_defined_config, group, hostname, ip):
|
||||
# Sets an IP address for a specified host.
|
||||
user_defined_config[group][hostname]['ip'] = ip
|
||||
self.write_config()
|
||||
|
||||
def test_provider_networks_check(self):
|
||||
# create config file without provider networks
|
||||
self.delete_config_key(self.user_defined_config, 'provider_networks')
|
||||
@ -555,12 +561,8 @@ class TestConfigChecks(unittest.TestCase):
|
||||
ret = di._check_multiple_ips_to_host(config)
|
||||
self.assertTrue(ret)
|
||||
|
||||
def tearDown(self):
|
||||
if self.config_changed:
|
||||
self.restore_config()
|
||||
|
||||
|
||||
class TestStaticRouteConfig(TestConfigChecks):
|
||||
class TestStaticRouteConfig(TestConfigCheckBase):
|
||||
def setUp(self):
|
||||
super(TestStaticRouteConfig, self).setUp()
|
||||
self.expectedMsg = ("Static route provider network with queue "
|
||||
@ -652,7 +654,7 @@ class TestStaticRouteConfig(TestConfigChecks):
|
||||
self.assertEqual(exception.message, self.expectedMsg)
|
||||
|
||||
|
||||
class TestGlobalOverridesConfigDeletion(TestConfigChecks):
|
||||
class TestGlobalOverridesConfigDeletion(TestConfigCheckBase):
|
||||
def setUp(self):
|
||||
super(TestGlobalOverridesConfigDeletion, self).setUp()
|
||||
self.inventory = get_inventory()
|
||||
|
Loading…
x
Reference in New Issue
Block a user