Example #1
0
    def test_on_ended(self, run, move_completed):
        """Once a step ends the FSM checks if it completed or else"""
        f = FSM(state_id)

        consume_completed = [
            mock.Mock(name="method_mocked"),
            mock.Mock(name="properties_mocked"),
            json.dumps(msg_completed)
        ]

        consume_errored = [
            mock.Mock(name="method_mocked"),
            mock.Mock(name="properties_mocked"),
            json.dumps(msg_errored)
        ]

        # First check in the case where the job completed
        result = f.on_ended(f.ch, *consume_completed)
        f.move_active_to_completed.assert_called_once_with()
        f._run.assert_called_once_with()

        # Check the case where the job ended not "completed"
        f.move_active_to_completed.reset_mock()
        f._run.reset_mock()
        result = f.on_ended(f.ch, *consume_errored)

        self.assertFalse(f.move_active_to_completed.called)
        self.assertFalse(f._run.called)
        self.assertFalse(result)
Example #2
0
    def test_step_notification_failed(self, send_notification, move_remaining, setup, updatestate):
        """Per-step notifications work when a step fails

Tests for the case where only one notification transport (irc, email, etc) is defined"""
        f = FSM(TEST_PBID, state_id)

        msg_failed = {'status': 'failed'}

        consume_iter = [
            (mock.Mock(name="method_mocked"),
             mock.Mock(name="properties_mocked"),
             json.dumps(msg_failed))
        ]

        # Pre-test scaffolding. Hard-code some mocked out
        # attributes/variables because we're skipping the usual
        # initialization steps.
        f.conn = mock.Mock(pika.connection.Connection)
        f.executed = []
        f.execution = []
        f.state_coll = {}
        f.post_deploy_action = []
        publish = mock.Mock()
        channel = mock.Mock()
        channel.consume.return_value = iter(consume_iter)
        channel.basic_publish = publish
        f.ch = channel
        f.active_sequence = {'hosts': ['localhost']}
        f.group = 'testgroup'
        f.dynamic = {}
        f.active_step = new_notify_step('failed')
        set_field = mock.MagicMock()
        filter = mock.MagicMock(return_value=set_field)
        f.filter = filter

        # Run the ended method with a body having 'status' as failed
        f.on_ended(channel,
                   mock.Mock(name="method_mocked"),
                   mock.Mock(name="header_mocked"),
                   json.dumps(msg_failed))

        self.assertEqual(send_notification.call_count, 1)
        self.assertEqual(send_notification.call_args[0][1], 'notify.irc')
        self.assertEqual(send_notification.call_args[0][2], state_id)
        self.assertEqual(send_notification.call_args[0][3], ['#achannel'])
        self.assertEqual(send_notification.call_args[0][4], 'failed')