Do not request NFVi metrics from empty nodes 73/59673/1
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Wed, 11 Jul 2018 11:39:51 +0000 (12:39 +0100)
committerRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Wed, 11 Jul 2018 11:42:26 +0000 (12:42 +0100)
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 <rodolfo.alonso.hernandez@intel.com>
yardstick/network_services/collector/subscriber.py
yardstick/tests/unit/network_services/collector/test_subscriber.py

index 937c266..0c6d977 100644 (file)
@@ -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():
index 4271f85..cffa4d4 100644 (file)
 # 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))