From d99cfd9eaac88851d7efbb95292c2752755ae070 Mon Sep 17 00:00:00 2001 From: Myron Sosyak Date: Wed, 19 Sep 2018 14:10:57 +0100 Subject: Implement functionality for updating http client Implemented functionality for updating http client configuration. Extended http_ixload.py with functions for update page object and count of simulated users in http client on netTraffic. JIRA: YARDSTICK-1435 Change-Id: I9a0be226d4201d861d3a764864b42e5d87a4a305 Signed-off-by: Myron Sosyak Signed-off-by: Taras Chornyi --- .../benchmark/scenarios/networking/vnf_generic.py | 25 +++++++++- .../traffic_profile/http_ixload.py | 51 +++++++++++++++++++ .../scenarios/networking/test_vnf_generic.py | 22 ++++++++- .../traffic_profile/test_http_ixload.py | 57 +++++++++++++++++++++- 4 files changed, 151 insertions(+), 4 deletions(-) (limited to 'yardstick') diff --git a/yardstick/benchmark/scenarios/networking/vnf_generic.py b/yardstick/benchmark/scenarios/networking/vnf_generic.py index d8f062522..5ac51cdfc 100644 --- a/yardstick/benchmark/scenarios/networking/vnf_generic.py +++ b/yardstick/benchmark/scenarios/networking/vnf_generic.py @@ -151,6 +151,26 @@ class NetworkServiceTestCase(scenario_base.Scenario): return options.get('duration', tprofile_base.TrafficProfileConfig.DEFAULT_DURATION) + def _key_list_to_dict(self, key, value_list): + value_dict = {} + try: + for index, count in enumerate(value_list[key]): + value_dict["{}_{}".format(key, index)] = count + except KeyError: + value_dict = {} + + return value_dict + + def _get_simulated_users(self): + users = self.scenario_cfg.get("options", {}).get("simulated_users", {}) + simulated_users = self._key_list_to_dict("uplink", users) + return {"simulated_users": simulated_users} + + def _get_page_object(self): + objects = self.scenario_cfg.get("options", {}).get("page_object", {}) + page_object = self._key_list_to_dict("uplink", objects) + return {"page_object": page_object} + def _fill_traffic_profile(self): tprofile = self._get_traffic_profile() extra_args = self.scenario_cfg.get('extra_args', {}) @@ -160,8 +180,9 @@ class NetworkServiceTestCase(scenario_base.Scenario): tprofile_base.TrafficProfile.UPLINK: {}, tprofile_base.TrafficProfile.DOWNLINK: {}, 'extra_args': extra_args, - 'duration': self._get_duration()} - + 'duration': self._get_duration(), + 'page_object': self._get_page_object(), + 'simulated_users': self._get_simulated_users()} traffic_vnfd = vnfdgen.generate_vnfd(tprofile, tprofile_data) traffic_config = \ diff --git a/yardstick/network_services/traffic_profile/http_ixload.py b/yardstick/network_services/traffic_profile/http_ixload.py index 9210f3c6d..c64e7511f 100644 --- a/yardstick/network_services/traffic_profile/http_ixload.py +++ b/yardstick/network_services/traffic_profile/http_ixload.py @@ -264,6 +264,57 @@ class IXLOADHttpTest(object): continue self.update_network_param(net_traffic, param["ip"]) + if "uplink" in name: + self.update_http_client_param(net_traffic, param["http_client"]) + + def update_http_client_param(self, net_traffic, param): + """Update http client object in net_traffic + + Update http client object in net_traffic by parameters + specified in param. + Do not return anything. + + :param net_traffic: (IxLoadObjectProxy) proxy obj to tcl net_traffic object + :param param: (dict) http_client section from traffic profile + :return: + """ + self.update_page_size(net_traffic, param["page_object"]) + self.update_user_count(net_traffic, param["simulated_users"]) + + def update_page_size(self, net_traffic, page_object): + """Update page_object field in http client object in net_traffic + + This function update field which configure page_object + which will be loaded from server + Do not return anything. + + :param net_traffic: (IxLoadObjectProxy) proxy obj to tcl net_traffic object + :param page_object: (str) path to object on server e.g. "/4k.html" + :return: + """ + try: + activity = net_traffic.activityList[0] + ix_http_command = activity.agent.actionList[0] + ix_http_command.config(pageObject=page_object) + except Exception: + raise exceptions.InvalidRxfFile + + def update_user_count(self, net_traffic, user_count): + """Update userObjectiveValue field in activity object in net_traffic + + This function update field which configure users count + which will be simulated by client. + Do not return anything. + + :param net_traffic: (IxLoadObjectProxy) proxy obj to tcl net_traffic object + :param user_count: (int) number of simulated users + :return: + """ + try: + activity = net_traffic.activityList[0] + activity.config(userObjectiveValue=user_count) + except Exception: + raise exceptions.InvalidRxfFile def start_http_test(self): self.ix_load = IxLoad() diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py index 90248d1bf..8214782b2 100644 --- a/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py +++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py @@ -325,6 +325,8 @@ class TestNetworkServiceTestCase(unittest.TestCase): }, }, 'options': { + 'simulated_users': {'uplink': [1, 2]}, + 'page_object': {'uplink': [1, 2]}, 'framesize': {'64B': 100} }, 'runner': { @@ -620,6 +622,20 @@ class TestNetworkServiceTestCase(unittest.TestCase): with self.assertRaises(IOError): self.s._get_traffic_profile() + def test__key_list_to_dict(self): + result = self.s._key_list_to_dict("uplink", {"uplink": [1, 2]}) + self.assertEqual({"uplink_0": 1, "uplink_1": 2}, result) + + def test__get_simulated_users(self): + result = self.s._get_simulated_users() + self.assertEqual({'simulated_users': {'uplink_0': 1, 'uplink_1': 2}}, + result) + + def test__get_page_object(self): + result = self.s._get_page_object() + self.assertEqual({'page_object': {'uplink_0': 1, 'uplink_1': 2}}, + result) + def test___get_traffic_imix_exception(self): with mock.patch.dict(self.scenario_cfg["traffic_options"], {'imix': ''}): self.assertEqual({'imix': {'64B': 100}}, @@ -642,7 +658,11 @@ class TestNetworkServiceTestCase(unittest.TestCase): 'flow': {'flow': {}}, 'imix': {'imix': {'64B': 100}}, 'uplink': {}, - 'duration': 30} + 'duration': 30, + 'simulated_users': { + 'simulated_users': {'uplink_0': 1, 'uplink_1': 2}}, + 'page_object': { + 'page_object': {'uplink_0': 1, 'uplink_1': 2}},} ) mock_tprofile_get.assert_called_once_with(fake_vnfd) diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_http_ixload.py b/yardstick/tests/unit/network_services/traffic_profile/test_http_ixload.py index 1adab48bc..c9be200b2 100644 --- a/yardstick/tests/unit/network_services/traffic_profile/test_http_ixload.py +++ b/yardstick/tests/unit/network_services/traffic_profile/test_http_ixload.py @@ -249,16 +249,20 @@ class TestIxLoadTrafficGen(unittest.TestCase): ixload = http_ixload.IXLOADHttpTest( jsonutils.dump_as_bytes(self.test_input)) - ixload.links_param = {"uplink_0": {"ip": {}}} + ixload.links_param = {"uplink_0": {"ip": {}, + "http_client": {}}} ixload.test = mock.Mock() ixload.test.communityList = community_list ixload.update_network_param = mock.Mock() + ixload.update_http_client_param = mock.Mock() ixload.update_config() ixload.update_network_param.assert_called_once_with(net_taraffic_0, {}) + ixload.update_http_client_param.assert_called_once_with(net_taraffic_0, + {}) def test_update_network_mac_address(self): ethernet = mock.MagicMock() @@ -338,6 +342,57 @@ class TestIxLoadTrafficGen(unittest.TestCase): net_traffic, "mac") + def test_update_http_client_param(self): + net_traffic = mock.Mock() + + ixload = http_ixload.IXLOADHttpTest( + jsonutils.dump_as_bytes(self.test_input)) + + ixload.update_page_size = mock.Mock() + ixload.update_user_count = mock.Mock() + + param = {"page_object": "page_object", + "simulated_users": "simulated_users"} + + ixload.update_http_client_param(net_traffic, param) + + ixload.update_page_size.assert_called_once_with(net_traffic, + "page_object") + ixload.update_user_count.assert_called_once_with(net_traffic, + "simulated_users") + + def test_update_page_size(self): + activity = mock.MagicMock() + net_traffic = mock.Mock() + + ixload = http_ixload.IXLOADHttpTest( + jsonutils.dump_as_bytes(self.test_input)) + + net_traffic.activityList = [activity] + ix_http_command = activity.agent.actionList[0] + ixload.update_page_size(net_traffic, "page_object") + ix_http_command.config.assert_called_once_with( + pageObject="page_object") + + net_traffic.activityList = [] + with self.assertRaises(exceptions.InvalidRxfFile): + ixload.update_page_size(net_traffic, "page_object") + + def test_update_user_count(self): + activity = mock.MagicMock() + net_traffic = mock.Mock() + + ixload = http_ixload.IXLOADHttpTest( + jsonutils.dump_as_bytes(self.test_input)) + + net_traffic.activityList = [activity] + ixload.update_user_count(net_traffic, 123) + activity.config.assert_called_once_with(userObjectiveValue=123) + + net_traffic.activityList = [] + with self.assertRaises(exceptions.InvalidRxfFile): + ixload.update_user_count(net_traffic, 123) + @mock.patch('yardstick.network_services.traffic_profile.http_ixload.IxLoad') @mock.patch('yardstick.network_services.traffic_profile.http_ixload.StatCollectorUtils') def test_start_http_test(self, *args): -- cgit 1.2.3-korg