summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2018-07-12 11:28:04 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-07-12 11:28:04 +0000
commit5e531e1e38da7670a1226aec4c664ef96a77335e (patch)
tree937084b41124438ce19893591d26a356aeb00163
parentc35fe95566156f9bec4c516f6e0cd9c79c96a492 (diff)
parent1a34e5d4ae77f064c598fe84b4c5c1237b1d763d (diff)
Merge "Do not request NFVi metrics from empty nodes"
-rw-r--r--yardstick/network_services/collector/subscriber.py11
-rw-r--r--yardstick/tests/unit/network_services/collector/test_subscriber.py43
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))