예제 #1
0
    def test_get_server(self, mock_get_service_by_name, mock_get_node_ip,
                        mock_get_pod_by_name):
        class Service(object):
            def __init__(self):
                self.name = 'yardstick'
                self.node_port = 30000

        class Services(object):
            def __init__(self):
                self.ports = [Service()]

        class Status(object):
            def __init__(self):
                self.pod_ip = '172.16.10.131'

        class Pod(object):
            def __init__(self):
                self.status = Status()

        k8s_context = KubernetesContext()
        k8s_context.init(context_cfg)

        mock_get_service_by_name.return_value = Services()
        mock_get_pod_by_name.return_value = Pod()
        mock_get_node_ip.return_value = '172.16.10.131'

        server = k8s_context._get_server('server')
        self.assertIsNotNone(server)
예제 #2
0
    def test_get_server(self, mock_get_pod_list):
        k8s_context = KubernetesContext()
        k8s_context.init(context_cfg)

        mock_get_pod_list.return_value.items = []
        server = k8s_context._get_server('server')
        self.assertIsNone(server)
예제 #3
0
    def test_ssh_key(self, mock_create, mock_delete):

        k8s_context = KubernetesContext()
        k8s_context.init(context_cfg)
        k8s_context._set_ssh_key()
        k8s_context._delete_ssh_key()
        self.assertTrue(mock_create.called)
        self.assertTrue(mock_delete.called)
예제 #4
0
    def test_ssh_key(self, mock_create, mock_delete, mock_open, mock_utils,
                     mock_resources, mock_paramiko):

        k8s_context = KubernetesContext()
        k8s_context.init(context_cfg)
        k8s_context._set_ssh_key()
        k8s_context._delete_ssh_key()
        self.assertTrue(mock_create.called)
        self.assertTrue(mock_delete.called)
예제 #5
0
    def test_wait_until_running(self, mock_read_pod_status):

        k8s_context = KubernetesContext()
        k8s_context.init(context_cfg)
        k8s_context.template.pods = ['server']
        mock_read_pod_status.return_value = 'Running'
        k8s_context._wait_until_running()
예제 #6
0
    def test_undeploy(self, mock_delete_pods, mock_delete_rcs, mock_delete_ssh,
                      mock_delete_services):

        k8s_context = KubernetesContext()
        k8s_context.init(context_cfg)
        k8s_context.undeploy()
        self.assertTrue(mock_delete_ssh.called)
        self.assertTrue(mock_delete_rcs.called)
        self.assertTrue(mock_delete_pods.called)
        self.assertTrue(mock_delete_services.called)
예제 #7
0
    def test_deploy(self, mock_set_ssh_key, mock_create_rcs, mock_get_rc_pods,
                    mock_wait_until_running, mock_create_services):

        k8s_context = KubernetesContext()
        k8s_context.init(context_cfg)
        with mock.patch("yardstick.benchmark.contexts.kubernetes.time"):
            k8s_context.deploy()
        self.assertTrue(mock_set_ssh_key.called)
        self.assertTrue(mock_create_rcs.called)
        self.assertTrue(mock_create_services.called)
        self.assertTrue(mock_get_rc_pods.called)
        self.assertTrue(mock_wait_until_running.called)
예제 #8
0
 def test_delete_services(self, mock_delete):
     k8s_context = KubernetesContext()
     k8s_context.init(context_cfg)
     k8s_context._delete_services()
     self.assertTrue(mock_delete.called)
예제 #9
0
    def test_get_node_ip(self, mock_get_node_list):

        k8s_context = KubernetesContext()
        k8s_context.init(context_cfg)
        k8s_context._get_node_ip()
        self.assertTrue(mock_get_node_list.called)
예제 #10
0
 def test_delete_rc(self, mock_delete_replication_controller):
     k8s_context = KubernetesContext()
     k8s_context.init(context_cfg)
     k8s_context._delete_rc({})
     self.assertTrue(mock_delete_replication_controller.called)
예제 #11
0
 def test_create_rcs(self, mock_create_rc):
     k8s_context = KubernetesContext()
     k8s_context.init(context_cfg)
     k8s_context._create_rcs()
     self.assertTrue(mock_create_rc.called)