Ejemplo n.º 1
0
 def test_base(self, depl: chkit.Deployment):
     svc = chkit.Service(name="test-external-service",
                         deploy=depl.name,
                         ports=[
                             chkit.ServicePort(name="test-external-port",
                                               target_port=80)
                         ])
     try:
         chkit.create_service(svc)
         self.assertIn(svc.name,
                       [service.name for service in chkit.get_services()])
         got_svc = chkit.get_service(svc.name)
         self.assertEqual(svc.name, got_svc.name)
         self.assertTrue(got_svc.is_external())
         attempts, max_attempts = 1, 40
         while attempts <= max_attempts:
             try:
                 response = requests.get(
                     f"http://{got_svc.ips[0]}:{got_svc.ports[0].port}",
                     headers={"Host": got_svc.domain},
                     timeout=1)
                 response.raise_for_status()
                 if response.status_code == 200:
                     break
             except requests.exceptions.ConnectionError:
                 pass
             time.sleep(15)
             attempts += 1
         self.assertLessEqual(attempts, max_attempts)
     finally:
         chkit.delete_service(svc.name)
         time.sleep(1)
         self.assertNotIn(
             svc.name, [service.name for service in chkit.get_services()])
Ejemplo n.º 2
0
    def test_base(self, depl: chkit.Deployment, svc: chkit.Service):
        ingr = chkit.Ingress(name="test-ingress",
                             rules=[
                                 chkit.IngressRules(
                                     host="test-host",
                                     path=[
                                         chkit.IngressPath(
                                             path="/",
                                             service_name=svc.name,
                                             service_port=svc.ports[0].port)
                                     ])
                             ])
        try:
            got_svc = chkit.get_service(svc.name)
            ingr.rules[0].path[0].service_port = got_svc.ports[0].port
            chkit.create_ingress(ingr)
            self.assertIn(ingr.name[0],
                          [ingr.name[0] for ingr in chkit.get_ingresses()])
            got_ingr = chkit.get_ingress(ingr.name[0])
            self.assertEqual(got_ingr.name[0], ingr.name[0])
            self.assertEqual(got_ingr.rules[0].host,
                             ingr.rules[0].host + ".hub.containerum.io")
            self.assertEqual(got_ingr.rules[0].path[0].path,
                             ingr.rules[0].path[0].path)
            self.assertEqual(got_ingr.rules[0].path[0].service_port,
                             ingr.rules[0].path[0].service_port)
            self.assertEqual(got_ingr.rules[0].path[0].service_name,
                             ingr.rules[0].path[0].service_name)

            url = "http://" + got_ingr.rules[0].host
            attempts, max_attempts = 1, 40
            while attempts <= max_attempts:
                try:
                    response = requests.get(url)
                    response.raise_for_status()
                    if response.status_code < 400:
                        break
                except requests.exceptions.ConnectionError:
                    pass
                time.sleep(15)
                attempts += 1
            self.assertLessEqual(attempts, max_attempts)

        finally:
            chkit.delete_ingress(ingr.name[0])
            time.sleep(1)
            self.assertNotIn(
                ingr.name[0],
                [ingrs.name[0] for ingrs in chkit.get_ingresses()])
Ejemplo n.º 3
0
 def test_update(self, depl: chkit.Deployment, svc: chkit.Service):
     new_svc = chkit.Service(name=svc.name,
                             deploy=depl.name,
                             ports=[
                                 chkit.ServicePort(
                                     name="test-external-port-update",
                                     target_port=443)
                             ])
     chkit.replace_service(service=new_svc, file=True)
     got_svc = chkit.get_service(service=new_svc.name)
     self.assertEqual(new_svc.name, got_svc.name)
     self.assertEqual(len(got_svc.ports), 1)
     self.assertEqual(got_svc.ports[0].name, new_svc.ports[0].name)
     self.assertEqual(got_svc.ports[0].target_port,
                      new_svc.ports[0].target_port)
Ejemplo n.º 4
0
 def test_update(self, depl: chkit.Deployment, svc: chkit.Service):
     new_svc = chkit.Service(
         name=svc.name,
         deploy=depl.name,
         ports=[
             chkit.ServicePort(name="test-internal-port-update",
                               target_port=443,
                               port=9999)
         ],
     )
     chkit.replace_service(new_svc)
     got_svc = chkit.get_service(svc.name)
     self.assertEqual(got_svc.name, new_svc.name)
     self.assertEqual(got_svc.deploy, new_svc.deploy)
     self.assertEqual(got_svc.ports[0].name, new_svc.ports[0].name)
     self.assertEqual(got_svc.ports[0].target_port,
                      new_svc.ports[0].target_port)
     self.assertEqual(got_svc.ports[0].port, new_svc.ports[0].port)
Ejemplo n.º 5
0
 def test_base(self, depl: chkit.Deployment):
     svc = chkit.Service(name="test-internal-service",
                         deploy=depl.name,
                         ports=[
                             chkit.ServicePort(name="test-internal-port",
                                               target_port=80,
                                               port=8888)
                         ])
     try:
         chkit.create_service(svc)
         self.assertIn(svc.name,
                       [service.name for service in chkit.get_services()])
         got_svc = chkit.get_service(svc.name)
         self.assertEqual(svc.name, got_svc.name)
         self.assertFalse(got_svc.is_external())
     finally:
         chkit.delete_service(svc.name)
         time.sleep(1)
         self.assertNotIn(
             svc.name, [service.name for service in chkit.get_services()])