def test_check_existing_image(self, mock_glance_create_client): ctx = self.existing_image_context sahara_ctx = sahara_image.SaharaImage(ctx) sahara_ctx.setup() mock_glance_create_client.images.get.asser_called_once_with("some_id")
def test_check_existing_private_image_fail(self, mock_clients_glance): mock_clients_glance.return_value.images.get.return_value = ( mock.MagicMock(is_public=False)) ctx = self.existing_image_context sahara_ctx = sahara_image.SaharaImage(ctx) self.assertRaises(exceptions.BenchmarkSetupFailure, sahara_ctx.setup) mock_clients_glance.images.get.asser_called_once_with("some_id")
def test_setup_and_cleanup_url_image(self, mock_clients, mock_cleanup, mock_image): ctx = self.url_image_context sahara_ctx = sahara_image.SaharaImage(ctx) sahara_ctx.generate_random_name = mock.Mock() image_service = mock.Mock() mock_image.return_value = image_service image_service.create_image.return_value = mock.Mock(id=42) clients = mock.Mock() mock_clients.return_value = clients sahara_client = mock.Mock() clients.sahara.return_value = sahara_client glance_calls = [] for i in range(self.tenants_num): glance_calls.append( mock.call(container_format="bare", image_location="http://somewhere", disk_format="qcow2")) sahara_update_image_calls = [] sahara_update_tags_calls = [] for i in range(self.tenants_num): sahara_update_image_calls.append( mock.call(image_id=42, user_name="test_user", desc="")) sahara_update_tags_calls.append( mock.call(image_id=42, new_tags=["test_plugin", "test_version"])) sahara_ctx.setup() image_service.create_image.assert_has_calls(glance_calls) sahara_client.images.update_image.assert_has_calls( sahara_update_image_calls) sahara_client.images.update_tags.assert_has_calls( sahara_update_tags_calls) sahara_ctx.cleanup() mock_cleanup.assert_called_once_with(names=["glance.images"], users=ctx["users"], superclass=sahara_ctx.__class__, task_id=ctx["owner_id"])
def test_setup_and_cleanup_existing_image( self, mock_clients, mock_cleanup, mock_glance_scenario__create_image): mock_clients.glance.images.get.return_value = mock.MagicMock( is_public=True) ctx = self.existing_image_context sahara_ctx = sahara_image.SaharaImage(ctx) sahara_ctx.setup() for tenant_id in sahara_ctx.context["tenants"]: image_id = sahara_ctx.context["tenants"][tenant_id]["sahara_image"] self.assertEqual("some_id", image_id) self.assertEqual(False, mock_glance_scenario__create_image.called) sahara_ctx.cleanup() self.assertEqual(False, mock_cleanup.called)
def test_setup_and_cleanup_url_image(self, mock_cleanup, mock_glance_scenario__create_image): ctx = self.url_image_context sahara_ctx = sahara_image.SaharaImage(ctx) sahara_ctx.generate_random_name = mock.Mock() glance_calls = [] for i in range(self.tenants_num): glance_calls.append( mock.call(container_format="bare", image_location="http://somewhere", disk_format="qcow2", name=sahara_ctx.generate_random_name.return_value)) sahara_update_image_calls = [] sahara_update_tags_calls = [] for i in range(self.tenants_num): sahara_update_image_calls.append( mock.call(image_id=42, user_name="test_user", desc="")) sahara_update_tags_calls.append( mock.call(image_id=42, new_tags=["test_plugin", "test_version"])) sahara_ctx.setup() mock_glance_scenario__create_image.assert_has_calls(glance_calls) self.clients("sahara").images.update_image.assert_has_calls( sahara_update_image_calls) self.clients("sahara").images.update_tags.assert_has_calls( sahara_update_tags_calls) sahara_ctx.cleanup() mock_cleanup.assert_called_once_with( names=["glance.images"], users=ctx["users"], superclass=glance_utils.GlanceScenario, task_id=ctx["task"]["uuid"])