Example #1
0
    def test_get_expected_count(self):
        actor = elb_actor.WaitUntilHealthy('Unit Test Action', {
            'name': 'unit-test-queue',
            'region': 'us-west-2',
            'count': 3
        })

        self.assertEquals(actor._get_expected_count(5, 1), 5)
        self.assertEquals(actor._get_expected_count('50%', 20), 10)
Example #2
0
    def integration_01b_check_elb_not_found(self):
        actor = elb.WaitUntilHealthy('Test', {
            'name': 'Not-Found-ELB',
            'count': 50,
            'region': self.region
        })

        with self.assertRaises(exceptions.RecoverableActorFailure):
            yield actor.execute()
Example #3
0
    def test_require_env(self):

        settings.AWS_ACCESS_KEY_ID = ''
        with self.assertRaises(exceptions.InvalidCredentials):
            elb_actor.WaitUntilHealthy('Unit Test Action', {
                'name': 'unit-test-queue',
                'region': 'us-west-2',
                'count': 3
            })
Example #4
0
    def integration_01a_check_elb_health(self):
        actor = elb.WaitUntilHealthy('Test', {
            'name': self.elb_name,
            'count': 0,
            'region': self.region
        })

        done = yield actor.execute()

        self.assertEquals(done, None)
Example #5
0
    def test_execute_fail(self):

        actor = elb_actor.WaitUntilHealthy('Unit Test Action', {
            'name': 'unit-test-queue',
            'region': 'us-west-2',
            'count': 7
        })
        # ELB not found...
        actor.elb_conn.get_all_load_balancers = mock.Mock(
            side_effect=BotoServerError(400, 'LoadBalancerNotFound'))

        with self.assertRaises(elb_actor.base.ELBNotFound):
            yield actor.execute()
Example #6
0
    def integration_02_wait_for_elb_health(self):
        actor = elb.WaitUntilHealthy('Test', {
            'name': self.elb_name,
            'count': 1,
            'region': self.region
        })

        # NOTE: We are not "yielding" the execution here, but the task
        # goes on top of the IOLoop. The sleep statement below allows
        # the wait_task's actions to get executed by tornado's loop.
        wait_task = actor.execute()
        yield utils.tornado_sleep(1)

        # Expected count is 1, so this should not be done yet...
        self.assertFalse(wait_task.done())
Example #7
0
    def test_execute(self):

        actor = elb_actor.WaitUntilHealthy('Unit Test Action', {
            'name': 'unit-test-queue',
            'region': 'us-west-2',
            'count': 3
        })

        actor._find_elb = mock.Mock(return_value=helper.tornado_value('ELB'))
        actor._is_healthy = mock.Mock(return_value=helper.tornado_value(True))

        val = yield actor._execute()
        self.assertEquals(actor._find_elb.call_count, 1)
        self.assertEquals(actor._is_healthy.call_count, 1)
        self.assertEquals(val, None)
Example #8
0
    def test_execute_dry(self):

        actor = elb_actor.WaitUntilHealthy('Unit Test Action', {
            'name': 'unit-test-queue',
            'region': 'us-west-2',
            'count': 3
        },
                                           dry=True)

        actor._find_elb = mock.Mock(return_value=helper.tornado_value('ELB'))
        # NOTE: this is false, but assertion is True!
        actor._is_healthy = mock.Mock(return_value=helper.tornado_value(False))

        val = yield actor._execute()
        self.assertEqual(actor._find_elb.call_count, 1)
        self.assertEqual(actor._is_healthy.call_count, 1)
        self.assertEqual(val, None)
Example #9
0
    def test_is_healthy(self):
        actor = elb_actor.WaitUntilHealthy('Unit Test Action', {
            'name': 'unit-test-queue',
            'region': 'us-west-2',
            'count': 3
        })

        elb = mock.Mock()
        elb.get_instance_health.return_value = [
            mock.Mock(state='InService'),
            mock.Mock(state='InService'),
            mock.Mock(state='InService'),
            mock.Mock(state='OutOfService'),
            mock.Mock(state='OutOfService'),
        ]
        val = yield actor._is_healthy(elb, 3)

        self.assertTrue(val)
Example #10
0
    def test_execute_retry(self):

        actor = elb_actor.WaitUntilHealthy('Unit Test Action', {
            'name': 'unit-test-queue',
            'region': 'us-west-2',
            'count': 3
        })

        actor._find_elb = mock.Mock(return_value=helper.tornado_value('ELB'))
        actor._is_healthy = mock.Mock(side_effect=[
            helper.tornado_value(False),
            helper.tornado_value(True)
        ])

        # Optional mock -- making the test quicker.
        short_sleep = utils.tornado_sleep(0)
        with mock.patch('kingpin.utils.tornado_sleep') as ts:
            ts.return_value = short_sleep
            val = yield actor._execute()

        self.assertEquals(actor._find_elb.call_count, 1)  # Don't refetch!
        self.assertEquals(actor._is_healthy.call_count, 2)  # Retry!
        self.assertEquals(val, None)