Example #1
0
 def test_delete_nonexistent(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     svc = _utils.create_service(name=name)
     svc.add_port(name="redis", port=5432, target_port=5432, protocol="tcp")
     if _utils.is_reachable(svc.config):
         with self.assertRaises(NotFoundException):
             svc.delete()
Example #2
0
 def test_add_label_invalid_args(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     k = object()
     v = object()
     with self.assertRaises(SyntaxError):
         svc.add_label(k, v)
Example #3
0
 def test_get_label(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     k = "yokey"
     v = "yovalue"
     svc.add_label(k, v)
     self.assertEqual(v, svc.get_label(k))
Example #4
0
 def test_get_annotation(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     k = "yokey"
     v_in = "yovalue"
     svc.add_annotation(k, v_in)
     v_out = svc.get_annotation(k)
     self.assertEqual(v_in, v_out)
Example #5
0
 def test_add_annotation(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     k = "yokey"
     v = "yovalue"
     svc.add_annotation(k, v)
     self.assertIn(k, svc.annotations)
     self.assertEqual(v, svc.annotations[k])
Example #6
0
 def test_update_nothing_changed(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     svc = _utils.create_service(name=name)
     svc.add_port(name="redis", port=5432, target_port=5432, protocol="tcp")
     if _utils.is_reachable(svc.config):
         from_create = svc.create()
         from_update = svc.update()
         self.assertEqual(from_create, from_update)
Example #7
0
 def test_add_annotation_none_args(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     try:
         svc.add_annotation()
         self.fail("Should not fail.")
     except Exception as err:
         self.assertIsInstance(err, SyntaxError)
Example #8
0
 def test_create(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     svc = _utils.create_service(name=name)
     svc.add_port(name="redis", port=5432, target_port=5432, protocol="tcp")
     if _utils.is_reachable(svc.config):
         svc.create()
         from_get = svc.get()
         self.assertEqual(svc, from_get)
Example #9
0
 def test_create_already_exists(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     svc = _utils.create_service(name=name)
     svc.add_port(name="redis", port=5432, target_port=5432, protocol="tcp")
     if _utils.is_reachable(svc.config):
         svc.create()
         with self.assertRaises(UnprocessableEntityException):
             svc.create()
Example #10
0
 def test_struct_service(self):
     name = "yoname"
     svc = _utils.create_service(name=name)
     self.assertIsInstance(svc, K8sService)
     self.assertIsInstance(svc.model, Service)
     self.assertIsInstance(svc.model.metadata, ObjectMeta)
     self.assertIsInstance(svc.model.spec, ServiceSpec)
     self.assertIsInstance(svc.model.status, ServiceStatus)
Example #11
0
 def test_get_by_name_nonexistent(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     svc = _utils.create_service(name=name)
     svc.add_port(name="redis", port=5432, target_port=5432, protocol="tcp")
     if _utils.is_reachable(svc.config):
         _list = K8sService.get_by_name(config=svc.config, name=name)
         self.assertIsInstance(_list, list)
         self.assertEqual(0, len(_list))
Example #12
0
 def test_init_with_name(self):
     name = "yoname"
     svc = _utils.create_service(name=name)
     self.assertIsNotNone(svc)
     self.assertIsInstance(svc, K8sService)
     self.assertEqual('Service', svc.obj_type)
     self.assertEqual(svc.name, name)
     self.assertIsInstance(svc.config, K8sConfig)
Example #13
0
 def test_struct_k8s_service(self):
     name = "yoname"
     svc = _utils.create_service(name=name)
     self.assertIsInstance(svc, K8sService)
     self.assertIsInstance(svc.base_url, str)
     self.assertIsInstance(svc.config, K8sConfig)
     self.assertIsInstance(svc.model, Service)
     self.assertIsInstance(svc.name, str)
     self.assertIsInstance(svc.obj_type, str)
Example #14
0
 def test_update_set_cluster_ip_fails(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     svc = _utils.create_service(name=name)
     svc.add_port(name="redis", port=5432, target_port=5432, protocol="tcp")
     if _utils.is_reachable(svc.config):
         svc.create()
         svc.cluster_ip = "192.168.123.123"
         with self.assertRaises(UnprocessableEntityException):
             svc.update()
Example #15
0
 def test_update_set_external_ips(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     svc = _utils.create_service(name=name)
     svc.add_port(name="redis", port=5432, target_port=5432, protocol="tcp")
     ip = '192.168.123.123'
     if _utils.is_reachable(svc.config):
         svc.create()
         svc.external_ips = [ip]
         svc.update()
         self.assertIn(ip, svc.external_ips)
Example #16
0
 def test_set_cluster_ip_invalid_ip_address(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     svc.add_port('http', 80, 80, 'TCP')
     if _utils.is_reachable(svc.config):
         svc.create()
         ip = "192.168.00000.1234345"
         svc.cluster_ip = ip
         with self.assertRaises(UnprocessableEntityException):
             svc.update()
Example #17
0
 def test_init_with_name_and_config(self):
     nspace = "yonamespace"
     config = K8sConfig(kubeconfig=_utils.kubeconfig_fallback, namespace=nspace)
     name = "yoname"
     svc = _utils.create_service(config=config, name=name)
     self.assertIsNotNone(svc)
     self.assertIsInstance(svc, K8sService)
     self.assertEqual(svc.name, name)
     self.assertEqual('Service', svc.obj_type)
     self.assertIsInstance(svc.config, K8sConfig)
     self.assertEqual(nspace, svc.config.namespace)
Example #18
0
 def test_delete(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     svc = _utils.create_service(name=name)
     svc.add_port(name="redis", port=5432, target_port=5432, protocol="tcp")
     if _utils.is_reachable(svc.config):
         svc.create()
         from_get = K8sService.get_by_name(svc.config, svc.name)
         self.assertIsInstance(from_get, list)
         self.assertIn(svc, from_get)
         svc.delete()
         from_get = K8sService.get_by_name(svc.config, svc.name)
         self.assertNotIn(svc, from_get)
Example #19
0
 def test_list(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     svc = _utils.create_service(name=name)
     svc.add_port(name="redis", port=5432, target_port=5432, protocol="tcp")
     if _utils.is_reachable(svc.config):
         svc.create()
         _list = svc.list()
         for x in _list:
             self.assertIsInstance(x, K8sService)
         self.assertIsInstance(_list, list)
         self.assertEqual(2, len(_list))  # api server exists already
         from_query = _list[1]
         self.assertEqual(name, from_query.name)
Example #20
0
 def test_get_annotations(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     count = 4
     for i in range(0, count):
         k = "yokey_{0}".format(i)
         v = "yovalue_{0}".format(i)
         svc.add_annotation(k, v)
     self.assertEqual(count, len(svc.annotations))
     for i in range(0, count):
         k = "yokey_{0}".format(i)
         v = "yovalue_{0}".format(i)
         self.assertIn(k, svc.annotations)
         self.assertEqual(v, svc.annotations[k])
Example #21
0
    def test_update_with_full_model(self):
        data = {
            "kind": "Service",
            "apiVersion": "v1",
            "metadata": {
                "name": "frontend",
                "namespace": "default",
                "labels": {
                    "name": "frontend"
                }
            },
            "spec": {
                "ports": [
                    {
                        "protocol": "TCP",
                        "port": 8082,
                        "targetPort": "feport",
                        "nodePort": 8082
                    }
                ],
                "selector": {
                    "name": "frontend"
                },
                "clusterIP": "10.250.1.27",
                "type": "NodePort",
                "sessionAffinity": "None"
            },
            "status": {
                "loadBalancer": {}
            }
        }

        svc = Service(data)
        k8s_service = _utils.create_service(name=svc.name)
        k8s_service.model = svc

        k8s_service.add_port(
            name="frontend",
            port=8082,
            target_port="feport",
            node_port=8082,
            protocol='tcp'
        )

        self.assertEqual(1, len(k8s_service.ports))
    def test_cassandra_setup(self):
        svc = Service(_utils.cassandra_service())
        k8s_service = _utils.create_service(name="cassandra")
        k8s_service.model = svc

        rc = ReplicationController(_utils.cassandra_rc())
        k8s_rc = _utils.create_rc(name="cassandra")
        k8s_rc.model = rc

        ds = DaemonSet(_utils.cassandra_daemonset())
        k8s_ds = _utils.create_daemonset(name="cassandra")
        k8s_ds.model = ds

        if _utils.is_reachable(k8s_rc.config):
            k8s_service.create()
            k8s_rc.create()
            self.assertIsInstance(k8s_service, K8sService)
            self.assertIsInstance(k8s_rc, K8sReplicationController)
Example #23
0
 def test_add_port_with_all_args(self):
     svc_name = "yoservice"
     svc = _utils.create_service(name=svc_name)
     port = 666
     port_name = "yoport"
     target_port = 666
     protocol = 'TCP'
     node_port = 666
     svc.add_port(
         port=port,
         name=port_name,
         target_port=target_port,
         protocol=protocol,
         node_port=node_port
     )
     self.assertEqual(1, len(svc.ports))
     self.assertEqual(port_name, svc.ports[0].name)
     self.assertEqual(port, svc.ports[0].port)
     self.assertEqual(target_port, svc.ports[0].target_port)
     self.assertEqual(protocol, svc.ports[0].protocol)
     self.assertEqual(node_port, svc.ports[0].node_port)
Example #24
0
    def test_system_service(self):
        config = _utils.create_config()
        config.namespace = 'kube-system'

        service = _utils.create_service(config, name="kubernetes-dashboard")
        service.type = 'ClusterIP'
        service.add_port(
            port=80,
            target_port="k8s-dashport",
            name="kubernetes-dashboard",
            protocol="TCP"
        )
        service.selector = {'k8s-app': "kubernetes-dashboard"}
        service.labels = {
            'k8s-app': "kubernetes-dashboard",
            'kubernetes.io/cluster-service': 'true'
        }

        if _utils.is_reachable(service.config):
            with self.assertRaises(AlreadyExistsException):
                service.create()
            service.get()
            service.update()
Example #25
0
 def test_set_labels(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     labels = {'yokey': 'yovalue'}
     svc.labels = labels
     self.assertEqual(labels, svc.labels)
Example #26
0
 def test_set_labels_invalid_arg(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     labels = object()
     with self.assertRaises(SyntaxError):
         svc.labels = labels
Example #27
0
 def test_init_with_invalid_name(self):
     name = object()
     with self.assertRaises(SyntaxError):
         _utils.create_service(name=name)
Example #28
0
 def test_set_external_ips_invalid_arg(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     eips = object()
     with self.assertRaises(SyntaxError):
         svc.external_ips = eips
Example #29
0
 def test_set_cluster_ip(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     cip = "192.168.99.100"
     svc.cluster_ip = cip
     self.assertEqual(cip, svc.cluster_ip)
Example #30
0
 def test_set_annotations_str_int(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     labels = {'yokey': 1234}
     svc.annotations = labels
     self.assertEqual(svc.annotations, labels)
Example #31
0
 def test_set_service_type(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     for i in ['ClusterIP', 'NodePort', 'LoadBalancer']:
         svc.type = i
         self.assertEqual(i, svc.type)
Example #32
0
 def test_set_namespace_invalid_arg(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     nspace = object()
     with self.assertRaises(SyntaxError):
         svc.namespace = nspace
Example #33
0
 def test_set_session_affinity_invalid_string(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     aff = 'yoaffinity'
     with self.assertRaises(SyntaxError):
         svc.session_affinity = aff
Example #34
0
 def test_set_session_affinity(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     for i in ['None', 'ClientIP']:
         svc.session_affinity = i
         self.assertEqual(i, svc.session_affinity)
Example #35
0
 def test_set_service_type_none_arg(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     with self.assertRaises(SyntaxError):
         svc.type = None
Example #36
0
 def test_set_service_type_invalid_string(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     stype = "yoservicetype"
     with self.assertRaises(SyntaxError):
         svc.type = stype
Example #37
0
 def test_set_load_balancer_ip_invalid_arg(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     ip = object()
     with self.assertRaises(SyntaxError):
         svc.load_balancer_ip = ip
Example #38
0
 def test_get_annotation_none_arg(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     ann = svc.get_annotation()
     self.assertIsNone(ann)
Example #39
0
 def test_set_load_balancer_ip(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     ip = "192.168.99.100"
     svc.load_balancer_ip = ip
     self.assertEqual(ip, svc.load_balancer_ip)
Example #40
0
 def test_get_annotation_invalid_arg(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     k = object()
     ann = svc.get_annotation(k)
     self.assertIsNone(ann)
Example #41
0
 def test_set_annotations_none_arg(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     with self.assertRaises(SyntaxError):
         svc.annotations = None
Example #42
0
 def test_get_annotation_doesnt_exist(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     k = "yokey"
     v = svc.get_annotation(k)
     self.assertIsNone(v)
Example #43
0
 def test_set_annotations(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     anns = {'yokey': 'yovalue'}
     svc.annotations = anns
     self.assertEqual(anns, svc.annotations)
Example #44
0
 def test_get_annotations_doesnt_exist(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     self.assertEqual({}, svc.annotations)
Example #45
0
 def test_set_external_ips_none_arg(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     with self.assertRaises(SyntaxError):
         svc.external_ips = None
Example #46
0
 def test_get_cluster_ip_doesnt_exist(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     self.assertIsNone(svc.cluster_ip)
Example #47
0
 def test_set_external_ips_invalid_ip_address(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     eips = ["192.168.00000.1234345"]
     with self.assertRaises(SyntaxError):
         svc.external_ips = eips
Example #48
0
 def test_get_external_ips_doesnt_exist(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     self.assertEqual([], svc.external_ips)
Example #49
0
 def test_set_external_ip(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     eips = ["192.168.99.100"]
     svc.external_ips = eips
     self.assertEqual(eips, svc.external_ips)
Example #50
0
 def test_get_label_none_arg(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     self.assertIsNone(svc.get_label())
Example #51
0
 def test_set_labels_invalid_dict(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     labels = {'yokey': 1234}
     with self.assertRaises(SyntaxError):
         svc.labels = labels
Example #52
0
 def test_get_label_invalid_arg(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     k = object()
     self.assertIsNone(svc.get_label(k))
Example #53
0
 def test_set_load_balancer_ip_none_arg(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     with self.assertRaises(SyntaxError):
         svc.load_balancer_ip = None
Example #54
0
 def test_get_label_doesnt_exist(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     k = "yokey"
     self.assertIsNone(svc.get_label(k))
Example #55
0
 def test_set_load_balancer_ip_invalid_ip_address(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     ip = "192.168.00000.1234345"
     with self.assertRaises(SyntaxError):
         svc.load_balancer_ip = ip
Example #56
0
 def test_get_labels_doesnt_exist(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     self.assertIsNotNone(svc.labels)  # 'name' is already a label
     self.assertIn('name', svc.labels)
Example #57
0
 def test_set_namespace_none_arg(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     with self.assertRaises(SyntaxError):
         svc.namespace = None
Example #58
0
 def test_list_without_create(self):
     name = "yo-{0}".format(str(uuid.uuid4().hex[:16]))
     svc = _utils.create_service(name=name)
     svc.add_port(name="redis", port=5432, target_port=5432, protocol="tcp")
     if _utils.is_reachable(svc.config):
         _list = svc.list()
Example #59
0
 def test_set_namespace(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     nspace = "yonamespace"
     svc.namespace = nspace
     self.assertEqual(nspace, svc.namespace)
Example #60
0
 def test_get_nonexistent(self):
     name = "yoservice"
     svc = _utils.create_service(name=name)
     if _utils.is_reachable(svc.config):
         with self.assertRaises(NotFoundException):
             svc.get()