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()
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))
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)
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__))
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)
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)
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()
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))
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()
def test_init_with_invalid_config(self): config = object() with self.assertRaises(SyntaxError): K8sNode(config=config)