def test_init_with_all_data_v6(self, group_name): data = { group_name: { 'standalone_network_plugin_gateway': '2001:db8::0001', 'standalone_network_plugin_mask': '88', 'standalone_network_plugin_segmentation_id': '3999', 'standalone_network_plugin_allowed_ip_ranges': ( '2001:db8::-2001:db8:0000:0000:0000:007f:ffff:ffff'), 'standalone_network_plugin_ip_version': 6, }, } with test_utils.create_temp_config_with_opts(data): instance = plugin.StandaloneNetworkPlugin( config_group_name=group_name) self.assertEqual(6, instance.ip_version) self.assertEqual('2001:db8::0001', instance.gateway) self.assertEqual('88', instance.mask) self.assertEqual('3999', instance.segmentation_id) self.assertEqual(['2001:db8::/89'], instance.allowed_cidrs) self.assertEqual( ['2001:db8::-2001:db8:0000:0000:0000:007f:ffff:ffff'], instance.allowed_ip_ranges) self.assertEqual( netaddr.IPNetwork('2001:db8::0001/88'), instance.net) self.assertEqual( ('2001:db8::', '2001:db8::0001', '2001:db8::ff:ffff:ffff'), instance.reserved_addresses)
def test_deallocate_network(self): share_server_id = 'fake_share_server_id' data = { 'DEFAULT': { 'standalone_network_plugin_gateway': '10.0.0.1', 'standalone_network_plugin_mask': '24', }, } fake_allocations = [{'id': 'fake1'}, {'id': 'fake2'}] with test_utils.create_temp_config_with_opts(data): instance = plugin.StandaloneNetworkPlugin() self.mock_object( instance.db, 'network_allocations_get_for_share_server', mock.Mock(return_value=fake_allocations)) self.mock_object(instance.db, 'network_allocation_delete') instance.deallocate_network(fake_context, share_server_id) instance.db.network_allocations_get_for_share_server.\ assert_called_once_with(fake_context, share_server_id) instance.db.network_allocation_delete.\ assert_has_calls([ mock.call(fake_context, 'fake1'), mock.call(fake_context, 'fake2'), ])
def test_allocate_network_no_available_ipv4_addresses(self): data = { 'DEFAULT': { 'standalone_network_plugin_gateway': '10.0.0.1', 'standalone_network_plugin_mask': '30', }, } with test_utils.create_temp_config_with_opts(data): instance = plugin.StandaloneNetworkPlugin() self.mock_object(instance.db, 'share_network_update') self.mock_object(instance.db, 'network_allocation_create') self.mock_object( instance.db, 'network_allocations_get_by_ip_address', mock.Mock(return_value=['not empty list'])) self.assertRaises( exception.NetworkBadConfigurationException, instance.allocate_network, fake_context, fake_share_server, fake_share_network) instance.db.share_network_update.assert_called_once_with( fake_context, fake_share_network['id'], dict(segmentation_id=None, cidr=instance.net.cidr, ip_version=4)) instance.db.network_allocations_get_by_ip_address.assert_has_calls( [mock.call(fake_context, '10.0.0.2')])
def test_init_valid(self): nova_net_id = 'fake_nova_net_id' config_data = dict( DEFAULT=dict(nova_single_network_plugin_net_id=nova_net_id)) with test_utils.create_temp_config_with_opts(config_data): instance = plugin.NovaSingleNetworkPlugin() self.assertEqual(nova_net_id, instance.net_id)
def test_allocate_network_one_ip_address_ipv4_no_usages_exist(self): data = { 'DEFAULT': { 'standalone_network_plugin_gateway': '10.0.0.1', 'standalone_network_plugin_mask': '24', }, } with test_utils.create_temp_config_with_opts(data): instance = plugin.StandaloneNetworkPlugin() self.mock_object(instance.db, 'share_network_update') self.mock_object(instance.db, 'network_allocation_create') self.mock_object( instance.db, 'network_allocations_get_by_ip_address', mock.Mock(return_value=[])) allocations = instance.allocate_network( fake_context, fake_share_server, fake_share_network) self.assertEqual(1, len(allocations)) instance.db.share_network_update.assert_called_once_with( fake_context, fake_share_network['id'], dict(segmentation_id=None, cidr=instance.net.cidr, ip_version=4)) instance.db.network_allocations_get_by_ip_address.assert_has_calls( [mock.call(fake_context, '10.0.0.2')]) instance.db.network_allocation_create.assert_called_once_with( fake_context, dict(share_server_id=fake_share_server['id'], ip_address='10.0.0.2', status=constants.STATUS_ACTIVE))
def test_init_with_all_data_v4(self, group_name): data = { group_name: { 'standalone_network_plugin_gateway': '10.0.0.1', 'standalone_network_plugin_mask': '255.255.0.0', 'standalone_network_plugin_segmentation_id': '1001', 'standalone_network_plugin_allowed_ip_ranges': ( '10.0.0.3-10.0.0.7,10.0.0.69-10.0.0.157,10.0.0.213'), 'standalone_network_plugin_ip_version': 4, }, } allowed_cidrs = [ '10.0.0.3/32', '10.0.0.4/30', '10.0.0.69/32', '10.0.0.70/31', '10.0.0.72/29', '10.0.0.80/28', '10.0.0.96/27', '10.0.0.128/28', '10.0.0.144/29', '10.0.0.152/30', '10.0.0.156/31', '10.0.0.213/32', ] with test_utils.create_temp_config_with_opts(data): instance = plugin.StandaloneNetworkPlugin( config_group_name=group_name) self.assertEqual(4, instance.ip_version) self.assertEqual('10.0.0.1', instance.gateway) self.assertEqual('255.255.0.0', instance.mask) self.assertEqual('1001', instance.segmentation_id) self.assertEqual(allowed_cidrs, instance.allowed_cidrs) self.assertEqual( ['10.0.0.3-10.0.0.7', '10.0.0.69-10.0.0.157', '10.0.0.213'], instance.allowed_ip_ranges) self.assertEqual( netaddr.IPNetwork('10.0.0.1/255.255.0.0'), instance.net) self.assertEqual( ('10.0.0.0', '10.0.0.1', '10.0.255.255'), instance.reserved_addresses)
def test_init_only_with_required_data_v6(self, group_name): data = { group_name: { 'standalone_network_plugin_gateway': ( '2001:cdba::3257:9652'), 'standalone_network_plugin_mask': '48', 'standalone_network_plugin_ip_version': 6, }, } with test_utils.create_temp_config_with_opts(data): instance = plugin.StandaloneNetworkPlugin( config_group_name=group_name) self.assertEqual( '2001:cdba::3257:9652', instance.gateway) self.assertEqual('48', instance.mask) self.assertEqual(None, instance.segmentation_id) self.assertEqual(None, instance.allowed_ip_ranges) self.assertEqual(6, instance.ip_version) self.assertEqual( netaddr.IPNetwork('2001:cdba::3257:9652/48'), instance.net) self.assertEqual( ['2001:cdba::3257:9652/48'], instance.allowed_cidrs) self.assertEqual( ('2001:cdba::', '2001:cdba::3257:9652', '2001:cdba:0:ffff:ffff:ffff:ffff:ffff'), instance.reserved_addresses)
def test_no_auth_obj(self): mock_client_loader = self.mock_object( neutron_api.client_auth, 'AuthClientLoader') fake_context = 'fake_context' data = { 'neutron': { 'endpoint_type': 'foo_endpoint_type', 'region_name': 'foo_region_name', } } self.client = None with test_utils.create_temp_config_with_opts(data): self.client = neutron_api.API() self.client.get_client(fake_context) mock_client_loader.assert_called_once_with( client_class=neutron_api.clientv20.Client, exception_module=neutron_api.neutron_client_exc, cfg_group=neutron_api.NEUTRON_GROUP ) mock_client_loader.return_value.get_client.assert_called_once_with( self.client, fake_context, endpoint_type=data['neutron']['endpoint_type'], region_name=data['neutron']['region_name'], )
def test_no_auth_obj(self): mock_client_loader = self.mock_object( nova.client_auth, 'AuthClientLoader') fake_context = 'fake_context' data = { 'nova': { 'api_microversion': 'foo_api_microversion', 'endpoint_type': 'foo_endpoint_type', 'region_name': 'foo_region_name', } } with test_utils.create_temp_config_with_opts(data): nova.novaclient(fake_context) mock_client_loader.assert_called_once_with( client_class=nova.nova_client.Client, exception_module=nova.nova_exception, cfg_group=nova.NOVA_GROUP ) mock_client_loader.return_value.get_client.assert_called_once_with( fake_context, version=data['nova']['api_microversion'], endpoint_type=data['nova']['endpoint_type'], region_name=data['nova']['region_name'], )
def _setup_manage_network_allocations(self, label=None): data = { 'DEFAULT': { 'standalone_network_plugin_gateway': '192.168.0.1', 'standalone_network_plugin_mask': '24', }, } with test_utils.create_temp_config_with_opts(data): instance = plugin.StandaloneNetworkPlugin(label=label) return instance
def test_allocate_network_two_ip_addresses_ipv4_two_usages_exist(self): ctxt = type('FakeCtxt', (object,), {'fake': ['10.0.0.2', '10.0.0.4']}) def fake_get_allocations_by_ip_address(context, ip_address): if ip_address not in context.fake: context.fake.append(ip_address) return [] else: return context.fake data = { 'DEFAULT': { 'standalone_network_plugin_gateway': '10.0.0.1', 'standalone_network_plugin_mask': '24', }, } with test_utils.create_temp_config_with_opts(data): instance = plugin.StandaloneNetworkPlugin() self.mock_object(instance.db, 'share_network_update') self.mock_object(instance.db, 'network_allocation_create') self.mock_object( instance.db, 'network_allocations_get_by_ip_address', mock.Mock(side_effect=fake_get_allocations_by_ip_address)) allocations = instance.allocate_network( ctxt, fake_share_server, fake_share_network, count=2) self.assertEqual(2, len(allocations)) na_data = { 'network_type': None, 'segmentation_id': None, 'cidr': six.text_type(instance.net.cidr), 'gateway': six.text_type(instance.gateway), 'ip_version': 4, 'mtu': 1500, } instance.db.share_network_update.assert_called_once_with( ctxt, fake_share_network['id'], dict(**na_data)) instance.db.network_allocations_get_by_ip_address.assert_has_calls( [mock.call(ctxt, '10.0.0.2'), mock.call(ctxt, '10.0.0.3'), mock.call(ctxt, '10.0.0.4'), mock.call(ctxt, '10.0.0.5')]) instance.db.network_allocation_create.assert_has_calls([ mock.call( ctxt, dict(share_server_id=fake_share_server['id'], ip_address='10.0.0.3', status=constants.STATUS_ACTIVE, label='user', **na_data)), mock.call( ctxt, dict(share_server_id=fake_share_server['id'], ip_address='10.0.0.5', status=constants.STATUS_ACTIVE, label='user', **na_data)), ])
def test_invalid_init_required_data_improper(self, data): group_name = 'custom_group_name' if 'gateway' in data: data['standalone_network_plugin_gateway'] = data.pop('gateway') if 'mask' in data: data['standalone_network_plugin_mask'] = data.pop('mask') data = {group_name: data} with test_utils.create_temp_config_with_opts(data): self.assertRaises( exception.NetworkBadConfigurationException, plugin.StandaloneNetworkPlugin, config_group_name=group_name)
def test_init_invalid(self, net, subnet): config_data = dict() # Simulate absence of set values if net: config_data['neutron_net_id'] = net if subnet: config_data['neutron_subnet_id'] = subnet config_data = dict(DEFAULT=config_data) with test_utils.create_temp_config_with_opts(config_data): self.assertRaises( exception.NetworkBadConfigurationException, plugin.NeutronSingleNetworkPlugin)
def _get_neutron_single_network_plugin_instance(self): fake_subnet_id = 'fake_subnet_id' config_data = { 'DEFAULT': { 'neutron_net_id': 'fake_net_id', 'neutron_subnet_id': fake_subnet_id, } } fake_net = {'subnets': [fake_subnet_id]} self.mock_object( neutron_api.API, 'get_network', mock.Mock(return_value=fake_net)) with test_utils.create_temp_config_with_opts(config_data): instance = plugin.NeutronSingleNetworkPlugin() return instance
def test_invalid_init_mismatch_of_versions(self, gateway, vers): group_name = 'DEFAULT' data = { group_name: { 'standalone_network_plugin_gateway': gateway, 'standalone_network_plugin_ip_version': vers, 'standalone_network_plugin_mask': '25', }, } with test_utils.create_temp_config_with_opts(data): self.assertRaises( exception.NetworkBadConfigurationException, plugin.StandaloneNetworkPlugin, config_group_name=group_name)
def test_invalid_init_incorrect_allowed_ip_ranges_v4(self, ip_range): group_name = 'DEFAULT' data = { group_name: { 'standalone_network_plugin_gateway': '10.0.0.1', 'standalone_network_plugin_mask': '255.255.255.0', 'standalone_network_plugin_allowed_ip_ranges': ip_range, }, } with test_utils.create_temp_config_with_opts(data): self.assertRaises( exception.NetworkBadConfigurationException, plugin.StandaloneNetworkPlugin, config_group_name=group_name)
def test_init_with_valid_network_types_v4(self, network_type): data = { 'DEFAULT': { 'standalone_network_plugin_gateway': '10.0.0.1', 'standalone_network_plugin_mask': '255.255.0.0', 'standalone_network_plugin_network_type': network_type, 'standalone_network_plugin_segmentation_id': 1001, 'standalone_network_plugin_ip_version': 4, }, } with test_utils.create_temp_config_with_opts(data): instance = plugin.StandaloneNetworkPlugin( config_group_name='DEFAULT') self.assertEqual(instance.network_type, network_type)
def test_init_with_fake_network_types_v4(self, fake_network_type): data = { 'DEFAULT': { 'standalone_network_plugin_gateway': '10.0.0.1', 'standalone_network_plugin_mask': '255.255.0.0', 'standalone_network_plugin_network_type': fake_network_type, 'standalone_network_plugin_segmentation_id': 1001, 'standalone_network_plugin_ip_version': 4, }, } with test_utils.create_temp_config_with_opts(data): self.assertRaises( cfg.ConfigFileValueError, plugin.StandaloneNetworkPlugin, config_group_name='DEFAULT', )
def test_init_subnet_does_not_belong_to_net(self, fake_net): fake_net_id = 'fake_net_id' config_data = { 'DEFAULT': { 'neutron_net_id': fake_net_id, 'neutron_subnet_id': 'fake_subnet_id', } } self.mock_object( neutron_api.API, 'get_network', mock.Mock(return_value=fake_net)) with test_utils.create_temp_config_with_opts(config_data): self.assertRaises( exception.NetworkBadConfigurationException, plugin.NeutronSingleNetworkPlugin) neutron_api.API.get_network.assert_called_once_with(fake_net_id)
def test_allocate_network_zero_addresses_ipv4(self): data = { 'DEFAULT': { 'standalone_network_plugin_gateway': '10.0.0.1', 'standalone_network_plugin_mask': '24', }, } with test_utils.create_temp_config_with_opts(data): instance = plugin.StandaloneNetworkPlugin() self.mock_object(instance.db, 'share_network_update') allocations = instance.allocate_network( fake_context, fake_share_server, fake_share_network, count=0) self.assertEqual([], allocations) instance.db.share_network_update.assert_called_once_with( fake_context, fake_share_network['id'], dict(segmentation_id=None, cidr=instance.net.cidr, ip_version=4))
def test_invalid_init_mismatch_of_versions(self, gateway, vers): group_name = 'DEFAULT' data = { group_name: { 'standalone_network_plugin_gateway': gateway, 'standalone_network_plugin_mask': '25', }, } if vers == 4: data[group_name]['network_plugin_ipv4_enabled'] = True if vers == 6: data[group_name]['network_plugin_ipv4_enabled'] = False data[group_name]['network_plugin_ipv6_enabled'] = True with test_utils.create_temp_config_with_opts(data): self.assertRaises( exception.NetworkBadConfigurationException, plugin.StandaloneNetworkPlugin, config_group_name=group_name)
def test_init_valid(self): fake_net_id = 'fake_net_id' fake_subnet_id = 'fake_subnet_id' config_data = { 'DEFAULT': { 'neutron_net_id': fake_net_id, 'neutron_subnet_id': fake_subnet_id, } } fake_net = {'subnets': ['fake1', 'fake2', fake_subnet_id]} self.mock_object( neutron_api.API, 'get_network', mock.Mock(return_value=fake_net)) with test_utils.create_temp_config_with_opts(config_data): instance = plugin.NeutronSingleNetworkPlugin() self.assertEqual(fake_net_id, instance.net) self.assertEqual(fake_subnet_id, instance.subnet) neutron_api.API.get_network.assert_called_once_with(fake_net_id)
def test_with_auth_obj(self): fake_context = 'fake_context' data = { 'nova': { 'api_microversion': 'foo_api_microversion', 'endpoint_type': 'foo_endpoint_type', 'region_name': 'foo_region_name', } } with test_utils.create_temp_config_with_opts(data): nova.novaclient(fake_context) nova.AUTH_OBJ.get_client.assert_called_once_with( fake_context, version=data['nova']['api_microversion'], endpoint_type=data['nova']['endpoint_type'], region_name=data['nova']['region_name'], )
def test_no_auth_obj(self): mock_client_loader = self.mock_object( nova.client_auth, 'AuthClientLoader') fake_context = 'fake_context' data = { 'DEFAULT': { 'nova_admin_username': '******', 'nova_admin_password': '******', 'nova_admin_tenant_name': 'foo_tenant_name', 'nova_admin_auth_url': 'foo_auth_url', }, 'nova': { 'api_microversion': 'foo_api_microversion', 'api_insecure': True, 'ca_certificates_file': 'foo_ca_certificates_file', 'endpoint_type': 'foo_endpoint_type', 'region_name': 'foo_region_name', } } with test_utils.create_temp_config_with_opts(data): nova.novaclient(fake_context) mock_client_loader.assert_called_once_with( client_class=nova.nova_client.Client, exception_module=nova.nova_exception, cfg_group=nova.NOVA_GROUP, deprecated_opts_for_v2={ 'username': data['DEFAULT']['nova_admin_username'], 'password': data['DEFAULT']['nova_admin_password'], 'tenant_name': data['DEFAULT']['nova_admin_tenant_name'], 'auth_url': data['DEFAULT']['nova_admin_auth_url'], }, ) mock_client_loader.return_value.get_client.assert_called_once_with( fake_context, version=data['nova']['api_microversion'], insecure=data['nova']['api_insecure'], cacert=data['nova']['ca_certificates_file'], endpoint_type=data['nova']['endpoint_type'], region_name=data['nova']['region_name'], )
def test_no_auth_obj(self): mock_client_loader = self.mock_object( cinder.client_auth, 'AuthClientLoader') fake_context = 'fake_context' data = { 'DEFAULT': { 'cinder_admin_username': '******', 'cinder_admin_password': '******', 'cinder_admin_tenant_name': 'foo_tenant_name', 'cinder_admin_auth_url': 'foo_auth_url', }, 'cinder': { 'api_insecure': True, 'ca_certificates_file': 'foo_ca_certificates_file', 'http_retries': 3, 'endpoint_type': 'foo_endpoint_type', 'region_name': 'foo_region_name', } } with test_utils.create_temp_config_with_opts(data): cinder.cinderclient(fake_context) mock_client_loader.assert_called_once_with( client_class=cinder.cinder_client.Client, exception_module=cinder.cinder_exception, cfg_group=cinder.CINDER_GROUP, deprecated_opts_for_v2={ 'username': data['DEFAULT']['cinder_admin_username'], 'password': data['DEFAULT']['cinder_admin_password'], 'tenant_name': data['DEFAULT']['cinder_admin_tenant_name'], 'auth_url': data['DEFAULT']['cinder_admin_auth_url'], }, ) mock_client_loader.return_value.get_client.assert_called_once_with( fake_context, insecure=data['cinder']['api_insecure'], cacert=data['cinder']['ca_certificates_file'], retries=data['cinder']['http_retries'], endpoint_type=data['cinder']['endpoint_type'], region_name=data['cinder']['region_name'], )
def test_allocate_network_host_id_prconfigured(self): has_provider_nw_ext = mock.patch.object( self.plugin, '_has_provider_network_extension').start() has_provider_nw_ext.return_value = True save_nw_data = mock.patch.object(self.plugin, '_save_neutron_network_data').start() save_subnet_data = mock.patch.object( self.plugin, '_save_neutron_subnet_data').start() config_data = { 'DEFAULT': { 'neutron_host_id': 'fake_host_id', } } with test_utils.create_temp_config_with_opts(config_data): with mock.patch.object(self.plugin.neutron_api, 'create_port', mock.Mock(return_value=fake_neutron_port)): self.plugin.allocate_network( self.fake_context, fake_share_server, fake_share_network, allocation_info={'count': 1}) has_provider_nw_ext.assert_any_call() save_nw_data.assert_called_once_with(self.fake_context, fake_share_network) save_subnet_data.assert_called_once_with(self.fake_context, fake_share_network) self.plugin.neutron_api.create_port.assert_called_once_with( fake_share_network['project_id'], network_id=fake_share_network['neutron_net_id'], subnet_id=fake_share_network['neutron_subnet_id'], device_owner='manila:share', host_id='fake_host_id') db_api.network_allocation_create.assert_called_once_with( self.fake_context, fake_network_allocation) has_provider_nw_ext.stop() save_nw_data.stop() save_subnet_data.stop()
def test_init_only_with_required_data_v4(self, group_name): data = { group_name: { 'standalone_network_plugin_gateway': '10.0.0.1', 'standalone_network_plugin_mask': '24', }, } with test_utils.create_temp_config_with_opts(data): instance = plugin.StandaloneNetworkPlugin( config_group_name=group_name) self.assertEqual('10.0.0.1', instance.gateway) self.assertEqual('24', instance.mask) self.assertEqual(None, instance.segmentation_id) self.assertEqual(None, instance.allowed_ip_ranges) self.assertEqual(4, instance.ip_version) self.assertEqual(netaddr.IPNetwork('10.0.0.1/24'), instance.net) self.assertEqual(['10.0.0.1/24'], instance.allowed_cidrs) self.assertEqual( ('10.0.0.0', '10.0.0.1', '10.0.0.255'), instance.reserved_addresses)
def test_no_auth_obj(self): mock_client_loader = self.mock_object( neutron_api.client_auth, 'AuthClientLoader') fake_context = 'fake_context' data = { 'DEFAULT': { 'neutron_admin_username': '******', 'neutron_admin_password': '******', 'neutron_admin_tenant_name': 'foo_tenant_name', 'neutron_admin_auth_url': 'foo_auth_url', }, 'neutron': { 'endpoint_type': 'foo_endpoint_type', 'region_name': 'foo_region_name', } } self.client = None with test_utils.create_temp_config_with_opts(data): self.client = neutron_api.API() self.client.get_client(fake_context) mock_client_loader.assert_called_once_with( client_class=neutron_api.clientv20.Client, exception_module=neutron_api.neutron_client_exc, cfg_group=neutron_api.NEUTRON_GROUP, deprecated_opts_for_v2={ 'username': data['DEFAULT']['neutron_admin_username'], 'password': data['DEFAULT']['neutron_admin_password'], 'tenant_name': data['DEFAULT']['neutron_admin_tenant_name'], 'auth_url': data['DEFAULT']['neutron_admin_auth_url'], }, ) mock_client_loader.return_value.get_client.assert_called_once_with( self.client, fake_context, endpoint_type=data['neutron']['endpoint_type'], region_name=data['neutron']['region_name'], )
def test_with_auth_obj(self): fake_context = 'fake_context' data = { 'neutron': { 'endpoint_type': 'foo_endpoint_type', 'region_name': 'foo_region_name', } } self.client = None with test_utils.create_temp_config_with_opts(data): self.client = neutron_api.API() self.client.auth_obj = type( 'FakeAuthObj', (object, ), {'get_client': mock.Mock()}) self.client.get_client(fake_context) self.client.auth_obj.get_client.assert_called_once_with( self.client, fake_context, endpoint_type=data['neutron']['endpoint_type'], region_name=data['neutron']['region_name'], )
def test_allocate_network_zero_addresses_ipv6(self): data = { 'DEFAULT': { 'standalone_network_plugin_gateway': '2001:db8::0001', 'standalone_network_plugin_mask': '64', 'standalone_network_plugin_ip_version': 6, }, } with test_utils.create_temp_config_with_opts(data): instance = plugin.StandaloneNetworkPlugin() self.mock_object(instance.db, 'share_network_update') allocations = instance.allocate_network( fake_context, fake_share_server, fake_share_network, count=0) self.assertEqual([], allocations) instance.db.share_network_update.assert_called_once_with( fake_context, fake_share_network['id'], dict(network_type=None, segmentation_id=None, cidr=six.text_type(instance.net.cidr), gateway=six.text_type(instance.gateway), ip_version=6, mtu=1500))
def test_with_auth_obj(self): fake_context = 'fake_context' data = { 'neutron': { 'url': 'http://localhost:9696', 'endpoint_type': 'foo_endpoint_type', 'region_name': 'foo_region_name', } } self.client = None with test_utils.create_temp_config_with_opts(data): self.client = neutron_api.API() self.client.auth_obj = type( 'FakeAuthObj', (object, ), {'get_client': mock.Mock()}) self.client.get_client(fake_context) self.client.auth_obj.get_client.assert_called_once_with( self.client, fake_context, endpoint_type=data['neutron']['endpoint_type'], region_name=data['neutron']['region_name'], endpoint_override=data['neutron']['url'], )
def test_allocate_network_zero_addresses_ipv6(self): data = { 'DEFAULT': { 'standalone_network_plugin_gateway': '2001:db8::0001', 'standalone_network_plugin_mask': '64', 'standalone_network_plugin_ip_version': 6, }, } with test_utils.create_temp_config_with_opts(data): instance = plugin.StandaloneNetworkPlugin() self.mock_object(instance.db, 'share_network_update') allocations = instance.allocate_network(fake_context, fake_share_server, fake_share_network, count=0) self.assertEqual([], allocations) instance.db.share_network_update.assert_called_once_with( fake_context, fake_share_network['id'], dict(network_type=None, segmentation_id=None, cidr=six.text_type(instance.net.cidr), ip_version=6))
def test_no_auth_obj(self): mock_client_loader = self.mock_object(cinder.client_auth, 'AuthClientLoader') fake_context = 'fake_context' data = { 'cinder': { 'http_retries': 3, 'endpoint_type': 'foo_endpoint_type', 'region_name': 'foo_region_name', } } with test_utils.create_temp_config_with_opts(data): cinder.cinderclient(fake_context) mock_client_loader.assert_called_once_with( client_class=cinder.cinder_client.Client, cfg_group=cinder.CINDER_GROUP) mock_client_loader.return_value.get_client.assert_called_once_with( fake_context, retries=data['cinder']['http_retries'], endpoint_type=data['cinder']['endpoint_type'], region_name=data['cinder']['region_name'], )
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 _get_instance(self, label=None): nova_net_id = 'fake_nova_net_id' config_data = dict(DEFAULT=dict( nova_single_network_plugin_net_id=nova_net_id)) with test_utils.create_temp_config_with_opts(config_data): return plugin.NovaSingleNetworkPlugin(label=label)
def test_verify_share_protocols_invalid_cases(self, proto): data = dict(DEFAULT=dict(enabled_share_protocols=proto)) with test_utils.create_temp_config_with_opts(data): self.assertRaises(exception.ManilaException, config.verify_share_protocols)
def test_verify_share_protocols_valid_cases(self, proto): data = dict(DEFAULT=dict(enabled_share_protocols=proto)) with test_utils.create_temp_config_with_opts(data): config.verify_share_protocols()
def test_allocate_network_two_ip_addresses_ipv4_two_usages_exist(self): ctxt = type('FakeCtxt', (object, ), {'fake': ['10.0.0.2', '10.0.0.4']}) def fake_get_allocations_by_ip_address(context, ip_address): if ip_address not in context.fake: context.fake.append(ip_address) return [] else: return context.fake data = { 'DEFAULT': { 'standalone_network_plugin_gateway': '10.0.0.1', 'standalone_network_plugin_mask': '24', }, } with test_utils.create_temp_config_with_opts(data): instance = plugin.StandaloneNetworkPlugin() self.mock_object(instance.db, 'share_network_update') self.mock_object(instance.db, 'network_allocation_create') self.mock_object( instance.db, 'network_allocations_get_by_ip_address', mock.Mock(side_effect=fake_get_allocations_by_ip_address)) allocations = instance.allocate_network(ctxt, fake_share_server, fake_share_network, count=2) self.assertEqual(2, len(allocations)) na_data = { 'network_type': None, 'segmentation_id': None, 'cidr': six.text_type(instance.net.cidr), 'gateway': six.text_type(instance.gateway), 'ip_version': 4, } instance.db.share_network_update.assert_called_once_with( ctxt, fake_share_network['id'], dict(**na_data)) instance.db.network_allocations_get_by_ip_address.assert_has_calls([ mock.call(ctxt, '10.0.0.2'), mock.call(ctxt, '10.0.0.3'), mock.call(ctxt, '10.0.0.4'), mock.call(ctxt, '10.0.0.5') ]) instance.db.network_allocation_create.assert_has_calls([ mock.call( ctxt, dict(share_server_id=fake_share_server['id'], ip_address='10.0.0.3', status=constants.STATUS_ACTIVE, label='user', **na_data)), mock.call( ctxt, dict(share_server_id=fake_share_server['id'], ip_address='10.0.0.5', status=constants.STATUS_ACTIVE, label='user', **na_data)), ])
def test_init_invalid(self, data): config_data = dict(DEFAULT=data) with test_utils.create_temp_config_with_opts(config_data): self.assertRaises(exception.NetworkBadConfigurationException, plugin.NovaSingleNetworkPlugin)