Пример #1
0
 def test_api_create(self):
     name = "job-{}".format(uuid.uuid4())
     job = CronJob(utils.scheduledjob())
     k8s_cronjob = utils.create_cronjob(name=name)
     k8s_cronjob.model = job
     if utils.is_reachable(k8s_cronjob.config.api_host):
         k8s_cronjob.create()
         self.assertIsInstance(k8s_cronjob, K8sCronJob)
Пример #2
0
 def test_server_version_no_kubeconfig(self):
     api_host = "127.0.0.1:8001"
     cfg = K8sConfig(kubeconfig=None, api_host=api_host)
     if utils.is_reachable(cfg.api_host):
         container = utils.create_container(name="nginx", image="nginx:latest")
         cj = utils.create_cronjob(config=cfg, name="test")
         cj.add_container(container)
         cj.create()
         self.assertIsInstance(cj, K8sCronJob)
Пример #3
0
    def test_api_create_long_running_with_concurrency(self):
        name = "job-{}".format(uuid.uuid4())
        job = CronJob(utils.scheduledjob_90())

        k8s_cronjob = utils.create_cronjob(name=name)
        k8s_cronjob.model = job
        k8s_cronjob.concurrency_policy = "Allow"

        if utils.is_reachable(k8s_cronjob.config.api_host):
            k8s_cronjob.create()
            self.assertIsInstance(k8s_cronjob, K8sCronJob)
            self.assertEqual('Allow', k8s_cronjob.concurrency_policy)
Пример #4
0
    def test_api_create_long_running_no_concurrency(self):
        name = "job-{}".format(uuid.uuid4())
        job = CronJob(utils.scheduledjob_90())

        k8s_cronjob = utils.create_cronjob(name=name)
        k8s_cronjob.model = job
        k8s_cronjob.concurrency_policy = "Forbid"
        k8s_cronjob.starting_deadline_seconds = 10

        if utils.is_reachable(k8s_cronjob.config.api_host):
            k8s_cronjob.create()
            self.assertIsInstance(k8s_cronjob, K8sCronJob)
            self.assertEqual('Forbid', k8s_cronjob.concurrency_policy)
            self.assertEqual(10, k8s_cronjob.starting_deadline_seconds)
Пример #5
0
    def test_list(self):
        name = "job-{}".format(uuid.uuid4())
        job = CronJob(utils.scheduledjob_90())

        k8s_cronjob = utils.create_cronjob(name=name)
        k8s_cronjob.model = job
        k8s_cronjob.concurrency_policy = "Forbid"
        k8s_cronjob.starting_deadline_seconds = 10

        if utils.is_reachable(k8s_cronjob.config.api_host):
            k8s_cronjob.create()
            crons = k8s_cronjob.list()
            for c in crons:
                self.assertIsInstance(c, K8sCronJob)
Пример #6
0
    def test_containers(self):
        c_name = "redis"
        c_image = "redis:latest"
        c_image_2 = "redis:3.2.3"
        container = utils.create_container(name=c_name, image=c_image)
        name = "job-{}".format(uuid.uuid4())

        cj = utils.create_cronjob(name=name)
        cj.add_container(container)
        self.assertEqual(1, len(cj.containers))
        self.assertIn(c_name, cj.container_image)
        self.assertEqual(c_image, cj.container_image[c_name])

        container = utils.create_container(name=c_name, image=c_image_2)
        cj.add_container(container)
        self.assertEqual(1, len(cj.containers))
        self.assertEqual(c_image_2, cj.container_image[c_name])
Пример #7
0
 def test_init_with_invalid_name(self):
     name = object()
     with self.assertRaises(SyntaxError):
         utils.create_cronjob(name=name)
Пример #8
0
 def test_init_with_name(self):
     name = "yomama"
     rc = utils.create_cronjob(name=name)
     self.assertIsNotNone(rc)
     self.assertIsInstance(rc, K8sCronJob)
     self.assertEqual(rc.name, name)