Esempio n. 1
0
    def test__cleanup_post_failed(self, send_notification, post_deploy):
        """Cleanup marks release as failed if post deploy fails"""
        post_deploy.return_value = False
        f = FSM(state_id)
        f.ch = mock.Mock(pika.channel.Channel)
        f.conn = mock.Mock(pika.connection.Connection)
        f.reply_queue = temp_queue

        _update_state = {
            '$set': {
                'ended': UTCNOW,
                'failed': True
            }
        }

        with mock.patch.object(f, 'update_state', mock.Mock()) as (
                us):
            with mock.patch('recore.fsm.dt') as (
                    dt):
                with mock.patch('recore.amqp.CONF') as notif_conf:
                    notif_conf = NOTIFICATION_CONF
                    dt.now.return_value = UTCNOW
                    f._cleanup()

            # update state set the ended item in the state doc.
            us.assert_called_with(_update_state)
            f.conn.close.assert_called_once_with()
            f.ch.queue_delete.assert_called_once_with(queue=temp_queue)

        # At the very end a notification should go out no matter what
        self.assertEqual(send_notification.call_count, 1)
        assert send_notification.call_args[0][4] == 'failed'
        post_deploy.assert_called_once()
Esempio n. 2
0
    def test__cleanup_failed(self):
        """Cleanup fails if update_state raises"""
        f = FSM(state_id)
        f.ch = mock.Mock(pika.channel.Channel)
        f.conn = mock.Mock(pika.connection.Connection)

        with mock.patch.object(f, 'update_state',
                               mock.Mock(side_effect=Exception("derp"))) as (
                us_exception):
            with self.assertRaises(Exception):
                f._cleanup()
Esempio n. 3
0
    def test__setup_failed_pre_deploy_check(self, send_notification, move_remaining, amqp_conf):
        """Setup fails with an existing state document and a failed pre-deploy check"""
        f = FSM(TEST_PBID, state_id)
        # An AMQP connection hasn't been made yet
        amqp_conf.get.return_value = PRE_DEPLOY_CONF['PRE_DEPLOY_CHECK']
        msg_started = {'status': 'completed', 'data': {'exists': False}}

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

        f.conn = mock.Mock(pika.connection.Connection)
        publish = mock.Mock()
        channel = mock.Mock()
        channel.consume.return_value = iter(consume_iter)
        channel.basic_publish = publish
        f.ch = channel

        with mock.patch('recore.mongo.database') as (
                mongo.database):
            mongo.database = mock.MagicMock(pymongo.database.Database)
            mongo.database.__getitem__.return_value = mock.MagicMock(pymongo.collection.Collection)

            with mock.patch('recore.mongo.lookup_state') as (
                    mongo.lookup_state):
                mongo.lookup_state.return_value = _state

                with mock.patch('recore.amqp.MQ_CONF') as mq_conf:
                    mq_conf = MQ_CONF
                    set_field = mock.MagicMock()
                    filter = mock.MagicMock(return_value=set_field)
                    f.filter = filter
                    f._setup()
                    assert f.group == _state['group']

        # No matter where a release fails, 'move_remaining_to_skipped' will be called
        move_remaining.assert_called_once_with()
        # the first run/pre-deploy steps will record the failed state
        assert f.initialized == False

        # The starting phase notification will be sent
        assert send_notification.call_count == 1
        assert send_notification.call_args[0][4] == 'started'

        # After first_run finishes self.failed should be True
        with mock.patch('recore.amqp.MQ_CONF') as mq_conf:
            mq_conf = MQ_CONF
            f._cleanup()
        assert send_notification.call_count == 2
        assert send_notification.call_args[0][4] == 'failed'
        assert f.failed == True
Esempio n. 4
0
    def test__cleanup_failed(self, send_notification, post_deploy):
        """Cleanup fails if update_state raises"""
        f = FSM(state_id)
        f.ch = mock.Mock(pika.channel.Channel)
        f.conn = mock.Mock(pika.connection.Connection)
        f.failed = True  # Testing the fail notification too

        with mock.patch.object(f, 'update_state',
                               mock.Mock(side_effect=Exception("derp"))) as (
                us_exception):
            with self.assertRaises(Exception):
                with mock.patch('recore.amqp.CONF') as notif_conf:
                    notif_conf = NOTIFICATION_CONF
                    f._cleanup()

        # At the very end a notification should go out no matter what
        self.assertEqual(send_notification.call_count, 1)
        assert send_notification.call_args[0][4] == 'failed'
        post_deploy.assert_called_once()
Esempio n. 5
0
    def test__cleanup(self):
        """Cleanup erases the needful"""
        f = FSM(state_id)
        f.ch = mock.Mock(pika.channel.Channel)
        f.conn = mock.Mock(pika.connection.Connection)
        f.reply_queue = temp_queue

        _update_state = {
            '$set': {
                'ended': UTCNOW
            }
        }

        with mock.patch.object(f, 'update_state', mock.Mock()) as (
                us):
            with mock.patch('recore.fsm.dt') as (
                    dt):
                dt.now.return_value = UTCNOW
                f._cleanup()

            # update state set the ended item in the state doc.
            us.assert_called_with(_update_state)
            f.conn.close.assert_called_once_with()
            f.ch.queue_delete.assert_called_once_with(queue=temp_queue)
Esempio n. 6
0
    def test__cleanup(self, send_notification, post_deploy):
        """Cleanup erases the needful"""
        f = FSM(TEST_PBID, state_id)
        f.ch = mock.Mock(pika.channel.Channel)
        f.conn = mock.Mock(pika.connection.Connection)
        f.reply_queue = temp_queue

        _update_state = {
            '$set': {
                'ended': UTCNOW,
                'failed': False
            }
        }

        with mock.patch.object(f, 'update_state', mock.Mock()) as (
                us):
            with mock.patch('recore.fsm.dt') as (
                    dt):
                dt.utcnow.return_value = UTCNOW

                with mock.patch('recore.amqp.CONF') as notif_conf:
                    notif_conf = NOTIFICATION_CONF
                    set_field = mock.MagicMock()
                    filter = mock.MagicMock(return_value=set_field)
                    f.filter = filter
                    f._cleanup()

            # update state set the ended item in the state doc.
            us.assert_called_with(_update_state)
            f.conn.close.assert_called_once_with()
            f.ch.queue_delete.assert_called_once_with(queue=temp_queue)

        # At the very end a notification should go out no matter what
        self.assertEqual(send_notification.call_count, 1)
        assert send_notification.call_args[0][4] == 'completed'
        post_deploy.assert_called_once()