Esempio n. 1
0
 def test_delete(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     node = _utils.create_node(name=name)
     if _utils.is_reachable(node.config):
         node.create()
         from_get = K8sNode.get_by_name(node.config, node.name)
         self.assertIsInstance(from_get, K8sNode)
         self.assertEqual(from_get.name, name)
         node.delete()
         from_get = K8sNode.get_by_name(node.config, node.name)
         self.assertIsNone(from_get)
Esempio n. 2
0
    def test_taint_no_args(self):
        config = _utils.create_config()

        if _utils.is_reachable(config):
            nodes = K8sNode(config=config, name="yo").list()
            for node in nodes:
                with self.assertRaises(SyntaxError):
                    node.taint()
Esempio n. 3
0
    def test_untaint(self):
        config = _utils.create_config()
        key = "key"
        value = "value"

        if _utils.is_reachable(config):
            nodes = K8sNode(config=config, name="yo").list()
            for node in nodes:
                node.untaint(key=key, value=value)
                self.assertEqual(0, len(node.taints))
Esempio n. 4
0
    def test_taint_invalid_effect(self):
        config = _utils.create_config()
        key = "key"
        value = "value"
        effect = "AvadaKedavra"

        if _utils.is_reachable(config):
            nodes = K8sNode(config=config, name="yo").list()
            for node in nodes:
                with self.assertRaises(SyntaxError):
                    node.taint(key=key, value=value, effect=effect)
Esempio n. 5
0
 def test_init_no_args(self):
     try:
         K8sNode()
         self.fail("Should not fail.")
     except SyntaxError:
         pass
     except IOError:
         pass
     except Exception as err:
         self.fail("Unhandled exception: [ {0} ]".format(
             err.__class__.__name__))
Esempio n. 6
0
    def test_pods(self):
        cfg = _utils.create_config()

        if _utils.is_reachable(cfg):
            nodes = K8sNode(config=cfg, name="yo").list()

            for node in nodes:
                pods = node.pods
                self.assertIsInstance(pods, list)
                for pod in pods:
                    self.assertIsInstance(pod, K8sPod)
Esempio n. 7
0
    def test_taint_invalid_key_value(self):
        config = _utils.create_config()
        key1 = 34567
        key2 = "34567"
        value = 45678
        effect = "NoSchedule"

        if _utils.is_reachable(config):
            nodes = K8sNode(config=config, name="yo").list()
            for node in nodes:
                with self.assertRaises(SyntaxError):
                    node.taint(key=key1, value=value, effect=effect)
                with self.assertRaises(SyntaxError):
                    node.taint(key=key2, value=value, effect=effect)
Esempio n. 8
0
    def test_drain_vanilla(self):
        cfg = _utils.create_config()

        if _utils.is_reachable(cfg):
            nodes = K8sNode(config=cfg, name="yo").list()

            try:
                for node in nodes:
                    node.drain()
                    self.assertEqual(True, node.unschedulable)

            except Exception as err:
                self.assertIsInstance(err, DrainNodeException)

            finally:
                for node in nodes:
                    node.uncordon()
Esempio n. 9
0
    def test_taint_untaint(self):
        config = _utils.create_config()
        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)
                node.get()
                self.assertEqual(1, len(node.taints))
                self.assertEqual(node.taints[0].key, key)
                self.assertEqual(node.taints[0].value, value)
                self.assertEqual(node.taints[0].effect, effect)
            for node in nodes:
                node.untaint(key=key, value=value)
                node.get()
                self.assertEqual(0, len(node.taints))
Esempio n. 10
0
    def test_drain_ignore_daemonsets(self):
        cfg = _utils.create_config()

        if _utils.is_reachable(cfg):
            nodes = K8sNode(config=cfg, name="yo").list()

            try:
                for node in nodes:
                    node.drain(ignore_daemonsets=True)
                    self.assertTrue(node.unschedulable)
                    node.uncordon()
                    self.assertFalse(node.unschedulable)

            except Exception as err:
                self.assertIsInstance(err, DrainNodeException)

            finally:
                for node in nodes:
                    node.uncordon()
Esempio n. 11
0
 def test_init_with_invalid_config(self):
     config = object()
     with self.assertRaises(SyntaxError):
         K8sNode(config=config)