def test_tag_put_mismatch_with_agents(self):
        agent_id = uuid.uuid4()

        # create an agent to link to
        response1 = self.client.post(
            "/api/v1/agents/",
            content_type="application/json",
            data=dumps({
                "id": agent_id,
                "cpu_allocation": 1.0,
                "cpus": 16,
                "free_ram": 133,
                "hostname": "testagent1",
                "remote_ip": "10.0.200.1",
                "port": 64994,
                "ram": 2048,
                "ram_allocation": 0.8,
                "state": "running"}))
        self.assert_created(response1)
        agent_id = response1.json["id"]

        response2 = self.client.put(
            "/api/v1/tags/foo",
            content_type="application/json",
            data=dumps({
                "tag": "bar",
                "agents": [agent_id]}))
        self.assert_bad_request(response2)
    def test_task_logs_get_single_log_wrong_task(self):
        job_id, task_id, agent_id = self.make_objects()

        response1 = self.client.post(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/" % (job_id, task_id),
            content_type="application/json",
            data=dumps({
                "identifier": "testlogidentifier",
                "agent_id": agent_id}))
        self.assert_created(response1)

        response2 = self.client.post(
            "/api/v1/jobs/",
            content_type="application/json",
            data=dumps({
                    "start": 1.0,
                    "end": 1.0,
                    "title": "Test Job 2",
                    "jobtype": "TestJobType",
                    "data": {"foo": "bar"},
                    "software_requirements": []
                    }))
        self.assert_created(response2)
        job2_id = response2.json["id"]

        response3 = self.client.get("/api/v1/jobs/%s/tasks/" % job2_id)
        self.assert_ok(response3)
        self.assertEqual(len(response3.json), 1)
        task2_id = response3.json[0]["id"]

        response4 = self.client.get(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/testlogidentifier" %
                (job2_id, task2_id))
        self.assert_not_found(response4)
    def test_tag_put(self):
        response1 = self.client.put(
            "/api/v1/tags/foo",
            content_type="application/json",
            data=dumps({
                "tag": "foo"}))
        self.assert_created(response1)

        # Must be idempotent
        response2 = self.client.put(
            "/api/v1/tags/foo",
            content_type="application/json",
            data=dumps({
                "tag": "foo"}))
        self.assert_created(response2)
        id = response2.json["id"]

        response3 = self.client.get("/api/v1/tags/foo")
        self.assert_ok(response3)
        self.assertEqual(
            response3.json, {
                "agents": [],
                "id": id,
                "jobs": [],
                "tag": "foo"
                })
Beispiel #4
0
    def test_pathmap_edit(self):
        response1 = self.client.post("/api/v1/pathmaps/",
                                     content_type="application/json",
                                     data=dumps({
                                         "path_linux": "/test",
                                         "path_windows": "c:\\test",
                                         "path_osx": "/test",
                                         "tag": "testtag"
                                     }))
        self.assert_created(response1)
        id = response1.json['id']

        response2 = self.client.post("/api/v1/pathmaps/%s" % id,
                                     content_type="application/json",
                                     data=dumps({
                                         "path_linux": "/test2",
                                         "tag": "newtag"
                                     }))
        self.assert_ok(response2)
        self.assertEqual(
            response2.json, {
                "id": id,
                "path_linux": "/test2",
                "path_windows": "c:\\test",
                "path_osx": "/test",
                "tag": "newtag"
            })
    def make_objects(self):
        response1 = self.client.post("/api/v1/agents/",
                                     content_type="application/json",
                                     data=dumps({
                                         "id": uuid.uuid4(),
                                         "cpu_allocation": 1.0,
                                         "cpus": 16,
                                         "free_ram": 133,
                                         "hostname": "testagent1",
                                         "remote_ip": "10.0.200.1",
                                         "port": 64994,
                                         "ram": 2048,
                                         "ram_allocation": 0.8,
                                         "state": "running"
                                     }))
        self.assert_created(response1)
        agent_id = response1.json["id"]

        response2 = self.client.post(
            "/api/v1/jobtypes/",
            content_type="application/json",
            data=dumps({
                "name": "TestJobType",
                "description": "Jobtype for testing inserts and queries",
                "max_batch": 1,
                "code": "dummy code"
            }))
        self.assert_created(response2)
        jobtype_id = response2.json['id']

        response3 = self.client.post("/api/v1/jobs/",
                                     content_type="application/json",
                                     data=dumps({
                                         "start": 1.0,
                                         "end": 1.0,
                                         "title": "Test Job",
                                         "jobtype": "TestJobType",
                                         "data": {
                                             "foo": "bar"
                                         },
                                         "software_requirements": []
                                     }))
        self.assert_created(response3)
        job_id = response3.json["id"]

        response4 = self.client.get("/api/v1/jobs/%s/tasks/" % job_id)
        self.assert_ok(response4)
        self.assertEqual(len(response4.json), 1)

        return job_id, response4.json[0]["id"], agent_id
    def test_tag_post_existing(self):
        response1 = self.client.post(
            "/api/v1/tags/",
            content_type="application/json",
            data=dumps({
                "tag": "foo"}))
        self.assert_created(response1)

        response2 = self.client.post(
            "/api/v1/tags/",
            content_type="application/json",
            data=dumps({
                "tag": "foo"}))
        self.assert_ok(response2)
    def make_objects(self):
        response1 = self.client.post(
            "/api/v1/agents/",
            content_type="application/json",
            data=dumps({
                "id": uuid.uuid4(),
                "cpu_allocation": 1.0,
                "cpus": 16,
                "free_ram": 133,
                "hostname": "testagent1",
                "remote_ip": "10.0.200.1",
                "port": 64994,
                "ram": 2048,
                "ram_allocation": 0.8,
                "state": "running"}))
        self.assert_created(response1)
        agent_id = response1.json["id"]

        response2 = self.client.post(
            "/api/v1/jobtypes/",
            content_type="application/json",
            data=dumps({
                    "name": "TestJobType",
                    "description": "Jobtype for testing inserts and queries",
                    "max_batch": 1,
                    "code": "dummy code"
                    }))
        self.assert_created(response2)
        jobtype_id = response2.json['id']

        response3 = self.client.post(
            "/api/v1/jobs/",
            content_type="application/json",
            data=dumps({
                    "start": 1.0,
                    "end": 1.0,
                    "title": "Test Job",
                    "jobtype": "TestJobType",
                    "data": {"foo": "bar"},
                    "software_requirements": []
                    }))
        self.assert_created(response3)
        job_id = response3.json["id"]

        response4 = self.client.get("/api/v1/jobs/%s/tasks/" % job_id)
        self.assert_ok(response4)
        self.assertEqual(len(response4.json), 1)

        return job_id, response4.json[0]["id"], agent_id
 def test_tag_put_mismatch(self):
     response1 = self.client.put(
         "/api/v1/tags/foo",
         content_type="application/json",
         data=dumps({
             "tag": "bar"}))
     self.assert_bad_request(response1)
    def test_task_logs_get_single_log(self):
        job_id, task_id, agent_id = self.make_objects()

        response1 = self.client.post(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/" % (job_id, task_id),
            content_type="application/json",
            data=dumps({
                "identifier": "testlogidentifier",
                "agent_id": agent_id
            }))
        self.assert_created(response1)
        created_on = response1.json["created_on"]
        log_id = response1.json["id"]

        response2 = self.client.get(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/testlogidentifier" %
            (job_id, task_id))
        self.assert_ok(response2)
        self.assertEqual(
            response2.json, {
                "identifier": "testlogidentifier",
                "agent_id": agent_id,
                "created_on": created_on,
                "id": log_id
            })
    def test_task_logs_download_logfile(self):
        job_id, task_id, agent_id = self.make_objects()

        response1 = self.client.post(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/" % (job_id, task_id),
            content_type="application/json",
            data=dumps({
                "identifier": "testlogidentifier",
                "agent_id": agent_id
            }))
        self.assert_created(response1)
        created_on = response1.json["created_on"]

        response2 = self.client.put(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/testlogidentifier/logfile"
            % (job_id, task_id),
            content_type="text/csv",
            data=dummy_log)
        self.assert_created(response2)

        response3 = self.client.get(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/testlogidentifier/logfile"
            % (job_id, task_id))
        self.assert_ok(response3)
        self.assertEqual(response3.data.decode(), dummy_log)
    def test_agent_delete(self):
        agent_id = uuid.uuid4()
        response1 = self.client.post("/api/v1/agents/",
                                     content_type="application/json",
                                     data=dumps({
                                         "id": agent_id,
                                         "cpu_allocation": 1.0,
                                         "cpus": 16,
                                         "free_ram": 133,
                                         "hostname": "testagent4",
                                         "remote_ip": "10.0.200.5",
                                         "port": 64994,
                                         "ram": 2048,
                                         "ram_allocation": 0.8,
                                         "state": "running"
                                     }))
        self.assert_created(response1)
        id = response1.json["id"]

        response2 = self.client.delete("/api/v1/agents/%s" % id)
        self.assert_no_content(response2)
        response3 = self.client.delete("/api/v1/agents/%s" % id)
        self.assert_no_content(response3)
        response4 = self.client.get("/api/v1/agents/%s" % id)
        self.assert_not_found(response4)
    def test_agent_read_write(self):
        agent_id = uuid.uuid4()
        response1 = self.client.post(
            "/api/v1/agents/",
            content_type="application/json",
            data=dumps(
                {
                    "id": agent_id,
                    "cpu_allocation": 1.0,
                    "cpus": 16,
                    "os_class": "windows",
                    "os_fullname": "Windows 7 SP1",
                    "cpu_name": "Zilog Z80",
                    "free_ram": 133,
                    "hostname": "testagent1",
                    "remote_ip": "10.0.200.1",
                    "port": 64994,
                    "ram": 2048,
                    "ram_allocation": 0.8,
                    "state": "running",
                }
            ),
        )
        self.assert_created(response1)
        id = response1.json["id"]
        self.assertIn("last_heard_from", response1.json)
        last_heard_from = response1.json["last_heard_from"]

        response2 = self.client.get("/api/v1/agents/%s" % agent_id)
        self.assert_ok(response2)
        self.assertEqual(
            response2.json,
            {
                "ram": 2048,
                "cpu_allocation": 1.0,
                "use_address": "remote",
                "remote_ip": "10.0.200.1",
                "hostname": "testagent1",
                "version": None,
                "upgrade_to": None,
                "cpus": 16,
                "os_class": "windows",
                "os_fullname": "Windows 7 SP1",
                "cpu_name": "Zilog Z80",
                "ram_allocation": 0.8,
                "port": 64994,
                "time_offset": 0,
                "state": "running",
                "free_ram": 133,
                "id": id,
                "last_polled": None,
                "notes": "",
                "restart_requested": False,
                "last_heard_from": last_heard_from,
                "last_success_on": None,
                "disks": [],
                "gpus": [],
                "tags": [],
            },
        )
    def test_pathmap_edit_bad_col(self):
        response1 = self.client.post(
            "/api/v1/pathmaps/",
            content_type="application/json",
            data=dumps({"path_linux": "/test",
                        "path_windows": "c:\\test",
                        "path_osx": "/test",
                        "tag": "testtag"}))
        self.assert_created(response1)
        id = response1.json['id']

        response2 = self.client.post(
            "/api/v1/pathmaps/%s" % id,
            content_type="application/json",
            data=dumps({"unknown_key": 1.0}))
        self.assert_bad_request(response2)
    def test_agent_delete(self):
        agent_id = uuid.uuid4()
        response1 = self.client.post(
            "/api/v1/agents/",
            content_type="application/json",
            data=dumps(
                {
                    "id": agent_id,
                    "cpu_allocation": 1.0,
                    "cpus": 16,
                    "free_ram": 133,
                    "hostname": "testagent4",
                    "remote_ip": "10.0.200.5",
                    "port": 64994,
                    "ram": 2048,
                    "ram_allocation": 0.8,
                    "state": "running",
                }
            ),
        )
        self.assert_created(response1)
        id = response1.json["id"]

        response2 = self.client.delete("/api/v1/agents/%s" % id)
        self.assert_no_content(response2)
        response3 = self.client.delete("/api/v1/agents/%s" % id)
        self.assert_no_content(response3)
        response4 = self.client.get("/api/v1/agents/%s" % id)
        self.assert_not_found(response4)
Beispiel #15
0
    def test_pathmap_edit_bad_col(self):
        response1 = self.client.post("/api/v1/pathmaps/",
                                     content_type="application/json",
                                     data=dumps({
                                         "path_linux": "/test",
                                         "path_windows": "c:\\test",
                                         "path_osx": "/test",
                                         "tag": "testtag"
                                     }))
        self.assert_created(response1)
        id = response1.json['id']

        response2 = self.client.post("/api/v1/pathmaps/%s" % id,
                                     content_type="application/json",
                                     data=dumps({"unknown_key": 1.0}))
        self.assert_bad_request(response2)
 def test_task_logs_register_logfile_unknown_task(self):
     response1 = self.client.post(
         "/api/v1/jobs/42/tasks/42/attempts/1/logs/",
         content_type="application/json",
         data=dumps({
             "identifier": "testlogidentifier",
             "agent_id": uuid.uuid4()}))
     self.assert_not_found(response1)
 def test_tag_put_with_wrong_agent(self):
     response1 = self.client.put(
         "/api/v1/tags/foo",
         content_type="application/json",
         data=dumps({
             "tag": "foo",
             "agents": [uuid.uuid4()]}))
     self.assert_not_found(response1)
 def test_pathmap_post_bad_tag(self):
     response1 = self.client.post(
         "/api/v1/pathmaps/",
         content_type="application/json",
         data=dumps({"path_linux": "/test",
                     "path_windows": "c:\\test",
                     "path_osx": "/test",
                     "tag": 1.0}))
     self.assert_bad_request(response1)
 def test_task_logs_register_logfile_unknown_task(self):
     response1 = self.client.post(
         "/api/v1/jobs/42/tasks/42/attempts/1/logs/",
         content_type="application/json",
         data=dumps({
             "identifier": "testlogidentifier",
             "agent_id": uuid.uuid4()
         }))
     self.assert_not_found(response1)
    def test_task_logs_download_logfile_wrong_task(self):
        job_id, task_id, agent_id = self.make_objects()

        response1 = self.client.post(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/" % (job_id, task_id),
            content_type="application/json",
            data=dumps({
                "identifier": "testlogidentifier",
                "agent_id": agent_id
            }))
        self.assert_created(response1)
        created_on = response1.json["created_on"]

        response2 = self.client.put(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/testlogidentifier/logfile"
            % (job_id, task_id),
            content_type="text/csv",
            data=dummy_log)
        self.assert_created(response2)

        response3 = self.client.post("/api/v1/jobs/",
                                     content_type="application/json",
                                     data=dumps({
                                         "start": 1.0,
                                         "end": 1.0,
                                         "title": "Test Job 2",
                                         "jobtype": "TestJobType",
                                         "data": {
                                             "foo": "bar"
                                         },
                                         "software_requirements": []
                                     }))
        self.assert_created(response3)
        job2_id = response3.json["id"]

        response4 = self.client.get("/api/v1/jobs/%s/tasks/" % job2_id)
        self.assert_ok(response4)
        self.assertEqual(len(response4.json), 1)
        task2_id = response4.json[0]["id"]

        response5 = self.client.get(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/testlogidentifier/logfile"
            % (job2_id, task2_id))
        self.assert_not_found(response5)
    def test_tag_post_agent(self):
        agent_id = uuid.uuid4()

        # create an agent to link to
        response1 = self.client.post(
            "/api/v1/agents/",
            content_type="application/json",
            data=dumps({
                "id": agent_id,
                "cpu_allocation": 1.0,
                "cpus": 16,
                "free_ram": 133,
                "hostname": "testagent1",
                "remote_ip": "10.0.200.1",
                "port": 64994,
                "ram": 2048,
                "ram_allocation": 0.8,
                "state": "running"}))
        self.assert_created(response1)
        agent_id = response1.json["id"]

        response2 = self.client.put(
            "/api/v1/tags/foo",
            content_type="application/json",
            data=dumps({
                "tag": "foo"}))
        self.assert_created(response2)

        response3 = self.client.post(
            "/api/v1/tags/foo/agents/",
            content_type="application/json",
            data=dumps({"agent_id": agent_id}))
        self.assert_created(response3)

        response4 = self.client.get(
            "/api/v1/tags/foo/agents/",
            content_type="application/json")
        self.assert_ok(response4)
        self.assertEqual(
            response4.json, [
                {"hostname": "testagent1",
                 "href": "/api/v1/agents/%s" % agent_id,
                 "id": agent_id}])
Beispiel #22
0
 def test_pathmap_post_bad_tag(self):
     response1 = self.client.post("/api/v1/pathmaps/",
                                  content_type="application/json",
                                  data=dumps({
                                      "path_linux": "/test",
                                      "path_windows": "c:\\test",
                                      "path_osx": "/test",
                                      "tag": 1.0
                                  }))
     self.assert_bad_request(response1)
    def test_task_logs_register_logfile_twice(self):
        job_id, task_id, agent_id = self.make_objects()

        response1 = self.client.post(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/" % (job_id, task_id),
            content_type="application/json",
            data=dumps({
                "identifier": "testlogidentifier",
                "agent_id": agent_id}))
        self.assert_created(response1)
        created_on = response1.json["created_on"]

        response2 = self.client.post(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/" % (job_id, task_id),
            content_type="application/json",
            data=dumps({
                "identifier": "testlogidentifier",
                "agent_id": agent_id}))
        self.assert_conflict(response2)
    def test_agent_read_write(self):
        agent_id = uuid.uuid4()
        response1 = self.client.post("/api/v1/agents/",
                                     content_type="application/json",
                                     data=dumps({
                                         "id": agent_id,
                                         "cpu_allocation": 1.0,
                                         "cpus": 16,
                                         "os_class": "windows",
                                         "os_fullname": "Windows 7 SP1",
                                         "cpu_name": "Zilog Z80",
                                         "free_ram": 133,
                                         "hostname": "testagent1",
                                         "remote_ip": "10.0.200.1",
                                         "port": 64994,
                                         "ram": 2048,
                                         "ram_allocation": 0.8,
                                         "state": "running"
                                     }))
        self.assert_created(response1)
        id = response1.json["id"]
        self.assertIn("last_heard_from", response1.json)
        last_heard_from = response1.json["last_heard_from"]

        response2 = self.client.get("/api/v1/agents/%s" % agent_id)
        self.assert_ok(response2)
        self.assertEqual(
            response2.json, {
                "ram": 2048,
                "cpu_allocation": 1.0,
                "use_address": "remote",
                "remote_ip": "10.0.200.1",
                "hostname": "testagent1",
                "version": None,
                "upgrade_to": None,
                "cpus": 16,
                "os_class": "windows",
                "os_fullname": "Windows 7 SP1",
                "cpu_name": "Zilog Z80",
                "ram_allocation": 0.8,
                "port": 64994,
                "time_offset": 0,
                "state": "running",
                "free_ram": 133,
                "id": id,
                "last_polled": None,
                "notes": "",
                "restart_requested": False,
                "last_heard_from": last_heard_from,
                "last_success_on": None,
                "disks": [],
                "gpus": [],
                "tags": []
            })
    def test_task_logs_register_logfile_twice(self):
        job_id, task_id, agent_id = self.make_objects()

        response1 = self.client.post(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/" % (job_id, task_id),
            content_type="application/json",
            data=dumps({
                "identifier": "testlogidentifier",
                "agent_id": agent_id
            }))
        self.assert_created(response1)
        created_on = response1.json["created_on"]

        response2 = self.client.post(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/" % (job_id, task_id),
            content_type="application/json",
            data=dumps({
                "identifier": "testlogidentifier",
                "agent_id": agent_id
            }))
        self.assert_conflict(response2)
    def test_pathmap_edit(self):
        response1 = self.client.post(
            "/api/v1/pathmaps/",
            content_type="application/json",
            data=dumps({"path_linux": "/test",
                        "path_windows": "c:\\test",
                        "path_osx": "/test",
                        "tag": "testtag"}))
        self.assert_created(response1)
        id = response1.json['id']

        response2 = self.client.post(
            "/api/v1/pathmaps/%s" % id,
            content_type="application/json",
            data=dumps({"path_linux": "/test2",
                        "tag": "newtag"}))
        self.assert_ok(response2)
        self.assertEqual(response2.json,
                         {"id": id,
                          "path_linux": "/test2",
                          "path_windows": "c:\\test",
                          "path_osx": "/test",
                          "tag": "newtag"})
    def test_task_logs_download_logfile_failed_redirect(self):
        job_id, task_id, agent_id = self.make_objects()

        response1 = self.client.post(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/" % (job_id, task_id),
            content_type="application/json",
            data=dumps({"identifier": "testlogidentifier-neveruploaded"}))
        self.assert_created(response1)
        created_on = response1.json["created_on"]

        response2 = self.client.get("/api/v1/jobs/%s/tasks/%s/attempts/1/logs/"
                                    "testlogidentifier-neveruploaded/logfile" %
                                    (job_id, task_id))
        self.assert_not_found(response2)
    def test_task_logs_download_logfile_failed_redirect(self):
        job_id, task_id, agent_id = self.make_objects()

        response1 = self.client.post(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/" % (job_id, task_id),
            content_type="application/json",
            data=dumps({
                "identifier": "testlogidentifier-neveruploaded"}))
        self.assert_created(response1)
        created_on = response1.json["created_on"]

        response2 = self.client.get(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/"
            "testlogidentifier-neveruploaded/logfile" % (job_id, task_id))
        self.assert_not_found(response2)
    def test_pathmap_delete(self):
        response1 = self.client.post(
            "/api/v1/pathmaps/",
            content_type="application/json",
            data=dumps({"path_linux": "/test",
                        "path_windows": "c:\\test",
                        "path_osx": "/test",
                        "tag": "testtag"}))
        self.assert_created(response1)
        id = response1.json['id']

        response2 = self.client.delete("/api/v1/pathmaps/%s" % id)
        self.assert_no_content(response2)

        response3 = self.client.get("/api/v1/pathmaps/%s" % id)
        self.assert_not_found(response3)
Beispiel #30
0
    def test_pathmap_delete(self):
        response1 = self.client.post("/api/v1/pathmaps/",
                                     content_type="application/json",
                                     data=dumps({
                                         "path_linux": "/test",
                                         "path_windows": "c:\\test",
                                         "path_osx": "/test",
                                         "tag": "testtag"
                                     }))
        self.assert_created(response1)
        id = response1.json['id']

        response2 = self.client.delete("/api/v1/pathmaps/%s" % id)
        self.assert_no_content(response2)

        response3 = self.client.get("/api/v1/pathmaps/%s" % id)
        self.assert_not_found(response3)
    def test_tag_post(self):
        response1 = self.client.post(
            "/api/v1/tags/",
            content_type="application/json",
            data=dumps({
                "tag": "foo"}))
        self.assert_created(response1)
        id = response1.json["id"]

        response2 = self.client.get("/api/v1/tags/%d" % id)
        self.assert_ok(response2)
        self.assertEqual(
            response2.json, {
                "agents": [],
                "id": 1,
                "jobs": [],
                "tag": "foo"
                })
    def test_tag_delete(self):
        response1 = self.client.put(
            "/api/v1/tags/foo",
            content_type="application/json",
            data=dumps({
                "tag": "foo"}))
        self.assert_created(response1)

        response2 = self.client.delete("/api/v1/tags/foo")
        self.assert_no_content(response2)

        response3 = self.client.get("/api/v1/tags/foo")
        self.assert_not_found(response3)

        # Must be idempotent
        response4 = self.client.delete("/api/v1/tags/foo")
        self.assert_no_content(response4)

        response5 = self.client.get("/api/v1/tags/foo")
        self.assert_not_found(response5)
    def test_task_logs_download_logfile(self):
        job_id, task_id, agent_id = self.make_objects()

        response1 = self.client.post(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/" % (job_id, task_id),
            content_type="application/json",
            data=dumps({
                "identifier": "testlogidentifier",
                "agent_id": agent_id}))
        self.assert_created(response1)
        created_on = response1.json["created_on"]

        response2 = self.client.put(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/testlogidentifier/logfile"
            % (job_id, task_id),
            content_type="text/csv",
            data=dummy_log)
        self.assert_created(response2)

        response3 = self.client.get(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/testlogidentifier/logfile"
            % (job_id, task_id))
        self.assert_ok(response3)
        self.assertEqual(response3.data.decode(), dummy_log)
    def test_task_logs_get_single_log(self):
        job_id, task_id, agent_id = self.make_objects()

        response1 = self.client.post(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/" % (job_id, task_id),
            content_type="application/json",
            data=dumps({
                "identifier": "testlogidentifier",
                "agent_id": agent_id}))
        self.assert_created(response1)
        created_on = response1.json["created_on"]
        log_id = response1.json["id"]

        response2 = self.client.get(
            "/api/v1/jobs/%s/tasks/%s/attempts/1/logs/testlogidentifier" %
                (job_id, task_id))
        self.assert_ok(response2)
        self.assertEqual(response2.json,
                         {
                             "identifier": "testlogidentifier",
                             "agent_id": agent_id,
                             "created_on": created_on,
                             "id": log_id
                         })
    def test_post_agents(self):
        agent_id = uuid.uuid4()
        response1 = self.client.post(
            "/api/v1/agents/",
            content_type="application/json",
            data=dumps(
                {
                    "id": agent_id,
                    "cpu_allocation": 1.0,
                    "cpus": 16,
                    "os_class": "linux",
                    "os_fullname": "Linux-3.17.4-glibc-2.2",
                    "cpu_name": "Zilog Z80",
                    "free_ram": 133,
                    "hostname": "testagent3",
                    "remote_ip": "10.0.200.3",
                    "port": 64994,
                    "ram": 2048,
                    "ram_allocation": 0.8,
                    "state": "running",
                }
            ),
        )
        self.assert_created(response1)
        id = response1.json["id"]

        # Using this endpoint, we should be able to change everything about an
        # agent except its id
        response2 = self.client.post(
            "/api/v1/agents/%s" % id,
            content_type="application/json",
            data=dumps(
                {
                    "id": id,
                    "cpu_allocation": 1.2,
                    "ram": 8192,
                    "use_address": "hostname",
                    "remote_ip": "10.0.200.4",
                    "hostname": "testagent3-1",
                    "cpus": 64,
                    "os_class": "mac",
                    "os_fullname": "Mac OS X 10.10",
                    "cpu_name": "6502",
                    "ram_allocation": 0.2,
                    "port": 64995,
                    "time_offset": 5,
                    "state": "running",
                    "free_ram": 4096,
                }
            ),
        )
        self.assert_ok(response2)
        self.assertIn("last_heard_from", response2.json)
        last_heard_from = response2.json["last_heard_from"]

        # See if we get the updated data back
        response3 = self.client.get("/api/v1/agents/%s" % agent_id)
        self.assert_ok(response3)
        self.assertEqual(
            response3.json,
            {
                "ram": 8192,
                "cpu_allocation": 1.2,
                "use_address": "hostname",
                "remote_ip": "10.0.200.4",
                "hostname": "testagent3-1",
                "version": None,
                "upgrade_to": None,
                "cpus": 64,
                "os_class": "mac",
                "os_fullname": "Mac OS X 10.10",
                "cpu_name": "6502",
                "ram_allocation": 0.2,
                "port": 64995,
                "time_offset": 5,
                "state": "running",
                "free_ram": 4096,
                "id": str(agent_id),
                "last_polled": None,
                "notes": "",
                "restart_requested": False,
                "last_heard_from": last_heard_from,
                "last_success_on": None,
                "disks": [],
                "gpus": [],
                "tags": [],
            },
        )
    def setUp(self):
        super(TestAgentAPIFilter, self).setUp()
        self.agent_1_id = uuid.uuid4()
        self.assert_created(
            self.client.post("/api/v1/agents/",
                             content_type="application/json",
                             data=dumps({
                                 "id": self.agent_1_id,
                                 "cpu_allocation": 1.0,
                                 "cpus": 8,
                                 "free_ram": 133,
                                 "hostname": "lowcpu-lowram",
                                 "remote_ip": "10.0.200.6",
                                 "port": 64994,
                                 "ram": 1024,
                                 "ram_allocation": 0.8,
                                 "state": "running"
                             })))

        self.agent_2_id = uuid.uuid4()
        self.assert_created(
            self.client.post("/api/v1/agents/",
                             content_type="application/json",
                             data=dumps({
                                 "id": self.agent_2_id,
                                 "cpu_allocation": 1.0,
                                 "cpus": 8,
                                 "free_ram": 133,
                                 "hostname": "lowcpu-highram",
                                 "remote_ip": "10.0.200.7",
                                 "port": 64994,
                                 "ram": 4096,
                                 "ram_allocation": 0.8,
                                 "state": "running"
                             })))

        self.agent_3_id = uuid.uuid4()
        self.assert_created(
            self.client.post("/api/v1/agents/",
                             content_type="application/json",
                             data=dumps({
                                 "id": self.agent_3_id,
                                 "cpu_allocation": 1.0,
                                 "cpus": 16,
                                 "free_ram": 133,
                                 "hostname": "highcpu-lowram",
                                 "remote_ip": "10.0.200.8",
                                 "port": 64994,
                                 "ram": 1024,
                                 "ram_allocation": 0.8,
                                 "state": "running"
                             })))

        self.agent_4_id = uuid.uuid4()
        self.assert_created(
            self.client.post("/api/v1/agents/",
                             content_type="application/json",
                             data=dumps({
                                 "id": self.agent_4_id,
                                 "cpu_allocation": 1.0,
                                 "cpus": 16,
                                 "free_ram": 133,
                                 "hostname": "highcpu-highram",
                                 "remote_ip": "10.0.200.9",
                                 "port": 64994,
                                 "ram": 4096,
                                 "ram_allocation": 0.8,
                                 "state": "running"
                             })))

        self.agent_5_id = uuid.uuid4()
        self.assert_created(
            self.client.post("/api/v1/agents/",
                             content_type="application/json",
                             data=dumps({
                                 "id": self.agent_5_id,
                                 "cpu_allocation": 1.0,
                                 "cpus": 12,
                                 "free_ram": 133,
                                 "hostname": "middlecpu-middleram",
                                 "remote_ip": "10.0.200.10",
                                 "port": 64994,
                                 "ram": 2048,
                                 "ram_allocation": 0.8,
                                 "state": "running"
                             })))
    def test_post_agents(self):
        agent_id = uuid.uuid4()
        response1 = self.client.post("/api/v1/agents/",
                                     content_type="application/json",
                                     data=dumps({
                                         "id": agent_id,
                                         "cpu_allocation": 1.0,
                                         "cpus": 16,
                                         "os_class": "linux",
                                         "os_fullname":
                                         "Linux-3.17.4-glibc-2.2",
                                         "cpu_name": "Zilog Z80",
                                         "free_ram": 133,
                                         "hostname": "testagent3",
                                         "remote_ip": "10.0.200.3",
                                         "port": 64994,
                                         "ram": 2048,
                                         "ram_allocation": 0.8,
                                         "state": "running"
                                     }))
        self.assert_created(response1)
        id = response1.json["id"]

        # Using this endpoint, we should be able to change everything about an
        # agent except its id
        response2 = self.client.post("/api/v1/agents/%s" % id,
                                     content_type="application/json",
                                     data=dumps({
                                         "id": id,
                                         "cpu_allocation": 1.2,
                                         "ram": 8192,
                                         "use_address": "hostname",
                                         "remote_ip": "10.0.200.4",
                                         "hostname": "testagent3-1",
                                         "cpus": 64,
                                         "os_class": "mac",
                                         "os_fullname": "Mac OS X 10.10",
                                         "cpu_name": "6502",
                                         "ram_allocation": 0.2,
                                         "port": 64995,
                                         "time_offset": 5,
                                         "state": "running",
                                         "free_ram": 4096
                                     }))
        self.assert_ok(response2)
        self.assertIn("last_heard_from", response2.json)
        last_heard_from = response2.json["last_heard_from"]

        # See if we get the updated data back
        response3 = self.client.get("/api/v1/agents/%s" % agent_id)
        self.assert_ok(response3)
        self.assertEqual(
            response3.json, {
                "ram": 8192,
                "cpu_allocation": 1.2,
                "use_address": "hostname",
                "remote_ip": "10.0.200.4",
                "hostname": "testagent3-1",
                "version": None,
                "upgrade_to": None,
                "cpus": 64,
                "os_class": "mac",
                "os_fullname": "Mac OS X 10.10",
                "cpu_name": "6502",
                "ram_allocation": 0.2,
                "port": 64995,
                "time_offset": 5,
                "state": "running",
                "free_ram": 4096,
                "id": str(agent_id),
                "last_polled": None,
                "notes": "",
                "restart_requested": False,
                "last_heard_from": last_heard_from,
                "last_success_on": None,
                "disks": [],
                "gpus": [],
                "tags": []
            })
Beispiel #38
0
    def test_pathmap_list(self):
        response1 = self.client.post("/api/v1/pathmaps/",
                                     content_type="application/json",
                                     data=dumps({
                                         "path_linux": "/test",
                                         "path_windows": "c:\\test",
                                         "path_osx": "/test",
                                         "tag": "testtag1"
                                     }))
        self.assert_created(response1)
        id1 = response1.json['id']
        response2 = self.client.post("/api/v1/pathmaps/",
                                     content_type="application/json",
                                     data=dumps({
                                         "path_linux": "/test2",
                                         "path_windows": "c:\\test2",
                                         "path_osx": "/test2",
                                         "tag": "testtag2"
                                     }))
        self.assert_created(response2)
        id2 = response2.json['id']
        response3 = self.client.post("/api/v1/pathmaps/",
                                     content_type="application/json",
                                     data=dumps({
                                         "path_linux": "/test3",
                                         "path_windows": "c:\\test3",
                                         "path_osx": "/test3"
                                     }))
        self.assert_created(response3)
        id3 = response3.json['id']

        agent_id = uuid.uuid4()

        response4 = self.client.post("/api/v1/agents/",
                                     content_type="application/json",
                                     data=dumps({
                                         "id": agent_id,
                                         "cpus": 16,
                                         "free_ram": 133,
                                         "hostname": "testagent1",
                                         "remote_ip": "10.0.200.1",
                                         "port": 64994,
                                         "ram": 2048
                                     }))
        self.assert_created(response4)

        response5 = self.client.post("/api/v1/tags/testtag1/agents/",
                                     content_type="application/json",
                                     data=dumps({"agent_id": agent_id}))
        self.assert_created(response5)

        response6 = self.client.get("/api/v1/pathmaps/?for_agent=%s" %
                                    agent_id)
        self.assert_ok(response6)
        self.assertEqual(response6.json, [{
            "id": id1,
            "path_linux": "/test",
            "path_windows": "c:\\test",
            "path_osx": "/test",
            "tag": "testtag1"
        }, {
            "id": id3,
            "path_linux": "/test3",
            "path_windows": "c:\\test3",
            "path_osx": "/test3"
        }])
 def test_pathmap_edit_unknown(self):
     response1 = self.client.post(
         "/api/v1/pathmaps/42",
         content_type="application/json",
         data=dumps({"path_linux": "/test2"}))
     self.assert_not_found(response1)
    def test_create_agent(self):
        agent_id_1 = uuid.uuid4()
        agent_id_2 = uuid.uuid4()
        agent_id_3 = uuid.uuid4()
        agents = [
            {
                "cpu_allocation": 1.0,
                "cpus": 16,
                "free_ram": 133,
                "id": agent_id_1,
                "hostname": "testagent2",
                "remote_ip": "10.0.200.2",
                "port": 64994,
                "ram": 2048,
                "ram_allocation": 0.8,
                "state": "running",
            },
            {
                "cpu_allocation": 1.0,
                "cpus": 16,
                "free_ram": 133,
                "id": agent_id_2,
                "hostname": "testagent2",
                "remote_ip": "10.0.200.2",
                "port": 64995,
                "ram": 2048,
                "ram_allocation": 0.8,
                "state": "running",
            },
            {
                "cpu_allocation": 1.0,
                "cpus": 16,
                "free_ram": 133,
                "id": agent_id_3,
                "hostname": "testagent2",
                "remote_ip": "10.0.200.2",
                "port": 64996,
                "ram": 2048,
                "ram_allocation": 0.8,
                "state": "running",
            },
        ]
        expected_agents = [
            {
                "free_ram": 133,
                "ram_allocation": 0.8,
                "id": str(agent_id_1),
                "ram": 2048,
                "time_offset": 0,
                "cpu_allocation": 1.0,
                "state": "running",
                "port": 64994,
                "cpus": 16,
                "cpu_name": None,
                "hostname": "testagent2",
                "version": None,
                "upgrade_to": None,
                "use_address": "remote",
                "remote_ip": "10.0.200.2",
                "os_class": None,
                "os_fullname": None,
                "last_polled": None,
                "restart_requested": False,
                "notes": "",
                "tags": [],
                "last_success_on": None,
            },
            {
                "free_ram": 133,
                "ram_allocation": 0.8,
                "id": str(agent_id_2),
                "ram": 2048,
                "time_offset": 0,
                "cpu_allocation": 1.0,
                "state": "running",
                "port": 64995,
                "cpus": 16,
                "cpu_name": None,
                "hostname": "testagent2",
                "version": None,
                "upgrade_to": None,
                "use_address": "remote",
                "remote_ip": "10.0.200.2",
                "os_class": None,
                "os_fullname": None,
                "last_polled": None,
                "restart_requested": False,
                "notes": "",
                "tags": [],
                "last_success_on": None,
            },
            {
                "free_ram": 133,
                "ram_allocation": 0.8,
                "id": str(agent_id_3),
                "ram": 2048,
                "time_offset": 0,
                "cpu_allocation": 1.0,
                "state": "running",
                "port": 64996,
                "cpus": 16,
                "cpu_name": None,
                "hostname": "testagent2",
                "version": None,
                "upgrade_to": None,
                "use_address": "remote",
                "remote_ip": "10.0.200.2",
                "os_class": None,
                "os_fullname": None,
                "last_polled": None,
                "restart_requested": False,
                "notes": "",
                "tags": [],
                "last_success_on": None,
            },
        ]

        created_agents = []
        for agent in agents:
            response = self.client.post("/api/v1/agents/", content_type="application/json", data=dumps(agent))
            self.assert_created(response)
            self.assertIn("last_heard_from", response.json)
            del response.json["last_heard_from"]
            created_agents.append(response.json)

        self.assert_contents_equal(created_agents, expected_agents)
Beispiel #41
0
 def test_pathmap_edit_unknown(self):
     response1 = self.client.post("/api/v1/pathmaps/42",
                                  content_type="application/json",
                                  data=dumps({"path_linux": "/test2"}))
     self.assert_not_found(response1)
    def test_pathmap_list(self):
        response1 = self.client.post(
            "/api/v1/pathmaps/",
            content_type="application/json",
            data=dumps({"path_linux": "/test",
                        "path_windows": "c:\\test",
                        "path_osx": "/test",
                        "tag": "testtag1"}))
        self.assert_created(response1)
        id1 = response1.json['id']
        response2 = self.client.post(
            "/api/v1/pathmaps/",
            content_type="application/json",
            data=dumps({"path_linux": "/test2",
                        "path_windows": "c:\\test2",
                        "path_osx": "/test2",
                        "tag": "testtag2"}))
        self.assert_created(response2)
        id2 = response2.json['id']
        response3 = self.client.post(
            "/api/v1/pathmaps/",
            content_type="application/json",
            data=dumps({"path_linux": "/test3",
                        "path_windows": "c:\\test3",
                        "path_osx": "/test3"}))
        self.assert_created(response3)
        id3 = response3.json['id']

        agent_id = uuid.uuid4()

        response4 = self.client.post(
            "/api/v1/agents/",
            content_type="application/json",
            data=dumps({
                "id": agent_id,
                "cpus": 16,
                "free_ram": 133,
                "hostname": "testagent1",
                "remote_ip": "10.0.200.1",
                "port": 64994,
                "ram": 2048}))
        self.assert_created(response4)

        response5 = self.client.post(
            "/api/v1/tags/testtag1/agents/",
            content_type="application/json",
            data=dumps({"agent_id": agent_id}))
        self.assert_created(response5)

        response6 = self.client.get("/api/v1/pathmaps/?for_agent=%s" % agent_id)
        self.assert_ok(response6)
        self.assertEqual(
            response6.json,
                [
                    {
                        "id": id1,
                        "path_linux": "/test",
                        "path_windows": "c:\\test",
                        "path_osx": "/test",
                        "tag": "testtag1"
                    },
                    {
                        "id": id3,
                        "path_linux": "/test3",
                        "path_windows": "c:\\test3",
                        "path_osx": "/test3"
                    }
                ])
    def setUp(self):
        super(TestAgentAPIFilter, self).setUp()
        self.agent_1_id = uuid.uuid4()
        self.assert_created(
            self.client.post(
                "/api/v1/agents/",
                content_type="application/json",
                data=dumps(
                    {
                        "id": self.agent_1_id,
                        "cpu_allocation": 1.0,
                        "cpus": 8,
                        "free_ram": 133,
                        "hostname": "lowcpu-lowram",
                        "remote_ip": "10.0.200.6",
                        "port": 64994,
                        "ram": 1024,
                        "ram_allocation": 0.8,
                        "state": "running",
                    }
                ),
            )
        )

        self.agent_2_id = uuid.uuid4()
        self.assert_created(
            self.client.post(
                "/api/v1/agents/",
                content_type="application/json",
                data=dumps(
                    {
                        "id": self.agent_2_id,
                        "cpu_allocation": 1.0,
                        "cpus": 8,
                        "free_ram": 133,
                        "hostname": "lowcpu-highram",
                        "remote_ip": "10.0.200.7",
                        "port": 64994,
                        "ram": 4096,
                        "ram_allocation": 0.8,
                        "state": "running",
                    }
                ),
            )
        )

        self.agent_3_id = uuid.uuid4()
        self.assert_created(
            self.client.post(
                "/api/v1/agents/",
                content_type="application/json",
                data=dumps(
                    {
                        "id": self.agent_3_id,
                        "cpu_allocation": 1.0,
                        "cpus": 16,
                        "free_ram": 133,
                        "hostname": "highcpu-lowram",
                        "remote_ip": "10.0.200.8",
                        "port": 64994,
                        "ram": 1024,
                        "ram_allocation": 0.8,
                        "state": "running",
                    }
                ),
            )
        )

        self.agent_4_id = uuid.uuid4()
        self.assert_created(
            self.client.post(
                "/api/v1/agents/",
                content_type="application/json",
                data=dumps(
                    {
                        "id": self.agent_4_id,
                        "cpu_allocation": 1.0,
                        "cpus": 16,
                        "free_ram": 133,
                        "hostname": "highcpu-highram",
                        "remote_ip": "10.0.200.9",
                        "port": 64994,
                        "ram": 4096,
                        "ram_allocation": 0.8,
                        "state": "running",
                    }
                ),
            )
        )

        self.agent_5_id = uuid.uuid4()
        self.assert_created(
            self.client.post(
                "/api/v1/agents/",
                content_type="application/json",
                data=dumps(
                    {
                        "id": self.agent_5_id,
                        "cpu_allocation": 1.0,
                        "cpus": 12,
                        "free_ram": 133,
                        "hostname": "middlecpu-middleram",
                        "remote_ip": "10.0.200.10",
                        "port": 64994,
                        "ram": 2048,
                        "ram_allocation": 0.8,
                        "state": "running",
                    }
                ),
            )
        )
    def test_create_agent(self):
        agent_id_1 = uuid.uuid4()
        agent_id_2 = uuid.uuid4()
        agent_id_3 = uuid.uuid4()
        agents = [{
            "cpu_allocation": 1.0,
            "cpus": 16,
            "free_ram": 133,
            "id": agent_id_1,
            "hostname": "testagent2",
            "remote_ip": "10.0.200.2",
            "port": 64994,
            "ram": 2048,
            "ram_allocation": 0.8,
            "state": "running"
        }, {
            "cpu_allocation": 1.0,
            "cpus": 16,
            "free_ram": 133,
            "id": agent_id_2,
            "hostname": "testagent2",
            "remote_ip": "10.0.200.2",
            "port": 64995,
            "ram": 2048,
            "ram_allocation": 0.8,
            "state": "running"
        }, {
            "cpu_allocation": 1.0,
            "cpus": 16,
            "free_ram": 133,
            "id": agent_id_3,
            "hostname": "testagent2",
            "remote_ip": "10.0.200.2",
            "port": 64996,
            "ram": 2048,
            "ram_allocation": 0.8,
            "state": "running"
        }]
        expected_agents = [{
            "free_ram": 133,
            "ram_allocation": 0.8,
            "id": str(agent_id_1),
            "ram": 2048,
            "time_offset": 0,
            "cpu_allocation": 1.0,
            "state": "running",
            "port": 64994,
            "cpus": 16,
            "cpu_name": None,
            "hostname": "testagent2",
            "version": None,
            "upgrade_to": None,
            "use_address": "remote",
            "remote_ip": "10.0.200.2",
            "os_class": None,
            "os_fullname": None,
            "last_polled": None,
            "restart_requested": False,
            "notes": "",
            "tags": [],
            "last_success_on": None
        }, {
            "free_ram": 133,
            "ram_allocation": 0.8,
            "id": str(agent_id_2),
            "ram": 2048,
            "time_offset": 0,
            "cpu_allocation": 1.0,
            "state": "running",
            "port": 64995,
            "cpus": 16,
            "cpu_name": None,
            "hostname": "testagent2",
            "version": None,
            "upgrade_to": None,
            "use_address": "remote",
            "remote_ip": "10.0.200.2",
            "os_class": None,
            "os_fullname": None,
            "last_polled": None,
            "restart_requested": False,
            "notes": "",
            "tags": [],
            "last_success_on": None
        }, {
            "free_ram": 133,
            "ram_allocation": 0.8,
            "id": str(agent_id_3),
            "ram": 2048,
            "time_offset": 0,
            "cpu_allocation": 1.0,
            "state": "running",
            "port": 64996,
            "cpus": 16,
            "cpu_name": None,
            "hostname": "testagent2",
            "version": None,
            "upgrade_to": None,
            "use_address": "remote",
            "remote_ip": "10.0.200.2",
            "os_class": None,
            "os_fullname": None,
            "last_polled": None,
            "restart_requested": False,
            "notes": "",
            "tags": [],
            "last_success_on": None
        }]

        created_agents = []
        for agent in agents:
            response = self.client.post("/api/v1/agents/",
                                        content_type="application/json",
                                        data=dumps(agent))
            self.assert_created(response)
            self.assertIn("last_heard_from", response.json)
            del response.json["last_heard_from"]
            created_agents.append(response.json)

        self.assert_contents_equal(created_agents, expected_agents)