Beispiel #1
0
    def test_node_affinity_with_required(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"})
                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.update()
        pass
Beispiel #2
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 #3
0
    def test_pod_affinity_no_good_nodes(self):
        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):
            nodes = K8sNode(config=config, name="yo").list()
            # untag all nodes
            for node in nodes:
                node.labels.pop("kubernetes.io/e2e-az-name", None)
                node.update()
            with self.assertRaises(TimedOutException):
                # timeout because of required
                k8s.create()
Beispiel #4
0
    def test_tolerations_timeout(self):
        config = _utils.create_config()
        container = _utils.create_container(name="nginx", image="nginx:latest")
        pod = _utils.create_pod(config=config, name="yo")
        pod.add_container(container)

        key = "key"
        value = "value"
        effect = "NoSchedule"

        if _utils.is_reachable(config):
            nodes = K8sNode(config=config, name="yo").list()
            for node in nodes:
                node.taint(key=key, value=value, effect=effect)
            with self.assertRaises(TimedOutException):
                pod.create()
            for node in nodes:
                node.untaint(key=key, value=value)
Beispiel #5
0
    def test_tolerations_noschedule(self):
        config = _utils.create_config()
        container = _utils.create_container(name="nginx", image="nginx:latest")
        pod = _utils.create_pod(config=config, name="yo")
        pod.add_container(container)

        key = "key"
        value = "value"
        effect = "NoSchedule"

        if _utils.is_reachable(config):
            nodes = K8sNode(config=config, name="yo").list()
            for node in nodes:
                node.taint(key=key, value=value, effect=effect)
            pod.add_toleration(key=key, value=value, effect=effect)
            pod.create()
            self.assertEqual(3, len(pod.tolerations))
            for node in nodes:
                node.untaint(key=key, value=value)
Beispiel #6
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 #7
0
def create_node(config=None, name=None):
    if config is None:
        config = create_config()
    obj = K8sNode(config=config, name=name)
    return obj