Check if scope is None

if scope is None, don't create data model

Change-Id: Icf611966c9b0a3882615d778ee6c72a8da73841d
Closed-Bug: #1881920
(cherry picked from commit 9f0138e1cf)
This commit is contained in:
licanwei 2020-06-06 11:02:23 +08:00
parent 043ebb71c6
commit cbb06e6765
4 changed files with 45 additions and 0 deletions

View File

@ -152,6 +152,9 @@ class CinderClusterDataModelCollector(base.BaseClusterDataModelCollector):
if self._audit_scope_handler is None: if self._audit_scope_handler is None:
LOG.debug("No audit, Don't Build storage data model") LOG.debug("No audit, Don't Build storage data model")
return return
if self._data_model_scope is None:
LOG.debug("No audit scope, Don't Build storage data model")
return
builder = CinderModelBuilder(self.osc) builder = CinderModelBuilder(self.osc)
return builder.execute(self._data_model_scope) return builder.execute(self._data_model_scope)

View File

@ -63,6 +63,9 @@ class BaremetalClusterDataModelCollector(base.BaseClusterDataModelCollector):
if self._audit_scope_handler is None: if self._audit_scope_handler is None:
LOG.debug("No audit, Don't Build Baremetal data model") LOG.debug("No audit, Don't Build Baremetal data model")
return return
if self._data_model_scope is None:
LOG.debug("No audit scope, Don't Build Baremetal data model")
return
builder = BareMetalModelBuilder(self.osc) builder = BareMetalModelBuilder(self.osc)
return builder.execute(self._data_model_scope) return builder.execute(self._data_model_scope)

View File

@ -184,6 +184,9 @@ class NovaClusterDataModelCollector(base.BaseClusterDataModelCollector):
if self._audit_scope_handler is None: if self._audit_scope_handler is None:
LOG.debug("No audit, Don't Build compute data model") LOG.debug("No audit, Don't Build compute data model")
return return
if self._data_model_scope is None:
LOG.debug("No audit scope, Don't Build compute data model")
return
builder = NovaModelBuilder(self.osc) builder = NovaModelBuilder(self.osc)
return builder.execute(self._data_model_scope) return builder.execute(self._data_model_scope)

View File

@ -17,6 +17,9 @@
import mock import mock
from watcher.decision_engine.model.collector import base from watcher.decision_engine.model.collector import base
from watcher.decision_engine.model.collector import cinder
from watcher.decision_engine.model.collector import ironic
from watcher.decision_engine.model.collector import nova
from watcher.decision_engine.model import model_root from watcher.decision_engine.model import model_root
from watcher.tests import base as test_base from watcher.tests import base as test_base
@ -55,3 +58,36 @@ class TestClusterDataModelCollector(test_base.TestCase):
self.assertIsNot( self.assertIsNot(
collector.cluster_data_model, collector.cluster_data_model,
collector.get_latest_cluster_data_model()) collector.get_latest_cluster_data_model())
class TestComputeDataModelCollector(test_base.TestCase):
def test_model_scope_is_none(self):
m_config = mock.Mock()
collector = nova.NovaClusterDataModelCollector(config=m_config)
collector._audit_scope_handler = mock.Mock()
collector._data_model_scope = None
self.assertIsNone(collector.execute())
class TestStorageDataModelCollector(test_base.TestCase):
def test_model_scope_is_none(self):
m_config = mock.Mock()
collector = cinder.CinderClusterDataModelCollector(config=m_config)
collector._audit_scope_handler = mock.Mock()
collector._data_model_scope = None
self.assertIsNone(collector.execute())
class TestBareMetalDataModelCollector(test_base.TestCase):
def test_model_scope_is_none(self):
m_config = mock.Mock()
collector = ironic.BaremetalClusterDataModelCollector(config=m_config)
collector._audit_scope_handler = mock.Mock()
collector._data_model_scope = None
self.assertIsNone(collector.execute())