diff --git a/neutron/agent/metadata/driver_base.py b/neutron/agent/metadata/driver_base.py index 8fb3952dde1..8c8e8f46f72 100644 --- a/neutron/agent/metadata/driver_base.py +++ b/neutron/agent/metadata/driver_base.py @@ -159,6 +159,8 @@ class HaproxyConfiguratorBase(object): class MetadataDriverBase(object, metaclass=abc.ABCMeta): + monitors = {} + @staticmethod @abc.abstractmethod def haproxy_configurator(): @@ -253,6 +255,8 @@ class MetadataDriverBase(object, metaclass=abc.ABCMeta): return monitor.register(uuid, METADATA_SERVICE_NAME, pm) + cls.monitors[uuid] = pm + @classmethod def destroy_monitored_metadata_proxy(cls, monitor, uuid, conf, ns_name): monitor.unregister(uuid, METADATA_SERVICE_NAME) @@ -272,6 +276,8 @@ class MetadataDriverBase(object, metaclass=abc.ABCMeta): configurator = cls.haproxy_configurator() configurator.cleanup_config_file(uuid, cfg.CONF.state_path) + cls.monitors.pop(uuid, None) + @classmethod def _get_metadata_proxy_process_manager(cls, router_id, conf, ns_name=None, callback=None): diff --git a/neutron/tests/unit/agent/metadata/test_driver.py b/neutron/tests/unit/agent/metadata/test_driver.py index 707d7f702d5..0fe5ba44ffe 100644 --- a/neutron/tests/unit/agent/metadata/test_driver.py +++ b/neutron/tests/unit/agent/metadata/test_driver.py @@ -312,6 +312,7 @@ class TestMetadataDriverProcess(base.BaseTestCase): network_id=network_id) error_log.assert_called_once() process_monitor.register.assert_not_called() + self.assertNotIn(network_id, metadata_driver.MetadataDriver.monitors) def test_create_config_file_wrong_user(self): with mock.patch('pwd.getpwnam', side_effect=KeyError): diff --git a/neutron/tests/unit/agent/ovn/metadata/test_driver.py b/neutron/tests/unit/agent/ovn/metadata/test_driver.py index 190ae0ac3de..263c8daca32 100644 --- a/neutron/tests/unit/agent/ovn/metadata/test_driver.py +++ b/neutron/tests/unit/agent/ovn/metadata/test_driver.py @@ -197,6 +197,7 @@ class TestMetadataDriverProcess(base.BaseTestCase): error_log.assert_called_once() process_monitor.register.assert_not_called() + self.assertNotIn(network_id, metadata_driver.MetadataDriver.monitors) def test_create_config_file_wrong_user(self): with mock.patch('pwd.getpwnam', side_effect=KeyError):