diff --git a/tacker/tests/unit/vnfm/test_plugin.py b/tacker/tests/unit/vnfm/test_plugin.py index be03bbf1f..fef337ef0 100644 --- a/tacker/tests/unit/vnfm/test_plugin.py +++ b/tacker/tests/unit/vnfm/test_plugin.py @@ -29,6 +29,7 @@ from tacker.extensions import vnfm from tacker.plugins.common import constants from tacker.tests.unit.db import base as db_base from tacker.tests.unit.db import utils +from tacker.vnfm import monitor from tacker.vnfm import plugin @@ -110,6 +111,12 @@ class TestVNFMPluginMonitor(db_base.SqlTestCase): }] mock_get_vnfs.return_value = vnfs + # NOTE(bhagyashris): VNFMonitor class is using a singleton pattern + # and '_hosting_vnfs' is defined as a class level attribute. + # If one of the unit test adds a VNF to monitor it will show up here + # provided both the unit tests runs in the same process. + # Hence, you must reinitialize '_hosting_vnfs' to empty dict. + monitor.VNFMonitor._hosting_vnfs = dict() vnfm_plugin = plugin.VNFMPlugin() hosting_vnfs = vnfm_plugin._vnf_monitor._hosting_vnfs.values() hosting_vnf = hosting_vnfs[0]['vnf'] diff --git a/tacker/vnfm/monitor.py b/tacker/vnfm/monitor.py index b8aa3dbc3..ad45c1f09 100644 --- a/tacker/vnfm/monitor.py +++ b/tacker/vnfm/monitor.py @@ -95,7 +95,7 @@ class VNFMonitor(object): time.sleep(self._status_check_intvl) with self._lock: - for hosting_vnf in self._hosting_vnfs.values(): + for hosting_vnf in VNFMonitor._hosting_vnfs.values(): if hosting_vnf.get('dead', False): LOG.debug('monitor skips dead vnf %s', hosting_vnf) continue @@ -120,7 +120,7 @@ class VNFMonitor(object): 'ips': new_vnf['management_ip_addresses']}) new_vnf['boot_at'] = timeutils.utcnow() with self._lock: - self._hosting_vnfs[new_vnf['id']] = new_vnf + VNFMonitor._hosting_vnfs[new_vnf['id']] = new_vnf attrib_dict = new_vnf['vnf']['attributes'] mon_policy_dict = attrib_dict['monitoring_policy'] @@ -132,7 +132,7 @@ class VNFMonitor(object): def delete_hosting_vnf(self, vnf_id): LOG.debug('deleting vnf_id %(vnf_id)s', {'vnf_id': vnf_id}) with self._lock: - hosting_vnf = self._hosting_vnfs.pop(vnf_id, None) + hosting_vnf = VNFMonitor._hosting_vnfs.pop(vnf_id, None) if hosting_vnf: LOG.debug('deleting vnf_id %(vnf_id)s, Mgmt IP %(ips)s', {'vnf_id': vnf_id, @@ -175,7 +175,7 @@ class VNFMonitor(object): hosting_vnf['action_cb'](action) def mark_dead(self, vnf_id): - self._hosting_vnfs[vnf_id]['dead'] = True + VNFMonitor._hosting_vnfs[vnf_id]['dead'] = True def _invoke(self, driver, **kwargs): method = inspect.stack()[1][3] diff --git a/tox.ini b/tox.ini index c1ab409cf..3689687df 100644 --- a/tox.ini +++ b/tox.ini @@ -17,7 +17,7 @@ install_command = deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt commands = - stestr run --slowest {posargs} + stestr run --slowest --concurrency 1 {posargs} [testenv:functional] setenv = {[testenv]setenv}