def test_does_not_add_region_if_not_set_in_config(self, n_client): cloud = mock.MagicMock() config = mock.MagicMock() tenant = 'tenant' user = '******' auth_url = 'auth_url' password = '******' insecure = False cacert = '' ep_type = 'internalURL' config.cloud.region = None config.cloud.user = user config.cloud.tenant = tenant config.cloud.auth_url = auth_url config.cloud.password = password config.cloud.insecure = insecure config.cloud.cacert = cacert config.cloud.endpoint_type = ep_type n = neutron.NeutronNetwork(config, cloud) n.get_client() n_client.assert_called_with(tenant_name=tenant, password=password, auth_url=auth_url, username=user, cacert=cacert, insecure=insecure, region_name=None, endpoint_type=ep_type)
def test_adds_region_if_set_in_config(self, n_client): cloud = mock.MagicMock() config = mock.MagicMock() tenant = 'tenant' region = 'region' user = '******' auth_url = 'auth_url' password = '******' insecure = False cacert = '' config.cloud.user = user config.cloud.tenant = tenant config.cloud.region = region config.cloud.auth_url = auth_url config.cloud.password = password config.cloud.insecure = insecure config.cloud.cacert = cacert n = neutron.NeutronNetwork(config, cloud) n.get_client() n_client.assert_called_with( region_name=region, tenant_name=tenant, password=password, auth_url=auth_url, username=user, cacert=cacert, insecure=insecure )
def setUp(self): super(NeutronTestCase, self).setUp() self.neutron_mock_client = mock.MagicMock() self.neutron_client_patch = \ mockpatch.PatchObject(neutron_client, 'Client', new=self.neutron_mock_client) self.useFixture(self.neutron_client_patch) self.identity_mock = mock.Mock() self.network_mock = mock.Mock() self.network_mock.neutron_client = self.neutron_mock_client self.fake_cloud = mock.MagicMock() self.fake_cloud.mysql_connector = mock.Mock() self.fake_cloud.resources = dict(identity=self.identity_mock, network=self.network_mock) self.neutron_network_client = \ neutron.NeutronNetwork(FAKE_CONFIG, self.fake_cloud) self.identity_mock.get_tenant_id_by_name = self.f_tenant_id_by_name self.identity_mock.get_tenants_func = \ mock.Mock(return_value=self.f_mock) self.neutron_network_client.get_lb_pools = mock.Mock() self.neutron_network_client.get_lb_pools.return_value = [{ 'name': 'pool2', 'description': 'desc2', 'tenant_name': 'fake_tenant_name_1', 'subnet_id': 'sub_id_2_src', 'id': 'pool_id_2_dst', 'protocol': 'HTTP', 'lb_method': 'SOURCE_IP', 'provider': 'haproxy', 'res_hash': 'hash2' }] self.net_1_info = { 'name': 'fake_network_name_1', 'id': 'fake_network_id_1', 'admin_state_up': True, 'shared': False, 'tenant_id': 'fake_tenant_id_1', 'tenant_name': 'fake_tenant_name_1', 'subnets': [mock.MagicMock()], 'router:external': False, 'provider:physical_network': None, 'provider:network_type': 'gre', 'provider:segmentation_id': 5, 'res_hash': 'fake_net_hash_1', 'subnets_hash': {'fake_subnet_hash_1'}, 'meta': {} } self.net_2_info = { 'name': 'fake_network_name_2', 'id': 'fake_network_id_2', 'admin_state_up': True, 'shared': False, 'tenant_id': 'fake_tenant_id_2', 'tenant_name': 'fake_tenant_name_2', 'subnet_names': ['fake_subnet_name_2'], 'router:external': False, 'provider:physical_network': 'physnet', 'provider:network_type': 'vlan', 'provider:segmentation_id': 10, 'res_hash': 'fake_net_hash_2', 'subnets_hash': {'fake_subnet_hash_2'}, 'meta': {} } self.subnet_1_info = { 'name': 'fake_subnet_name_1', 'id': 'fake_subnet_id_1', 'enable_dhcp': True, 'allocation_pools': [{ 'start': 'fake_start_ip_1', 'end': 'fake_end_ip_1' }], 'gateway_ip': 'fake_gateway_ip_1', 'ip_version': 4, 'cidr': '1.1.1.0/24', 'network_name': 'fake_network_name_1', 'external': False, 'network_id': 'fake_network_id_1', 'tenant_name': 'fake_tenant_name_1', 'res_hash': 'fake_subnet_hash_1', 'dns_nameservers': ['5.5.5.5'], 'meta': {} } self.subnet_2_info = { 'name': 'fake_subnet_name_2', 'id': 'fake_subnet_id_2', 'enable_dhcp': True, 'allocation_pools': [{ 'start': 'fake_start_ip_2', 'end': 'fake_end_ip_2' }], 'gateway_ip': 'fake_gateway_ip_2', 'ip_version': 4, 'cidr': '2.2.2.0/25', 'network_name': 'fake_network_name_2', 'external': False, 'network_id': 'fake_network_id_2', 'tenant_name': 'fake_tenant_name_2', 'res_hash': 'fake_subnet_hash_2', 'meta': {} } self.segmentation_ids = { 'gre': [2, 4, 6], 'vlan': [3, 5, 7], 'vxlan': [10, 20] }
def run(self, **kwargs): """Check write access to cloud.""" ks_client = keystone.KeystoneIdentity(config=self.cloud.cloud_config, cloud=self.dst_cloud) nt_client = neutron.NeutronNetwork(config=self.cloud.cloud_config, cloud=self.dst_cloud) gl_client = glance_image.GlanceImage(config=self.cloud.cloud_config, cloud=self.dst_cloud) cn_client = cinder.CinderStorage(config=self.cloud.cloud_config, cloud=self.dst_cloud) adm_tenant_name = self.cloud.cloud_config.cloud.tenant adm_tenant_id = ks_client.get_tenant_id_by_name(adm_tenant_name) unique = str(int(time.time())) tenant_name = 'tenant_%s' % unique flavor = { 'name': 'flavor_%s' % unique, 'is_public': True, 'ram': 1, 'vcpus': 1, 'disk': 1, } image_info = { 'name': 'image_%s' % unique, 'container_format': 'bare', 'disk_format': 'qcow2', 'is_public': True, 'protected': False, 'owner': adm_tenant_id, 'size': 4, 'properties': { 'user_name': 'test_user_name' }, 'data': 'test' } shared_network_info = { 'network': { 'tenant_id': adm_tenant_id, 'admin_state_up': True, 'shared': True, 'name': 'shared_net_%s' % unique, 'router:external': True } } try: with self.create_tenant(ks_client, tenant_name) as tenant, \ self.create_image(gl_client, image_info) as image_id, \ self.create_network(nt_client, shared_network_info): private_network_info = { 'network': { 'tenant_id': tenant.id, 'name': 'private_net_%s' % unique, } } volume_info = { 'size': 1, 'display_name': 'volume_%s' % unique, 'project_id': tenant.id } with self.create_network(nt_client, private_network_info) as \ private_network_id, \ self.create_volume(cn_client, volume_info): subnet_info = { 'subnet': { 'name': 'subnet_%s' % unique, 'network_id': private_network_id, 'cidr': '192.168.1.0/24', 'ip_version': 4, 'tenant_id': tenant.id, } } nv_client_config = copy.deepcopy(self.cloud.cloud_config) nv_client_config.cloud.tenant = tenant.name nv_client = nova_compute.NovaCompute( config=nv_client_config, cloud=self.dst_cloud) with self.create_subnet(nt_client, subnet_info), \ self.create_flavor(nv_client, flavor) as flavor_id: instance_info = { 'name': 'test_vm_%s' % unique, 'image': image_id, 'flavor': flavor_id, 'nics': [{ 'net-id': private_network_id }] } with self.create_instance(nv_client, instance_info): pass except (ks_exc.ClientException, nova_exc.ClientException, cinder_exc.ClientException, glance_exc.ClientException, neutron_exc.NeutronClientException) as e: raise exception.AbortMigrationError( "Destination cloud verification failed: {error_message}", error_message=e.message)