Rename command to audit

This patchset is there to change the code structure.

Some Python class and packages need to be renamed
for a better compliance with the shared terminology
which provides a better understanding of Watcher
objects and components by every contributor.

This patchset is there to rename the folder command to audit

Partially implements: blueprint glossary-related-refactoring

Change-Id: I76616fb58d5e79a7dc209b80e882d216850d18a4
This commit is contained in:
Jean-Emile DARTOIS
2015-12-14 10:52:30 +01:00
parent 22dd6d42c3
commit 69152f2449
9 changed files with 46 additions and 45 deletions

View File

@@ -15,7 +15,7 @@
# limitations under the License.
from mock import call
from mock import MagicMock
from watcher.decision_engine.command.audit import TriggerAuditCommand
from watcher.decision_engine.audit.default import DefaultAuditHandler
from watcher.decision_engine.messaging.events import Events
from watcher.objects.audit import Audit
from watcher.objects.audit import AuditStatus
@@ -25,9 +25,9 @@ from watcher.tests.decision_engine.strategy.strategies.faker_cluster_state \
from watcher.tests.objects import utils as obj_utils
class TestTriggerAuditCommand(DbTestCase):
class TestDefaultAuditHandler(DbTestCase):
def setUp(self):
super(TestTriggerAuditCommand, self).setUp()
super(TestDefaultAuditHandler, self).setUp()
self.audit_template = obj_utils.create_test_audit_template(
self.context)
self.audit = obj_utils.create_test_audit(
@@ -36,24 +36,24 @@ class TestTriggerAuditCommand(DbTestCase):
def test_trigger_audit_without_errors(self):
model_collector = FakerModelCollector()
command = TriggerAuditCommand(MagicMock(), model_collector)
command.execute(self.audit.uuid, self.context)
audit_handler = DefaultAuditHandler(MagicMock(), model_collector)
audit_handler.execute(self.audit.uuid, self.context)
def test_trigger_audit_state_success(self):
model_collector = FakerModelCollector()
command = TriggerAuditCommand(MagicMock(), model_collector)
command.strategy_context.execute_strategy = MagicMock()
command.execute(self.audit.uuid, self.context)
audit_handler = DefaultAuditHandler(MagicMock(), model_collector)
audit_handler.strategy_context.execute_strategy = MagicMock()
audit_handler.execute(self.audit.uuid, self.context)
audit = Audit.get_by_uuid(self.context, self.audit.uuid)
self.assertEqual(AuditStatus.SUCCEEDED, audit.state)
def test_trigger_audit_send_notification(self):
messaging = MagicMock()
model_collector = FakerModelCollector()
command = TriggerAuditCommand(messaging, model_collector)
command.strategy_context.execute_strategy = MagicMock()
audit_handler = DefaultAuditHandler(messaging, model_collector)
audit_handler.strategy_context.execute_strategy = MagicMock()
command.execute(self.audit.uuid, self.context)
audit_handler.execute(self.audit.uuid, self.context)
call_on_going = call(Events.TRIGGER_AUDIT.name, {
'audit_status': AuditStatus.ONGOING,

View File

@@ -15,9 +15,8 @@
# limitations under the License.
import mock
from mock import MagicMock
from watcher.common import utils
from watcher.decision_engine.command.audit import TriggerAuditCommand
from watcher.decision_engine.audit.default import DefaultAuditHandler
from watcher.decision_engine.messaging.audit_endpoint import AuditEndpoint
from watcher.metrics_engine.cluster_model_collector.manager import \
CollectorManager
@@ -26,9 +25,9 @@ from watcher.tests.decision_engine.strategy.strategies.faker_cluster_state impor
FakerModelCollector
class TriggerAuditCommandWithExecutor(TriggerAuditCommand):
class DefaultAuditHandlerMock(DefaultAuditHandler):
def setUp(self):
super(TriggerAuditCommand, self).setUp()
super(DefaultAuditHandlerMock, self).setUp()
def executor(self):
pass
@@ -42,28 +41,28 @@ class TestAuditEndpoint(base.TestCase):
def test_do_trigger_audit(self):
audit_uuid = utils.generate_uuid()
model_collector = FakerModelCollector()
command = TriggerAuditCommand(MagicMock(), model_collector)
endpoint = AuditEndpoint(command)
audit_handler = DefaultAuditHandler(MagicMock(), model_collector)
endpoint = AuditEndpoint(audit_handler)
with mock.patch.object(CollectorManager, 'get_cluster_model_collector') \
as mock_call2:
mock_call2.return_value = 0
with mock.patch.object(TriggerAuditCommand, 'execute') \
with mock.patch.object(DefaultAuditHandler, 'execute') \
as mock_call:
mock_call.return_value = 0
endpoint.do_trigger_audit(command, audit_uuid)
endpoint.do_trigger_audit(audit_handler, audit_uuid)
# mock_call.assert_called_once_with()
mock_call2.assert_called_once_with()
def test_trigger_audit(self):
audit_uuid = utils.generate_uuid()
model_collector = FakerModelCollector()
command = TriggerAuditCommandWithExecutor(MagicMock(),
model_collector)
endpoint = AuditEndpoint(command)
audit_handler = DefaultAuditHandlerMock(MagicMock(),
model_collector)
endpoint = AuditEndpoint(audit_handler)
with mock.patch.object(TriggerAuditCommandWithExecutor, 'executor') \
with mock.patch.object(DefaultAuditHandlerMock, 'executor') \
as mock_call:
mock_call.return_value = 0
endpoint.trigger_audit(command, audit_uuid)
endpoint.trigger_audit(audit_handler, audit_uuid)