def test_get_share_stats_refresh_false(self): share_driver = driver.ShareDriver(True, configuration=None) share_driver._stats = {'fake_key': 'fake_value'} result = share_driver.get_share_stats(False) self.assertEqual(share_driver._stats, result)
def test_instantiate_share_driver_no_configuration(self): self.mock_object(network, 'API') share_driver = driver.ShareDriver(True, configuration=None) self.assertIsNone(share_driver.configuration) network.API.assert_called_once_with(config_group_name=None)
def _setup_mocks_copy_share_data(self): get_migration_info_value = { 'mount': 'fake', 'umount': 'fake', 'access': { 'access_type': 'fake', 'access_to': 'fake' } } self.mock_object(rpcapi.ShareAPI, 'get_migration_info', mock.Mock(return_value=get_migration_info_value)) self.mock_object(driver.ShareDriver, 'get_migration_info', mock.Mock(return_value=get_migration_info_value)) self.mock_object(share_utils.Copy, 'run') self.mock_object(time, 'sleep') driver.CONF.set_default('driver_handles_share_servers', False) share_driver = driver.ShareDriver( False, configuration=configuration.Configuration(None)) return share_driver
def test_migration_get_driver_info_default(self): driver.CONF.set_default('driver_handles_share_servers', False) share_driver = driver.ShareDriver(False) self.assertIsNone( share_driver.migration_get_driver_info(None, None, None), None)
def test_migration_cancel(self): driver.CONF.set_default('driver_handles_share_servers', False) share_driver = driver.ShareDriver(False) self.assertRaises(NotImplementedError, share_driver.migration_cancel, None, None, None, None, None, None, None)
def test_get_migration_info_default(self): expected = { 'mount': ['mount', '-t', 'fake_proto', '/fake/fake_id', '/tmp/fake_id'], 'umount': ['umount', '/tmp/fake_id'], 'access': { 'access_type': 'ip', 'access_level': 'rw', 'access_to': None } } fake_share = { 'id': 'fake_id', 'share_proto': 'fake_proto', 'export_locations': [{ 'path': '/fake/fake_id' }] } driver.CONF.set_default('driver_handles_share_servers', False) share_driver = driver.ShareDriver(False) share_driver.configuration = configuration.Configuration(None) migration_info = share_driver.get_migration_info( None, fake_share, "fake_server") self.assertEqual(expected, migration_info)
def test_get_migration_info_parameters(self): expected = { 'mount': ['fake_mount', '/200.200.200.200/fake_id', '/tmp/fake_id'], 'umount': ['umount', '/tmp/fake_id'], 'access': { 'access_type': 'ip', 'access_level': 'rw', 'access_to': '100.100.100.100' } } fake_share = { 'id': 'fake_id', 'export_locations': [{ 'path': '/5.5.5.5/fake_id' }] } driver.CONF.set_default('driver_handles_share_servers', False) driver.CONF.set_default('migration_protocol_mount_command', 'fake_mount') driver.CONF.set_default('migration_mounting_backend_ip', '200.200.200.200') driver.CONF.set_default('migration_data_copy_node_ip', '100.100.100.100') share_driver = driver.ShareDriver(False) share_driver.configuration = configuration.Configuration(None) migration_info = share_driver.get_migration_info( None, fake_share, "fake_server") self.assertEqual(expected, migration_info)
def test_migrate_share(self): driver.CONF.set_default('driver_handles_share_servers', False) share_driver = driver.ShareDriver(False) self.assertEqual((None, None), share_driver.migrate_share(None, None, None, None))
def test_connection_get_info(self, admin): expected = { 'mount': 'mount -vt nfs %(options)s /fake/fake_id %(path)s', 'unmount': 'umount -v %(path)s', 'access_mapping': { 'ip': ['nfs'] } } fake_share = { 'id': 'fake_id', 'share_proto': 'nfs', 'export_locations': [{ 'path': '/fake/fake_id', 'is_admin_only': admin }] } driver.CONF.set_default('driver_handles_share_servers', False) share_driver = driver.ShareDriver(False) share_driver.configuration = configuration.Configuration(None) connection_info = share_driver.connection_get_info( None, fake_share, "fake_server") self.assertEqual(expected, connection_info)
def test_instantiate_share_driver_no_configuration(self): self.stubs.Set(network, 'API', mock.Mock()) share_driver = driver.ShareDriver(configuration=None) self.assertEqual(None, share_driver.configuration) network.API.assert_called_once_with(config_group_name=None)
def test_get_share_stats_refresh_true(self): conf = configuration.Configuration(None) expected_keys = [ 'qos', 'driver_version', 'share_backend_name', 'free_capacity_gb', 'total_capacity_gb', 'driver_handles_share_servers', 'reserved_percentage', 'vendor_name', 'storage_protocol', 'snapshot_support', 'mount_snapshot_support', ] share_driver = driver.ShareDriver(True, configuration=conf) fake_stats = {'fake_key': 'fake_value'} share_driver._stats = fake_stats result = share_driver.get_share_stats(True) self.assertNotEqual(fake_stats, result) for key in expected_keys: self.assertIn(key, result) self.assertEqual('Open Source', result['vendor_name'])
def test_check_for_setup_error(self, value): driver.CONF.set_default('driver_handles_share_servers', False) share_driver = driver.ShareDriver(False) share_driver.configuration = configuration.Configuration(None) self.mock_object(share_driver.configuration, 'safe_get', mock.Mock(return_value=value)) if value and float(value) >= 1.0: share_driver.check_for_setup_error() else: self.assertRaises(exception.InvalidParameterValue, share_driver.check_for_setup_error)
def test_update_access(self): share_driver = driver.ShareDriver(True, configuration=None) self.assertRaises( NotImplementedError, share_driver.update_access, 'ctx', 'fake_share', 'fake_access_rules', 'fake_add_rules', 'fake_delete_rules' )
def test_share_group_snapshot_support_exists_and_equals_snapshot_support( self, snapshots_are_supported): driver.CONF.set_default('driver_handles_share_servers', True) child_class_instance = driver.ShareDriver(True) child_class_instance._snapshots_are_supported = snapshots_are_supported self.mock_object(child_class_instance, "configuration") child_class_instance._update_share_stats() self.assertEqual(snapshots_are_supported, child_class_instance._stats["snapshot_support"]) self.assertTrue(child_class_instance.configuration.safe_get.called)
def test_verify_share_driver_mode_option_type(self): with utils.tempdir() as tmpdir: tmpfilename = os.path.join(tmpdir, 'share_driver_mode.conf') with open(tmpfilename, "w") as configfile: configfile.write("""[DEFAULT]\nshare_driver_mode = fake""") # Add config file with updated opt driver.CONF.default_config_files = [configfile.name] # Reload config instance to use redefined opt driver.CONF.reload_config_files() share_driver = driver.ShareDriver() self.assertEqual('fake', share_driver.mode)
def test_migration_check_compatibility(self): driver.CONF.set_default('driver_handles_share_servers', False) share_driver = driver.ShareDriver(False) share_driver.configuration = configuration.Configuration(None) expected = { 'compatible': False, 'writable': False, 'preserve_metadata': False, 'nondisruptive': False, } result = share_driver.migration_check_compatibility( None, None, None, None, None) self.assertEqual(expected, result)
def _instantiate_share_driver(self, network_config_group): self.stubs.Set(network, 'API', mock.Mock()) config = mock.Mock() config.append_config_values = mock.Mock() config.config_group = 'fake_config_group' config.network_config_group = network_config_group share_driver = driver.ShareDriver(configuration=config) self.assertTrue(hasattr(share_driver, 'configuration')) config.append_config_values.assert_called_once_with(driver.share_opts) if network_config_group: network.API.assert_called_once_with( config_group_name=config.network_config_group) else: network.API.assert_called_once_with( config_group_name=config.config_group) self.assertTrue(hasattr(share_driver, 'mode')) return share_driver
def _instantiate_share_driver(self, network_config_group, driver_handles_share_servers, admin_network_config_group=None): self.mock_object(network, 'API') config = mock.Mock() config.append_config_values = mock.Mock() config.config_group = 'fake_config_group' config.network_config_group = network_config_group if admin_network_config_group: config.admin_network_config_group = admin_network_config_group config.safe_get = mock.Mock(return_value=driver_handles_share_servers) share_driver = driver.ShareDriver([True, False], configuration=config) self.assertTrue(hasattr(share_driver, 'configuration')) config.append_config_values.assert_called_once_with(driver.share_opts) if driver_handles_share_servers: calls = [] if network_config_group: calls.append( mock.call(config_group_name=config.network_config_group)) else: calls.append(mock.call(config_group_name=config.config_group)) if admin_network_config_group: calls.append( mock.call( config_group_name=config.admin_network_config_group, label='admin')) network.API.assert_has_calls(calls) self.assertTrue(hasattr(share_driver, 'network_api')) self.assertTrue(hasattr(share_driver, 'admin_network_api')) self.assertIsNotNone(share_driver.network_api) self.assertIsNotNone(share_driver.admin_network_api) else: self.assertFalse(hasattr(share_driver, 'network_api')) self.assertTrue(hasattr(share_driver, 'admin_network_api')) self.assertIsNone(share_driver.admin_network_api) self.assertFalse(network.API.called) return share_driver
def test_migration_get_info(self, admin): expected = { 'mount': 'mount -vt fake_proto /fake/fake_id %(path)s', 'unmount': 'umount -v %(path)s' } fake_share = { 'id': 'fake_id', 'share_proto': 'fake_proto', 'export_locations': [{ 'path': '/fake/fake_id', 'is_admin_only': admin }] } driver.CONF.set_default('driver_handles_share_servers', False) share_driver = driver.ShareDriver(False) share_driver.configuration = configuration.Configuration(None) migration_info = share_driver.migration_get_info( None, fake_share, "fake_server") self.assertEqual(expected, migration_info)
def _instantiate_share_driver(self, network_config_group, driver_handles_share_servers): self.mock_object(network, 'API') config = mock.Mock() config.append_config_values = mock.Mock() config.config_group = 'fake_config_group' config.network_config_group = network_config_group config.safe_get = mock.Mock(return_value=driver_handles_share_servers) share_driver = driver.ShareDriver([True, False], configuration=config) self.assertTrue(hasattr(share_driver, 'configuration')) config.append_config_values.assert_called_once_with(driver.share_opts) if driver_handles_share_servers: if network_config_group: network.API.assert_called_once_with( config_group_name=config.network_config_group) else: network.API.assert_called_once_with( config_group_name=config.config_group) else: self.assertFalse(hasattr(share_driver, 'network_api')) self.assertFalse(network.API.called) return share_driver
def test_verify_share_driver_mode_option_type(self): data = {'DEFAULT': {'driver_handles_share_servers': 'True'}} with test_utils.create_temp_config_with_opts(data): share_driver = driver.ShareDriver([True, False]) self.assertTrue(share_driver.driver_handles_share_servers)
def test_migration_complete(self): driver.CONF.set_default('driver_handles_share_servers', False) share_driver = driver.ShareDriver(False) share_driver.migration_complete(None, None, None, None)
def test_get_share_server_pools(self, value): driver.CONF.set_default('driver_handles_share_servers', value) share_driver = driver.ShareDriver(value) self.assertEqual([], share_driver.get_share_server_pools('fake_server'))
def test__verify_share_server_handling_valid_cases(self, opt, allowed): conf = configuration.Configuration(None) self.mock_object(conf, 'safe_get', mock.Mock(return_value=opt)) share_driver = driver.ShareDriver(allowed, configuration=conf) self.assertTrue(conf.safe_get.celled) self.assertEqual(opt, share_driver.driver_handles_share_servers)