Example #1
0
    def setUp(self):
        self._querier = StatQuerier()

        flexmock(OpServerUtils).should_receive('post_url_http').once(
        ).replace_with(lambda x, y, w, z, **kwargs: self.custom_post_url_http(
            x, y, kwargs))
        flexmock(self._querier).should_receive('display').replace_with(
            lambda x: self.custom_display(x))
Example #2
0
class StatQuerierTest(unittest.TestCase):
    @staticmethod
    def custom_post_url_http(url, params, sync=True):
        global query_dict
        query_dict = json.loads(params)
        if (test_num == 1):
            return result_1

        return []

    def custom_display(self, result):
        if (test_num == 1):
            expect_result = json.loads(result_1)
            expect_result = expect_result['value']
            self.assertTrue(result == expect_result)

    def setUp(self):
        self._querier = StatQuerier()

        flexmock(OpServerUtils).should_receive('post_url_http').once(
        ).replace_with(lambda x, y, w, z, **kwargs: self.custom_post_url_http(
            x, y, kwargs))
        flexmock(self._querier).should_receive('display').replace_with(
            lambda x: self.custom_display(x))

    #@unittest.skip("skip test_1_analytics_cpu_query")
    def test_1_analytics_cpu_query(self):
        global test_num
        global query_dict
        test_num = 1

        argv = sys.argv
        sys.argv = "contrail-stats --table NodeStatus.process_mem_cpu_usage --select T=60 SUM(process_mem_cpu_usage.cpu_share) --where name=*".split(
        )
        self._querier.run()
        sys.argv = argv

        expected_result_str = '{"select_fields": ["T=60", "SUM(process_mem_cpu_usage.cpu_share)"], "table": "StatTable.NodeStatus.process_mem_cpu_usage", "where": [[{"suffix": null, "value2": null, "name": "name", "value": "", "op": 7}]]}'
        expected_result_dict = json.loads(expected_result_str)
        self.assertEqual(
            int(query_dict['end_time']) - int(query_dict['start_time']),
            10 * 60 * pow(10, 6))
        del query_dict['start_time']
        del query_dict['end_time']
        for key in expected_result_dict:
            self.assertTrue(key in query_dict)
            self.assertTrue(expected_result_dict[key] == query_dict[key])
class StatQuerierTest(unittest.TestCase):

    @staticmethod
    def custom_post_url_http(url, params, sync = True):
        global query_dict
        query_dict = json.loads(params)
        if (test_num == 1):
            return result_1

        return []

    def custom_display(self, result):
        if (test_num == 1):
            expect_result = json.loads(result_1)
            expect_result = expect_result['value']
            self.assertTrue(result == expect_result)

    def setUp(self):
        self._querier = StatQuerier()

        flexmock(OpServerUtils).should_receive('post_url_http').once().replace_with(lambda x, y, w, z, **kwargs: self.custom_post_url_http(x, y, kwargs))
        flexmock(self._querier).should_receive('display').replace_with(lambda x: self.custom_display(x))


    #@unittest.skip("skip test_1_analytics_cpu_query")
    def test_1_analytics_cpu_query(self):
        global test_num
        global query_dict
        test_num = 1

        argv = sys.argv
        sys.argv = "contrail-stats --table NodeStatus.process_mem_cpu_usage --select T=60 SUM(process_mem_cpu_usage.cpu_share) --where name=*".split()
        self._querier.run()
        sys.argv = argv

        expected_result_str = '{"select_fields": ["T=60", "SUM(process_mem_cpu_usage.cpu_share)"], "table": "StatTable.NodeStatus.process_mem_cpu_usage", "where": [[{"suffix": null, "value2": null, "name": "name", "value": "", "op": 7}]]}'
        expected_result_dict = json.loads(expected_result_str)
        self.assertEqual(int(query_dict['end_time']) - int(query_dict['start_time']), 10*60*pow(10,6))
        del query_dict['start_time']
        del query_dict['end_time']
        for key in expected_result_dict:
            self.assertTrue(key in query_dict)
            self.assertTrue(expected_result_dict[key] == query_dict[key])
    def setUp(self):
        self._querier = StatQuerier()

        flexmock(OpServerUtils).should_receive('post_url_http').once().replace_with(lambda x, y, **kwargs: self.custom_post_url_http(x, y, kwargs))
        flexmock(self._querier).should_receive('display').replace_with(lambda x: self.custom_display(x))