def test_access_list_is_updated_for_non_public_flavors(self): flavors = { 'flavor1': { 'flavor': { 'is_public': False, 'name': 'flavor1', 'tenants': [] }, 'meta': {} } } tenant_map = {} config = mock.Mock() 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 setUp(self): super(NovaComputeTestCase, self).setUp() 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' with mock.patch( 'cloudferrylib.os.compute.nova_compute.mysql_connector'): self.nova_client = nova_compute.NovaCompute(FAKE_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_flavor_is_not_created_if_already_exists_on_dest(self): existing_flavor = mock.Mock() existing_flavor.id = 'existing-id' existing_flavor.name = 'existing-name' flavors = { existing_flavor.id: { 'flavor': { 'is_public': True, 'name': existing_flavor.name, 'tenants': [] }, 'meta': {} } } config = mock.Mock() 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 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 = '' 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.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)
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_flavor_is_updated_with_destination_id(self): config = mock.Mock() cloud = mock.MagicMock() cloud.position = 'dst' expected_id = 'flavor1' existing_flavor = mock.Mock() existing_flavor.id = 'non-public-flavor' existing_flavor.name = 'non-public-flavor' created_flavor = mock.Mock() created_flavor.id = expected_id nc = nova_compute.NovaCompute(config, cloud) nc.get_flavor_list = mock.MagicMock() nc.get_flavor_list.return_value = [existing_flavor] nc.add_flavor_access = mock.MagicMock() nc._create_flavor_if_not_exists = mock.MagicMock() nc._create_flavor_if_not_exists.return_value = created_flavor flavors = { expected_id: { 'flavor': { 'is_public': True, 'name': 'flavor1', 'tenants': [] }, 'meta': {} }, existing_flavor.id: { 'flavor': { 'is_public': False, 'name': existing_flavor.name, 'tenants': ['t1', 't2'] }, 'meta': {} } } tenant_map = { 't1': 't1dest', 't2': 't2dest', } nc._deploy_flavors(flavors, tenant_map) for f in flavors: self.assertTrue('id' in flavors[f]['meta']) self.assertEqual(flavors[f]['meta']['id'], f)
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 = '******' config.cloud.region = None config.cloud.user = user config.cloud.tenant = tenant config.cloud.auth_url = auth_url config.cloud.password = password n = nova_compute.NovaCompute(config, cloud) n.get_client() n_client.assert_called_with(user, password, tenant, auth_url)
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