def _create_schedules(self): fixture = { 'id': unit_utils.SCHEDULE_UUID1, 'tenant': str(TENANT_1), 'action': 'snapshot', 'minute': 30, 'hour': 2, 'next_run': qonos_utils.cron_string_to_next_datetime(30, 2), 'schedule_metadata': [ { 'key': 'instance_id', 'value': 'my_instance_1', }, ], } self.schedule_1 = self.db_api.schedule_create(fixture) fixture = { 'id': unit_utils.SCHEDULE_UUID2, 'tenant': str(TENANT_2), 'action': 'snapshot', 'minute': 30, 'hour': 3, 'next_run': qonos_utils.cron_string_to_next_datetime(30, 3), } self.schedule_2 = self.db_api.schedule_create(fixture)
def test_cron_string_to_datetime_from_time(self): start_time = datetime.datetime(1900, 5, 16, 0, 0, 0, 0) next_run = utils.cron_string_to_next_datetime(minute=30, hour=5, start_time=start_time) expected = datetime.datetime(1900, 5, 16, 5, 30, 0, 0) self.assertTrue(next_run == expected)
def _create_schedules(self): fixture = { 'tenant_id': unit_utils.TENANT1, 'action': 'snapshot', 'minute': '30', 'hour': '2', 'next_run': qonos_utils.cron_string_to_next_datetime(30, 2) } self.schedule_1 = db_api.schedule_create(fixture) fixture = { 'tenant_id': unit_utils.TENANT2, 'action': 'snapshot', 'minute': '30', 'hour': '3', 'next_run': qonos_utils.cron_string_to_next_datetime(30, 3) } self.schedule_2 = db_api.schedule_create(fixture)
def _schedule_to_next_run(self, schedule): minute = schedule.get('minute', '*') hour = schedule.get('hour', '*') day_of_month = schedule.get('day_of_month', '*') month = schedule.get('month', '*') day_of_week = schedule.get('day_of_week', '*') return utils.cron_string_to_next_datetime(minute, hour, day_of_month, month, day_of_week)
def test_cron_string_to_datetime_from_time(self): start_time = datetime.datetime(1980, 5, 16, 0, 0, 0, 0) next_run = utils.cron_string_to_next_datetime(minute=30, hour=5, start_time=start_time) expected = datetime.datetime(1980, 5, 16, 5, 30, 0, 0) self.assertTrue(next_run == expected)
def schedule_to_next_run(schedule, start_time=None): start_time = start_time or timeutils.utcnow() minute = schedule.get('minute', '*') hour = schedule.get('hour', '*') day_of_month = schedule.get('day_of_month', '*') month = schedule.get('month', '*') day_of_week = schedule.get('day_of_week', '*') return utils.cron_string_to_next_datetime(minute, hour, day_of_month, month, day_of_week, start_time)
def _create_schedules(self): fixture = { 'id': unit_utils.SCHEDULE_UUID1, 'tenant': unit_utils.TENANT1, 'action': 'snapshot', 'minute': '30', 'hour': '2', 'next_run': qonos_utils.cron_string_to_next_datetime(30, 2) } self.schedule_1 = db_api.schedule_create(fixture) fixture = { 'id': unit_utils.SCHEDULE_UUID2, 'tenant': unit_utils.TENANT2, 'action': 'snapshot', 'minute': '30', 'hour': '3', 'next_run': qonos_utils.cron_string_to_next_datetime(30, 3) } self.schedule_2 = db_api.schedule_create(fixture) fixture = { 'id': unit_utils.SCHEDULE_UUID3, 'tenant': unit_utils.TENANT3, 'action': 'snapshot', 'minute': '30', 'hour': '4', 'next_run': qonos_utils.cron_string_to_next_datetime(30, 4) } self.schedule_3 = db_api.schedule_create(fixture) fixture = { 'id': unit_utils.SCHEDULE_UUID4, 'tenant': unit_utils.TENANT4, 'action': 'other', 'minute': '30', 'hour': '5', 'next_run': qonos_utils.cron_string_to_next_datetime(30, 5) } self.schedule_4 = db_api.schedule_create(fixture)
def _create_schedules(self): fixture = { "id": unit_utils.SCHEDULE_UUID1, "tenant": unit_utils.TENANT1, "action": "snapshot", "minute": "30", "hour": "2", "next_run": qonos_utils.cron_string_to_next_datetime(30, 2), } self.schedule_1 = db_api.schedule_create(fixture) fixture = { "id": unit_utils.SCHEDULE_UUID2, "tenant": unit_utils.TENANT2, "action": "snapshot", "minute": "30", "hour": "3", "next_run": qonos_utils.cron_string_to_next_datetime(30, 3), } self.schedule_2 = db_api.schedule_create(fixture) fixture = { "id": unit_utils.SCHEDULE_UUID3, "tenant": unit_utils.TENANT3, "action": "snapshot", "minute": "30", "hour": "4", "next_run": qonos_utils.cron_string_to_next_datetime(30, 4), } self.schedule_3 = db_api.schedule_create(fixture) fixture = { "id": unit_utils.SCHEDULE_UUID4, "tenant": unit_utils.TENANT4, "action": "other", "minute": "30", "hour": "5", "next_run": qonos_utils.cron_string_to_next_datetime(30, 5), } self.schedule_4 = db_api.schedule_create(fixture)
def test_cron_string_to_datetime(self): minute = timeutils.utcnow().minute if minute == 0: minute = 59 else: minute -= 1 hour = timeutils.utcnow().hour if hour == 0: hour = 23 else: hour -= 1 next_run = utils.cron_string_to_next_datetime(minute=minute, hour=hour) self.assertTrue(next_run > timeutils.utcnow())