Example #1
0
    def test_setup(self, mock__create_cluster):
        tenants_count = 2
        users_per_tenant = 5

        tenants = self._gen_tenants_with_cluster_template(tenants_count)
        users = []
        for ten_id in tenants:
            for i in range(users_per_tenant):
                users.append({
                    "id": i,
                    "tenant_id": ten_id,
                    "credential": mock.MagicMock()
                })

        self.context.update({
            "config": {
                "users": {
                    "tenants": tenants_count,
                    "users_per_tenant": users_per_tenant,
                    "concurrent": 10,
                },
                "cluster_templates": {
                    "dns_nameserver": "8.8.8.8",
                    "external_network_id": "public",
                    "flavor_id": "m1.small",
                    "docker_volume_size": 5,
                    "coe": "kubernetes",
                    "image_id": "fedora-atomic-latest",
                    "network_driver": "flannel"
                },
                "clusters": {
                    "node_count": 2
                }
            },
            "users": users,
            "tenants": tenants
        })

        mock_cluster = mock__create_cluster.return_value
        new_context = copy.deepcopy(self.context)
        for id_ in new_context["tenants"]:
            new_context["tenants"][id_]["cluster"] = mock_cluster.uuid

        cluster_ctx = clusters.ClusterGenerator(self.context)
        cluster_ctx.setup()

        self.assertEqual(new_context, self.context)
        cluster_ctx_config = self.context["config"]["clusters"]
        node_count = cluster_ctx_config.get("node_count")
        mock_calls = [
            mock.call(cluster_template="rally_ct_uuid", node_count=node_count)
            for i in range(tenants_count)
        ]
        mock__create_cluster.assert_has_calls(mock_calls)
Example #2
0
 def test_cleanup(self, mock_cleanup):
     self.context.update({
         "users": mock.MagicMock()
     })
     clusters_ctx = clusters.ClusterGenerator(self.context)
     clusters_ctx.cleanup()
     mock_cleanup.assert_called_once_with(
         names=["magnum.clusters"],
         users=self.context["users"],
         superclass=magnum_utils.MagnumScenario,
         task_id=self.context["owner_id"])
Example #3
0
    def test_setup_using_existing_cluster_template(self, mock__create_cluster):
        tenants_count = 2
        users_per_tenant = 5

        tenants = self._gen_tenants(tenants_count)
        users = []
        for ten_id in tenants:
            for i in range(users_per_tenant):
                users.append({
                    "id": i,
                    "tenant_id": ten_id,
                    "credential": mock.MagicMock()
                })

        self.context.update({
            "config": {
                "users": {
                    "tenants": tenants_count,
                    "users_per_tenant": users_per_tenant,
                    "concurrent": 10,
                },
                "clusters": {
                    "cluster_template_uuid": "123456789",
                    "node_count": 2
                }
            },
            "users": users,
            "tenants": tenants
        })

        mock_cluster = mock__create_cluster.return_value
        new_context = copy.deepcopy(self.context)
        for id_ in new_context["tenants"]:
            new_context["tenants"][id_]["cluster"] = mock_cluster.uuid

        cluster_ctx = clusters.ClusterGenerator(self.context)
        cluster_ctx.setup()

        self.assertEqual(new_context, self.context)
        cluster_ctx_config = self.context["config"]["clusters"]
        node_count = cluster_ctx_config.get("node_count")
        cluster_template_uuid = cluster_ctx_config.get("cluster_template_uuid")
        mock_calls = [
            mock.call(cluster_template=cluster_template_uuid,
                      node_count=node_count) for i in range(tenants_count)
        ]
        mock__create_cluster.assert_has_calls(mock_calls)
Example #4
0
 def test_cleanup(self, mock_cleanup):
     self.context.update({"users": mock.MagicMock()})
     clusters_ctx = clusters.ClusterGenerator(self.context)
     clusters_ctx.cleanup()
     mock_cleanup.assert_called_once_with(names=["magnum.clusters"],
                                          users=self.context["users"])