def test_api_create(self): name = "job-{}".format(uuid.uuid4()) job = CronJob(_constants.scheduledjob()) k8s_cronjob = _utils.create_cronjob(name=name) k8s_cronjob.model = job if _utils.is_reachable(k8s_cronjob.config): k8s_cronjob.create() self.assertIsInstance(k8s_cronjob, K8sCronJob)
def test_api_create(self): name = "job-{}".format(uuid.uuid4()) job = CronJob(_constants.scheduledjob()) k8s_cronjob = _utils.create_cronjob(name=name) k8s_cronjob.model = job if _utils.is_reachable(k8s_cronjob.config): k8s_cronjob.create() self.assertIsInstance(k8s_cronjob, K8sCronJob)
def test_add_image_pull_secrets(self): cfg = _utils.create_config() cfg.pull_secret = [ {'name': 'secret-name'}, {'name': 'other-secret-name'}, {'name': 'secret-name'} # duplicate ] cj = _utils.create_cronjob(config=cfg, name="yo") self.assertEqual(2, len(cj.image_pull_secrets)) # duplicate not present
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)
def test_api_create_long_running_with_concurrency(self): name = "job-{}".format(uuid.uuid4()) job = CronJob(_constants.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): k8s_cronjob.create() self.assertIsInstance(k8s_cronjob, K8sCronJob) self.assertEqual('Allow', k8s_cronjob.concurrency_policy)
def test_add_image_pull_secrets(self): cfg = _utils.create_config() cfg.pull_secret = [{ "name": "secret-name" }, { "name": "other-secret-name" }, { "name": "secret-name" }] # duplicate cj = _utils.create_cronjob(config=cfg, name="yo") self.assertEqual(2, len(cj.image_pull_secrets)) # duplicate not present
def test_api_create_long_running_with_concurrency(self): name = "job-{}".format(uuid.uuid4()) job = CronJob(_constants.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): k8s_cronjob.create() self.assertIsInstance(k8s_cronjob, K8sCronJob) self.assertEqual('Allow', k8s_cronjob.concurrency_policy)
def test_run(self): name = "job-{}".format(uuid.uuid4()) model = CronJob(_constants.cronjob_90()) cj = _utils.create_cronjob(name=name) cj.model = model cj.concurrency_policy = "Forbid" cj.starting_deadline_seconds = 10 if _utils.is_reachable(cj.config): cj.create() self.assertFalse(cj.suspend) cj.run() self.assertFalse(cj.suspend)
def test_api_create_long_running_no_concurrency(self): name = "job-{}".format(uuid.uuid4()) job = CronJob(_constants.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): k8s_cronjob.create() self.assertIsInstance(k8s_cronjob, K8sCronJob) self.assertEqual('Forbid', k8s_cronjob.concurrency_policy) self.assertEqual(10, k8s_cronjob.starting_deadline_seconds)
def test_list(self): name = "job-{}".format(uuid.uuid4()) job = CronJob(_constants.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): k8s_cronjob.create() crons = k8s_cronjob.list() for c in crons: self.assertIsInstance(c, K8sCronJob)
def test_run(self): name = "job-{}".format(uuid.uuid4()) model = CronJob(_constants.scheduledjob_90()) cj = _utils.create_cronjob(name=name) cj.model = model cj.concurrency_policy = "Forbid" cj.starting_deadline_seconds = 10 if _utils.is_reachable(cj.config): cj.create() self.assertFalse(cj.suspend) cj.run() self.assertFalse(cj.suspend)
def test_api_create_long_running_no_concurrency(self): name = "job-{}".format(uuid.uuid4()) job = CronJob(_constants.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): k8s_cronjob.create() self.assertIsInstance(k8s_cronjob, K8sCronJob) self.assertEqual('Forbid', k8s_cronjob.concurrency_policy) self.assertEqual(10, k8s_cronjob.starting_deadline_seconds)
def test_list(self): name = "job-{}".format(uuid.uuid4()) job = CronJob(_constants.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): k8s_cronjob.create() crons = k8s_cronjob.list() for c in crons: self.assertIsInstance(c, K8sCronJob)
def test_run_already_running(self): name = "job-{}".format(uuid.uuid4()) model = CronJob(_constants.cronjob_90()) cj = _utils.create_cronjob(name=name) cj.model = model cj.concurrency_policy = "Forbid" cj.starting_deadline_seconds = 10 if _utils.is_reachable(cj.config): cj.create() while not cj.last_schedule_time: cj.get() time.sleep(2) with self.assertRaises(CronJobAlreadyRunningException): cj.run()
def test_pod(self): name = "job-{}".format(uuid.uuid4()) model = CronJob(_constants.cronjob_90()) cj = _utils.create_cronjob(name=name) cj.model = model cj.concurrency_policy = "Forbid" cj.starting_deadline_seconds = 10 if _utils.is_reachable(cj.config): cj.create() while not cj.last_schedule_time: cj.get() time.sleep(2) pod = cj.pod self.assertIsInstance(pod, K8sPod)
def test_pod(self): name = "job-{}".format(uuid.uuid4()) model = CronJob(_constants.scheduledjob_90()) cj = _utils.create_cronjob(name=name) cj.model = model cj.concurrency_policy = "Forbid" cj.starting_deadline_seconds = 10 if _utils.is_reachable(cj.config): cj.create() while not cj.last_schedule_time: cj.get() time.sleep(2) pod = cj.pod self.assertIsInstance(pod, K8sPod)
def test_run_already_running(self): name = "job-{}".format(uuid.uuid4()) model = CronJob(_constants.scheduledjob_90()) cj = _utils.create_cronjob(name=name) cj.model = model cj.concurrency_policy = "Forbid" cj.starting_deadline_seconds = 10 if _utils.is_reachable(cj.config): cj.create() while not cj.last_schedule_time: cj.get() time.sleep(2) with self.assertRaises(CronJobAlreadyRunningException): cj.run()
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])
def test_last_schedule_time(self): name = "job-{}".format(uuid.uuid4()) job = CronJob(_constants.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): k8s_cronjob.create() while not k8s_cronjob.last_schedule_time: k8s_cronjob.get() time.sleep(2) lst = k8s_cronjob.last_schedule_time self.assertIsNotNone(lst) self.assertIsInstance(lst, str)
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])
def test_last_schedule_time(self): name = "job-{}".format(uuid.uuid4()) job = CronJob(_constants.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): k8s_cronjob.create() while not k8s_cronjob.last_schedule_time: k8s_cronjob.get() time.sleep(2) lst = k8s_cronjob.last_schedule_time self.assertIsNotNone(lst) self.assertIsInstance(lst, str)
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)
def test_init_with_invalid_name(self): name = object() with self.assertRaises(SyntaxError): _utils.create_cronjob(name=name)
def test_init_with_invalid_name(self): name = object() with self.assertRaises(SyntaxError): _utils.create_cronjob(name=name)
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)