示例#1
0
文件: base.py 项目: pperezrubio/qonos
 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)
示例#2
0
    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)
示例#3
0
 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)
示例#4
0
 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)
示例#5
0
    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)
示例#6
0
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)
示例#7
0
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)
示例#8
0
 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)
示例#9
0
 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)
示例#10
0
 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)
示例#11
0
    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())
示例#12
0
    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())