def cleanup(self): for user, tenant_id in rutils.iterate_per_tenants( self.context["users"]): magnum_scenario = magnum_utils.MagnumScenario({ "user": user, "task": self.context["task"], "config": { "api_versions": self.context["config"].get("api_versions", []) } }) # get the cluster and cluster_template cluster_uuid = str(self.context["tenants"][tenant_id]["cluster"]) cluster = magnum_scenario._get_cluster(cluster_uuid) cluster_template = magnum_scenario._get_cluster_template( cluster.cluster_template_id) if not cluster_template.tls_disabled: dir = self.context["ca_certs_directory"] fname = os.path.join(dir, cluster_uuid + ".key") os.remove(fname) fname = os.path.join(dir, cluster_uuid + "_ca.crt") os.remove(fname) fname = os.path.join(dir, cluster_uuid + ".crt") os.remove(fname)
def test_get_k8s_api_client_using_tls(self, mock_core_v1_api, mock_api_client): if hasattr(kubernetes_client, "ConfigurationObject"): # it is k8s-client < 4.0.0 m = mock.patch("kubernetes.client.ConfigurationObject") else: m = mock.patch("kubernetes.client.Configuration") mock_configuration_object = m.start() self.addCleanup(m.stop) self.context.update({ "ca_certs_directory": "/home/stack", "tenant": { "id": "rally_tenant_id", "cluster": "rally_cluster_uuid" } }) self.scenario = utils.MagnumScenario(self.context) cluster_uuid = self.context["tenant"]["cluster"] client = self.clients("magnum") client.clusters.get.return_value = self.cluster cluster = self.scenario._get_cluster(cluster_uuid) self.cluster_template.tls_disabled = False client.cluster_templates.get.return_value = self.cluster_template dir = self.context["ca_certs_directory"] key_file = os.path.join(dir, cluster_uuid.__add__(".key")) cert_file = os.path.join(dir, cluster_uuid.__add__(".crt")) ca_certs = os.path.join(dir, cluster_uuid.__add__("_ca.crt")) config = mock_configuration_object.return_value config.host = cluster.api_address config.ssl_ca_cert = ca_certs config.cert_file = cert_file config.key_file = key_file _api_client = mock_api_client.return_value self.scenario._get_k8s_api_client() mock_configuration_object.assert_called_once_with() if hasattr(kubernetes_client, "ConfigurationObject"): # k8s-python < 4.0.0 mock_api_client.assert_called_once_with(config=config) else: mock_api_client.assert_called_once_with(config) mock_core_v1_api.assert_called_once_with(_api_client)
def setup(self): for user, tenant_id in self._iterate_per_tenants(): magnum_scenario = magnum_utils.MagnumScenario({ "user": user, "task": self.context["task"], "owner_id": self.context["owner_id"], "config": { "api_versions": self.context["config"].get("api_versions", []) } }) cluster_template = magnum_scenario._create_cluster_template( **self.config) ct_uuid = cluster_template.uuid self.context["tenants"][tenant_id]["cluster_template"] = ct_uuid
def setup(self): for user, tenant_id in self._iterate_per_tenants(): magnum_scenario = magnum_utils.MagnumScenario({ "user": user, "task": self.context["task"], "config": { "api_versions": self.context["config"].get("api_versions", []) } }) # get the cluster and cluster_template cluster_uuid = str(self.context["tenants"][tenant_id]["cluster"]) cluster = magnum_scenario._get_cluster(cluster_uuid) cluster_template = magnum_scenario._get_cluster_template( cluster.cluster_template_id) if not cluster_template.tls_disabled: tls = self._generate_csr_and_key() dir = "" if self.config.get("directory") is not None: dir = self.config.get("directory") self.context["ca_certs_directory"] = dir fname = os.path.join(dir, cluster_uuid + ".key") with open(fname, "w") as key_file: key_file.write(tls["key"]) # get CA certificate for this cluster ca_cert = magnum_scenario._get_ca_certificate(cluster_uuid) fname = os.path.join(dir, cluster_uuid + "_ca.crt") with open(fname, "w") as ca_cert_file: ca_cert_file.write(ca_cert.pem) # send csr to Magnum to have it signed csr_req = {"cluster_uuid": cluster_uuid, "csr": tls["csr"]} cert = magnum_scenario._create_ca_certificate(csr_req) fname = os.path.join(dir, cluster_uuid + ".crt") with open(fname, "w") as cert_file: cert_file.write(cert.pem)
def setup(self): for user, tenant_id in self._iterate_per_tenants(): nova_scenario = nova_utils.NovaScenario({ "user": user, "task": self.context["task"], "owner_id": self.context["owner_id"], "config": { "api_versions": self.context["config"].get("api_versions", []) } }) keypair = nova_scenario._create_keypair() magnum_scenario = magnum_utils.MagnumScenario({ "user": user, "task": self.context["task"], "owner_id": self.context["owner_id"], "config": { "api_versions": self.context["config"].get("api_versions", []) } }) # create a cluster ct_uuid = self.config.get("cluster_template_uuid", None) if ct_uuid is None: ctx = self.context["tenants"][tenant_id] ct_uuid = ctx.get("cluster_template") cluster = magnum_scenario._create_cluster( cluster_template=ct_uuid, node_count=self.config.get("node_count"), keypair=keypair) self.context["tenants"][tenant_id]["cluster"] = cluster.uuid
def test_get_k8s_api_client(self, mock_core_v1_api, mock_api_client): if hasattr(kubernetes_client, "ConfigurationObject"): # it is k8s-client < 4.0.0 m = mock.patch("kubernetes.client.ConfigurationObject") else: m = mock.patch("kubernetes.client.Configuration") mock_configuration_object = m.start() self.addCleanup(m.stop) self.context.update({ "tenant": { "id": "rally_tenant_id", "cluster": "rally_cluster_uuid" } }) self.scenario = utils.MagnumScenario(self.context) cluster_uuid = self.context["tenant"]["cluster"] client = self.clients("magnum") client.clusters.get.return_value = self.cluster cluster = self.scenario._get_cluster(cluster_uuid) self.cluster_template.tls_disabled = True client.cluster_templates.get.return_value = self.cluster_template config = mock_configuration_object.return_value config.host = cluster.api_address config.ssl_ca_cert = None config.cert_file = None config.key_file = None _api_client = mock_api_client.return_value self.scenario._get_k8s_api_client() mock_configuration_object.assert_called_once_with() if hasattr(kubernetes_client, "ConfigurationObject"): # k8s-python < 4.0.0 mock_api_client.assert_called_once_with(config=config) else: mock_api_client.assert_called_once_with(config) mock_core_v1_api.assert_called_once_with(_api_client)
def setUp(self): super(MagnumScenarioTestCase, self).setUp() self.cluster_template = mock.Mock() self.cluster = mock.Mock() self.pod = mock.Mock() self.scenario = utils.MagnumScenario(self.context)