From 1a34e5d4ae77f064c598fe84b4c5c1237b1d763d Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Wed, 11 Jul 2018 12:39:51 +0100 Subject: Do not request NFVi metrics from empty nodes In Collector class [1], the information from the nodes is retrieved to create a ResourceProfile object per node. If the node information is empty, Collector should skip this node. [1] https://github.com/opnfv/yardstick/blob/master/yardstick/network_services/collector/subscriber.py#L34 JIRA: YARDSTICK-1302 Change-Id: I84dff3e20881352263736b682a60a4f382960153 Signed-off-by: Rodolfo Alonso Hernandez --- yardstick/network_services/collector/subscriber.py | 11 +++--- .../network_services/collector/test_subscriber.py | 43 +++++++++++++++------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/yardstick/network_services/collector/subscriber.py b/yardstick/network_services/collector/subscriber.py index 937c266a6..0c6d97771 100644 --- a/yardstick/network_services/collector/subscriber.py +++ b/yardstick/network_services/collector/subscriber.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -"""This module implements stub for publishing results in yardstick format.""" + import logging from yardstick.network_services.nfvi.resource import ResourceProfile @@ -31,12 +31,13 @@ class Collector(object): self.bin_path = get_nsb_option('bin_path', '') self.resource_profiles = {} - for ctx_name, nodes in contexts_nodes.items(): - for node in (node for node in nodes if node.get('collectd')): + for ctx_name, nodes in ((ctx_name, nodes) for (ctx_name, nodes) + in contexts_nodes.items() if nodes): + for node in (node for node in nodes + if node and node.get('collectd')): name = ".".join([node['name'], ctx_name]) self.resource_profiles.update( - {name: ResourceProfile.make_from_node(node, timeout)} - ) + {name: ResourceProfile.make_from_node(node, timeout)}) def start(self): for resource in self.resource_profiles.values(): diff --git a/yardstick/tests/unit/network_services/collector/test_subscriber.py b/yardstick/tests/unit/network_services/collector/test_subscriber.py index 4271f852c..cffa4d492 100644 --- a/yardstick/tests/unit/network_services/collector/test_subscriber.py +++ b/yardstick/tests/unit/network_services/collector/test_subscriber.py @@ -11,10 +11,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# -import unittest +import copy import mock +import unittest from yardstick.network_services.collector import subscriber from yardstick import ssh @@ -38,14 +38,15 @@ class MockVnfAprrox(object): class CollectorTestCase(unittest.TestCase): - NODES = {'context1': [{'name': 'node1', - 'ip': '1.2.3.4', - 'collectd': { - 'plugins': {'abc': 12, 'def': 34}, - 'interval': 987 - }, - }] - } + NODES = { + 'context1': [{'name': 'node1', + 'ip': '1.2.3.4', + 'collectd': { + 'plugins': {'abc': 12, 'def': 34}, + 'interval': 987} + } + ] + } def setUp(self): vnf = MockVnfAprrox() @@ -61,13 +62,29 @@ class CollectorTestCase(unittest.TestCase): def tearDown(self): self.ssh_patch.stop() - def test___init__(self, *_): + def test___init__(self, *args): vnf = MockVnfAprrox() collector = subscriber.Collector([vnf], self.NODES) self.assertEqual(len(collector.vnfs), 1) self.assertEqual(len(collector.nodes), 1) - def test_start(self, *_): + def test___init__no_node_information(self, *args): + vnf = MockVnfAprrox() + nodes = copy.deepcopy(self.NODES) + nodes['context1'].append(None) + collector = subscriber.Collector([vnf], nodes) + self.assertEqual(len(collector.vnfs), 1) + self.assertEqual(len(collector.nodes), 1) + + def test___init__no_node_information_in_context(self, *args): + vnf = MockVnfAprrox() + nodes = copy.deepcopy(self.NODES) + nodes['context1'] = None + collector = subscriber.Collector([vnf], nodes) + self.assertEqual(len(collector.vnfs), 1) + self.assertEqual(len(collector.nodes), 1) + + def test_start(self, *args): resource_profile = mock.MagicMock() self.collector.resource_profiles = {'key': resource_profile} self.collector.bin_path = 'path' @@ -92,7 +109,7 @@ class CollectorTestCase(unittest.TestCase): for resource in self.collector.resource_profiles.values(): resource.stop.assert_called_once() - def test_get_kpi(self, *_): + def test_get_kpi(self, *args): result = self.collector.get_kpi() self.assertEqual(2, len(result)) -- cgit 1.2.3-korg