def test_access_list_is_updated_for_non_public_flavors(self, _): flavors = { 'flavor1': { 'flavor': { 'is_public': False, 'name': 'flavor1', 'tenants': [], 'ram': 48, 'vcpus': 1, 'disk': 0, 'ephemeral': 1, 'swap': 0, 'rxtx_factor': 1.0, }, 'meta': {} } } tenant_map = {} config = mock.Mock() config.migrate.override_rules = None cloud = mock.MagicMock() cloud.position = 'dst' nc = nova_compute.NovaCompute(config, cloud) nc._create_flavor_if_not_exists = mock.Mock() nc._add_flavor_access_for_tenants = mock.Mock() nc.get_flavor_list = mock.Mock() nc.get_flavor_list.return_value = [] nc._deploy_flavors(flavors, tenant_map) assert nc._add_flavor_access_for_tenants.called
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.nova_endpoint_type = ep_type config.migrate.override_rules = None cloud.position = 'src' n = nova_compute.NovaCompute(config, cloud) n.get_client() n_client.assert_called_with(user, password, tenant, auth_url, cacert=cacert, insecure=insecure, region_name=None, endpoint_type=ep_type)
def setUp(self): super(BaseNovaComputeTestCase, self).setUp() self.override_config(FAKE_CONFIG) self.mock_client = mock.MagicMock() self.nc_patch = mockpatch.PatchObject(nova_client, 'Client', new=self.mock_client) self.useFixture(self.nc_patch) self.identity_mock = mock.Mock() self.fake_cloud = mock.Mock() self.fake_cloud.resources = dict(identity=self.identity_mock) self.fake_cloud.position = 'src' self.fake_cloud.config = self.cloud_config('src') with mock.patch('cloudferry.lib.os.compute.nova_compute.' 'mysql_connector'): self.nova_client = nova_compute.NovaCompute( self.fake_cloud.config, self.fake_cloud) self.fake_instance_0 = mock.Mock() self.fake_instance_1 = mock.Mock() self.fake_instance_0.id = 'fake_instance_id' self.fake_getter = mock.Mock() self.fake_flavor_0 = mock.Mock() self.fake_flavor_1 = mock.Mock() self.fake_tenant_quota_0 = mock.Mock()
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 config.migrate.override_rules = None cloud.position = 'src' n = nova_compute.NovaCompute(config, cloud) n.get_client() n_client.assert_called_with(user, password, tenant, auth_url, region_name=region, cacert=cacert, insecure=insecure)
def setUp(self): super(FlavorDeploymentTestCase, self).setUp() config = mock.Mock() config.migrate.override_rules = None cloud = mock.MagicMock() cloud.position = 'dst' self.nc = nova_compute.NovaCompute(config, cloud)
def test_flavor_is_not_created_if_already_exists_on_dest(self): existing_flavor = mock.Mock() existing_flavor.id = 'existing-id' existing_flavor.name = 'existing-name' existing_flavor.is_public = True existing_flavor.ram = 48 existing_flavor.vcpus = 1 existing_flavor.disk = 0 existing_flavor.ephemeral = 1 existing_flavor.swap = 0 existing_flavor.rxtx_factor = 1.0 flavors = { existing_flavor.id: { 'flavor': { 'is_public': True, 'name': existing_flavor.name, 'tenants': [], 'ram': 48, 'vcpus': 1, 'disk': 0, 'ephemeral': 1, 'swap': 0, 'rxtx_factor': 1.0, }, 'meta': {} } } config = mock.Mock() config.migrate.override_rules = None cloud = mock.MagicMock() cloud.position = 'dst' nc = nova_compute.NovaCompute(config, cloud) nc._create_flavor_if_not_exists = mock.Mock() nc.get_flavor_list = mock.Mock() nc.get_flavor_list.return_value = [existing_flavor] nc._deploy_flavors(flavors, tenant_map={}) assert not nc._create_flavor_if_not_exists.called
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)