def _init_qonos_client(self, schedule=None): if schedule is not None: self.qonos_client.get_schedule(mox.IsA(str)).\ AndReturn(schedule) else: self.qonos_client.get_schedule(mox.IsA(str)).\ AndRaise(qonos_ex.NotFound())
def _do_request(self, method, url, body=None): conn = httplib.HTTPConnection(self.endpoint, self.port) if body and isinstance(body, dict): body = json.dumps(body) try: conn.request(method, url, body=body, headers={'Content-Type': 'application/json'}) except Exception: msg = 'Could not contact Qonos API, is it running?' raise exception.ConnRefused(msg) response = conn.getresponse() if response.status == 400: raise exception.BadRequest('Bad Request Received') if response.status == 404: raise exception.NotFound('Resource Not Found') if response.status == 409: raise exception.Duplicate('Resource Exists') if method != 'DELETE': body = response.read() if body != '': return json.loads(body)
def _do_request(self, method, url, body=None): conn = httplib.HTTPConnection(self.endpoint, self.port) if body and isinstance(body, dict): body = json.dumps(body) try: qonos_req_id = uuid.uuid4() msg = 'Making Qonos request, method: %s, url: %s, id: %s' LOG.info(msg % (method, url, qonos_req_id)) conn.request(method, url, body=body, headers={'Content-Type': 'application/json', 'x-qonos-request-id': str(qonos_req_id)}) except Exception: msg = 'Could not contact Qonos API, is it running?' raise exception.ConnRefused(msg) msg = 'Reading response for Qonos request, method: %s, url: %s, id: %s' LOG.info(msg % (method, url, qonos_req_id)) response = conn.getresponse() if response.status == 400: raise exception.BadRequest('Bad Request Received') if response.status == 404: raise exception.NotFound('Resource Not Found') if response.status == 409: raise exception.Duplicate('Resource Exists') if method != 'DELETE': body = response.read() if body != '': return json.loads(body)
def test_process_job_should_cancel_if_schedule_not_exist(self): server = self.server_instance_fixture("INSTANCE_ID", "test") job = self.job_fixture(server.id) with TestableSnapshotProcessor(job, server, []) as processor: processor.qonosclient.get_schedule = mock.Mock( side_effect=qonos_ex.NotFound()) processor.process_job(job) self.assert_update_job_statuses(processor, ['CANCELLED']) self.assertEqual('CANCELLED', job['status'])
def test_notifications_for_cancelled_job_on_schedule_not_exist(self): server = self.server_instance_fixture("INSTANCE_ID", "test") job = self.job_fixture(server.id) with TestableSnapshotProcessor(job, server, []) as processor: processor.qonosclient.get_schedule = mock.Mock( side_effect=qonos_ex.NotFound()) processor.process_job(job) self.assertEqual('CANCELLED', job['status']) expected_notifications = [ ('qonos.job.run.start', 'INFO', 'QUEUED'), ('qonos.job.update', 'INFO', 'CANCELLED')] self.assert_job_notification_events(processor, expected_notifications)