Fix initialization of the PhysicalHostMonitorPlugin

The PhysicalHostMonitorPlugin class uses the singleton design pattern.
An instance of this class is generated only once but __init__ can be
called multiple times.

This patch moves class member initialization from __init__ to __new__.

Change-Id: I999e5e27d0fda51297fffd2f75e29efb3b464061
This commit is contained in:
Hiroaki Kobayashi 2018-04-16 14:37:12 +09:00
parent fcef4ce011
commit ad575d3d32
1 changed files with 12 additions and 7 deletions

View File

@ -613,16 +613,21 @@ class PhysicalHostMonitorPlugin(base.BaseMonitorPlugin,
def __new__(cls):
if not cls._instance:
cls._instance = super(PhysicalHostMonitorPlugin, cls).__new__(cls)
cls._instance.healing_handlers = []
super(PhysicalHostMonitorPlugin, cls._instance).__init__(
password=CONF.os_admin_password,
user_domain_name=CONF.os_admin_user_domain_name,
project_name=CONF.os_admin_project_name,
project_domain_name=CONF.os_admin_user_domain_name)
return cls._instance
def __init__(self):
super(PhysicalHostMonitorPlugin, self).__init__(
username=CONF.os_admin_username,
password=CONF.os_admin_password,
user_domain_name=CONF.os_admin_user_domain_name,
project_name=CONF.os_admin_project_name,
project_domain_name=CONF.os_admin_user_domain_name)
self.healing_handlers = []
"""Do nothing.
This class uses the Singleton design pattern and an instance of this
class is generated and initialized in __new__().
"""
pass
def register_healing_handler(self, handler):
self.healing_handlers.append(handler)