Add HA support
This patch set adds hostname field to Audit and Action Plan objects to track services which execute these objects. Change-Id: I786e419952925c380c969b12cc60f9a1004af96b Partially-Implements: blueprint support-watcher-ha-active-active-mode
This commit is contained in:
@@ -21,12 +21,63 @@ from apscheduler.triggers import interval as interval_trigger
|
||||
import eventlet
|
||||
import mock
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from watcher.decision_engine.loading import default as default_loading
|
||||
from watcher.decision_engine import scheduling
|
||||
from watcher.decision_engine.strategy.strategies import dummy_strategy
|
||||
from watcher import notifications
|
||||
from watcher import objects
|
||||
from watcher.tests import base
|
||||
from watcher.tests.db import base as db_base
|
||||
from watcher.tests.decision_engine.model import faker_cluster_state
|
||||
from watcher.tests.objects import utils as obj_utils
|
||||
|
||||
|
||||
class TestCancelOngoingAudits(db_base.DbTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCancelOngoingAudits, self).setUp()
|
||||
p_audit_notifications = mock.patch.object(
|
||||
notifications, 'audit', autospec=True)
|
||||
self.m_audit_notifications = p_audit_notifications.start()
|
||||
self.addCleanup(p_audit_notifications.stop)
|
||||
|
||||
self.goal = obj_utils.create_test_goal(
|
||||
self.context, id=1, name=dummy_strategy.DummyStrategy.get_name())
|
||||
self.strategy = obj_utils.create_test_strategy(
|
||||
self.context, name=dummy_strategy.DummyStrategy.get_name(),
|
||||
goal_id=self.goal.id)
|
||||
audit_template = obj_utils.create_test_audit_template(
|
||||
self.context, strategy_id=self.strategy.id)
|
||||
self.audit = obj_utils.create_test_audit(
|
||||
self.context,
|
||||
id=999,
|
||||
name='My Audit 999',
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
audit_template_id=audit_template.id,
|
||||
goal_id=self.goal.id,
|
||||
audit_type=objects.audit.AuditType.ONESHOT.value,
|
||||
goal=self.goal,
|
||||
hostname='hostname1',
|
||||
state=objects.audit.State.ONGOING)
|
||||
cfg.CONF.set_override('host', 'hostname1')
|
||||
|
||||
@mock.patch.object(objects.audit.Audit, 'save')
|
||||
@mock.patch.object(objects.audit.Audit, 'list')
|
||||
def test_cancel_ongoing_audits(self, m_list, m_save):
|
||||
m_list.return_value = [self.audit]
|
||||
scheduler = scheduling.DecisionEngineSchedulingService()
|
||||
|
||||
scheduler.cancel_ongoing_audits()
|
||||
m_list.assert_called()
|
||||
m_save.assert_called()
|
||||
self.assertEqual(self.audit.state, objects.audit.State.CANCELLED)
|
||||
|
||||
|
||||
@mock.patch.object(objects.audit.Audit, 'save')
|
||||
@mock.patch.object(objects.audit.Audit, 'list')
|
||||
class TestDecisionEngineSchedulingService(base.TestCase):
|
||||
|
||||
@mock.patch.object(
|
||||
@@ -35,7 +86,7 @@ class TestDecisionEngineSchedulingService(base.TestCase):
|
||||
default_loading.ClusterDataModelCollectorLoader, 'list_available')
|
||||
@mock.patch.object(background.BackgroundScheduler, 'start')
|
||||
def test_start_de_scheduling_service(self, m_start, m_list_available,
|
||||
m_load):
|
||||
m_load, m_list, m_save):
|
||||
m_list_available.return_value = {
|
||||
'fake': faker_cluster_state.FakerModelCollector}
|
||||
fake_collector = faker_cluster_state.FakerModelCollector(
|
||||
@@ -61,7 +112,7 @@ class TestDecisionEngineSchedulingService(base.TestCase):
|
||||
default_loading.ClusterDataModelCollectorLoader, 'list_available')
|
||||
@mock.patch.object(background.BackgroundScheduler, 'start')
|
||||
def test_execute_sync_job_fails(self, m_start, m_list_available,
|
||||
m_load):
|
||||
m_load, m_list, m_save):
|
||||
fake_config = mock.Mock(period=.01)
|
||||
fake_collector = faker_cluster_state.FakerModelCollector(
|
||||
config=fake_config)
|
||||
|
||||
Reference in New Issue
Block a user