Esempio n. 1
0
    def test__generate_csr_and_key(self):

        ca_cert_ctx = ca_certs.CaCertGenerator(self.context)
        result = ca_cert_ctx._generate_csr_and_key()

        assert result["csr"] is not None
        assert result["key"] is not None
Esempio n. 2
0
    def test_tls_disabled_cleanup(self, mock_magnum_scenario__get_cluster,
                                  mock_magnum_scenario__get_cluster_template,
                                  mock_os_path_join, mock_os_remove):

        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": {},
            "ca_certs_directory": "",
            "users": users,
            "tenants": tenants
        })

        fake_ct = mock.Mock()
        fake_ct.tls_disabled = True
        mock_magnum_scenario__get_cluster_template.return_value = fake_ct

        ca_cert_ctx = ca_certs.CaCertGenerator(self.context)
        ca_cert_ctx.cleanup()

        mock_os_path_join.assert_not_called()
        mock_os_remove.assert_not_called()
Esempio n. 3
0
    def test_tls_disabled_setup(self, mock_magnum_scenario__get_cluster,
                                mock_magnum_scenario__get_cluster_template,
                                mock_magnum_scenario__get_ca_certificate,
                                mock_magnum_scenario__create_ca_certificate):
        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
                },
                "ca_certs": {
                    "directory": ""
                }
            },
            "users": users,
            "tenants": tenants
        })

        fake_ct = mock.Mock()
        fake_ct.tls_disabled = True
        mock_magnum_scenario__get_cluster_template.return_value = fake_ct

        ca_cert_ctx = ca_certs.CaCertGenerator(self.context)
        ca_cert_ctx.setup()

        mock_cluster = mock_magnum_scenario__get_cluster.return_value
        mock_calls = [
            mock.call(mock_cluster.cluster_template_id)
            for i in range(tenants_count)
        ]
        mock_magnum_scenario__get_cluster_template.assert_has_calls(mock_calls)
        mock_calls = [
            mock.call("rally_cluster_uuid") for i in range(tenants_count)
        ]
        mock_magnum_scenario__get_cluster.assert_has_calls(mock_calls)
        mock_magnum_scenario__get_ca_certificate.assert_not_called()
        mock_magnum_scenario__create_ca_certificate.assert_not_called()
Esempio n. 4
0
    def test_cleanup(self, mock_magnum_scenario__get_cluster,
                     mock_magnum_scenario__get_cluster_template,
                     mock_os_path_join, mock_os_remove):

        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": {},
            "ca_certs_directory": "",
            "users": users,
            "tenants": tenants
        })

        fake_ct = mock.Mock()
        fake_ct.tls_disabled = False
        mock_magnum_scenario__get_cluster_template.return_value = fake_ct

        ca_cert_ctx = ca_certs.CaCertGenerator(self.context)
        ca_cert_ctx.cleanup()

        cluster_uuid = "rally_cluster_uuid"
        dir = self.context["ca_certs_directory"]
        mock_os_path_join.assert_has_calls(dir, cluster_uuid.__add__(".key"))
        mock_os_path_join.assert_has_calls(dir,
                                           cluster_uuid.__add__("_ca.crt"))
        mock_os_path_join.assert_has_calls(dir, cluster_uuid.__add__(".crt"))