|
|
|
|
@@ -17,7 +17,6 @@ import os
|
|
|
|
|
import mock
|
|
|
|
|
|
|
|
|
|
from kubernetes import client as kubernetes_client
|
|
|
|
|
from kubernetes.client import api_client
|
|
|
|
|
from kubernetes.client.rest import ApiException
|
|
|
|
|
from rally import exceptions
|
|
|
|
|
from rally_openstack.scenarios.magnum import utils
|
|
|
|
|
@@ -136,7 +135,7 @@ class MagnumScenarioTestCase(test.ScenarioTestCase):
|
|
|
|
|
self.scenario.atomic_actions(), "magnum.create_ca_certificate")
|
|
|
|
|
|
|
|
|
|
@mock.patch("kubernetes.client.api_client.ApiClient")
|
|
|
|
|
@mock.patch("kubernetes.client.apis.core_v1_api.CoreV1Api")
|
|
|
|
|
@mock.patch("kubernetes.client.api.core_v1_api.CoreV1Api")
|
|
|
|
|
def test_get_k8s_api_client_using_tls(self, mock_core_v1_api,
|
|
|
|
|
mock_api_client):
|
|
|
|
|
|
|
|
|
|
@@ -184,7 +183,7 @@ class MagnumScenarioTestCase(test.ScenarioTestCase):
|
|
|
|
|
mock_core_v1_api.assert_called_once_with(_api_client)
|
|
|
|
|
|
|
|
|
|
@mock.patch("kubernetes.client.api_client.ApiClient")
|
|
|
|
|
@mock.patch("kubernetes.client.apis.core_v1_api.CoreV1Api")
|
|
|
|
|
@mock.patch("kubernetes.client.api.core_v1_api.CoreV1Api")
|
|
|
|
|
def test_get_k8s_api_client(self, mock_core_v1_api, mock_api_client):
|
|
|
|
|
|
|
|
|
|
if hasattr(kubernetes_client, "ConfigurationObject"):
|
|
|
|
|
@@ -246,23 +245,23 @@ class MagnumScenarioTestCase(test.ScenarioTestCase):
|
|
|
|
|
podname = podname + mock_random_choice.return_value
|
|
|
|
|
k8s_api.create_namespaced_pod = mock.MagicMock(
|
|
|
|
|
side_effect=[ApiException(status=403), self.pod])
|
|
|
|
|
not_ready_pod = api_client.models.V1Pod()
|
|
|
|
|
not_ready_status = api_client.models.V1PodStatus()
|
|
|
|
|
not_ready_pod = kubernetes_client.models.V1Pod()
|
|
|
|
|
not_ready_status = kubernetes_client.models.V1PodStatus()
|
|
|
|
|
not_ready_status.phase = "not_ready"
|
|
|
|
|
not_ready_pod.status = not_ready_status
|
|
|
|
|
almost_ready_pod = api_client.models.V1Pod()
|
|
|
|
|
almost_ready_status = api_client.models.V1PodStatus()
|
|
|
|
|
almost_ready_pod = kubernetes_client.models.V1Pod()
|
|
|
|
|
almost_ready_status = kubernetes_client.models.V1PodStatus()
|
|
|
|
|
almost_ready_status.phase = "almost_ready"
|
|
|
|
|
almost_ready_pod.status = almost_ready_status
|
|
|
|
|
ready_pod = api_client.models.V1Pod()
|
|
|
|
|
ready_condition = api_client.models.V1PodCondition(status="True",
|
|
|
|
|
type="Ready")
|
|
|
|
|
ready_status = api_client.models.V1PodStatus()
|
|
|
|
|
ready_pod = kubernetes_client.models.V1Pod()
|
|
|
|
|
ready_condition = kubernetes_client.models.V1PodCondition(
|
|
|
|
|
status="True", type="Ready")
|
|
|
|
|
ready_status = kubernetes_client.models.V1PodStatus()
|
|
|
|
|
ready_status.phase = "Running"
|
|
|
|
|
ready_status.conditions = [ready_condition]
|
|
|
|
|
ready_pod_metadata = api_client.models.V1ObjectMeta()
|
|
|
|
|
ready_pod_metadata = kubernetes_client.models.V1ObjectMeta()
|
|
|
|
|
ready_pod_metadata.uid = "123456789"
|
|
|
|
|
ready_pod_spec = api_client.models.V1PodSpec(
|
|
|
|
|
ready_pod_spec = kubernetes_client.models.V1PodSpec(
|
|
|
|
|
node_name="host_abc",
|
|
|
|
|
containers=[]
|
|
|
|
|
)
|
|
|
|
|
@@ -290,10 +289,10 @@ class MagnumScenarioTestCase(test.ScenarioTestCase):
|
|
|
|
|
"metadata": {"name": "nginx"}})
|
|
|
|
|
k8s_api.create_namespaced_pod.return_value = self.pod
|
|
|
|
|
mock_time.side_effect = [1, 2, 3, 4, 5, 1800, 1801]
|
|
|
|
|
not_ready_pod = api_client.models.V1Pod()
|
|
|
|
|
not_ready_status = api_client.models.V1PodStatus()
|
|
|
|
|
not_ready_pod = kubernetes_client.models.V1Pod()
|
|
|
|
|
not_ready_status = kubernetes_client.models.V1PodStatus()
|
|
|
|
|
not_ready_status.phase = "not_ready"
|
|
|
|
|
not_ready_pod_metadata = api_client.models.V1ObjectMeta()
|
|
|
|
|
not_ready_pod_metadata = kubernetes_client.models.V1ObjectMeta()
|
|
|
|
|
not_ready_pod_metadata.uid = "123456789"
|
|
|
|
|
not_ready_pod.status = not_ready_status
|
|
|
|
|
not_ready_pod.metadata = not_ready_pod_metadata
|
|
|
|
|
@@ -332,19 +331,20 @@ class MagnumScenarioTestCase(test.ScenarioTestCase):
|
|
|
|
|
for i in range(5):
|
|
|
|
|
suffix = suffix + mock_random_choice.return_value
|
|
|
|
|
rcname = manifest["metadata"]["name"] + suffix
|
|
|
|
|
rc = api_client.models.V1ReplicationController()
|
|
|
|
|
rc.spec = api_client.models.V1ReplicationControllerSpec()
|
|
|
|
|
rc = kubernetes_client.models.V1ReplicationController()
|
|
|
|
|
rc.spec = kubernetes_client.models.V1ReplicationControllerSpec()
|
|
|
|
|
rc.spec.replicas = manifest["spec"]["replicas"]
|
|
|
|
|
k8s_api.create_namespaced_replication_controller.return_value = rc
|
|
|
|
|
not_ready_rc = api_client.models.V1ReplicationController()
|
|
|
|
|
not_ready_rc = kubernetes_client.models.V1ReplicationController()
|
|
|
|
|
not_ready_rc_status = (
|
|
|
|
|
api_client.models.V1ReplicationControllerStatus(replicas=0))
|
|
|
|
|
kubernetes_client.models.V1ReplicationControllerStatus(replicas=0))
|
|
|
|
|
not_ready_rc.status = not_ready_rc_status
|
|
|
|
|
ready_rc = api_client.models.V1ReplicationController()
|
|
|
|
|
ready_rc_status = api_client.models.V1ReplicationControllerStatus(
|
|
|
|
|
replicas=manifest["spec"]["replicas"]
|
|
|
|
|
ready_rc = kubernetes_client.models.V1ReplicationController()
|
|
|
|
|
ready_rc_status = (
|
|
|
|
|
kubernetes_client.models.V1ReplicationControllerStatus(
|
|
|
|
|
replicas=manifest["spec"]["replicas"])
|
|
|
|
|
)
|
|
|
|
|
ready_rc_metadata = api_client.models.V1ObjectMeta()
|
|
|
|
|
ready_rc_metadata = kubernetes_client.models.V1ObjectMeta()
|
|
|
|
|
ready_rc_metadata.uid = "123456789"
|
|
|
|
|
ready_rc_metadata.name = rcname
|
|
|
|
|
ready_rc.status = ready_rc_status
|
|
|
|
|
@@ -374,15 +374,15 @@ class MagnumScenarioTestCase(test.ScenarioTestCase):
|
|
|
|
|
"template": {"metadata":
|
|
|
|
|
{"labels":
|
|
|
|
|
{"name": "nginx"}}}}})
|
|
|
|
|
rc = api_client.models.V1ReplicationController()
|
|
|
|
|
rc.spec = api_client.models.V1ReplicationControllerSpec()
|
|
|
|
|
rc = kubernetes_client.models.V1ReplicationController()
|
|
|
|
|
rc.spec = kubernetes_client.models.V1ReplicationControllerSpec()
|
|
|
|
|
rc.spec.replicas = manifest["spec"]["replicas"]
|
|
|
|
|
mock_time.side_effect = [1, 2, 3, 4, 5, 1800, 1801]
|
|
|
|
|
k8s_api.create_namespaced_replication_controller.return_value = rc
|
|
|
|
|
not_ready_rc = api_client.models.V1ReplicationController()
|
|
|
|
|
not_ready_rc = kubernetes_client.models.V1ReplicationController()
|
|
|
|
|
not_ready_rc_status = (
|
|
|
|
|
api_client.models.V1ReplicationControllerStatus(replicas=0))
|
|
|
|
|
not_ready_rc_metadata = api_client.models.V1ObjectMeta()
|
|
|
|
|
kubernetes_client.models.V1ReplicationControllerStatus(replicas=0))
|
|
|
|
|
not_ready_rc_metadata = kubernetes_client.models.V1ObjectMeta()
|
|
|
|
|
not_ready_rc_metadata.uid = "123456789"
|
|
|
|
|
not_ready_rc.status = not_ready_rc_status
|
|
|
|
|
not_ready_rc.metadata = not_ready_rc_metadata
|
|
|
|
|
|