def step_impl(context): request = """ { "description": "desc", "id": "example.disk-zero", "labels": {}, "run": { "artifacts": [], "cmd": "echo", "args": ["hello"], "cpus": 0.1, "disk": 0, "maxLaunchDelay": 3600, "mem": 32, "restart": { "activeDeadlineSeconds": 120, "policy": "NEVER" }, "user": "******", "volumes": [] } } """ job = Parse(request, models.JobSpec()) context.client.create_job(job=job)
def step_impl(context): actual = context.client.get_job(job_id='example.complex') expected = models.JobSpec() expected.id = 'example.complex' expected.description = 'Example Application' expected.labels['location'] = 'olympus' expected.labels['owner'] = 'zeus' run = expected.run artifact = run.artifacts.add() artifact.uri = 'http://foo.example.com/application.zip' artifact.extract = True artifact.executable = True artifact.cache = False run.cmd = 'nuke --dry --master local' run.cpus = 1.5 run.mem = 32 run.disk = 128 run.docker.image = 'foo/bla:test' run.env['MON'] = 'test' run.env['CONNECT'] = 'direct' run.maxLaunchDelay = 3600 constraint = run.placement.constraints.add() constraint.attribute = 'rack' constraint.operator = constraint.EQ constraint.value = 'rack-2' run.restart.activeDeadlineSeconds = 120 run.restart.policy = run.restart.NEVER run.user = '******' volume = run.volumes.add() volume.containerPath = '/mnt/test' volume.hostPath = '/etc/guest' volume.mode = volume.RW print(actual) print(expected) assert actual == expected
def base_job(): json_str = """ { "description": "desc", "id": "example.run", "labels": {}, "run": { "artifacts": [], "cmd": "sleep", "args": ["30"], "cpus": 0.1, "disk": 0, "docker": { "image": "library/alpine" }, "maxLaunchDelay": 1, "mem": 32, "restart": { "activeDeadlineSeconds": 120, "policy": "NEVER" }, "user": "******", "volumes": [] } } """ job = Parse(json_str, models.JobSpec()) return job
def test_get_job(): fake_response = """ { "description": "desc", "id": "example", "labels": {}, "run": { "artifacts": [], "cmd": "example", "cpus": 0.1, "mem": 32, "disk": 0, "docker": { "image": "foo" }, "env": { "key1": "val1" }, "maxLaunchDelay": 3600, "restart": { "activeDeadlineSeconds": 120, "policy": "NEVER" }, "user": "******", "volumes": [ { "containerPath": "/mnt/test", "hostPath": "/etc/guest", "mode": "RW" } ] } } """ with requests_mock.mock() as m: m.get('http://fake_server/v1/jobs/example', text=fake_response) mock_client = MetronomeClient(servers='http://fake_server') actual = mock_client.get_job(job_id='example') expected = models.JobSpec() expected.description = 'desc' expected.id = 'example' run = expected.run run.cmd = 'example' run.cpus = 0.1 run.mem = 32.0 run.disk = 0 run.docker.image = 'foo' run.env['key1'] = 'val1' run.maxLaunchDelay = 3600 restart = run.restart restart.activeDeadlineSeconds = 120 restart.policy = restart.NEVER run.user = '******' volume = run.volumes.add() volume.containerPath = '/mnt/test' volume.hostPath = '/etc/guest' volume.mode = volume.RW assert expected == actual
def step_impl(context): request = """ { "description": "Example Application", "id": "example.complex", "labels": { "location": "olympus", "owner": "zeus" }, "run": { "artifacts": [ { "uri": "http://foo.example.com/application.zip", "extract": true, "executable": true, "cache": false } ], "cmd": "nuke --dry --master local", "cpus": 1.5, "mem": 32, "disk": 128, "docker": { "image": "foo/bla:test" }, "env": { "MON": "test", "CONNECT": "direct" }, "maxLaunchDelay": 3600, "placement": { "constraints": [ { "attribute": "rack", "operator": "EQ", "value": "rack-2" } ] }, "restart": { "activeDeadlineSeconds": 120, "policy": "NEVER" }, "user": "******", "volumes": [ { "containerPath": "/mnt/test", "hostPath": "/etc/guest", "mode": "RW" } ] } } """ job = Parse(request, models.JobSpec()) context.client.create_job(job=job)
def test_create_job(): fake_response = """ { "description": "desc", "id": "example", "labels": {}, "run": { "artifacts": [], "cmd": "example", "cpus": 0.1, "disk": 0, "env": {}, "maxLaunchDelay": 3600, "mem": 32, "restart": { "activeDeadlineSeconds": 120, "policy": "NEVER" }, "volumes": [] } } """ request = fake_response with requests_mock.mock() as m: m.post('http://fake_server/v1/jobs', text=fake_response, status_code=201) mock_client = MetronomeClient(servers='http://fake_server') job = Parse(request, models.JobSpec()) actual = mock_client.create_job(job=job) expected = models.JobSpec() expected.description = 'desc' expected.id = 'example' run = expected.run run.cmd = 'example' run.cpus = 0.1 run.disk.value = 0 run.maxLaunchDelay = 3600 run.mem = 32.0 restart = run.restart restart.activeDeadlineSeconds = 120 restart.policy = restart.NEVER assert expected == actual
def test_list_job(): fake_response = """ [ { "description": "desc", "id": "example", "labels": {}, "run": { "artifacts": [], "cmd": "example", "cpus": 0.1, "disk": 0, "env": {}, "maxLaunchDelay": 3600, "mem": 32, "restart": { "activeDeadlineSeconds": 120, "policy": "NEVER" }, "volumes": [] } } ] """ with requests_mock.mock() as m: m.get('http://fake_server/v1/jobs', text=fake_response) mock_client = MetronomeClient(servers='http://fake_server') actual = mock_client.list_jobs() expected = [models.JobSpec()] expected[0].description = 'desc' expected[0].id = 'example' run = expected[0].run run.cmd = 'example' run.cpus = 0.1 run.disk = 0 run.maxLaunchDelay = 3600 run.mem = 32.0 restart = run.restart restart.activeDeadlineSeconds = 120 restart.policy = restart.NEVER assert expected == actual