Ejemplo n.º 1
0
 def test_create_already_exists(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     node = _utils.create_node(name=name)
     if _utils.is_reachable(node.config):
         node.create()
         with self.assertRaises(AlreadyExistsException):
             node.create()
Ejemplo n.º 2
0
 def test_add_label_invalid_args(self):
     name = "yo-node"
     n = _utils.create_node(name=name)
     k = object()
     v = object()
     with self.assertRaises(SyntaxError):
         n.add_label(k, v)
Ejemplo n.º 3
0
 def test_create(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 = node.get()
         self.assertEqual(node, from_get)
Ejemplo n.º 4
0
 def test_create(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 = node.get()
         self.assertEqual(node, from_get)
Ejemplo n.º 5
0
 def test_create_already_exists(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     node = _utils.create_node(name=name)
     if _utils.is_reachable(node.config):
         node.create()
         with self.assertRaises(AlreadyExistsException):
             node.create()
Ejemplo n.º 6
0
 def test_add_label_invalid_args(self):
     name = "yo-node"
     n = _utils.create_node(name=name)
     k = object()
     v = object()
     with self.assertRaises(SyntaxError):
         n.add_label(k, v)
Ejemplo n.º 7
0
    def test_list(self):
        name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
        node = _utils.create_node(name=name)

        if _utils.is_reachable(node.config):
            node_pattern = re.compile(r'yo-')
            _pre_list = node.list()
            for x in _pre_list:
                self.assertIsInstance(x, K8sNode)
            _filtered = list(
                filter(lambda x: node_pattern.match(x.name) is not None,
                       _pre_list))
            pre_create_length = len(_filtered)

            node.create()
            _post_list = node.list()
            for x in _post_list:
                self.assertIsInstance(x, K8sNode)
            _filtered = list(
                filter(lambda x: node_pattern.match(x.name) is not None,
                       _post_list))
            post_create_length = len(_filtered)
            self.assertIsInstance(_filtered, list)
            self.assertEqual(1 + pre_create_length, post_create_length)

            from_query = list(filter(lambda x: x.name == name, _filtered))
            self.assertIsInstance(from_query, list)
            self.assertEqual(len(from_query), 1)
Ejemplo n.º 8
0
 def test_get(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     n = _utils.create_node(name=name)
     if _utils.is_reachable(n.config):
         n.create()
         from_get = n.get()
         self.assertIsInstance(from_get, K8sNode)
         self.assertEqual(n, from_get)
Ejemplo n.º 9
0
 def test_add_annotation(self):
     name = "yo-node"
     n = _utils.create_node(name=name)
     k = "yokey"
     v = "yovalue"
     n.add_annotation(k, v)
     self.assertIn(k, n.annotations)
     self.assertEqual(v, n.annotations[k])
Ejemplo n.º 10
0
 def test_get(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     n = _utils.create_node(name=name)
     if _utils.is_reachable(n.config):
         n.create()
         from_get = n.get()
         self.assertIsInstance(from_get, K8sNode)
         self.assertEqual(n, from_get)
Ejemplo n.º 11
0
 def test_add_label(self):
     name = "yo-node"
     n = _utils.create_node(name=name)
     k = "yokey"
     v = "yovalue"
     n.add_label(k, v)
     self.assertIn(k, n.labels)
     self.assertEqual(v, n.labels[k])
Ejemplo n.º 12
0
 def test_init_with_name(self):
     name = "yo-name"
     n = _utils.create_node(name=name)
     self.assertIsNotNone(n)
     self.assertIsInstance(n, K8sNode)
     self.assertEqual('Node', n.obj_type)
     self.assertEqual(n.name, name)
     self.assertIsInstance(n.config, K8sConfig)
Ejemplo n.º 13
0
 def test_add_annotation(self):
     name = "yo-node"
     n = _utils.create_node(name=name)
     k = "yokey"
     v = "yovalue"
     n.add_annotation(k, v)
     self.assertIn(k, n.annotations)
     self.assertEqual(v, n.annotations[k])
Ejemplo n.º 14
0
 def test_add_annotation_none_args(self):
     name = "yo-node"
     n = _utils.create_node(name=name)
     try:
         n.add_annotation()
         self.fail("Should not fail.")
     except Exception as err:
         self.assertIsInstance(err, SyntaxError)
Ejemplo n.º 15
0
 def test_add_label(self):
     name = "yo-node"
     n = _utils.create_node(name=name)
     k = "yokey"
     v = "yovalue"
     n.add_label(k, v)
     self.assertIn(k, n.labels)
     self.assertEqual(v, n.labels[k])
Ejemplo n.º 16
0
 def test_add_annotation_none_args(self):
     name = "yo-node"
     n = _utils.create_node(name=name)
     try:
         n.add_annotation()
         self.fail("Should not fail.")
     except Exception as err:
         self.assertIsInstance(err, SyntaxError)
Ejemplo n.º 17
0
 def test_struct_node(self):
     name = "yo-name"
     n = _utils.create_node(name=name)
     self.assertIsInstance(n, K8sNode)
     self.assertIsInstance(n.model, Node)
     self.assertIsInstance(n.model.metadata, ObjectMeta)
     self.assertIsInstance(n.model.spec, NodeSpec)
     self.assertIsInstance(n.model.status, NodeStatus)
Ejemplo n.º 18
0
 def test_struct_node(self):
     name = "yo-name"
     n = _utils.create_node(name=name)
     self.assertIsInstance(n, K8sNode)
     self.assertIsInstance(n.model, Node)
     self.assertIsInstance(n.model.metadata, ObjectMeta)
     self.assertIsInstance(n.model.spec, NodeSpec)
     self.assertIsInstance(n.model.status, NodeStatus)
Ejemplo n.º 19
0
 def test_init_with_name(self):
     name = "yo-name"
     n = _utils.create_node(name=name)
     self.assertIsNotNone(n)
     self.assertIsInstance(n, K8sNode)
     self.assertEqual('Node', n.obj_type)
     self.assertEqual(n.name, name)
     self.assertIsInstance(n.config, K8sConfig)
Ejemplo n.º 20
0
 def test_struct_k8s_node(self):
     name = "yo-name"
     n = _utils.create_node(name=name)
     self.assertIsInstance(n, K8sNode)
     self.assertIsInstance(n.base_url, str)
     self.assertIsInstance(n.config, K8sConfig)
     self.assertIsInstance(n.model, Node)
     self.assertIsInstance(n.name, str)
     self.assertIsInstance(n.obj_type, str)
Ejemplo n.º 21
0
 def test_struct_k8s_node(self):
     name = "yo-name"
     n = _utils.create_node(name=name)
     self.assertIsInstance(n, K8sNode)
     self.assertIsInstance(n.base_url, str)
     self.assertIsInstance(n.config, K8sConfig)
     self.assertIsInstance(n.model, Node)
     self.assertIsInstance(n.name, str)
     self.assertIsInstance(n.obj_type, str)
Ejemplo n.º 22
0
 def test_init_with_name_and_config(self):
     nspace = "default"
     config = K8sConfig(kubeconfig=_utils.kubeconfig_fallback, namespace=nspace)
     name = "yo-name"
     n = _utils.create_node(config=config, name=name)
     self.assertIsNotNone(n)
     self.assertIsInstance(n, K8sNode)
     self.assertEqual(n.name, name)
     self.assertEqual('Node', n.obj_type)
     self.assertIsInstance(n.config, K8sConfig)
Ejemplo n.º 23
0
 def test_init_with_name_and_config(self):
     nspace = "default"
     config = K8sConfig(kubeconfig=_utils.kubeconfig_fallback, namespace=nspace)
     name = "yo-name"
     n = _utils.create_node(config=config, name=name)
     self.assertIsNotNone(n)
     self.assertIsInstance(n, K8sNode)
     self.assertEqual(n.name, name)
     self.assertEqual('Node', n.obj_type)
     self.assertIsInstance(n.config, K8sConfig)
Ejemplo n.º 24
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)
Ejemplo n.º 25
0
 def test_list_without_create(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     nodes = _utils.create_node(name=name)
     if _utils.is_reachable(nodes.config):
         _list = nodes.list()
         for x in _list:
             self.assertIsInstance(x, K8sNode)
         node_pattern = re.compile("yo\-")
         _filtered = list(filter(lambda x: node_pattern.match(x.name) is not None, _list))
         self.assertIsInstance(_filtered, list)
         self.assertEqual(0, len(_filtered))
Ejemplo n.º 26
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)
Ejemplo n.º 27
0
 def test_list_without_create(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     nodes = _utils.create_node(name=name)
     if _utils.is_reachable(nodes.config):
         _list = nodes.list()
         for x in _list:
             self.assertIsInstance(x, K8sNode)
         node_pattern = re.compile("yo\-")
         _filtered = list(filter(lambda x: node_pattern.match(x.name) is not None, _list))
         self.assertIsInstance(_filtered, list)
         self.assertLessEqual(0, len(_filtered))  # there might be a few nodes already (see setUp/tearDown)
Ejemplo n.º 28
0
    def test_node_selectors(self):
        node = _utils.create_node(name="yo")

        c_nginx = _utils.create_container("yo-nginx", "nginx:latest")
        c_pg = _utils.create_container("yo-pg", "postgres:alpine")
        c_redis = _utils.create_container("yo-redis", "redis:latest")

        d_nginx = _utils.create_deployment(name="yo-nginx")
        d_nginx.desired_replicas = 1
        d_nginx.add_container(c_nginx)

        d_pg = _utils.create_deployment(name="yo-pg")
        d_pg.desired_replicas = 1
        d_pg.add_container(c_pg)

        d_redis = _utils.create_deployment(name="yo-redis")
        d_redis.desired_replicas = 1
        d_redis.add_container(c_redis)

        if _utils.is_reachable(node.config):
            nodes = node.list()

            for i in range(len(nodes)):
                node = nodes[i]
                labels = node.labels
                labels.update({'mnubo.com/selector': str(i)})
                node.labels = labels
                node.update()

            d_nginx.node_selector = {"mnubo.com/selector": "0"}
            d_pg.node_selector = {"mnubo.com/selector": "1"}
            d_redis.node_selector = {"mnubo.com/selector": "2"}

            d_nginx.create()
            d_pg.create()
            d_redis.create()

            self.assertEqual(d_nginx.node_selector,
                             {"mnubo.com/selector": "0"})
            self.assertEqual(d_pg.node_selector, {"mnubo.com/selector": "1"})
            self.assertEqual(d_redis.node_selector,
                             {"mnubo.com/selector": "2"})

            pass  # set breakpoint; play around with killing pods
Ejemplo n.º 29
0
    def test_node_selectors(self):
        node = _utils.create_node(name="yo")

        c_nginx = _utils.create_container("yo-nginx", "nginx:latest")
        c_pg = _utils.create_container("yo-pg", "postgres:alpine")
        c_redis = _utils.create_container("yo-redis", "redis:latest")

        d_nginx = _utils.create_deployment(name="yo-nginx")
        d_nginx.desired_replicas = 1
        d_nginx.add_container(c_nginx)

        d_pg = _utils.create_deployment(name="yo-pg")
        d_pg.desired_replicas = 1
        d_pg.add_container(c_pg)

        d_redis = _utils.create_deployment(name="yo-redis")
        d_redis.desired_replicas = 1
        d_redis.add_container(c_redis)

        if _utils.is_reachable(node.config):
            nodes = node.list()

            for i in range(len(nodes)):
                node = nodes[i]
                labels = node.labels
                labels.update({'mnubo.com/selector': str(i)})
                node.labels = labels
                node.update()

            d_nginx.node_selector = {"mnubo.com/selector": "0"}
            d_pg.node_selector = {"mnubo.com/selector": "1"}
            d_redis.node_selector = {"mnubo.com/selector": "2"}

            d_nginx.create()
            d_pg.create()
            d_redis.create()

            self.assertEqual(d_nginx.node_selector, {"mnubo.com/selector": "0"})
            self.assertEqual(d_pg.node_selector, {"mnubo.com/selector": "1"})
            self.assertEqual(d_redis.node_selector, {"mnubo.com/selector": "2"})

            pass  # set breakpoint; play around with killing pods
Ejemplo n.º 30
0
    def test_list(self):
        name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
        node = _utils.create_node(name=name)

        if _utils.is_reachable(node.config):
            node_pattern = re.compile(r'yo-')
            _pre_list = node.list()
            for x in _pre_list:
                self.assertIsInstance(x, K8sNode)
            _filtered = list(filter(lambda x: node_pattern.match(x.name) is not None, _pre_list))
            pre_create_length = len(_filtered)

            node.create()
            _post_list = node.list()
            for x in _post_list:
                self.assertIsInstance(x, K8sNode)
            _filtered = list(filter(lambda x: node_pattern.match(x.name) is not None, _post_list))
            post_create_length = len(_filtered)
            self.assertIsInstance(_filtered, list)
            self.assertEqual(1 + pre_create_length, post_create_length)

            from_query = list(filter(lambda x: x.name == name, _filtered))
            self.assertIsInstance(from_query, list)
            self.assertEqual(len(from_query), 1)
Ejemplo n.º 31
0
 def test_add_label_none_args(self):
     name = "yo-node"
     n = _utils.create_node(name=name)
     with self.assertRaises(SyntaxError):
         n.add_label()
Ejemplo n.º 32
0
 def test_delete_nonexistent(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     node = _utils.create_node(name=name)
     if _utils.is_reachable(node.config):
         with self.assertRaises(NotFoundException):
             node.delete()
Ejemplo n.º 33
0
 def test_get_nonexistent(self):
     name = "yo-node"
     n = _utils.create_node(name=name)
     if _utils.is_reachable(n.config):
         with self.assertRaises(NotFoundException):
             n.get()
Ejemplo n.º 34
0
 def test_delete_nonexistent(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     node = _utils.create_node(name=name)
     if _utils.is_reachable(node.config):
         with self.assertRaises(NotFoundException):
             node.delete()
Ejemplo n.º 35
0
 def test_get_nonexistent(self):
     name = "yo-node"
     n = _utils.create_node(name=name)
     if _utils.is_reachable(n.config):
         with self.assertRaises(NotFoundException):
             n.get()
Ejemplo n.º 36
0
 def test_add_label_none_args(self):
     name = "yo-node"
     n = _utils.create_node(name=name)
     with self.assertRaises(SyntaxError):
         n.add_label()