Esempio n. 1
0
    def test_worker_log_event(self):
        w = Worker("w1", "ubuntu", 12, 2, "aarch64", "key", 2, [])
        w.enlisted = True
        db.session.add(w)
        db.session.commit()
        headers = [
            ("Content-type", "application/json"),
            ("Authorization", "Token key"),
        ]

        event = '{"key": "val"}'
        resp = self.client.post("/workers/w1/events/",
                                headers=headers,
                                data=event)
        self.assertEqual(201, resp.status_code, resp.data)
        p = os.path.join(jobserv.models.WORKER_DIR, "w1/events.log")
        with open(p) as f:
            buf = f.read()
            self.assertEqual(event, buf)

        w.deleted = True
        db.session.commit()
        resp = self.client.post("/workers/w1/events/",
                                headers=headers,
                                data=event)
        self.assertEqual(404, resp.status_code, resp.data)
Esempio n. 2
0
    def test_worker_log_event(self):
        w = Worker('w1', 'ubuntu', 12, 2, 'aarch64', 'key', 2, [])
        w.enlisted = True
        db.session.add(w)
        db.session.commit()
        headers = [
            ('Content-type', 'application/json'),
            ('Authorization', 'Token key'),
        ]

        event = '{"key": "val"}'
        resp = self.client.post('/workers/w1/events/',
                                headers=headers,
                                data=event)
        self.assertEqual(201, resp.status_code, resp.data)
        p = os.path.join(jobserv.models.WORKER_DIR, 'w1/events.log')
        with open(p) as f:
            buf = f.read()
            self.assertEqual(event, buf)

        w.deleted = True
        db.session.commit()
        resp = self.client.post('/workers/w1/events/',
                                headers=headers,
                                data=event)
        self.assertEqual(404, resp.status_code, resp.data)
Esempio n. 3
0
    def test_surge_complex(self):
        # we'll have two amd64 workers and one armhf
        worker = Worker('w2', 'd', 1, 1, 'amd64', 'k', 1, 'amd64')
        worker.enlisted = True
        worker.online = True
        db.session.add(worker)
        worker = Worker('w3', 'd', 1, 1, 'armhf', 'k', 1, 'armhf')
        worker.enlisted = True
        worker.online = True
        db.session.add(worker)
        db.session.commit()

        self.create_projects('proj1')
        b = Build.create(Project.query.all()[0])
        for x in range(SURGE_SUPPORT_RATIO + 1):
            r = Run(b, 'amd%d' % x)
            r.host_tag = 'amd64'
            db.session.add(r)
            r = Run(b, 'armhf%d' % x)
            r.host_tag = 'armhf'
            db.session.add(r)

        db.session.commit()
        _check_queue()
        self.assertFalse(os.path.exists(jobserv.worker.SURGE_FILE + '-amd64'))
        self.assertTrue(os.path.exists(jobserv.worker.SURGE_FILE + '-armhf'))

        # get us under surge for armhf
        db.session.delete(Run.query.filter(Run.host_tag == 'armhf').first())
        # and over surge for amd64
        for x in range(SURGE_SUPPORT_RATIO + 1):
            r = Run(b, 'run%d' % x)
            r.host_tag = 'amd64'
            db.session.add(r)

        db.session.commit()
        worker_module.DETECT_FLAPPING = False
        _check_queue()
        self.assertTrue(os.path.exists(jobserv.worker.SURGE_FILE + '-amd64'))
        self.assertFalse(os.path.exists(jobserv.worker.SURGE_FILE + '-armhf'))

        # make sure we know about deleted workers
        worker.deleted = True
        db.session.commit()
        _check_queue()
        self.assertTrue(os.path.exists(jobserv.worker.SURGE_FILE + '-armhf'))
Esempio n. 4
0
    def test_worker_list(self):
        db.session.add(Worker('w1', 'ubuntu', 12, 2, 'aarch64', 'key', 2, []))
        w = Worker('w2', 'fedora', 14, 4, 'amd64', 'key', 2, [])
        db.session.add(w)
        db.session.commit()
        data = self.get_json('/workers/')
        self.assertEqual(2, len(data['workers']))
        self.assertEqual('w1', data['workers'][0]['name'])
        self.assertEqual(False, data['workers'][0]['enlisted'])
        self.assertEqual('w2', data['workers'][1]['name'])
        self.assertEqual(False, data['workers'][1]['enlisted'])

        w.deleted = True
        db.session.commit()
        data = self.get_json('/workers/')
        self.assertEqual(1, len(data['workers']))
        self.assertEqual('w1', data['workers'][0]['name'])
Esempio n. 5
0
    def test_surge_complex(self):
        # we'll have two amd64 workers and one armhf
        worker = Worker("w2", "d", 1, 1, "amd64", "k", 1, "amd64")
        worker.enlisted = True
        worker.online = True
        db.session.add(worker)
        worker = Worker("w3", "d", 1, 1, "armhf", "k", 1, "armhf")
        worker.enlisted = True
        worker.online = True
        db.session.add(worker)
        db.session.commit()

        self.create_projects("proj1")
        b = Build.create(Project.query.all()[0])
        for x in range(SURGE_SUPPORT_RATIO + 1):
            r = Run(b, "amd%d" % x)
            r.host_tag = "amd64"
            db.session.add(r)
            r = Run(b, "armhf%d" % x)
            r.host_tag = "armhf"
            db.session.add(r)

        db.session.commit()
        _check_queue()
        self.assertFalse(os.path.exists(jobserv.worker.SURGE_FILE + "-amd64"))
        self.assertTrue(os.path.exists(jobserv.worker.SURGE_FILE + "-armhf"))

        # get us under surge for armhf
        db.session.delete(Run.query.filter(Run.host_tag == "armhf").first())
        # and over surge for amd64
        for x in range(SURGE_SUPPORT_RATIO + 1):
            r = Run(b, "run%d" % x)
            r.host_tag = "amd64"
            db.session.add(r)

        db.session.commit()
        worker_module.DETECT_FLAPPING = False
        _check_queue()
        self.assertTrue(os.path.exists(jobserv.worker.SURGE_FILE + "-amd64"))
        self.assertFalse(os.path.exists(jobserv.worker.SURGE_FILE + "-armhf"))

        # make sure we know about deleted workers
        worker.deleted = True
        db.session.commit()
        _check_queue()
        self.assertTrue(os.path.exists(jobserv.worker.SURGE_FILE + "-armhf"))
Esempio n. 6
0
    def test_worker_list(self):
        db.session.add(Worker("w1", "ubuntu", 12, 2, "aarch64", "key", 2, []))
        w = Worker("w2", "fedora", 14, 4, "amd64", "key", 2, [])
        db.session.add(w)
        db.session.commit()
        data = self.get_json("/workers/")
        self.assertEqual(2, len(data["workers"]))
        self.assertEqual("w1", data["workers"][0]["name"])
        self.assertEqual(False, data["workers"][0]["enlisted"])
        self.assertEqual("w2", data["workers"][1]["name"])
        self.assertEqual(False, data["workers"][1]["enlisted"])

        w.deleted = True
        db.session.commit()
        data = self.get_json("/workers/")
        self.assertEqual(1, len(data["workers"]))
        self.assertEqual("w1", data["workers"][0]["name"])
Esempio n. 7
0
    def test_worker_update(self):
        headers = [
            ('Content-type', 'application/json'),
            ('Authorization', 'Token key'),
        ]
        w = Worker('w1', 'ubuntu', 12, 2, 'aarch64', 'key', 2, [])
        db.session.add(w)
        db.session.commit()
        data = {'distro': 'ArchLinux'}
        r = self.client.patch('/workers/w1/',
                              headers=headers,
                              data=json.dumps(data))
        self.assertEqual(200, r.status_code)

        data = self.get_json('/workers/w1/')
        self.assertEqual('ArchLinux', data['worker']['distro'])

        w.deleted = True
        db.session.commit()
        r = self.client.patch('/workers/w1/',
                              headers=headers,
                              data=json.dumps(data))
        self.assertEqual(404, r.status_code)
Esempio n. 8
0
    def test_worker_update(self):
        headers = [
            ("Content-type", "application/json"),
            ("Authorization", "Token key"),
        ]
        w = Worker("w1", "ubuntu", 12, 2, "aarch64", "key", 2, [])
        db.session.add(w)
        db.session.commit()
        data = {"distro": "ArchLinux"}
        r = self.client.patch("/workers/w1/",
                              headers=headers,
                              data=json.dumps(data))
        self.assertEqual(200, r.status_code)

        data = self.get_json("/workers/w1/", headers=headers)
        self.assertEqual("ArchLinux", data["worker"]["distro"])

        w.deleted = True
        db.session.commit()
        r = self.client.patch("/workers/w1/",
                              headers=headers,
                              data=json.dumps(data))
        self.assertEqual(404, r.status_code)