示例#1
0
    def test_trigger_audit_state_succeeded(self, m_collector):
        m_collector.return_value = faker.FakerModelCollector()
        audit_handler = oneshot.OneShotAuditHandler()
        audit_handler.execute(self.audit, self.context)
        audit = objects.audit.Audit.get_by_uuid(self.context, self.audit.uuid)
        self.assertEqual(objects.audit.State.SUCCEEDED, audit.state)

        expected_calls = [
            mock.call(self.context,
                      self.audit,
                      action=objects.fields.NotificationAction.STRATEGY,
                      phase=objects.fields.NotificationPhase.START),
            mock.call(self.context,
                      self.audit,
                      action=objects.fields.NotificationAction.STRATEGY,
                      phase=objects.fields.NotificationPhase.END),
            mock.call(self.context,
                      self.audit,
                      action=objects.fields.NotificationAction.PLANNER,
                      phase=objects.fields.NotificationPhase.START),
            mock.call(self.context,
                      self.audit,
                      action=objects.fields.NotificationAction.PLANNER,
                      phase=objects.fields.NotificationPhase.END)
        ]

        self.assertEqual(
            expected_calls,
            self.m_audit_notifications.send_action_notification.call_args_list)
示例#2
0
    def test_trigger_audit_without_errors(self, m_collector):
        m_collector.return_value = faker.FakerModelCollector()
        audit_handler = oneshot.OneShotAuditHandler()
        audit_handler.execute(self.audit, self.context)

        expected_calls = [
            mock.call(self.context,
                      self.audit,
                      action=objects.fields.NotificationAction.STRATEGY,
                      phase=objects.fields.NotificationPhase.START),
            mock.call(self.context,
                      self.audit,
                      action=objects.fields.NotificationAction.STRATEGY,
                      phase=objects.fields.NotificationPhase.END),
            mock.call(self.context,
                      self.audit,
                      action=objects.fields.NotificationAction.PLANNER,
                      phase=objects.fields.NotificationPhase.START),
            mock.call(self.context,
                      self.audit,
                      action=objects.fields.NotificationAction.PLANNER,
                      phase=objects.fields.NotificationPhase.END)
        ]

        self.assertEqual(
            expected_calls,
            self.m_audit_notifications.send_action_notification.call_args_list)
示例#3
0
 def __init__(self, messaging):
     self._messaging = messaging
     self._executor = futures.ThreadPoolExecutor(
         max_workers=CONF.watcher_decision_engine.max_workers)
     self._oneshot_handler = oneshot_handler.OneShotAuditHandler(
         self.messaging)
     self._continuous_handler = continuous_handler.ContinuousAuditHandler(
         self.messaging)
示例#4
0
 def test_trigger_action_plan_with_ongoing(self, mock_get_by_id, mock_list):
     mock_get_by_id.return_value = self.audit
     mock_list.return_value = [self.ongoing_action_plan]
     auto_trigger_handler = oneshot.OneShotAuditHandler(mock.MagicMock())
     with mock.patch.object(auto_trigger_handler, 'do_schedule'):
         self.assertRaises(exception.ActionPlanIsOngoing,
                           auto_trigger_handler.post_execute, self.audit,
                           mock.MagicMock(), self.context)
示例#5
0
    def test_do_trigger_audit(self, mock_collector):
        mock_collector.return_value = faker_cluster_state.FakerModelCollector()

        audit_handler = oneshot_handler.OneShotAuditHandler(mock.MagicMock())
        endpoint = audit_endpoint.AuditEndpoint(audit_handler)

        with mock.patch.object(oneshot_handler.OneShotAuditHandler,
                               'execute') as mock_call:
            mock_call.return_value = 0
            endpoint.do_trigger_audit(self.context, self.audit.uuid)

        self.assertEqual(mock_call.call_count, 1)
示例#6
0
 def test_trigger_action_plan_without_ongoing(self, mock_get_by_id,
                                              mock_list, mock_applier):
     mock_get_by_id.return_value = self.audit
     mock_list.return_value = []
     auto_trigger_handler = oneshot.OneShotAuditHandler()
     with mock.patch.object(auto_trigger_handler,
                            'do_schedule') as m_schedule:
         m_schedule().uuid = self.recommended_action_plan.uuid
         auto_trigger_handler.post_execute(self.audit, mock.MagicMock(),
                                           self.context)
     mock_applier.assert_called_once_with(self.context,
                                          self.recommended_action_plan.uuid)
示例#7
0
    def test_trigger_audit_with_error(self, m_collector, m_do_execute):
        m_collector.return_value = faker.FakerModelCollector()
        m_do_execute.side_effect = Exception
        audit_handler = oneshot.OneShotAuditHandler()
        audit_handler.execute(self.audit, self.context)

        expected_calls = [
            mock.call(self.context, self.audit,
                      action=objects.fields.NotificationAction.STRATEGY,
                      phase=objects.fields.NotificationPhase.START),
            mock.call(self.context, self.audit,
                      action=objects.fields.NotificationAction.STRATEGY,
                      priority=objects.fields.NotificationPriority.ERROR,
                      phase=objects.fields.NotificationPhase.ERROR)]

        self.assertEqual(
            expected_calls,
            self.m_audit_notifications.send_action_notification.call_args_list)
示例#8
0
    def test_trigger_audit_send_notification(self, mock_collector):
        messaging = mock.MagicMock()
        mock_collector.return_value = faker.FakerModelCollector()
        audit_handler = oneshot.OneShotAuditHandler(messaging)
        audit_handler.execute(self.audit, self.context)

        call_on_going = mock.call(
            events.Events.TRIGGER_AUDIT.name, {
                'audit_status': audit_objects.State.ONGOING,
                'audit_uuid': self.audit.uuid
            })
        call_succeeded = mock.call(
            events.Events.TRIGGER_AUDIT.name, {
                'audit_status': audit_objects.State.SUCCEEDED,
                'audit_uuid': self.audit.uuid
            })

        calls = [call_on_going, call_succeeded]
        messaging.publish_status_event.assert_has_calls(calls)
        self.assertEqual(2, messaging.publish_status_event.call_count)
示例#9
0
 def test_trigger_audit_with_actionplan_ongoing(self, mock_list,
                                                mock_do_execute):
     mock_list.return_value = [self.ongoing_action_plan]
     audit_handler = oneshot.OneShotAuditHandler()
     audit_handler.execute(self.audit, self.context)
     self.assertFalse(mock_do_execute.called)
示例#10
0
 def test_trigger_audit_with_force(self, mock_do_execute):
     audit_handler = oneshot.OneShotAuditHandler()
     self.audit.force = True
     audit_handler.execute(self.audit, self.context)
     self.assertTrue(mock_do_execute.called)
示例#11
0
 def test_trigger_audit_state_succeeded(self, mock_collector):
     mock_collector.return_value = faker.FakerModelCollector()
     audit_handler = oneshot.OneShotAuditHandler(mock.MagicMock())
     audit_handler.execute(self.audit, self.context)
     audit = audit_objects.Audit.get_by_uuid(self.context, self.audit.uuid)
     self.assertEqual(audit_objects.State.SUCCEEDED, audit.state)
示例#12
0
 def test_trigger_audit_without_errors(self, mock_collector):
     mock_collector.return_value = faker.FakerModelCollector()
     audit_handler = oneshot.OneShotAuditHandler(mock.MagicMock())
     audit_handler.execute(self.audit, self.context)