def cinder_context(self, infinisdk, pool, provisioning="thick", volume_backend_name=None): with config.get_config_parser(write_on_exit=True) as config_parser: key = config.apply( config_parser, self.infinisdk.get_name(), pool.get_name(), "admin", "123456", thick_provisioning=provisioning.lower() == "thick", prefer_fc=self.prefer_fc, infinidat_allow_pool_not_found=True, infinidat_purge_volume_on_deletion=True, volume_backend_name=volume_backend_name, ) config.enable(config_parser, key) config.update_volume_type(self.get_cinder_client(), key, self.infinisdk.get_name(), pool.get_name()) restart_cinder() self.wait_for_type_creation(pool) with cinder_logs_context(), iscsi_manager_logs_context(), var_log_messages_logs_context(): yield with config.get_config_parser(write_on_exit=True) as config_parser: config.delete_volume_type(self.get_cinder_client(), key) config.disable(config_parser, key) config.remove(config_parser, key) restart_cinder()
def test_adding_pool_that_was_renamed(self, filepath="tests/conf/adding_after_pool_rename.conf"): kwargs = {'address': '1.2.3.4', 'password': '******', 'pool_name': 'pool', 'username': '******'} box = {'address': '1.2.3.4', 'password': '******', 'pool_id': 1, 'username': '******', 'key': 'infinibox-1-pool-1'} self.prepare_conf(filepath) with config.get_config_parser(filepath, True) as config_parser: self.assertEquals(config.get_enabled_backends(config_parser), list()) with patch("infinisdk.InfiniBox") as InfiniBox, \ patch("infinidat_openstack.versioncheck.get_system_version") as system_version: InfiniBox().get_serial.return_value = 1 system_version.return_value = '1.5' pool = Mock() pool.get_id.return_value = 1 InfiniBox().pools.safe_get.return_value = pool key = config.apply(config_parser, **kwargs) config.enable(config_parser, key) with patch("infinisdk.InfiniBox") as InfiniBox, \ patch("infinidat_openstack.versioncheck.get_system_version") as system_version: InfiniBox().get_serial.return_value = 1 system_version.return_value = '1.5' pool = Mock() pool.get_id.return_value = 1 InfiniBox().pools.safe_get.return_value = pool kwargs['pool_name'] = 'pool2' key = config.apply(config_parser, **kwargs) config.enable(config_parser, key) with config.get_config_parser(filepath) as config_parser: self.assertEquals(len(config.get_volume_backends(config_parser)), 1) self.assertEquals(len(config.get_enabled_backends(config_parser)), 1)
def test_saving_does_not_fuck_up_the_defaults(self, filepath="tests/conf/empty_copy.conf"): self.prepare_conf(filepath) with config.get_config_parser(filepath, True) as config_parser: before = config_parser.get("DEFAULT", "sql_idle_timeout") with config.get_config_parser(filepath) as config_parser: after = config_parser.get("DEFAULT", "sql_idle_timeout") self.assertEquals(before, "3600") self.assertEquals(before, after)
def test_update_field(self, filepath="tests/conf/testing_update_field.conf"): self.prepare_conf(filepath, "tests/conf/one.conf") with open(filepath) as fd: before = fd.read() with config.get_config_parser(filepath, True) as config_parser: config.update_field(config_parser, "infinibox-1-pool-1", "infinidat_prefer_fc", False) with open(filepath) as fd: after = fd.read() self.assertIn("infinidat_prefer_fc=False", before) self.assertNotIn("infinidat_prefer_fc = True", after)
def test_saving_deletes_comments(self, filepath="tests/conf/empty_copy.conf"): self.prepare_conf(filepath) with open(filepath) as fd: before = fd.read() with config.get_config_parser(filepath, True) as config_parser: pass with open(filepath) as fd: after = fd.read() self.assertIn("#", before) self.assertNotIn("#", after)
def test_backup(self, filepath="tests/conf/testing_backup.conf"): from glob import glob from os import remove [remove(path) for path in glob(filepath + ".*")] self.prepare_conf(filepath, "tests/conf/one.conf") with open(filepath) as fd: before = fd.read() with config.get_config_parser(filepath, True) as config_parser: config.remove(config_parser, key="infinibox-1-pool-1'") with open(filepath+".1") as fd: backup = fd.read() with open(filepath) as fd: after = fd.read() self.assertNotEquals(before, after) self.assertEquals(before, backup)
def get_name(): from infinidat_openstack.config import get_config_parser with get_config_parser("buildout.cfg", False) as buildout: return buildout.get("project", "name").replace("_", "-")
def cleanup_volume_backends(): with config.get_config_parser(write_on_exit=True) as config_parser: config.set_enabled_backends(config_parser, []) for section in config.get_infinibox_sections(config_parser): config_parser.remove_section(section) restart_cinder()
def _set_cinder_config_values(self, **kwargs): from infinidat_openstack.config import get_config_parser with get_config_parser(write_on_exit=True) as config_parser: for key, value in kwargs.items(): config_parser.set("DEFAULT", key, str(value)) test_case.restart_cinder(cinder_volume_only=False)
def test_empty_config_file(self): with config.get_config_parser("tests/conf/empty.conf") as config_parser: self.assertEquals(config.get_volume_backends(config_parser), list()) self.assertEquals(config.get_enabled_backends(config_parser), list())
def test_config_file_with_one_system(self): box = {'address': '1.2.3.4', 'password': '******', 'pool_id': 1, 'username': '******', 'key': 'infinibox-1-pool-1'} with config.get_config_parser("tests/conf/one.conf") as config_parser: self.assertEquals(config.get_volume_backends(config_parser), [box]) self.assertEquals(config.get_enabled_backends(config_parser), ["foobar"])