예제 #1
0
 def _test_is_newer_than(self, fn, datetime_mock):
     datetime_mock.utcnow.return_value = self.skynet_self_aware_time
     expect_true = timeutils.is_newer_than(fn(self.one_minute_after), 59)
     self.assertTrue(expect_true)
     expect_false = timeutils.is_newer_than(fn(self.one_minute_after), 60)
     self.assertFalse(expect_false)
     expect_false = timeutils.is_newer_than(fn(self.one_minute_after), 61)
     self.assertFalse(expect_false)
예제 #2
0
파일: test_timeutils.py 프로젝트: to30/tmp
 def _test_is_newer_than(self, fn):
     strptime = datetime.datetime.strptime
     with mock.patch('datetime.datetime') as datetime_mock:
         datetime_mock.utcnow.return_value = self.skynet_self_aware_time
         datetime_mock.strptime = strptime
         expect_true = timeutils.is_newer_than(fn(self.one_minute_after),
                                               59)
         self.assertTrue(expect_true)
         expect_false = timeutils.is_newer_than(fn(self.one_minute_after),
                                                60)
         self.assertFalse(expect_false)
         expect_false = timeutils.is_newer_than(fn(self.one_minute_after),
                                                61)
         self.assertFalse(expect_false)
예제 #3
0
 def _test_is_newer_than(self, fn):
     strptime = datetime.datetime.strptime
     with mock.patch('datetime.datetime') as datetime_mock:
         datetime_mock.utcnow.return_value = self.skynet_self_aware_time
         datetime_mock.strptime = strptime
         expect_true = timeutils.is_newer_than(fn(self.one_minute_after),
                                               59)
         self.assertTrue(expect_true)
         expect_false = timeutils.is_newer_than(fn(self.one_minute_after),
                                                60)
         self.assertFalse(expect_false)
         expect_false = timeutils.is_newer_than(fn(self.one_minute_after),
                                                61)
         self.assertFalse(expect_false)
예제 #4
0
def refresh_cluster_ssc(backend, na_server, vserver, synchronous=False):
    """Refresh cluster ssc for backend."""
    if not isinstance(na_server, netapp_api.NaServer):
        raise exception.InvalidInput(reason=_("Backend server not NaServer."))
    delta_secs = getattr(backend, 'ssc_run_delta_secs', 1800)
    if getattr(backend, 'ssc_job_running', None):
        LOG.warning(_LW('ssc job in progress. Returning... '))
        return
    elif (getattr(backend, 'ssc_run_time', None) is None
          or (backend.ssc_run_time
              and timeutils.is_newer_than(backend.ssc_run_time, delta_secs))):
        if synchronous:
            get_cluster_latest_ssc(backend, na_server, vserver)
        else:
            t = threading.Timer(0,
                                get_cluster_latest_ssc,
                                args=[backend, na_server, vserver])
            t.start()
    elif getattr(backend, 'refresh_stale_running', None):
        LOG.warning(_LW('refresh stale ssc job in progress. Returning... '))
        return
    else:
        if backend.stale_vols:
            if synchronous:
                refresh_cluster_stale_ssc(backend, na_server, vserver)
            else:
                t = threading.Timer(0,
                                    refresh_cluster_stale_ssc,
                                    args=[backend, na_server, vserver])
                t.start()
예제 #5
0
def refresh_cluster_ssc(backend, na_server, vserver, synchronous=False):
    """Refresh cluster ssc for backend."""
    if not isinstance(na_server, netapp_api.NaServer):
        raise exception.InvalidInput(reason=_("Backend server not NaServer."))
    delta_secs = getattr(backend, 'ssc_run_delta_secs', 1800)
    if getattr(backend, 'ssc_job_running', None):
        LOG.warning(_LW('ssc job in progress. Returning... '))
        return
    elif (getattr(backend, 'ssc_run_time', None) is None or
          (backend.ssc_run_time and
           timeutils.is_newer_than(backend.ssc_run_time, delta_secs))):
        if synchronous:
            get_cluster_latest_ssc(backend, na_server, vserver)
        else:
            t = threading.Timer(0, get_cluster_latest_ssc,
                                args=[backend, na_server, vserver])
            t.start()
    elif getattr(backend, 'refresh_stale_running', None):
        LOG.warning(_LW('refresh stale ssc job in progress. Returning... '))
        return
    else:
        if backend.stale_vols:
            if synchronous:
                refresh_cluster_stale_ssc(backend, na_server, vserver)
            else:
                t = threading.Timer(0, refresh_cluster_stale_ssc,
                                    args=[backend, na_server, vserver])
                t.start()
예제 #6
0
    def _refresh_volume_info(self):
        """Saves the volume information for the filer."""

        if (self.vol_refresh_time is None or self.vol_refresh_voluntary or
                timeutils.is_newer_than(self.vol_refresh_time,
                                        self.vol_refresh_interval)):
            try:
                job_set = na_utils.set_safe_attr(self, 'vol_refresh_running',
                                                 True)
                if not job_set:
                    LOG.warning(_LW("Volume refresh job already running. "
                                    "Returning..."))
                    return
                self.vol_refresh_voluntary = False
                self.vols = self.zapi_client.get_filer_volumes()
                self.vol_refresh_time = timeutils.utcnow()
            except Exception as e:
                LOG.warning(_LW("Error refreshing volume info. Message: %s"),
                            e)
            finally:
                na_utils.set_safe_attr(self, 'vol_refresh_running', False)
예제 #7
0
    def _refresh_volume_info(self):
        """Saves the volume information for the filer."""

        if (self.vol_refresh_time is None
                or self.vol_refresh_voluntary or timeutils.is_newer_than(
                    self.vol_refresh_time, self.vol_refresh_interval)):
            try:
                job_set = na_utils.set_safe_attr(self, 'vol_refresh_running',
                                                 True)
                if not job_set:
                    LOG.warning("Volume refresh job already running. "
                                "Returning...")
                    return
                self.vol_refresh_voluntary = False
                self.vols = self.zapi_client.get_filer_volumes()
                self.volume_list = self._get_filtered_pools()
                self.vol_refresh_time = timeutils.utcnow()
            except Exception as e:
                LOG.warning("Error refreshing volume info. Message: %s", e)
            finally:
                na_utils.set_safe_attr(self, 'vol_refresh_running', False)
예제 #8
0
파일: ec2utils.py 프로젝트: zeus911/ec2-api
def is_ec2_timestamp_expired(request, expires=None):
    """Checks the timestamp or expiry time included in an EC2 request

    and returns true if the request is expired
    """
    query_time = None
    timestamp = request.get('Timestamp')
    expiry_time = request.get('Expires')

    def parse_strtime(strtime):
        if _ms_time_regex.match(strtime):
            # NOTE(MotoKen): time format for aws-sdk-java contains millisecond
            time_format = "%Y-%m-%dT%H:%M:%S.%fZ"
        else:
            time_format = "%Y-%m-%dT%H:%M:%SZ"
        return timeutils.parse_strtime(strtime, time_format)

    try:
        if timestamp and expiry_time:
            msg = _("Request must include either Timestamp or Expires,"
                    " but cannot contain both")
            LOG.error(msg)
            raise exception.InvalidRequest(msg)
        elif expiry_time:
            query_time = parse_strtime(expiry_time)
            return timeutils.is_older_than(query_time, -1)
        elif timestamp:
            query_time = parse_strtime(timestamp)

            # Check if the difference between the timestamp in the request
            # and the time on our servers is larger than 5 minutes, the
            # request is too old (or too new).
            if query_time and expires:
                return (timeutils.is_older_than(query_time, expires) or
                        timeutils.is_newer_than(query_time, expires))
        return False
    except ValueError:
        LOG.exception(_("Timestamp is invalid: "))
        return True