3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
12 # Unittest for yardstick.dispatcher.influxdb
14 from __future__ import absolute_import
19 from unittest import mock
23 from yardstick import _init_logging
26 from yardstick.dispatcher.influxdb import InfluxdbDispatcher
29 class InfluxdbDispatcherTestCase(unittest.TestCase):
36 "ip": "10.229.43.154",
38 "/root/yardstick/yardstick/resources/files"
44 "ipaddr": "10.229.44.134"
50 "object": "yardstick.benchmark.scenarios.networking.ping"
52 "output_filename": "/tmp/yardstick.out",
59 "target": "10.229.44.134",
65 "task_id": "ea958583-c91e-461a-af14-2a7f9d7f79e7"
70 "timestamp": "1451478117.883505",
80 self.yardstick_conf = {'dispatcher_influxdb': {}}
82 @mock.patch('yardstick.dispatcher.influxdb.requests')
83 def test_record_result_data(self, mock_requests):
84 type(mock_requests.post.return_value).status_code = 204
85 influxdb = InfluxdbDispatcher(self.yardstick_conf)
92 'task_id': 'b9e2bbc2-dfd8-410d-8c24-07771e9f7979',
97 self.assertEqual(influxdb.flush_result_data(data), 0)
99 def test__get_nano_timestamp(self):
100 influxdb = InfluxdbDispatcher(self.yardstick_conf)
101 results = {'timestamp': '1451461248.925574'}
102 self.assertEqual(influxdb._get_nano_timestamp(results),
103 '1451461248925574144')
105 @mock.patch('yardstick.dispatcher.influxdb.time')
106 def test__get_nano_timestamp_except(self, mock_time):
108 influxdb = InfluxdbDispatcher(self.yardstick_conf)
109 mock_time.time.return_value = 1451461248.925574
110 self.assertEqual(influxdb._get_nano_timestamp(results),
111 '1451461248925574144')
118 if __name__ == '__main__':