def test_op_with_embedded_job_template(self): # Embedding a bad template config_dict = { "dependencies": ["foo", "bar"], "params": {"param1": {"value": "foo"}, "param2": {"value": "bar"}}, "trigger": "all_succeeded", "component": { "not_supported_key": "build-template", "tags": ["kaniko"], "run": {"kind": V1RunKind.JOB, "container": {"image": "test"}}, }, } with self.assertRaises(ValidationError): V1Operation.from_dict(config_dict) # Embedding a template without container config_dict = { "dependencies": ["foo", "bar"], "params": {"param1": {"value": "foo"}, "param2": {"value": "bar"}}, "trigger": "all_succeeded", "component": {"name": "build-template", "tags": ["kaniko"]}, } with self.assertRaises(ValidationError): V1Operation.from_dict(config_dict) # Embedding a correct template config_dict = { "dependencies": ["foo", "bar"], "params": {"param1": {"value": "foo"}, "param2": {"value": "bar"}}, "trigger": "all_succeeded", "component": { "name": "build-template", "tags": ["kaniko"], "run": { "kind": V1RunKind.JOB, "container": {"image": "test"}, "init": [{"connection": "foo", "container": {"image": "dev"}}], }, }, } config = V1Operation.from_dict(config_dict) assert config.to_dict() == config_dict
def test_validation(self): config_dict = {"hubRef": "foo", "concurrency": "foo"} with self.assertRaises(ValidationError): V1Operation.from_dict(config_dict) config_dict = {"hubRef": "foo", "dependencies": "foo"} with self.assertRaises(ValidationError): V1Operation.from_dict(config_dict) config_dict = { "hubRef": "foo", "dependencies": ["foo", "bar"], "params": { "param1": { "value": "foo" }, "param2": { "value": "bar" } }, "trigger": "all_succeeded", } config = V1Operation.from_dict(config_dict) assert config.to_dict() == config_dict config_dict = {"hubRef": "foo"} config = V1Operation.from_dict(config_dict) assert config.to_dict() == config_dict config_dict = { "hubRef": "foo", "dependencies": [{ "name": "foo" }, { "name": "bar" }], # Wrong "params": { "param1": { "value": "foo" }, "param2": { "value": "bar" } }, "trigger": "all_succeeded", } with self.assertRaises(ValidationError): V1Operation.from_dict(config_dict)
def test_op_raises_for_template_action_event(self): config_dict = {"hubRef": "foo", "urlRef": "bar"} with self.assertRaises(ValidationError): V1Operation.from_dict(config_dict) config_dict = {"pathRef": "bar", "urlRef": "foo"} with self.assertRaises(ValidationError): V1Operation.from_dict(config_dict) config_dict = {"hubRef": "bar", "urlRef": "foo"} with self.assertRaises(ValidationError): V1Operation.from_dict(config_dict)
def test_op_and_hooks(self): config_dict = { "hooks": [ {"trigger": "succeeded", "connection": "connection1", "hubRef": "ref1"}, {"connection": "connection1", "hubRef": "ref2"}, ], "component": { "run": { "kind": V1RunKind.JOB, "environment": { "nodeSelector": {"polyaxon.com": "node_for_notebook_jobs"} }, "container": {"image": "jupyterlab"}, }, }, } config = V1Operation.from_dict(config_dict) assert config.to_dict() == config_dict
def test_op_template(self): config_dict = { "hooks": [ {"trigger": "succeeded", "connection": "connection1", "hubRef": "ref1"}, {"connection": "connection1", "hubRef": "ref2"}, ], "events": [ {"kinds": [V1EventKind.RUN_STATUS_SCHEDULED], "ref": "test.r1"}, {"kinds": [V1EventKind.RUN_NEW_ARTIFACTS], "ref": "test.r2"}, ], "joins": [ { "query": "dummy: query1", "sort": "dummy sort1", "params": { "u": {"value": "outputs.value"}, }, }, { "query": "dummy: query1", "sort": "-dummy-sort2", "params": { "u": {"value": "artifacts"}, }, }, ], "component": { "run": { "kind": V1RunKind.JOB, "environment": { "nodeSelector": {"polyaxon.com": "node_for_notebook_jobs"} }, "container": {"image": "jupyterlab"}, }, }, "template": { "description": "This is a template, check the fields", "fields": ["actions[1].hubRef", "hooks[0].trigger"], }, } config = V1Operation.from_dict(config_dict) assert config.to_dict() == config_dict
def test_op_template(self): config_dict = { "actions": [ { "hubRef": "ref1" }, { "hubRef": "ref2", "label": "customLabel", "many": True }, ], "hooks": [ { "trigger": "succeeded", "connection": "connection1" }, { "connection": "connection1", "hubRef": "ref2" }, ], "component": { "run": { "kind": V1RunKind.JOB, "environment": { "nodeSelector": { "polyaxon.com": "node_for_notebook_jobs" } }, "container": { "image": "jupyterlab" }, }, }, "template": { "description": "This is a template, check the fields", "fields": ["actions[1].hubRef", "hooks[0].trigger"], }, } config = V1Operation.from_dict(config_dict) assert config.to_dict() == config_dict
def test_op_with_embedded_service_template(self): # Embedding a bad template config_dict = { "dependencies": ["foo", "bar"], "params": { "param1": { "value": "foo" }, "param2": { "value": "bar" } }, "trigger": "all_succeeded", "runPatch": { "kind": V1RunKind.JOB, "init": [{ "connection": "foo", "git": { "revision": "dev" } }], }, "component": { "not_supported_key": "build-template", "tags": ["lab"], "run": { "kind": V1RunKind.JOB, "container": { "image": "jupyterlab" }, "environment": { "nodeSelector": { "polyaxon.com": "node_for_notebook_jobs" }, "config_maps": [{ "name": "config_map1" }], }, }, }, } with self.assertRaises(ValidationError): V1Operation.from_dict(config_dict) # Embedding a correct template config_dict = { "dependencies": ["foo", "bar"], "params": { "param1": { "value": "foo" }, "param2": { "value": "bar" } }, "trigger": "all_succeeded", "runPatch": { "kind": V1RunKind.JOB, "init": [ { "connection": "git-repo1", "git": { "revision": "dev" } }, { "connection": "git-repo1", "container": { "args": "--branch=dev" } }, ], }, "component": { "name": "build-template", "tags": ["lab"], "run": { "kind": V1RunKind.JOB, "environment": { "nodeSelector": { "polyaxon.com": "node_for_notebook_jobs" } }, "container": { "image": "jupyterlab" }, }, }, } config = V1Operation.from_dict(config_dict) assert config.to_dict() == config_dict
def test_op_and_joins(self): config_dict = { "joins": [ { "sort": 2, "params": { "u": { "value": "outputs.value" }, }, }, ], "component": { "run": { "kind": V1RunKind.JOB, "container": { "image": "test" } } }, } with self.assertRaises(ValidationError): V1Operation.from_dict(config_dict) config_dict = { "joins": [ { "query": "dummy: query1", "limit": "foo", }, ], "component": { "run": { "kind": V1RunKind.JOB, "container": { "image": "test" } } }, } with self.assertRaises(ValidationError): V1Operation.from_dict(config_dict) config_dict = { "joins": [ { "query": "dummy: query1", "sort": "dummy sort1", "params": { "u": { "value": "outputs.value" }, }, }, { "query": "dummy: query1", "sort": "-dummy-sort2", "params": { "u": { "value": "artifacts" }, }, }, ], "component": { "run": { "kind": V1RunKind.JOB, "container": { "image": "test" } } }, } config = V1Operation.from_dict(config_dict) assert config.to_dict() == config_dict