X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Ftests%2Funit%2Fcollector%2Ftest_collector_service.py;h=fc2146cc34fe3079bd5bc0cd59d4aca1d0d9b0aa;hb=34a0a0f1b7ccbecfbed40d3e68fb9fd16564052c;hp=22d4410afad25cb37fd8b492d07f9f923900826a;hpb=8283936d7cecd8941116409edbfaceeba6570acb;p=osm%2FMON.git diff --git a/osm_mon/tests/unit/collector/test_collector_service.py b/osm_mon/tests/unit/collector/test_collector_service.py index 22d4410..fc2146c 100644 --- a/osm_mon/tests/unit/collector/test_collector_service.py +++ b/osm_mon/tests/unit/collector/test_collector_service.py @@ -23,8 +23,8 @@ from unittest import TestCase, mock from osm_mon.collector.service import CollectorService -from osm_mon.collector.utils.collector import CollectorUtils from osm_mon.collector.vnf_collectors.openstack import OpenstackCollector +from osm_mon.collector.vnf_collectors.vio import VIOCollector from osm_mon.core.common_db import CommonDbClient from osm_mon.core.config import Config @@ -37,24 +37,43 @@ class CollectorServiceTest(TestCase): @mock.patch.object(OpenstackCollector, "__init__", lambda *args, **kwargs: None) @mock.patch.object(OpenstackCollector, "collect") - @mock.patch.object(CollectorUtils, "get_vim_type") - def test_init_vim_collector_and_collect_openstack(self, _get_vim_type, collect): - _get_vim_type.return_value = 'openstack' + @mock.patch.object(CommonDbClient, "get_vim_account") + def test_init_vim_collector_and_collect_openstack(self, _get_vim_account, collect): + _get_vim_account.return_value = {'vim_type': 'openstack'} collector = CollectorService(self.config) - collector._collect_vim_metrics({}, 'test_vim_account_id') + collector._collect_vim_metrics(self.config, {}, 'test_vim_account_id') collect.assert_called_once_with({}) @mock.patch.object(OpenstackCollector, "collect") - @mock.patch.object(CollectorUtils, "get_vim_type") - def test_init_vim_collector_and_collect_unknown(self, _get_vim_type, openstack_collect): - _get_vim_type.return_value = 'unknown' + @mock.patch.object(CommonDbClient, "get_vim_account") + def test_init_vim_collector_and_collect_unknown(self, _get_vim_account, openstack_collect): + _get_vim_account.return_value = {'vim_type': 'unknown'} collector = CollectorService(self.config) - collector._collect_vim_metrics({}, 'test_vim_account_id') + collector._collect_vim_metrics(self.config, {}, 'test_vim_account_id') openstack_collect.assert_not_called() + @mock.patch.object(OpenstackCollector, "__init__", lambda *args, **kwargs: None) + @mock.patch.object(OpenstackCollector, "collect") + @mock.patch.object(CommonDbClient, "get_vim_account") + def test_init_vim_collector_and_collect_vio_with_openstack_collector(self, _get_vim_account, openstack_collect): + _get_vim_account.return_value = {'vim_type': 'openstack', 'config': {'vim_type': 'VIO'}} + collector = CollectorService(self.config) + collector._collect_vim_metrics(self.config, {}, 'test_vim_account_id') + openstack_collect.assert_called_once_with({}) + + @mock.patch.object(VIOCollector, "__init__", lambda *args, **kwargs: None) + @mock.patch.object(VIOCollector, "collect") + @mock.patch.object(CommonDbClient, "get_vim_account") + def test_init_vim_collector_and_collect_vio_with_vrops_collector(self, _get_vim_account, vio_collect): + _get_vim_account.return_value = {'vim_type': 'openstack', + 'config': {'vim_type': 'VIO', 'vrops_site': 'https://vrops'}} + collector = CollectorService(self.config) + collector._collect_vim_metrics(self.config, {}, 'test_vim_account_id') + vio_collect.assert_called_once_with({}) + @mock.patch("osm_mon.collector.service.VCACollector", autospec=True) def test_collect_vca_metrics(self, vca_collector): collector = CollectorService(self.config) - collector._collect_vca_metrics({}) + collector._collect_vca_metrics(self.config, {}) vca_collector.assert_called_once_with(self.config) vca_collector.return_value.collect.assert_called_once_with({})