Example #1
0
    class Serialization(Spec):
        def before_all(self):
            target = create_target()
            self.targets = [target]

            action = Action(targets=self.targets, action_type='soft-reboot')
            self.actions = [action]

            self.job = Job(
                tenant_id='123',
                name='do_stuff',
                actions=self.actions,
                job_id='12345'
            )

        def can_serialize_to_a_dictionary(self):
            job_dict = self.job.as_dict()
            action_dict = self.actions[0].as_dict()

            expect(job_dict['id']).to.equal(self.job.id)
            expect(job_dict['name']).to.equal(self.job.name)
            expect(job_dict['actions']).to.equal([action_dict])

        def can_serialize_to_a_summary_dictionary(self):
            job_dict = self.job.summary_dict()

            expect(job_dict['id']).to.equal(self.job.id)
            expect(job_dict['name']).to.equal(self.job.name)
Example #2
0
    def on_post(self, req, resp, tenant_id):
        body = self.load_body(req, self.validator)
        body['tenant_id'] = tenant_id

        job = Job.build_job_from_dict(body)
        Job.save_job(job)

        resp.status = falcon.HTTP_201
        resp.body = self.format_response_body({'job_id': job.id})
Example #3
0
        def can_deserialize_from_a_dictionary(self):
            job = Job.build_job_from_dict(self.job_dict)
            test_action_type = self.job_dict['actions'][0]['type']

            expect(job.id).to.equal(self.job_dict['id'])
            expect(job.name).to.equal(self.job_dict['name'])
            expect(job.actions[0].action_type).to.equal(test_action_type)
Example #4
0
    def on_head(self, req, resp, tenant_id, job_id):
        job = Job.get_job(job_id)
        job_ex = JobExecution.build_job_from_dict(job.as_dict())

        if job:
            # TODO(jmv): Figure out scheduling of jobs
            JobExecution.save_job(job_ex)
            job.run_numbers.append(job_ex.run_number)
            Job.update_job(job)
            job = Job.get_job(job_id)

            execute_job.delay(job.id)
            resp.status = falcon.HTTP_200
        else:
            msg = 'Cannot find job: {job_id}'.format(job_id=job_id)
            resp.status = falcon.HTTP_404
            resp.body = json.dumps({'description': msg})
Example #5
0
 def on_get(self, req, resp, tenant_id, job_id):
     job = Job.get_job(job_id)
     if job:
         resp.body = self.format_response_body(job.as_dict())
     else:
         msg = 'Cannot find job: {job_id}'.format(job_id=job_id)
         resp.status = falcon.HTTP_404
         resp.body = json.dumps({'description': msg})
Example #6
0
 def on_head(self, req, resp, tenant_id, job_id):
     job = Job.get_job(job_id)
     if job:
         # TODO(jmv): Figure out scheduling of jobs
         execute_job.delay(job.id)
         resp.status = falcon.HTTP_200
     else:
         msg = 'Cannot find job: {job_id}'.format(job_id=job_id)
         resp.status = falcon.HTTP_404
         resp.body = json.dumps({'description': msg})
Example #7
0
def execute_job(job_id):
    job = Job.get_job(job_id)
    if not job:
        return

    for action in job.actions:
        plugin = get_action_plugin(ACTION_PLUGINS, action.action_type)

        if plugin:
            plugin.execute_action(job, action)
        else:
            print('Failed to execute action: {0}'.format(action.action_type))
Example #8
0
        def before_all(self):
            target = create_target()
            self.targets = [target]

            action = Action(targets=self.targets, action_type='soft-reboot')
            self.actions = [action]

            self.job = Job(
                tenant_id='123',
                name='do_stuff',
                actions=self.actions,
                job_id='12345'
            )
Example #9
0
def execute_job(job_id, run_number):
    job = Job.get_job(job_id)
    if not job:
        return

    job_execution = JobExecution.get_job(run_number)

    for action in job.actions:
        plugin = get_action_plugin(ACTION_PLUGINS, action.action_type)

        if plugin:
            plugin.execute_action(job, action)
        else:
            job_execution.status = 'error'
            JobExecution.update_job(job_execution)
            print('Failed to execute action: {0}'.format(action.action_type))

    if job_execution.status == 'in-progress':
        job_execution.status = 'complete'
        JobExecution.update_job(job_execution)
Example #10
0
 def can_delete(self):
     Job.delete_job(self.job.id, handler=self.handler)
     expect(len(self.handler.delete_document.calls)).to.equal(1)
Example #11
0
        def can_get_jobs(self):
            tenant_id = self.job.tenant_id
            retrieved_jobs = Job.get_jobs(tenant_id, handler=self.handler)

            expect(len(self.handler.get_documents.calls)).to.equal(1)
            expect(len(retrieved_jobs)).to.equal(1)
Example #12
0
        def can_get_a_job(self):
            retrieved_job = Job.get_job(self.job.id, handler=self.handler)

            expect(len(self.handler.get_document.calls)).to.equal(1)
            expect(retrieved_job.id).to.equal(self.job.id)
Example #13
0
 def can_update(self):
     Job.update_job(self.job, handler=self.handler)
     expect(len(self.handler.update_document.calls)).to.equal(1)
Example #14
0
 def can_save(self):
     Job.save_job(self.job, handler=self.handler)
     expect(len(self.handler.insert_document.calls)).to.equal(1)
Example #15
0
 def before_all(self):
     self.job_dict = example_job_dict
     self.job = Job.build_job_from_dict(self.job_dict)
Example #16
0
 def on_get(self, req, resp, tenant_id):
     jobs_list = [job.summary_dict() for job in Job.get_jobs(tenant_id)]
     resp.body = self.format_response_body({'jobs': jobs_list})
Example #17
0
 def on_delete(self, req, resp, tenant_id, job_id):
     Job.delete_job(job_id=job_id)
Example #18
0
 def on_delete(self, req, resp, tenant_id, job_id):
     Job.delete_job(job_id=job_id)
Example #19
0
 def on_get(self, req, resp, tenant_id):
     jobs_list = [job.summary_dict() for job in Job.get_jobs(tenant_id)]
     resp.body = self.format_response_body({'jobs': jobs_list})