Ejemplo n.º 1
0
 def test_list_statistics_with_end_time(self):
     start_time = timeutils.iso8601_from_timestamp(self._start_timestamp / 1000)
     end_time = timeutils.iso8601_from_timestamp(self._end_timestamp / 1000)
     query_parms = "?name=name-1&merge_metrics=true&statistics=avg&" "start_time=" + str(
         start_time
     ) + "&end_time=" + str(end_time)
     resp, response_body = self.monasca_client.list_statistics(query_parms)
     self.assertEqual(200, resp.status)
Ejemplo n.º 2
0
 def test_list_measurements_with_endtime(self):
     start_time = timeutils.iso8601_from_timestamp(self._start_timestamp /
                                                   1000)
     end_time = timeutils.iso8601_from_timestamp(self._end_timestamp / 1000)
     query_parms = '?name=name-1&merge_metrics=true&true&start_time=' + str(
         start_time) + '&end_time' + str(end_time)
     resp, body = self.monasca_client.list_measurements(query_parms)
     self.assertEqual(200, resp.status)
     len_measurements = len(body['elements'][0]['measurements'])
     self.assertEqual(len_measurements, NUM_MEASUREMENTS)
Ejemplo n.º 3
0
 def test_list_statistics_with_end_time(self):
     start_time = timeutils.iso8601_from_timestamp(
         self._start_timestamp / 1000)
     end_time = timeutils.iso8601_from_timestamp(
         self._end_timestamp / 1000)
     query_parms = '?name=name-1&merge_metrics=true&statistics=avg&' \
                   'start_time=' + str(start_time) + '&end_time=' + \
                   str(end_time)
     resp, response_body = self.monasca_client.list_statistics(
         query_parms)
     self.assertEqual(200, resp.status)
Ejemplo n.º 4
0
    def test_create_trust_admin(self):
        """check externals calls and result of create_trust_admin"""
        resp = MagicMock()
        body_response = {'trust': {'id': 'generatedtrustid'}}
        trustor = MagicMock(id='trustor_id', name='trustor_name',
                            cloud_project_id='trustor_tenant')
        trustee = MagicMock(id='trustee_id', name='trustee_name')
        config = {
            'trusts.client.post.return_value': (resp, body_response),
            'users.get.return_value': trustor,
            'users.find.return_value': trustee
        }
        self.trustfactory.keystone.configure_mock(**config)

        now = time.time()
        with patch('fiwareskuld.impersonate.time.time') as time_mock:
            time_mock.configure_mock(return_value=now)
            result = self.trustfactory.create_trust_admin(
                'trustor_id', 'trustee_name')

            # check result
            self.assertCreateResult(result, trustor)

        # check call
        body = {'trust': {'impersonation': True, 'trustor_user_id': trustor.id,
                          'allow_redelegation': True,
                          'roles': [{'name': 'owner'}],
                          'expires_at': timeutils.iso8601_from_timestamp(
                              now + self.trustfactory.trustid_validity, True),
                          'trustee_user_id': trustee.id,
                          'project_id': trustor.cloud_project_id}}
        self.trustfactory.keystone.trusts.client.post.assert_called_once_with(
            'OS-TRUST/trusts_for_admin', body=body)
Ejemplo n.º 5
0
    def resource_setup(cls):
        super(TestMetricsNames, cls).resource_setup()
        name = data_utils.rand_name()
        key = data_utils.rand_name()
        value = data_utils.rand_name()
        cls._param = key + ':' + value
        metric = helpers.create_metric(name=name,
                                       dimensions={key: value})
        cls._test_metric = metric
        cls.monasca_client.create_metrics(metric)

        start_time = str(timeutils.iso8601_from_timestamp(
                         metric['timestamp'] / 1000.0))
        query_params = '?name=' + str(cls._test_metric['name']) +\
                       '&start_time=' + start_time

        for i in xrange(constants.MAX_RETRIES):
            resp, response_body = cls.monasca_client.list_metrics(
                query_params)
            elements = response_body['elements']
            for element in elements:
                if str(element['name']) == cls._test_metric['name']:
                    return
            time.sleep(constants.RETRY_WAIT_SECS)

        cls.fail('Unable to initialize metrics')
Ejemplo n.º 6
0
def swift_get_container(request, container_name, with_data=True):
    if with_data:
        headers, data = swift_api(request).get_object(container_name, "")
    else:
        data = None
        headers = swift_api(request).head_container(container_name)
    timestamp = None
    is_public = False
    public_url = None
    try:
        is_public = GLOBAL_READ_ACL in headers.get('x-container-read', '')
        if is_public:
            swift_endpoint = base.url_for(request,
                                          'object-store',
                                          endpoint_type='publicURL')
            parameters = urlparse.quote(container_name.encode('utf8'))
            public_url = swift_endpoint + '/' + parameters
        ts_float = float(headers.get('x-timestamp'))
        timestamp = timeutils.iso8601_from_timestamp(ts_float)
    except Exception:
        pass
    container_info = {
        'name': container_name,
        'container_object_count': headers.get('x-container-object-count'),
        'container_bytes_used': headers.get('x-container-bytes-used'),
        'timestamp': timestamp,
        'data': data,
        'is_public': is_public,
        'public_url': public_url,
    }
    return Container(container_info)
Ejemplo n.º 7
0
def swift_get_object(request,
                     container_name,
                     object_name,
                     with_data=True,
                     resp_chunk_size=CHUNK_SIZE):
    if with_data:
        headers, data = swift_api(request).get_object(
            container_name, object_name, resp_chunk_size=resp_chunk_size)
    else:
        data = None
        headers = swift_api(request).head_object(container_name, object_name)
    orig_name = headers.get("x-object-meta-orig-filename")
    timestamp = None
    try:
        ts_float = float(headers.get('x-timestamp'))
        timestamp = timeutils.iso8601_from_timestamp(ts_float)
    except Exception:
        pass
    obj_info = {
        'name': object_name,
        'bytes': headers.get('content-length'),
        'content_type': headers.get('content-type'),
        'etag': headers.get('etag'),
        'timestamp': timestamp,
    }
    return StorageObject(obj_info,
                         container_name,
                         orig_name=orig_name,
                         data=data)
Ejemplo n.º 8
0
 def test_list_measurements_with_no_merge_metrics(self):
     start_time = timeutils.iso8601_from_timestamp(self._start_timestamp /
                                                   1000)
     query_parms = '?name=name-1&merge_metrics=false&start_time=' + str(
         start_time)
     self.assertRaises(exceptions.Conflict,
                       self.monasca_client.list_measurements, query_parms)
Ejemplo n.º 9
0
    def create_trust_admin(self, trustor_id, trustee_name):
        """
        Create a TRUST_ID. This method must be invoked by the administrator and
        only works if the keystone server has been adapted to allow the
        administrator to create a TRUST_ID for other users.

        :param trustor_id: the user id of the trustor user (who is
                           impersonated by the trustee)
        :param trustee_name: the user name of the trustee user (who
                             impersonates the trustor)
        :return: the tuple (trustor_username, trust_id, trustor_id), None if
                 error
        """
        trustor = self.keystone.users.get(trustor_id)
        trustee = self.keystone.users.find(name=trustee_name)
        data = dict()
        data['impersonation'] = True
        data['allow_redelegation'] = True
        data['project_id'] = trustor.cloud_project_id
        data['roles'] = [{'name': 'owner'}]
        data['trustee_user_id'] = trustee.id
        data['trustor_user_id'] = trustor.id
        data['expires_at'] = timeutils.iso8601_from_timestamp(
            time.time() + self.trustid_validity, True)
        # data['remaining_uses'] = 1
        request = {'trust': data}
        (resp, body_resp) = self.keystone.trusts.client.post(
            'OS-TRUST/trusts_for_admin', body=request)
        if resp.ok:
            return trustor.name, body_resp['trust']['id'], trustor.id
        else:
            return None
Ejemplo n.º 10
0
    def create_trust_admin(self, trustor_id, trustee_name):
        """
        Create a TRUST_ID. This method must be invoked by the administrator and
        only works if the keystone server has been adapted to allow the
        administrator to create a TRUST_ID for other users.

        :param trustor_id: the user id of the trustor user (who is
                           impersonated by the trustee)
        :param trustee_name: the user name of the trustee user (who
                             impersonates the trustor)
        :return: the tuple (trustor_username, trust_id, trustor_id), None if
                 error
        """
        trustor = self.keystone.users.get(trustor_id)
        trustee = self.keystone.users.find(name=trustee_name)
        data = dict()
        data['impersonation'] = True
        data['allow_redelegation'] = True
        data['project_id'] = trustor.cloud_project_id
        data['roles'] = [{'name': 'owner'}]
        data['trustee_user_id'] = trustee.id
        data['trustor_user_id'] = trustor.id
        data['expires_at'] = timeutils.iso8601_from_timestamp(
            time.time() + self.trustid_validity, True)
        # data['remaining_uses'] = 1
        request = {'trust': data}
        (resp, body_resp) = self.keystone.trusts.client.post(
            'OS-TRUST/trusts_for_admin', body=request)
        if resp.ok:
            return trustor.name, body_resp['trust']['id'], trustor.id
        else:
            return None
    def test_process_sample(self):
        s = sample.Sample(
            name='test',
            type=sample.TYPE_CUMULATIVE,
            unit='',
            volume=1,
            user_id='test',
            project_id='test',
            resource_id='test_run_tasks',
            timestamp=datetime.datetime.utcnow().isoformat(),
            resource_metadata={'name': 'TestPublish'},
        )

        to_patch = ("ceilometer.publisher.monasca_data_filter."
                    "MonascaDataFilter._get_mapping")
        with mock.patch(to_patch, side_effect=[self._field_mappings]):
            data_filter = mdf.MonascaDataFilter()
            r = data_filter.process_sample_for_monasca(s)

            self.assertEqual(s.name, r['name'])
            self.assertIsNotNone(r.get('dimensions'))
            self.assertIsNotNone(r.get('value_meta'))
            self.assertIsNotNone(r.get('value'))
            self.assertEqual(s.user_id, r['dimensions'].get('user_id'))
            self.assertEqual(s.project_id, r['dimensions'].get('project_id'))
            self.assertEqual(s.resource_id, r['dimensions'].get('resource_id'))
            # 2015-04-07T20:07:06.156986 compare upto millisec
            monasca_ts = \
                timeutils.iso8601_from_timestamp(r['timestamp'] / 1000.0,
                                                 microsecond=True)[:23]
            self.assertEqual(s.timestamp[:23], monasca_ts)
Ejemplo n.º 12
0
    def test_list_statistics(self):
        start_time = timeutils.iso8601_from_timestamp(self._start_timestamp /
                                                      1000)
        query_parms = '?name=name-1&merge_metrics=true&statistics=avg' \
                      '&start_time=' + str(start_time)
        resp, response_body = self.monasca_client.list_statistics(
            query_parms)
        self.assertEqual(200, resp.status)

        self.assertTrue(set(['links', 'elements']) == set(response_body))
        elements = response_body['elements']
        element = elements[0]
        self.assertTrue(set(['id', 'name', 'dimensions', 'columns',
                             'statistics']) == set(element))
        # check if 'id' is unicode type
        self.assertTrue(type(element['id']) is unicode)
        # check if 'name' is a string. NOPE its unicode
        self.assertTrue(type(element['name']) is unicode)
        self.assertTrue(type(element['dimensions']) is dict)
        self.assertTrue(type(element['columns']) is list)
        self.assertTrue(type(element['statistics']) is list)
        statistic = element['statistics']
        column = element['columns']
        self.assertTrue(type(statistic) is list)
        self.assertTrue(type(column) is list)
Ejemplo n.º 13
0
    def resource_setup(cls):
        super(TestMetricsNames, cls).resource_setup()
        name = data_utils.rand_name()
        key = data_utils.rand_name()
        value = data_utils.rand_name()
        cls._param = key + ':' + value
        metric = helpers.create_metric(name=name,
                                       dimensions={key: value})
        cls._test_metric = metric
        cls.monasca_client.create_metrics(metric)

        start_time = str(timeutils.iso8601_from_timestamp(
                         metric['timestamp'] / 1000.0))
        query_params = '?name=' + str(cls._test_metric['name']) +\
                       '&start_time=' + start_time

        for i in xrange(constants.MAX_RETRIES):
            resp, response_body = cls.monasca_client.list_metrics(
                query_params)
            elements = response_body['elements']
            for element in elements:
                if str(element['name']) == cls._test_metric['name']:
                    return
            time.sleep(constants.RETRY_WAIT_SECS)

        assert False, 'Unable to initialize metrics'
Ejemplo n.º 14
0
 def test_list_statistics_with_no_name(self):
     start_time = timeutils.iso8601_from_timestamp(self._start_timestamp /
                                                   1000)
     query_parms = '?merge_metrics=true&statistics=avg&start_time=' + \
                   str(start_time)
     self.assertRaises(exceptions.UnprocessableEntity,
                       self.monasca_client.list_statistics, query_parms)
    def test_process_sample(self):
        s = sample.Sample(
            name='test',
            type=sample.TYPE_CUMULATIVE,
            unit='',
            volume=1,
            user_id='test',
            project_id='test',
            resource_id='test_run_tasks',
            timestamp=datetime.datetime.utcnow().isoformat(),
            resource_metadata={'name': 'TestPublish'},
        )

        to_patch = ("ceilometer.publisher.monasca_data_filter."
                    "MonascaDataFilter._get_mapping")
        with mock.patch(to_patch, side_effect=[self._field_mappings]):
            data_filter = mdf.MonascaDataFilter()
            r = data_filter.process_sample_for_monasca(s)

            self.assertEqual(s.name, r['name'])
            self.assertIsNotNone(r.get('dimensions'))
            self.assertIsNotNone(r.get('value_meta'))
            self.assertIsNotNone(r.get('value'))
            self.assertEqual(s.user_id, r['dimensions'].get('user_id'))
            self.assertEqual(s.project_id, r['dimensions'].get('project_id'))
            self.assertEqual(s.resource_id, r['dimensions'].get('resource_id'))
            # 2015-04-07T20:07:06.156986 compare upto millisec
            monasca_ts = \
                timeutils.iso8601_from_timestamp(r['timestamp'] / 1000.0,
                                                 microsecond=True)[:23]
            self.assertEqual(s.timestamp[:23], monasca_ts)
Ejemplo n.º 16
0
def swift_get_object(request, container_name, object_name, with_data=True,
                     resp_chunk_size=CHUNK_SIZE):
    if with_data:
        headers, data = swift_api(request).get_object(
            container_name, object_name, resp_chunk_size=resp_chunk_size)
    else:
        data = None
        headers = swift_api(request).head_object(container_name,
                                                 object_name)
    orig_name = headers.get("x-object-meta-orig-filename")
    timestamp = None
    try:
        ts_float = float(headers.get('x-timestamp'))
        timestamp = timeutils.iso8601_from_timestamp(ts_float)
    except Exception:
        pass
    obj_info = {
        'name': object_name,
        'bytes': headers.get('content-length'),
        'content_type': headers.get('content-type'),
        'etag': headers.get('etag'),
        'timestamp': timestamp,
    }
    return StorageObject(obj_info,
                         container_name,
                         orig_name=orig_name,
                         data=data)
Ejemplo n.º 17
0
def swift_get_container(request, container_name, with_data=True):
    if with_data:
        headers, data = swift_api(request).get_object(container_name, "")
    else:
        data = None
        headers = swift_api(request).head_container(container_name)
    timestamp = None
    is_public = False
    public_url = None
    try:
        is_public = GLOBAL_READ_ACL in headers.get('x-container-read', '')
        if is_public:
            swift_endpoint = base.url_for(request,
                                          'object-store',
                                          endpoint_type='publicURL')
            parameters = urlparse.quote(container_name.encode('utf8'))
            public_url = swift_endpoint + '/' + parameters
        ts_float = float(headers.get('x-timestamp'))
        timestamp = timeutils.iso8601_from_timestamp(ts_float)
    except Exception:
        pass
    container_info = {
        'name': container_name,
        'container_object_count': headers.get('x-container-object-count'),
        'container_bytes_used': headers.get('x-container-bytes-used'),
        'timestamp': timestamp,
        'data': data,
        'is_public': is_public,
        'public_url': public_url,
    }
    return Container(container_info)
Ejemplo n.º 18
0
 def test_list_statistics_with_invalid_statistics(self):
     start_time = timeutils.iso8601_from_timestamp(
         self._start_timestamp / 1000)
     query_parms = '?name=name-1&statistics=abc&start_time=' + str(
         start_time)
     self.assertRaises(exceptions.UnprocessableEntity,
                       self.monasca_client.list_statistics, query_parms)
Ejemplo n.º 19
0
 def test_list_measurements_with_merge_metrics(self):
     start_time = timeutils.iso8601_from_timestamp(self._start_timestamp /
                                                   1000)
     query_parms = '?name=name-1&merge_metrics=true&start_time=' + str(
         start_time)
     resp, response_body = self.monasca_client.list_measurements(
         query_parms)
     self.assertEqual(200, resp.status)
Ejemplo n.º 20
0
 def test_list_measurements_with_name_exceeds_max_length(self):
     long_name = "x" * (constants.MAX_LIST_MEASUREMENTS_NAME_LENGTH + 1)
     start_time = timeutils.iso8601_from_timestamp(self._start_timestamp /
                                                   1000)
     query_parms = '?name=' + str(long_name) \
                   + '&merge_metrics=true&start_time=' + str(start_time)
     self.assertRaises(exceptions.UnprocessableEntity,
                       self.monasca_client.list_measurements, query_parms)
Ejemplo n.º 21
0
 def test_list_statistics_with_dimensions(self):
     start_time = timeutils.iso8601_from_timestamp(self._start_timestamp
                                                   / 1000)
     query_parms = '?name=name-1&merge_metrics=true&statistics=avg&' \
                   'start_time=' + str(start_time) + \
                   '&dimensions=key1:value1'
     resp, response_body = self.monasca_client.list_statistics(
         query_parms)
     self.assertEqual(200, resp.status)
Ejemplo n.º 22
0
 def test_list_statistics_response_body_statistic_result_type(self):
     start_time = timeutils.iso8601_from_timestamp(self._start_timestamp / 1000)
     query_parms = "?name=name-1&merge_metrics=true&statistics=avg&" "start_time=" + str(start_time)
     resp, response_body = self.monasca_client.list_statistics(query_parms)
     self.assertEqual(200, resp.status)
     element = response_body["elements"][0]
     statistic = element["statistics"]
     statistic_result_type = type(statistic[0][1])
     self.assertEqual(statistic_result_type, float)
Ejemplo n.º 23
0
def stat_message(message, now):
    """Creates a stat document from the given message, relative to now."""
    msg_id = message['id']
    created = oid_ts(to_oid(msg_id))
    age = now - created

    return {
        'id': msg_id,
        'age': int(age),
        'created': timeutils.iso8601_from_timestamp(created),
    }
Ejemplo n.º 24
0
def stat_message(message, now):
    """Creates a stat document from the given message, relative to now."""
    msg_id = message['id']
    created = oid_ts(to_oid(msg_id))
    age = now - created

    return {
        'id': msg_id,
        'age': int(age),
        'created': timeutils.iso8601_from_timestamp(created),
    }
Ejemplo n.º 25
0
 def test_list_statistics_response_body_statistic_result_type(self):
     start_time = timeutils.iso8601_from_timestamp(self._start_timestamp
                                                   / 1000)
     query_parms = '?name=name-1&merge_metrics=true&statistics=avg&' \
                   'start_time=' + str(start_time)
     resp, response_body = self.monasca_client.list_statistics(
         query_parms)
     self.assertEqual(200, resp.status)
     element = response_body['elements'][0]
     statistic = element['statistics']
     statistic_result_type = type(statistic[0][1])
     self.assertEqual(statistic_result_type, float)
Ejemplo n.º 26
0
def list_cached(options, args):
    """%(prog)s list-cached [options]

List all images currently cached.
    """
    client = get_client(options)
    images = client.get_cached_images()
    if not images:
        print("No cached images.")
        return SUCCESS

    print("Found %d cached images..." % len(images))

    pretty_table = utils.PrettyTable()
    pretty_table.add_column(36, label="ID")
    pretty_table.add_column(19, label="Last Accessed (UTC)")
    pretty_table.add_column(19, label="Last Modified (UTC)")
    # 1 TB takes 13 characters to display: len(str(2**40)) == 13
    pretty_table.add_column(14, label="Size", just="r")
    pretty_table.add_column(10, label="Hits", just="r")

    print(pretty_table.make_header())

    for image in images:
        last_modified = image['last_modified']
        last_modified = timeutils.iso8601_from_timestamp(last_modified)

        last_accessed = image['last_accessed']
        if last_accessed == 0:
            last_accessed = "N/A"
        else:
            last_accessed = timeutils.iso8601_from_timestamp(last_accessed)

        print(pretty_table.make_row(
            image['image_id'],
            last_accessed,
            last_modified,
            image['size'],
            image['hits']))
Ejemplo n.º 27
0
    def to_basic(self, now, include_created=False):
        basic_msg = {
            'id': self.id,
            'age': now - self.created,
            'ttl': self.ttl,
            'body': self.body,
            'claim_id': self.claim_id,
        }

        if include_created:
            created_iso = timeutils.iso8601_from_timestamp(self.created)
            basic_msg['created'] = created_iso

        return basic_msg
Ejemplo n.º 28
0
    def test_create_trust_admin(self):
        """check externals calls and result of create_trust_admin"""
        resp = MagicMock()
        body_response = {'trust': {'id': 'generatedtrustid'}}
        trustor = MagicMock(id='trustor_id',
                            name='trustor_name',
                            cloud_project_id='trustor_tenant')
        trustee = MagicMock(id='trustee_id', name='trustee_name')
        config = {
            'trusts.client.post.return_value': (resp, body_response),
            'users.get.return_value': trustor,
            'users.find.return_value': trustee
        }
        self.trustfactory.keystone.configure_mock(**config)

        now = time.time()
        with patch('fiwareskuld.impersonate.time.time') as time_mock:
            time_mock.configure_mock(return_value=now)
            result = self.trustfactory.create_trust_admin(
                'trustor_id', 'trustee_name')

            # check result
            self.assertCreateResult(result, trustor)

        # check call
        body = {
            'trust': {
                'impersonation':
                True,
                'trustor_user_id':
                trustor.id,
                'allow_redelegation':
                True,
                'roles': [{
                    'name': 'owner'
                }],
                'expires_at':
                timeutils.iso8601_from_timestamp(
                    now + self.trustfactory.trustid_validity, True),
                'trustee_user_id':
                trustee.id,
                'project_id':
                trustor.cloud_project_id
            }
        }
        self.trustfactory.keystone.trusts.client.post.assert_called_once_with(
            'OS-TRUST/trusts_for_admin', body=body)
    def test_list_alarms_state_history_with_start_time(self):
        current_time = int(time.time())
        current_time = timeutils.iso8601_from_timestamp(current_time)
        query_parms = '?start_time=' + str(current_time)
        resp, response_body = self.monasca_client.list_alarms_state_history(
            query_parms)
        elements = response_body['elements']
        self.assertEqual(0, len(elements))

        resp, response_body = self.monasca_client.list_alarms_state_history()
        elements = response_body['elements']
        timestamp = elements[1]['timestamp']
        query_parms = '?start_time=' + str(timestamp)
        resp, response_body = self.monasca_client.list_alarms_state_history(
            query_parms)
        elements = response_body['elements']
        self.assertEqual(2, len(elements))
Ejemplo n.º 30
0
    def test_list_alarms_state_history_with_start_time(self):
        current_time = int(time.time())
        current_time = timeutils.iso8601_from_timestamp(current_time)
        query_parms = '?start_time=' + str(current_time)
        resp, response_body = self.monasca_client.list_alarms_state_history(
            query_parms)
        elements = response_body['elements']
        self.assertEqual(0, len(elements))

        resp, response_body = self.monasca_client.list_alarms_state_history()
        elements = response_body['elements']
        timestamp = elements[1]['timestamp']
        query_parms = '?start_time=' + str(timestamp)
        resp, response_body = self.monasca_client.list_alarms_state_history(
            query_parms)
        elements = response_body['elements']
        self.assertEqual(2, len(elements))
Ejemplo n.º 31
0
    def stats(self, name, project=None):
        if not self._queue_ctrl.exists(name, project=project):
            raise errors.QueueDoesNotExist(name, project)

        total = 0
        claimed = 0
        container = utils._message_container(name, project)

        try:
            _, objects = self._client.get_container(container)
        except swiftclient.ClientException as exc:
            if exc.http_status == 404:
                raise errors.QueueIsEmpty(name, project)

        newest = None
        oldest = None
        now = timeutils.utcnow_ts(True)
        for obj in objects:
            try:
                headers = self._client.head_object(container, obj['name'])
            except swiftclient.ClientException as exc:
                if exc.http_status != 404:
                    raise
            else:
                created = float(headers['x-timestamp'])
                newest = {
                    'id': obj['name'],
                    'age': now - created,
                    'created': timeutils.iso8601_from_timestamp(created)
                }
                if oldest is None:
                    oldest = copy.deepcopy(newest)
                total += 1
                if headers.get('x-object-meta-claimid'):
                    claimed += 1

        msg_stats = {
            'claimed': claimed,
            'free': total - claimed,
            'total': total,
        }
        if newest is not None:
            msg_stats['newest'] = newest
            msg_stats['oldest'] = oldest

        return {'messages': msg_stats}
Ejemplo n.º 32
0
def swift_get_container(request, container_name, with_data=True):
    if with_data:
        headers, data = swift_api(request).get_object(container_name, "")
    else:
        data = None
        headers = swift_api(request).head_container(container_name)
    timestamp = None
    is_public = False
    public_url = None
    try:
        is_public = GLOBAL_READ_ACL in headers.get('x-container-read', '')
        if is_public:
            swift_endpoint = base.url_for(request,
                                          'object-store',
                                          endpoint_type='publicURL')
            parameters = urlparse.quote(container_name.encode('utf8'))
            public_url = swift_endpoint + '/' + parameters
        ts_float = float(headers.get('x-timestamp'))
        timestamp = timeutils.iso8601_from_timestamp(ts_float)

        metadata = ''
        for header in headers:
            if header.startswith('x-container-meta-'):
                key_name = header.replace('x-container-meta-',
                                          '').replace('-', ' ').title()
                value = headers[header]
                metadata += key_name + '=' + value + ', '

        metadata = metadata[0:-2]

    except Exception:
        pass
    container_info = {
        'name': container_name,
        'container_object_count': headers.get('x-container-object-count'),
        'container_bytes_used': headers.get('x-container-bytes-used'),
        'timestamp': timestamp,
        'data': data,
        'is_public': is_public,
        'public_url': public_url,
        'storage_policy': headers.get('x-storage-policy'),
        'metadata': metadata,
    }
    return Container(container_info)
Ejemplo n.º 33
0
    def test_list_measurements(self):
        start_time = timeutils.iso8601_from_timestamp(self._start_timestamp /
                                                      1000)
        query_parms = '?name=name-1&merge_metrics=true&start_time=' + str(
            start_time)
        resp, response_body = self.monasca_client.list_measurements(
            query_parms)
        self.assertEqual(200, resp.status)

        self.assertTrue(set(['links', 'elements']) == set(response_body))
        elements = response_body['elements']
        element = elements[0]
        self.assertTrue(
            set(['id', 'name', 'dimensions', 'columns', 'measurements']) ==
            set(element))
        self.assertTrue(type(element['name']) is unicode)
        self.assertTrue(type(element['dimensions']) is dict)
        self.assertTrue(type(element['columns']) is list)
        self.assertTrue(type(element['measurements']) is list)
Ejemplo n.º 34
0
    def test_list_statistics(self):
        start_time = timeutils.iso8601_from_timestamp(self._start_timestamp / 1000)
        query_parms = "?name=name-1&merge_metrics=true&statistics=avg" "&start_time=" + str(start_time)
        resp, response_body = self.monasca_client.list_statistics(query_parms)
        self.assertEqual(200, resp.status)

        self.assertTrue(set(["links", "elements"]) == set(response_body))
        elements = response_body["elements"]
        element = elements[0]
        self.assertTrue(set(["id", "name", "dimensions", "columns", "statistics"]) == set(element))
        # check if 'id' is unicode type
        self.assertTrue(type(element["id"]) is unicode)
        # check if 'name' is a string. NOPE its unicode
        self.assertTrue(type(element["name"]) is unicode)
        self.assertTrue(type(element["dimensions"]) is dict)
        self.assertTrue(type(element["columns"]) is list)
        self.assertTrue(type(element["statistics"]) is list)
        statistic = element["statistics"]
        column = element["columns"]
        self.assertTrue(type(statistic) is list)
        self.assertTrue(type(column) is list)
Ejemplo n.º 35
0
    def test_list_measurements_with_dimensions(self):
        key1 = data_utils.rand_name('key1')
        value1 = data_utils.rand_name('value1')
        start_timestamp = int(time.time() * 1000)
        name = data_utils.rand_name()
        metric = [
            helpers.create_metric(name=name,
                                  timestamp=start_timestamp,
                                  dimensions={key1: value1},
                                  value=123)
        ]
        resp, response_body = self.monasca_client.create_metrics(metric)
        time.sleep(WAIT_TIME)

        start_time = timeutils.iso8601_from_timestamp(self._start_timestamp /
                                                      1000)
        query_parms = '?name=' + name + '&start_time=' + str(
            start_time) + '&dimensions=' + key1 + ':' + value1
        resp, response_body = self.monasca_client.list_measurements(
            query_parms)
        value_new = response_body['elements'][0]['measurements'][0][1]
        self.assertEqual(200, resp.status)
        self.assertEqual(123, value_new)
Ejemplo n.º 36
0
 def test_list_measurements_with_no_name(self):
     start_time = timeutils.iso8601_from_timestamp(self._start_timestamp /
                                                   1000)
     query_parms = '?start_time=' + str(start_time)
     self.assertRaises(exceptions.UnprocessableEntity,
                       self.monasca_client.list_measurements, query_parms)
Ejemplo n.º 37
0
 def test_list_statistics_with_no_merge_metrics(self):
     start_time = timeutils.iso8601_from_timestamp(self._start_timestamp / 1000)
     query_parms = "?name=name-1&merge_metrics=false&" "statistics=avg,min,max&start_time=" + str(start_time)
     self.assertRaises(exceptions.Conflict, self.monasca_client.list_statistics, query_parms)
Ejemplo n.º 38
0
    def test_list_statistics_with_offset_limit(self):
        start_timestamp = int(time.time() * 1000)
        name = data_utils.rand_name()
        metric = [
            helpers.create_metric(name=name, timestamp=start_timestamp + 0,
                                  dimensions={'key1': 'value-1',
                                              'key2': 'value-1'},
                                  value=1),
            helpers.create_metric(name=name, timestamp=start_timestamp + 500,
                                  dimensions={'key1': 'value-2',
                                              'key2': 'value-2'},
                                  value=2),
            helpers.create_metric(name=name, timestamp=start_timestamp + 1000,
                                  dimensions={'key1': 'value-3',
                                              'key2': 'value-3'},
                                  value=3),
            helpers.create_metric(name=name, timestamp=start_timestamp + 1500,
                                  dimensions={'key1': 'value-4',
                                              'key2': 'value-4'},
                                  value=4)
        ]

        self.monasca_client.create_metrics(metric)
        query_parms = '?name=' + name
        for i in xrange(constants.MAX_RETRIES):
            resp, response_body = self.monasca_client.list_metrics(query_parms)
            self.assertEqual(200, resp.status)
            elements = response_body['elements']
            if elements:
                break
            else:
                time.sleep(constants.RETRY_WAIT_SECS)
        self._check_timeout(i, constants.MAX_RETRIES, elements, 4)

        start_time = helpers.timestamp_to_iso(start_timestamp)
        end_timestamp = start_timestamp + 4000
        end_time = helpers.timestamp_to_iso(end_timestamp)
        query_parms = '?name=' + name + '&merge_metrics=true&statistics=avg' \
                      + '&start_time=' + str(start_time) + '&end_time=' + \
                      str(end_time) + '&period=1'
        resp, body = self.monasca_client.list_statistics(query_parms)
        self.assertEqual(200, resp.status)
        elements = body['elements'][0]['statistics']
        first_element = elements[0]

        query_parms = '?name=' + name + '&merge_metrics=true&statistics=avg'\
                      + '&start_time=' + str(start_time) + '&end_time=' + \
                      str(end_time) + '&period=1' + '&limit=4'
        resp, response_body = self.monasca_client.list_statistics(
            query_parms)
        self.assertEqual(200, resp.status)
        elements = response_body['elements'][0]['statistics']
        self.assertEqual(4, len(elements))
        self.assertEqual(first_element, elements[0])

        for index in xrange(1, 5):
            max_limit = 5 - index

            for limit in xrange(1, max_limit):
                offset_timestamp = start_timestamp + (1000 * index)
                offset = timeutils.iso8601_from_timestamp(offset_timestamp / 1000)

                last_index = index + limit
                expected_elements = elements[index:last_index]

                query_parms = '?name=' + name + '&merge_metrics=true' + \
                                      '&statistics=avg' + '&start_time=' + \
                                      str(start_time) + '&end_time=' + \
                                      str(end_time) + '&period=1' + '&limit=' + \
                                      str(limit) + '&offset=' + str(offset)
                resp, response_body = self.monasca_client.list_statistics(query_parms)
                self.assertEqual(200, resp.status)
                if not response_body['elements']:
                    self.fail("No metrics returned")
                if not response_body['elements'][0]['statistics']:
                    self.fail("No statistics returned")
                new_elements = response_body['elements'][0]['statistics']

                self.assertEqual(limit, len(new_elements))
                # bug in the python API causes limit 1 to not have matching timestamps
                if limit > 1:
                    self.assertEqual(expected_elements, new_elements)
Ejemplo n.º 39
0
    def test_list_statistics_with_offset_limit(self):
        start_timestamp = int(time.time() * 1000)
        name = data_utils.rand_name()
        metric = [
            helpers.create_metric(name=name,
                                  timestamp=start_timestamp + 0,
                                  dimensions={
                                      'key1': 'value-1',
                                      'key2': 'value-1'
                                  },
                                  value=1),
            helpers.create_metric(name=name,
                                  timestamp=start_timestamp + 500,
                                  dimensions={
                                      'key1': 'value-2',
                                      'key2': 'value-2'
                                  },
                                  value=2),
            helpers.create_metric(name=name,
                                  timestamp=start_timestamp + 1000,
                                  dimensions={
                                      'key1': 'value-3',
                                      'key2': 'value-3'
                                  },
                                  value=3),
            helpers.create_metric(name=name,
                                  timestamp=start_timestamp + 1500,
                                  dimensions={
                                      'key1': 'value-4',
                                      'key2': 'value-4'
                                  },
                                  value=4)
        ]

        self.monasca_client.create_metrics(metric)
        query_parms = '?name=' + name
        for i in xrange(constants.MAX_RETRIES):
            resp, response_body = self.monasca_client.list_metrics(query_parms)
            self.assertEqual(200, resp.status)
            elements = response_body['elements']
            if elements:
                break
            else:
                time.sleep(constants.RETRY_WAIT_SECS)
        self._check_timeout(i, constants.MAX_RETRIES, elements, 4)

        start_time = helpers.timestamp_to_iso(start_timestamp)
        end_timestamp = start_timestamp + 4000
        end_time = helpers.timestamp_to_iso(end_timestamp)
        query_parms = '?name=' + name + '&merge_metrics=true&statistics=avg' \
                      + '&start_time=' + str(start_time) + '&end_time=' + \
                      str(end_time) + '&period=1'
        resp, body = self.monasca_client.list_statistics(query_parms)
        self.assertEqual(200, resp.status)
        elements = body['elements'][0]['statistics']
        first_element = elements[0]

        query_parms = '?name=' + name + '&merge_metrics=true&statistics=avg'\
                      + '&start_time=' + str(start_time) + '&end_time=' + \
                      str(end_time) + '&period=1' + '&limit=4'
        resp, response_body = self.monasca_client.list_statistics(query_parms)
        self.assertEqual(200, resp.status)
        elements = response_body['elements'][0]['statistics']
        self.assertEqual(4, len(elements))
        self.assertEqual(first_element, elements[0])

        for index in xrange(1, 5):
            max_limit = 5 - index

            for limit in xrange(1, max_limit):
                offset_timestamp = start_timestamp + (1000 * index)
                offset = timeutils.iso8601_from_timestamp(offset_timestamp /
                                                          1000)

                last_index = index + limit
                expected_elements = elements[index:last_index]

                query_parms = '?name=' + name + '&merge_metrics=true' + \
                                      '&statistics=avg' + '&start_time=' + \
                                      str(start_time) + '&end_time=' + \
                                      str(end_time) + '&period=1' + '&limit=' + \
                                      str(limit) + '&offset=' + str(offset)
                resp, response_body = self.monasca_client.list_statistics(
                    query_parms)
                self.assertEqual(200, resp.status)
                if not response_body['elements']:
                    self.fail("No metrics returned")
                if not response_body['elements'][0]['statistics']:
                    self.fail("No statistics returned")
                new_elements = response_body['elements'][0]['statistics']

                self.assertEqual(limit, len(new_elements))
                # bug in the python API causes limit 1 to not have matching timestamps
                if limit > 1:
                    self.assertEqual(expected_elements, new_elements)
Ejemplo n.º 40
0
 def test_iso8601_from_timestamp_ms(self):
     ts = timeutils.utcnow_ts(microsecond=True)
     utcnow = datetime.datetime.utcfromtimestamp(ts)
     iso = timeutils.isotime(utcnow, subsecond=True)
     self.assertEqual(iso, timeutils.iso8601_from_timestamp(ts, True))
Ejemplo n.º 41
0
 def test_iso8601_from_timestamp(self):
     utcnow = timeutils.utcnow()
     iso = timeutils.isotime(utcnow)
     ts = calendar.timegm(utcnow.timetuple())
     self.assertEqual(iso, timeutils.iso8601_from_timestamp(ts))
Ejemplo n.º 42
0
def ts2iso(timestamp):
    """timestamp to is8601 format."""
    if not isinstance(timestamp, float):
        timestamp = float(timestamp)
    return timeutils.iso8601_from_timestamp(timestamp)
Ejemplo n.º 43
0
    def test_list_measurements_with_offset_limit(self):
        start_timestamp = int(time.time() * 1000)
        name = data_utils.rand_name()
        metric = [
            helpers.create_metric(name=name,
                                  timestamp=start_timestamp + 0,
                                  dimensions={
                                      'key1': 'value-1',
                                      'key2': 'value-1'
                                  }),
            helpers.create_metric(name=name,
                                  timestamp=start_timestamp + 1,
                                  dimensions={
                                      'key1': 'value-2',
                                      'key2': 'value-2'
                                  }),
            helpers.create_metric(name=name,
                                  timestamp=start_timestamp + 2,
                                  dimensions={
                                      'key1': 'value-3',
                                      'key2': 'value-3'
                                  }),
            helpers.create_metric(name=name,
                                  timestamp=start_timestamp + 3,
                                  dimensions={
                                      'key1': 'value-4',
                                      'key2': 'value-4'
                                  })
        ]

        resp, response_body = self.monasca_client.create_metrics(metric)
        time.sleep(WAIT_TIME)

        query_parms = '?name=' + name
        resp, response_body = self.monasca_client.list_metrics(query_parms)
        self.assertEqual(200, resp.status)

        start_time = timeutils.iso8601_from_timestamp(start_timestamp / 1000)
        query_parms = '?name=' + name + '&merge_metrics=true&start_time=' + \
                      str(start_time)
        resp, body = self.monasca_client.list_measurements(query_parms)
        self.assertEqual(200, resp.status)
        elements = body['elements'][0]['measurements']
        first_element = elements[0]
        last_element = elements[3]

        query_parms = '?name=' + name + '&merge_metrics=true&start_time=' + \
                      str(start_time) + '&limit=4'
        resp, response_body = self.monasca_client.list_measurements(
            query_parms)
        self.assertEqual(200, resp.status)

        elements = response_body['elements'][0]['measurements']
        self.assertEqual(4, len(elements))

        self.assertEqual(first_element, elements[0])

        for limit in xrange(1, 5):
            next_element = elements[limit - 1]
            while True:
                query_parms = '?name=' + name + \
                              '&merge_metrics=true&start_time=' + \
                              str(start_time) + '&offset=' + \
                              str(next_element[0]) + '&limit=' + \
                              str(limit)
                resp, response_body = self.monasca_client.list_measurements(
                    query_parms)
                self.assertEqual(200, resp.status)
                new_elements = response_body['elements'][0]['measurements']

                if len(new_elements) > limit - 1:
                    self.assertEqual(limit, len(new_elements))
                    next_element = new_elements[limit - 1]
                elif len(new_elements) > 0 and len(new_elements) <= limit - 1:
                    self.assertEqual(last_element, new_elements[0])
                    break
                else:
                    self.assertEqual(last_element, next_element)
                    break
Ejemplo n.º 44
0
    def test_list_statistics_with_offset_limit(self):
        start_timestamp = int(time.time() * 1000)
        name = data_utils.rand_name()
        metric = [
            helpers.create_metric(name=name, timestamp=start_timestamp + 0,
                                  dimensions={'key1': 'value-1',
                                              'key2': 'value-1'},
                                  value=1),
            helpers.create_metric(name=name, timestamp=start_timestamp + 500,
                                  dimensions={'key1': 'value-2',
                                              'key2': 'value-2'},
                                  value=2),
            helpers.create_metric(name=name, timestamp=start_timestamp + 1000,
                                  dimensions={'key1': 'value-3',
                                              'key2': 'value-3'},
                                  value=3),
            helpers.create_metric(name=name, timestamp=start_timestamp + 1500,
                                  dimensions={'key1': 'value-4',
                                              'key2': 'value-4'},
                                  value=4),
            helpers.create_metric(name=name, timestamp=start_timestamp + 2000,
                                  dimensions={'key1': 'value-2',
                                              'key2': 'value-2'},
                                  value=5),
            helpers.create_metric(name=name, timestamp=start_timestamp + 2500,
                                  dimensions={'key1': 'value-3',
                                              'key2': 'value-3'},
                                  value=6),
            helpers.create_metric(name=name, timestamp=start_timestamp + 3000,
                                  dimensions={'key1': 'value-4',
                                              'key2': 'value-4'},
                                  value=7),
            helpers.create_metric(name=name, timestamp=start_timestamp + 3500,
                                  dimensions={'key1': 'value-4',
                                              'key2': 'value-4'},
                                  value=8)
        ]

        resp, response_body = self.monasca_client.create_metrics(metric)
        time.sleep(WAIT_TIME)

        query_parms = '?name=' + name
        resp, response_body = self.monasca_client.list_metrics(query_parms)
        self.assertEqual(200, resp.status)

        start_time = timeutils.iso8601_from_timestamp(
            start_timestamp / 1000)
        end_timestamp = start_timestamp + 4000
        end_time = timeutils.iso8601_from_timestamp(end_timestamp / 1000)
        query_parms = '?name=' + name + '&merge_metrics=true&statistics=avg,' \
                      'max,min,sum,count&start_time=' + str(start_time) + \
                      '&end_time=' + str(end_time) + '&period=1'
        resp, body = self.monasca_client.list_statistics(query_parms)
        self.assertEqual(200, resp.status)
        elements = body['elements'][0]['statistics']
        first_element = elements[0]
        last_element = elements[3]

        query_parms = '?name=' + name + '&merge_metrics=true&statistics=avg,' \
                      'max,min,sum,count&start_time=' + str(start_time) + \
                      '&end_time=' + str(end_time) + '&period=1' + '&limit=4'
        resp, response_body = self.monasca_client.list_statistics(
            query_parms)
        self.assertEqual(200, resp.status)
        elements = response_body['elements'][0]['statistics']
        self.assertEqual(4, len(elements))
        self.assertEqual(first_element, elements[0])

        for limit in xrange(1, 5):
            next_element = elements[limit - 1]
            offset_timestamp = start_timestamp
            while True:
                offset_timestamp += 1000 * limit
                offset = timeutils.iso8601_from_timestamp(offset_timestamp /
                                                          1000)
                query_parms = '?name=' + name + '&merge_metrics=true' + \
                              '&statistics=avg,max,min,sum,' \
                              'count&start_time=' + str(start_time) + \
                              '&end_time=' + str(end_time) + '&period=1' + \
                              '&limit=' + str(limit) + '&offset=' + str(offset)
                resp, response_body = self.monasca_client.list_statistics(
                    query_parms)
                self.assertEqual(200, resp.status)
                new_elements = response_body['elements'][0]['statistics']

                if len(new_elements) > limit - 1:
                    self.assertEqual(limit, len(new_elements))
                    next_element = new_elements[limit - 1]
                elif len(new_elements) > 0 and len(new_elements) <= limit - 1:
                    self.assertEqual(last_element, new_elements[0])
                    break
                else:
                    self.assertEqual(last_element, next_element)
                    break
Ejemplo n.º 45
0
 def test_iso8601_from_timestamp(self):
     utcnow = timeutils.utcnow()
     iso = timeutils.isotime(utcnow)
     ts = calendar.timegm(utcnow.timetuple())
     self.assertEqual(iso, timeutils.iso8601_from_timestamp(ts))
Ejemplo n.º 46
0
 def test_list_statistics_with_name_exceeds_max_length(self):
     long_name = "x" * (constants.MAX_LIST_STATISTICS_NAME_LENGTH + 1)
     start_time = timeutils.iso8601_from_timestamp(self._start_timestamp / 1000)
     query_parms = "?merge_metrics=true&name=" + str(long_name) + "&start_time=" + str(start_time)
     self.assertRaises(exceptions.UnprocessableEntity, self.monasca_client.list_statistics, query_parms)
Ejemplo n.º 47
0
 def test_list_statistics_with_no_name(self):
     start_time = timeutils.iso8601_from_timestamp(self._start_timestamp / 1000)
     query_parms = "?merge_metrics=true&statistics=avg&start_time=" + str(start_time)
     self.assertRaises(exceptions.UnprocessableEntity, self.monasca_client.list_statistics, query_parms)
Ejemplo n.º 48
0
 def test_list_statistics_with_invalid_statistics(self):
     start_time = timeutils.iso8601_from_timestamp(self._start_timestamp / 1000)
     query_parms = "?name=name-1&statistics=abc&start_time=" + str(start_time)
     self.assertRaises(exceptions.UnprocessableEntity, self.monasca_client.list_statistics, query_parms)
Ejemplo n.º 49
0
 def test_iso8601_from_timestamp_ms(self):
     ts = timeutils.utcnow_ts(microsecond=True)
     utcnow = datetime.datetime.utcfromtimestamp(ts)
     iso = timeutils.isotime(utcnow, subsecond=True)
     self.assertEqual(iso, timeutils.iso8601_from_timestamp(ts, True))
Ejemplo n.º 50
0
    def test_list_statistics_with_offset_limit(self):
        start_timestamp = int(time.time() * 1000)
        name = data_utils.rand_name()
        metric = [
            helpers.create_metric(
                name=name, timestamp=start_timestamp + 0, dimensions={"key1": "value-1", "key2": "value-1"}, value=1
            ),
            helpers.create_metric(
                name=name, timestamp=start_timestamp + 500, dimensions={"key1": "value-2", "key2": "value-2"}, value=2
            ),
            helpers.create_metric(
                name=name, timestamp=start_timestamp + 1000, dimensions={"key1": "value-3", "key2": "value-3"}, value=3
            ),
            helpers.create_metric(
                name=name, timestamp=start_timestamp + 1500, dimensions={"key1": "value-4", "key2": "value-4"}, value=4
            ),
            helpers.create_metric(
                name=name, timestamp=start_timestamp + 2000, dimensions={"key1": "value-2", "key2": "value-2"}, value=5
            ),
            helpers.create_metric(
                name=name, timestamp=start_timestamp + 2500, dimensions={"key1": "value-3", "key2": "value-3"}, value=6
            ),
            helpers.create_metric(
                name=name, timestamp=start_timestamp + 3000, dimensions={"key1": "value-4", "key2": "value-4"}, value=7
            ),
            helpers.create_metric(
                name=name, timestamp=start_timestamp + 3500, dimensions={"key1": "value-4", "key2": "value-4"}, value=8
            ),
        ]

        resp, response_body = self.monasca_client.create_metrics(metric)
        time.sleep(WAIT_TIME)

        query_parms = "?name=" + name
        resp, response_body = self.monasca_client.list_metrics(query_parms)
        self.assertEqual(200, resp.status)

        start_time = timeutils.iso8601_from_timestamp(start_timestamp / 1000)
        end_timestamp = start_timestamp + 4000
        end_time = timeutils.iso8601_from_timestamp(end_timestamp / 1000)
        query_parms = (
            "?name=" + name + "&merge_metrics=true&statistics=avg,"
            "max,min,sum,count&start_time=" + str(start_time) + "&end_time=" + str(end_time) + "&period=1"
        )
        resp, body = self.monasca_client.list_statistics(query_parms)
        self.assertEqual(200, resp.status)
        elements = body["elements"][0]["statistics"]
        first_element = elements[0]
        last_element = elements[3]

        query_parms = (
            "?name=" + name + "&merge_metrics=true&statistics=avg,"
            "max,min,sum,count&start_time=" + str(start_time) + "&end_time=" + str(end_time) + "&period=1" + "&limit=4"
        )
        resp, response_body = self.monasca_client.list_statistics(query_parms)
        self.assertEqual(200, resp.status)
        elements = response_body["elements"][0]["statistics"]
        self.assertEqual(4, len(elements))
        self.assertEqual(first_element, elements[0])

        for limit in xrange(1, 5):
            next_element = elements[limit - 1]
            offset_timestamp = start_timestamp
            while True:
                offset_timestamp += 1000 * limit
                offset = timeutils.iso8601_from_timestamp(offset_timestamp / 1000)
                query_parms = "?name=" + name + "&merge_metrics=true" + "&statistics=avg,max,min,sum," "count&start_time=" + str(
                    start_time
                ) + "&end_time=" + str(
                    end_time
                ) + "&period=1" + "&limit=" + str(
                    limit
                ) + "&offset=" + str(
                    offset
                )
                resp, response_body = self.monasca_client.list_statistics(query_parms)
                self.assertEqual(200, resp.status)
                new_elements = response_body["elements"][0]["statistics"]

                if len(new_elements) > limit - 1:
                    self.assertEqual(limit, len(new_elements))
                    next_element = new_elements[limit - 1]
                elif len(new_elements) > 0 and len(new_elements) <= limit - 1:
                    self.assertEqual(last_element, new_elements[0])
                    break
                else:
                    self.assertEqual(last_element, next_element)
                    break