def test_job_create_no_worker_assigned(self): fixture = { 'action': 'snapshot', 'tenant_id': unit_utils.TENANT1, 'schedule_id': unit_utils.SCHEDULE_UUID2, 'status': 'queued', 'job_metadata': [ { 'key': 'instance_id', 'value': 'my_instance', }, ], } timeutils.set_time_override() now = timeutils.utcnow() job = self.db_api.job_create(fixture) timeutils.clear_time_override() self.assertTrue(uuidutils.is_uuid_like(job['id'])) self.assertNotEqual(job['created_at'], None) self.assertNotEqual(job['updated_at'], None) self.assertEqual(job['timeout'], now + timedelta(seconds=30)) self.assertEqual(job['hard_timeout'], now + timedelta(seconds=30)) self.assertEqual(job['schedule_id'], fixture['schedule_id']) self.assertEqual(job['worker_id'], None) self.assertEqual(job['status'], fixture['status']) self.assertEqual(job['retry_count'], 0) metadata = job['job_metadata'] self.assertEqual(len(metadata), 1) self.assertEqual(metadata[0]['key'], fixture['job_metadata'][0]['key']) self.assertEqual(metadata[0]['value'], fixture['job_metadata'][0]['value'])
def test_schedule_create(self): fixture = { 'tenant_id': str(uuid.uuid4()), 'action': 'snapshot', 'minute': 30, 'hour': 2, 'schedule_metadata': [ { 'key': 'instance_id', 'value': 'my_instance', }, ], } schedule = self.db_api.schedule_create(fixture) self.assertTrue(uuidutils.is_uuid_like(schedule['id'])) self.assertEqual(schedule['tenant_id'], fixture['tenant_id']) self.assertEqual(schedule['action'], fixture['action']) self.assertEqual(schedule['minute'], fixture['minute']) self.assertEqual(schedule['hour'], fixture['hour']) metadata = schedule['schedule_metadata'] self.assertEqual(len(metadata), 1) self.assertEqual(metadata[0]['key'], fixture['schedule_metadata'][0]['key']) self.assertEqual(metadata[0]['value'], fixture['schedule_metadata'][0]['value']) self.assertNotEqual(schedule['created_at'], None) self.assertNotEqual(schedule['updated_at'], None)
def test_worker_create(self): fixture = {'host': 'i.am.cowman'} worker = self.db_api.worker_create(fixture) self.assertTrue(uuidutils.is_uuid_like(worker['id'])) self.assertEqual(worker['host'], fixture['host']) self.assertNotEqual(worker['created_at'], None) self.assertNotEqual(worker['updated_at'], None)
def test_schedule_update_remove_metadata(self): fixture = { 'id': str(uuid.uuid4()), 'tenant': str(uuid.uuid4()), 'action': 'snapshot', 'minute': 30, 'hour': 2, 'schedule_metadata': [ { 'key': 'instance_id', 'value': 'my_instance', }, ], } schedule = self.db_api.schedule_create(fixture) fixture = { 'schedule_metadata': [], } timeutils.set_time_override() timeutils.advance_time_seconds(2) updated_schedule = self.db_api.schedule_update(schedule['id'], fixture) timeutils.clear_time_override() self.assertTrue(uuidutils.is_uuid_like(schedule['id'])) self.assertEqual(updated_schedule['tenant'], schedule['tenant']) self.assertEqual(updated_schedule['action'], schedule['action']) self.assertEqual(updated_schedule['minute'], schedule['minute']) self.assertEqual(updated_schedule['hour'], schedule['hour']) metadata = updated_schedule['schedule_metadata'] self.assertEqual(len(metadata), 0) # updated child metadata collection doesn't update the parent schedule self.assertEqual(updated_schedule['updated_at'], schedule['updated_at'])
def test_job_fault_create_minimal(self): fixture = { 'schedule_id': str(uuid.uuid4()), 'tenant': str(uuid.uuid4()), 'worker_id': str(uuid.uuid4()), 'job_id': str(uuid.uuid4()), 'action': 'milking', } job_fault = self.db_api.job_fault_create(fixture) self.assertTrue(uuidutils.is_uuid_like(job_fault['id'])) self.assertEqual(job_fault['schedule_id'], fixture['schedule_id']) self.assertEqual(job_fault['tenant'], fixture['tenant']) self.assertEqual(job_fault['worker_id'], fixture['worker_id']) self.assertEqual(job_fault['job_id'], fixture['job_id']) self.assertEqual(job_fault['action'], fixture['action']) self.assertNotEqual(job_fault['created_at'], None) self.assertNotEqual(job_fault['updated_at'], None)
def test_job_fault_create_full(self): fixture = { 'schedule_id': str(uuid.uuid4()), 'tenant': str(uuid.uuid4()), 'worker_id': str(uuid.uuid4()), 'job_id': str(uuid.uuid4()), 'action': 'milking', 'message': 'There are too many cows here!', 'job_metadata': 'When were these cows supposed to leave?', } job_fault = self.db_api.job_fault_create(fixture) self.assertTrue(uuidutils.is_uuid_like(job_fault['id'])) self.assertEqual(job_fault['schedule_id'], fixture['schedule_id']) self.assertEqual(job_fault['tenant'], fixture['tenant']) self.assertEqual(job_fault['worker_id'], fixture['worker_id']) self.assertEqual(job_fault['job_id'], fixture['job_id']) self.assertEqual(job_fault['action'], fixture['action']) self.assertEqual(job_fault['message'], fixture['message']) self.assertEqual(job_fault['job_metadata'], fixture['job_metadata']) self.assertNotEqual(job_fault['created_at'], None) self.assertNotEqual(job_fault['updated_at'], None)
def test_job_create(self): now = timeutils.utcnow() timeout = now + datetime.timedelta(hours=1) hard_timeout = now + datetime.timedelta(hours=4) fixture = { 'action': 'snapshot', 'tenant': unit_utils.TENANT1, 'schedule_id': unit_utils.SCHEDULE_UUID2, 'worker_id': unit_utils.WORKER_UUID2, 'status': 'queued', 'timeout': timeout, 'hard_timeout': hard_timeout, 'job_metadata': [ { 'key': 'instance_id', 'value': 'my_instance', }, ], } job = self.db_api.job_create(fixture) self.assertTrue(uuidutils.is_uuid_like(job['id'])) self.assertNotEqual(job['created_at'], None) self.assertNotEqual(job['updated_at'], None) self.assertEqual(job['timeout'], fixture['timeout']) self.assertEqual(job['hard_timeout'], fixture['hard_timeout']) self.assertEqual(job['schedule_id'], fixture['schedule_id']) self.assertEqual(job['worker_id'], fixture['worker_id']) self.assertEqual(job['status'], fixture['status']) self.assertEqual(job['retry_count'], 0) metadata = job['job_metadata'] self.assertEqual(len(metadata), 1) self.assertEqual(metadata[0]['key'], fixture['job_metadata'][0]['key']) self.assertEqual(metadata[0]['value'], fixture['job_metadata'][0]['value'])
def test_schedule_update(self): fixture = { 'id': str(uuid.uuid4()), 'tenant_id': str(uuid.uuid4()), 'action': 'snapshot', 'minute': 30, 'hour': 2, } schedule = self.db_api.schedule_create(fixture) fixture = {'hour': 3} timeutils.set_time_override() timeutils.advance_time_seconds(2) updated_schedule = self.db_api.schedule_update(schedule['id'], fixture) timeutils.clear_time_override() self.assertTrue(uuidutils.is_uuid_like(schedule['id'])) self.assertEqual(updated_schedule['tenant_id'], schedule['tenant_id']) self.assertEqual(updated_schedule['action'], schedule['action']) self.assertEqual(updated_schedule['minute'], schedule['minute']) self.assertEqual(updated_schedule['hour'], fixture['hour']) self.assertEqual(updated_schedule['created_at'], schedule['created_at']) self.assertNotEqual(updated_schedule['updated_at'], schedule['updated_at'])