コード例 #1
0
    def test_setup(self, mock_osclients, mock_image_create):

        tenants_count = 2
        users_per_tenant = 5
        images_per_tenant = 5

        fc = fakes.FakeClients()
        mock_osclients.Clients.return_value = fc

        tenants = self._gen_tenants(tenants_count)
        users = list()
        for id in tenants:
            for i in range(users_per_tenant):
                users.append({
                    "id": i,
                    "tenant_id": id,
                    "endpoint": "endpoint"
                })

        real_context = {
            "config": {
                "users": {
                    "tenants": tenants_count,
                    "users_per_tenant": users_per_tenant,
                    "concurrent": 10,
                },
                "images": {
                    "image_url": "mock_url",
                    "image_type": "qcow2",
                    "image_container": "bare",
                    "images_per_tenant": images_per_tenant,
                    "image_name": "some_name",
                    "min_ram": 128,
                    "min_disk": 1,
                }
            },
            "admin": {
                "endpoint": mock.MagicMock()
            },
            "task": mock.MagicMock(),
            "users": users,
            "tenants": tenants
        }

        new_context = copy.deepcopy(real_context)
        for id in new_context["tenants"].keys():
            new_context["tenants"][id].setdefault("images", list())
            for j in range(images_per_tenant):
                new_context["tenants"][id]["images"].append("uuid")

        images_ctx = images.ImageGenerator(real_context)
        images_ctx.setup()
        self.assertEqual(new_context, real_context)
コード例 #2
0
ファイル: test_images.py プロジェクト: x-ion-de/rally
    def test_init(self, mock_base_context_init):
        context = {}
        context["task"] = mock.MagicMock()
        context["config"] = {
            "images": {
                "image_url": "mock_url",
                "image_type": "qcow2",
                "image_container": "bare",
                "images_per_tenant": 4,
            }
        }

        images.ImageGenerator(context)
        mock_base_context_init.assert_called_once_with(context)
コード例 #3
0
    def test_cleanup(self, mock_cleanup, mock_osclients):

        tenants_count = 2
        users_per_tenant = 5
        images_per_tenant = 5

        tenants = self._gen_tenants(tenants_count)
        users = list()
        for id_ in tenants:
            for i in range(users_per_tenant):
                users.append({
                    "id": i,
                    "tenant_id": id_,
                    "endpoint": "endpoint"
                })
            tenants[id_].setdefault("images", list())
            for j in range(images_per_tenant):
                tenants[id_]["images"].append("uuid")

        context = {
            "config": {
                "users": {
                    "tenants": 2,
                    "users_per_tenant": 5,
                    "concurrent": 10,
                },
                "images": {
                    "image_url": "mock_url",
                    "image_type": "qcow2",
                    "image_container": "bare",
                    "images_per_tenant": 5,
                    "image_name": "some_name",
                    "min_ram": 128,
                    "min_disk": 1,
                }
            },
            "admin": {
                "endpoint": mock.MagicMock()
            },
            "task": mock.MagicMock(),
            "users": users,
            "tenants": tenants
        }

        images_ctx = images.ImageGenerator(context)
        images_ctx.cleanup()
        mock_cleanup.assert_called_once_with(names=["glance.images"],
                                             users=context["users"])
コード例 #4
0
ファイル: test_images.py プロジェクト: sahanasj/rally
    def test_init(self):
        context = {}
        context["task"] = mock.MagicMock()
        context["config"] = {
            "images": {
                "image_url": "mock_url",
                "image_type": "qcow2",
                "image_container": "bare",
                "images_per_tenant": 4,
            }
        }

        new_context = copy.deepcopy(context)
        new_context["images"] = []
        images.ImageGenerator(context)
        self.assertEqual(new_context, context)
コード例 #5
0
ファイル: test_images.py プロジェクト: sahanasj/rally
    def test_setup(self, mock_osclients, mock_image_create):

        fc = fakes.FakeClients()
        mock_osclients.Clients.return_value = fc

        image_list = ["uuid"] * 5
        image_key = [{
            'image_id': image_list,
            'endpoint': 'endpoint',
            'tenant_id': i
        } for i in range(2)]
        user_key = [{
            'id': i,
            'tenant_id': j,
            'endpoint': 'endpoint'
        } for j in range(2) for i in range(5)]

        real_context = {
            "config": {
                "users": {
                    "tenants": 2,
                    "users_per_tenant": 5,
                    "concurrent": 10,
                },
                "images": {
                    "image_url": "mock_url",
                    "image_type": "qcow2",
                    "image_container": "bare",
                    "images_per_tenant": 5,
                }
            },
            "admin": {
                "endpoint": mock.MagicMock()
            },
            "task": mock.MagicMock(),
            "users": user_key,
        }

        new_context = copy.deepcopy(real_context)
        new_context["images"] = image_key

        images_ctx = images.ImageGenerator(real_context)
        images_ctx.setup()
        self.assertEqual(new_context, real_context)
コード例 #6
0
ファイル: test_images.py プロジェクト: sahanasj/rally
    def test_cleanup(self, mock_image_remover, mock_osclients):
        image_list = ["uuid"] * 5
        image_key = [{
            'image_id': image_list,
            'endpoint': 'endpoint',
            'tenant_id': i
        } for i in range(2)]
        user_key = [{
            'id': i,
            'tenant_id': j,
            'endpoint': 'endpoint'
        } for j in range(2) for i in range(5)]

        context = {
            "config": {
                "users": {
                    "tenants": 2,
                    "users_per_tenant": 5,
                    "concurrent": 10,
                },
                "images": {
                    "image_url": "mock_url",
                    "image_type": "qcow2",
                    "image_container": "bare",
                    "images_per_tenant": 5,
                }
            },
            "admin": {
                "endpoint": mock.MagicMock()
            },
            "task": mock.MagicMock(),
            "users": user_key,
            "images": image_key,
        }

        images_ctx = images.ImageGenerator(context)
        images_ctx.cleanup()

        self.assertEqual(2, len(mock_image_remover.mock_calls))

        mock_image_remover.side_effect = Exception('failed_deletion')
        self.assertRaises(exceptions.ImageCleanUpException, images_ctx.cleanup)