def test_image_valid_on_flavor_fail(self, mock_osclients): fakegclient = fakes.FakeGlanceClient() image = fakes.FakeImage() image.min_ram = 1 image.size = 1 image.min_disk = 1 fakegclient.images.get = mock.MagicMock(return_value=image) mock_osclients.glance.return_value = fakegclient fakenclient = fakes.FakeNovaClient() flavor = fakes.FakeFlavor() flavor.ram = 0 flavor.disk = 0 fakenclient.flavors.get = mock.MagicMock(return_value=flavor) mock_osclients.nova.return_value = fakenclient validator = validation.image_valid_on_flavor("flavor", "image") result = validator(clients=mock_osclients, flavor={"id": flavor.id}, image={"id": image.id}) fakenclient.flavors.get.assert_called_once_with(flavor=flavor.id) fakegclient.images.get.assert_called_once_with(image=image.id) self.assertFalse(result.is_valid) self.assertIsNotNone(result.msg)
def test_create_image_and_boot_instances(self, mock_osclients, mock_create_image, mock_boot_servers, mock_random_name): glance_scenario = images.GlanceImages() nova_scenario = servers.NovaServers() fc = fakes.FakeClients() mock_osclients.Clients.return_value = fc fake_glance = fakes.FakeGlanceClient() fc.glance = lambda: fake_glance fake_nova = fakes.FakeNovaClient() fc.nova = lambda: fake_nova user_endpoint = endpoint.Endpoint("url", "user", "password", "tenant") nova_scenario._clients = osclients.Clients(user_endpoint) fake_image = fakes.FakeImage() fake_servers = [object() for i in range(5)] mock_create_image.return_value = fake_image mock_boot_servers.return_value = fake_servers mock_random_name.return_value = "random_name" kwargs = {'fakearg': 'f'} with mock.patch("rally.benchmark.scenarios.glance.utils.time.sleep"): glance_scenario.\ create_image_and_boot_instances("cf", "url", "df", "fid", 5, **kwargs) mock_create_image.assert_called_once_with("random_name", "cf", "url", "df", **kwargs) mock_boot_servers.assert_called_once_with("random_name", "image-id-0", "fid", 5, **kwargs)
def test_image_valid_on_flavor_flavor_not_exist(self, mock_osclients): fakegclient = fakes.FakeGlanceClient() mock_osclients.glance.return_value = fakegclient fakenclient = fakes.FakeNovaClient() fakenclient.flavors = mock.MagicMock() fakenclient.flavors.get.side_effect = nova_exc.NotFound(code=404) mock_osclients.nova.return_value = fakenclient validator = validation.image_valid_on_flavor("flavor", "image") test_img_id = "test_image_id" test_flavor_id = 101 config = { "args": { "flavor": { "id": test_flavor_id }, "image": { "id": test_img_id } } } result = validator(config, clients=mock_osclients, task=None) fakenclient.flavors.get.assert_called_once_with(flavor=test_flavor_id) self.assertFalse(result.is_valid) self.assertEqual(result.msg, "Flavor with id '101' not found")
def test_image_valid_on_missing_flavor_disk(self, mock_osclients): fakegclient = fakes.FakeGlanceClient() image = fakes.FakeImage() image.min_ram = 0 image.size = 0 image.min_disk = 100 fakegclient.images.get = mock.MagicMock(return_value=image) mock_osclients.glance.return_value = fakegclient fakenclient = fakes.FakeNovaClient() flavor = fakes.FakeFlavor() flavor.ram = 1 fakenclient.flavors.get = mock.MagicMock(return_value=flavor) mock_osclients.nova.return_value = fakenclient validator = validation.image_valid_on_flavor("flavor", "image") config = { "args": { "image": { "id": image.id }, "flavor": { "id": flavor.id } } } result = validator(config, clients=mock_osclients, task=None) fakenclient.flavors.get.assert_called_once_with(flavor=flavor.id) fakegclient.images.get.assert_called_once_with(image=image.id) self.assertTrue(result.is_valid)
def test_image_exists(self, mock_osclients): fakegclient = fakes.FakeGlanceClient() fakegclient.images.get = mock.MagicMock() mock_osclients.glance.return_value = fakegclient validator = validation.image_exists("image_id") test_img_id = "test_image_id" result = validator(clients=mock_osclients, image_id=test_img_id) fakegclient.images.get.assert_called_once_with(image=test_img_id) self.assertTrue(result.is_valid) self.assertIsNone(result.msg)
def test_image_exists_fail(self, mock_osclients): fakegclient = fakes.FakeGlanceClient() fakegclient.images.get = mock.MagicMock() fakegclient.images.get.side_effect = glance_exc.HTTPNotFound mock_osclients.glance.return_value = fakegclient validator = validation.image_exists("image_id") test_img_id = "test_image_id" result = validator(clients=mock_osclients, image_id=test_img_id) fakegclient.images.get.assert_called_once_with(image=test_img_id) self.assertFalse(result.is_valid) self.assertIsNotNone(result.msg)
def test_image_exists(self, mock_osclients): fakegclient = fakes.FakeGlanceClient() fakegclient.images.get = mock.MagicMock() mock_osclients.glance.return_value = fakegclient validator = validation.image_exists("image") test_img_id = "test_image_id" resource = {"id": test_img_id} config = {"args": {"image": resource}} result = validator(config, clients=mock_osclients, task=None) fakegclient.images.get.assert_called_once_with(image=test_img_id) self.assertTrue(result.is_valid) self.assertIsNone(result.msg)
def setUp(self): super(ShowCommandsTestCase, self).setUp() self.show = show.ShowCommands() self.fake_endpoint = { 'username': '******', 'password': '******', 'tenant_name': 'fake_tenant_name', 'auth_url': 'http://fake.auth.url' } self.fake_deploy_id = str(uuid.uuid4) self.fake_clients = fakes.FakeClients() self.fake_glance_client = fakes.FakeGlanceClient() self.fake_nova_client = fakes.FakeNovaClient()
def setUp(self): super(ShowCommandsTestCase, self).setUp() self.show = show.ShowCommands() self.fake_endpoint = { 'username': '******', 'password': '******', 'tenant_name': 'fake_tenant_name', 'auth_url': 'http://fake.auth.url' } self.fake_deploy_id = '7f6e88e0-897e-45c0-947c-595ce2437bee' self.fake_clients = fakes.FakeClients() self.fake_glance_client = fakes.FakeGlanceClient() self.fake_nova_client = fakes.FakeNovaClient()
def test_glance(self): with mock.patch("rally.osclients.glance") as mock_glance: fake_glance = fakes.FakeGlanceClient() mock_glance.Client = mock.MagicMock(return_value=fake_glance) self.assertTrue("glance" not in self.clients.cache) client = self.clients.glance() self.assertEqual(client, fake_glance) kw = { "endpoint": self.service_catalog.url_for.return_value, "token": self.fake_keystone.auth_token, "timeout": cfg.CONF.openstack_client_http_timeout, "insecure": False, "cacert": None } self.service_catalog.url_for.assert_called_once_with( service_type='image', endpoint_type='public', region_name=self.endpoint.region_name) mock_glance.Client.assert_called_once_with("1", **kw) self.assertEqual(self.clients.cache["glance"], fake_glance)
def test_glance(self): with mock.patch("rally.osclients.glance") as mock_glance: fake_glance = fakes.FakeGlanceClient() mock_glance.Client = mock.MagicMock(return_value=fake_glance) kc = fakes.FakeKeystoneClient() self.clients.keystone = mock.MagicMock(return_value=kc) self.assertTrue("glance" not in self.clients.cache) client = self.clients.glance() self.assertEqual(client, fake_glance) endpoint = kc.service_catalog.get_endpoints()["image"][0] kw = { "endpoint": endpoint["publicURL"], "token": kc.auth_token, "timeout": cfg.CONF.openstack_client_http_timeout, "insecure": False, "cacert": None, "region_name": None } mock_glance.Client.assert_called_once_with("1", **kw) self.assertEqual(self.clients.cache["glance"], fake_glance)
def test_image_invalid_on_size(self, mock_osclients): fakegclient = fakes.FakeGlanceClient() image = fakes.FakeImage() image.min_ram = 0 image.size = 0 image.min_disk = 100 fakegclient.images.get = mock.MagicMock(return_value=image) mock_osclients.glance.return_value = fakegclient fakenclient = fakes.FakeNovaClient() flavor = fakes.FakeFlavor() flavor.ram = 1 flavor.disk = 99 fakenclient.flavors.get = mock.MagicMock(return_value=flavor) mock_osclients.nova.return_value = fakenclient validator = validation.image_valid_on_flavor("flavor", "image") config = { "args": { "image": { "id": image.id }, "flavor": { "id": flavor.id } } } result = validator(config, clients=mock_osclients, task=None) fakenclient.flavors.get.assert_called_once_with(flavor=flavor.id) fakegclient.images.get.assert_called_once_with(image=image.id) self.assertFalse(result.is_valid) self.assertEqual( result.msg, _("The disk size for flavor 'flavor-id-0'" " is too small for requested image 'image-id-0'"))
def test_image_valid_on_flavor_image_not_exist(self, mock_osclients): fakegclient = fakes.FakeGlanceClient() fakegclient.images.get = mock.MagicMock() fakegclient.images.get.side_effect = glance_exc.HTTPNotFound mock_osclients.glance.return_value = fakegclient fakenclient = fakes.FakeNovaClient() flavor = fakes.FakeFlavor() fakenclient.flavors.get = mock.MagicMock(return_value=flavor) mock_osclients.nova.return_value = fakenclient validator = validation.image_valid_on_flavor("flavor", "image") test_img_id = "test_image_id" result = validator(clients=mock_osclients, flavor={"id": flavor.id}, image={"id": test_img_id}) fakenclient.flavors.get.assert_called_once_with(flavor=flavor.id) fakegclient.images.get.assert_called_once_with(image=test_img_id) self.assertFalse(result.is_valid) self.assertEqual(result.msg, "Image with id 'test_image_id' not found")