Beispiel #1
0
    def test_pod_affinities(self):
        config = _utils.create_config()
        container = _utils.create_container(name="nginx", image="nginx:latest")

        pod_s1 = _utils.create_pod(config=config, name="s1")
        pod_s1.labels.update({'security': 'S1'})
        pod_s1.node_selector = {'kubernetes.io/e2e-az-name': 'e2e-az1'}
        pod_s1.add_container(container)

        pod_s2 = _utils.create_pod(config=config, name="s2")
        pod_s2.labels.update({'security': 'S2'})
        pod_s2.node_selector = {'kubernetes.io/e2e-az-name': 'e2e-az2'}
        pod_s2.add_container(container)

        model = _constants.pod_with_pod_affinity()
        pod = Pod(model)
        config = _utils.create_config()
        k8s = K8sPod(config=config, name="yo")
        k8s.model = pod

        if _utils.is_reachable(config):
            # ensure we have enough nodes
            nodes = K8sNode(config=config, name="yo").list()
            if len(nodes) < 3:
                self.skipTest(reason='Not enough nodes to perform test.')
            else:
                self.assertGreaterEqual(len(nodes), 3)
            # tag the nodes
            for i in range(len(nodes)):
                node = nodes[i]
                if i == 0:
                    node.labels.update({'kubernetes.io/e2e-az-name': 'e2e-az1'})
                if i == 1:
                    node.labels.update({'kubernetes.io/e2e-az-name': 'e2e-az2'})
                if i == 2:
                    node.labels.update({'kubernetes.io/e2e-az-name': 'e2e-az3'})
                node.update()
            # create the pods for affinity lookup
            pod_s1.create()
            pod_s2.create()
            # create the pod with affinities
            k8s.create()
            pass
Beispiel #2
0
    def test_update_namespace_fails(self):
        name = "yocontainer"
        container = _utils.create_container(name=name)
        name = "yopod-{0}".format(str(uuid.uuid4()))
        nspace = "yonamespace"
        pod1 = _utils.create_pod(name=name)
        pod1.add_container(container)

        if _utils.is_reachable(pod1.config):
            pod1.create()
            result = K8sPod.get_by_name(config=pod1.config, name=name)
            self.assertIsInstance(result, list)
            self.assertEqual(1, len(result))
            pod2 = result[0]
            self.assertIsInstance(pod2, K8sPod)
            self.assertNotEqual(pod2.namespace, nspace)
            self.assertEqual(pod1, pod2)
            pod2.namespace = nspace
            with self.assertRaises(BadRequestException):
                pod2.update()
Beispiel #3
0
 def delete(self, cascade=False):
     # delete cascade on top level
     super(K8sDeployment, self).delete(cascade)
     if cascade:
         rsets = K8sReplicaSet(config=self.config,
                               name="yo").list(pattern=self.name)
         # delete cascade on replicasets
         for rset in rsets:
             try:
                 rset.delete(cascade=cascade)
             except NotFoundException:
                 pass
         pods = K8sPod(config=self.config,
                       name="yo").list(pattern=self.name)
         # delete cascade on pods
         for pod in pods:
             try:
                 pod.delete(cascade=cascade)
             except NotFoundException:
                 pass
     return self
Beispiel #4
0
    def test_node_affinity_with_required_and_preferred(self):
        model = _constants.pod_with_node_affinity()
        pod = Pod(model)
        config = _utils.create_config()
        k8s = K8sPod(config=config, name="yo")
        k8s.model = pod

        if _utils.is_reachable(config):
            # ensure we have enough nodes
            nodes = K8sNode(config=config, name="yo").list()
            if len(nodes) < 3:
                self.skipTest(reason="Not enough nodes to perform test.")
            else:
                self.assertGreaterEqual(len(nodes), 3)
            # tag the nodes
            for i in range(len(nodes)):
                node = nodes[i]
                if i == 0:
                    node.labels.update({"kubernetes.io/e2e-az-name": "e2e-az1"})
                    node.labels.update({"another-node-label-key": "another-node-label-value"})
                if i == 1:
                    node.labels.update({"kubernetes.io/e2e-az-name": "e2e-az2"})
                if i == 2:
                    node.labels.update({"kubernetes.io/e2e-az-name": "e2e-az3"})
                node.update()
            nodes = K8sNode(config=config, name="yo").list()
            for node in nodes:
                self.assertIn("kubernetes.io/e2e-az-name", node.labels)
            # create the pod
            k8s.create()
            # untag the nodes
            for node in nodes:
                node.labels.pop("kubernetes.io/e2e-az-name", None)
                node.labels.pop("another-node-label-key", None)
                node.update()
        pass
Beispiel #5
0
 def test_get_by_labels_invalid_args(self):
     name = object()
     config = _utils.create_config()
     with self.assertRaises(SyntaxError):
         K8sPod.get_by_labels(config=config, labels=name)
Beispiel #6
0
 def test_get_by_labels_none_args(self):
     config = _utils.create_config()
     with self.assertRaises(SyntaxError):
         K8sPod.get_by_labels(config=config)
 def get_pods(self):
     pods = K8sPod.get_by_labels(config=self.config, labels=self.pod_labels)
     return pods
Beispiel #8
0
def create_pod(config=None, name=None):
    if config is None:
        config = create_config()
    obj = K8sPod(config=config, name=name)
    return obj
Beispiel #9
0
 def pod(self):
     podspec = self.model.spec.job_template.spec.template.spec
     name = "{}-{}".format(self.name, int(time.time()))
     pod = K8sPod(config=self.config, name=name)
     pod.model.spec = podspec
     return pod