Ejemplo n.º 1
0
 def test_list_alarms_by_offset_limit(self):
     helpers.delete_alarm_definitions(self.monasca_client)
     self._create_alarms_for_test_alarms(num=2)
     resp, response_body = self.monasca_client.list_alarms()
     self._verify_list_alarms_elements(resp, response_body,
                                       expect_num_elements=2)
     elements = response_body['elements']
     first_element = elements[0]
     next_element = elements[1]
     id_first_element = first_element['id']
     query_parms = '?offset=' + str(id_first_element) + '&limit=1'
     resp, response_body1 = self.monasca_client.list_alarms(query_parms)
     elements = response_body1['elements']
     self.assertEqual(1, len(elements))
     self.assertEqual(elements[0]['id'], next_element['id'])
     self.assertEqual(elements[0], next_element)
    def test_list_alarm_definitions_with_offset_limit(self):
        helpers.delete_alarm_definitions(self.monasca_client)
        expression = "max(cpu.system_perc) > 0"
        self._create_alarm_definitions(
            expression=expression, number_of_definitions=NUM_ALARM_DEFINITIONS)
        resp, response_body = self.monasca_client.list_alarm_definitions()
        self._verify_list_alarm_definitions_response_body(resp, response_body)
        first_element = response_body['elements'][0]
        last_element = response_body['elements'][1]

        query_parms = '?limit=2'
        resp, response_body = self.monasca_client.list_alarm_definitions(
            query_parms)
        self.assertEqual(200, resp.status)

        elements = response_body['elements']
        self.assertEqual(2, len(elements))
        self.assertEqual(first_element, elements[0])
        self.assertEqual(last_element, elements[1])

        timeout = time.time() + 60 * 1   # 1 minute timeout
        for limit in xrange(1, 3):
            next_element = elements[limit - 1]
            while True:
                if time.time() < timeout:
                    query_parms = '?offset=' + str(next_element['id']) + \
                                  '&limit=' + str(limit)
                    resp, response_body = self.monasca_client.\
                        list_alarm_definitions(query_parms)
                    self.assertEqual(200, resp.status)
                    new_elements = response_body['elements']
                    if len(new_elements) > limit - 1:
                        self.assertEqual(limit, len(new_elements))
                        next_element = new_elements[limit - 1]
                    elif 0 < len(new_elements) <= limit - 1:
                        self.assertEqual(last_element, new_elements[0])
                        break
                    else:
                        self.assertEqual(last_element, next_element)
                        break
                else:
                    msg = "Failed " \
                          "test_list_alarm_definitions_with_offset_limit: " \
                          "one minute timeout"
                    raise exceptions.TimeoutException(msg)
    def test_list_alarm_definitions_with_offset_limit(self):
        helpers.delete_alarm_definitions(self.monasca_client)
        expression = "max(cpu.system_perc) > 0"
        self._create_alarm_definitions(
            expression=expression, number_of_definitions=NUM_ALARM_DEFINITIONS)
        resp, response_body = self.monasca_client.list_alarm_definitions()
        self._verify_list_alarm_definitions_response_body(resp, response_body)
        first_element = response_body['elements'][0]
        last_element = response_body['elements'][1]

        query_parms = '?limit=2'
        resp, response_body = self.monasca_client.list_alarm_definitions(
            query_parms)
        self.assertEqual(200, resp.status)

        elements = response_body['elements']
        self.assertEqual(2, len(elements))
        self.assertEqual(first_element, elements[0])
        self.assertEqual(last_element, elements[1])

        timeout = time.time() + 60 * 1   # 1 minute timeout
        for limit in xrange(1, 3):
            next_element = elements[limit - 1]
            while True:
                if time.time() < timeout:
                    query_parms = '?offset=' + str(next_element['id']) + \
                                  '&limit=' + str(limit)
                    resp, response_body = self.monasca_client.\
                        list_alarm_definitions(query_parms)
                    self.assertEqual(200, resp.status)
                    new_elements = response_body['elements']
                    if len(new_elements) > limit - 1:
                        self.assertEqual(limit, len(new_elements))
                        next_element = new_elements[limit - 1]
                    elif 0 < len(new_elements) <= limit - 1:
                        self.assertEqual(last_element, new_elements[0])
                        break
                    else:
                        self.assertEqual(last_element, next_element)
                        break
                else:
                    msg = "Failed " \
                          "test_list_alarm_definitions_with_offset_limit: " \
                          "one minute timeout"
                    raise exceptions.TimeoutException(msg)
Ejemplo n.º 4
0
 def test_list_alarms_by_state(self):
     helpers.delete_alarm_definitions(self.monasca_client)
     self._create_alarms_for_test_alarms(num=3)
     resp, response_body = self.monasca_client.list_alarms()
     self._verify_list_alarms_elements(resp, response_body,
                                       expect_num_elements=3)
     elements = response_body['elements']
     len0 = len(elements)
     query_parms = '?state=UNDETERMINED'
     resp, response_body1 = self.monasca_client.list_alarms(query_parms)
     len1 = len(response_body1['elements'])
     self.assertEqual(200, resp.status)
     query_parms = '?state=OK'
     resp, response_body2 = self.monasca_client.list_alarms(query_parms)
     len2 = len(response_body2['elements'])
     self.assertEqual(200, resp.status)
     query_parms = '?state=ALARM'
     resp, response_body3 = self.monasca_client.list_alarms(query_parms)
     len3 = len(response_body3['elements'])
     self.assertEqual(200, resp.status)
     self.assertEqual(len0, len1 + len2 + len3)
Ejemplo n.º 5
0
    def test_list_alarm_definitions_with_offset_limit(self):
        helpers.delete_alarm_definitions(self.monasca_client)
        expression = "max(cpu.system_perc) > 0"
        self._create_alarm_definitions(
            expression=expression, number_of_definitions=NUM_ALARM_DEFINITIONS)
        resp, response_body = self.monasca_client.list_alarm_definitions()
        self._verify_list_alarm_definitions_response_body(resp, response_body)
        first_element = response_body['elements'][0]
        last_element = response_body['elements'][1]

        query_parms = '?limit=2'
        resp, response_body = self.monasca_client.list_alarm_definitions(
            query_parms)
        self.assertEqual(200, resp.status)

        elements = response_body['elements']
        self.assertEqual(2, len(elements))
        self.assertEqual(first_element, elements[0])
        self.assertEqual(last_element, elements[1])

        for offset in xrange(0, 2):
            for limit in xrange(1, 3 - offset):
                query_parms = '?offset=' + str(offset) + '&limit=' + str(limit)
                resp, response_body = self.monasca_client.list_alarm_definitions(
                    query_parms)
                self.assertEqual(200, resp.status)
                new_elements = response_body['elements']
                self.assertEqual(limit, len(new_elements))
                self.assertEqual(elements[offset], new_elements[0])
                self.assertEqual(elements[offset + limit - 1],
                                 new_elements[-1])
                links = response_body['links']
                for link in links:
                    if link['rel'] == 'next':
                        next_offset = helpers.get_query_param(
                            link['href'], 'offset')
                        next_limit = helpers.get_query_param(
                            link['href'], 'limit')
                        self.assertEqual(str(offset + limit), next_offset)
                        self.assertEqual(str(limit), next_limit)
Ejemplo n.º 6
0
 def test_list_alarms_by_state(self):
     helpers.delete_alarm_definitions(self.monasca_client)
     self._create_alarms_for_test_alarms(num=3)
     resp, response_body = self.monasca_client.list_alarms()
     self._verify_list_alarms_elements(resp,
                                       response_body,
                                       expect_num_elements=3)
     elements = response_body['elements']
     len0 = len(elements)
     query_parms = '?state=UNDETERMINED'
     resp, response_body1 = self.monasca_client.list_alarms(query_parms)
     len1 = len(response_body1['elements'])
     self.assertEqual(200, resp.status)
     query_parms = '?state=OK'
     resp, response_body2 = self.monasca_client.list_alarms(query_parms)
     len2 = len(response_body2['elements'])
     self.assertEqual(200, resp.status)
     query_parms = '?state=ALARM'
     resp, response_body3 = self.monasca_client.list_alarms(query_parms)
     len3 = len(response_body3['elements'])
     self.assertEqual(200, resp.status)
     self.assertEqual(len0, len1 + len2 + len3)
Ejemplo n.º 7
0
    def test_list_alarm_definitions_with_offset_limit(self):
        helpers.delete_alarm_definitions(self.monasca_client)
        expression = "max(cpu.system_perc) > 0"
        self._create_alarm_definitions(
            expression=expression, number_of_definitions=NUM_ALARM_DEFINITIONS)
        resp, response_body = self.monasca_client.list_alarm_definitions()
        self._verify_list_alarm_definitions_response_body(resp, response_body)
        first_element = response_body['elements'][0]
        last_element = response_body['elements'][1]

        query_parms = '?limit=2'
        resp, response_body = self.monasca_client.list_alarm_definitions(
            query_parms)
        self.assertEqual(200, resp.status)

        elements = response_body['elements']
        self.assertEqual(2, len(elements))
        self.assertEqual(first_element, elements[0])
        self.assertEqual(last_element, elements[1])

        for offset in xrange(0, 2):
            for limit in xrange(1, 3 - offset):
                query_parms = '?offset=' + str(offset) + '&limit=' + str(limit)
                resp, response_body = self.monasca_client.list_alarm_definitions(query_parms)
                self.assertEqual(200, resp.status)
                new_elements = response_body['elements']
                self.assertEqual(limit, len(new_elements))
                self.assertEqual(elements[offset], new_elements[0])
                self.assertEqual(elements[offset + limit - 1],
                                 new_elements[-1])
                links = response_body['links']
                for link in links:
                    if link['rel'] == 'next':
                        next_offset = helpers.get_query_param(link['href'], 'offset')
                        next_limit = helpers.get_query_param(link['href'], 'limit')
                        self.assertEqual(str(offset + limit), next_offset)
                        self.assertEqual(str(limit), next_limit)