Esempio n. 1
0
 def test_get_stacks(self):
     actor = cloudformation.CloudFormationBaseActor('unittest',
                                                    {'region': 'us-east-1'})
     actor.cf_conn.list_stacks = mock.MagicMock()
     actor.cf_conn.list_stacks.return_value = [1, 2, 3]
     ret = yield actor._get_stacks()
     self.assertEquals([1, 2, 3], ret)
Esempio n. 2
0
    def setUp(self):
        super(TestCloudFormationBaseActor, self).setUp()
        settings.AWS_ACCESS_KEY_ID = 'unit-test'
        settings.AWS_SECRET_ACCESS_KEY = 'unit-test'
        settings.RETRYING_SETTINGS = {'stop_max_attempt_number': 1}
        reload(cloudformation)

        self.actor = cloudformation.CloudFormationBaseActor(
            'unittest', {'region': 'us-east-1'})
        self.actor.cf3_conn = mock.MagicMock(name='cf3_conn')
Esempio n. 3
0
    def setUp(self):
        super(TestCloudFormationBaseActor, self).setUp()
        settings.AWS_ACCESS_KEY_ID = 'unit-test'
        settings.AWS_SECRET_ACCESS_KEY = 'unit-test'
        settings.RETRYING_SETTINGS = {'stop_max_attempt_number': 1}
        reload(cloudformation)

        self.actor = cloudformation.CloudFormationBaseActor(
            'unittest', {'region': 'us-east-1'})
        self.actor.cf3_conn = mock.MagicMock(name='cf3_conn')

        # Need to recreate the api call queues between tests
        # because nose creates a new ioloop per test run.
        base.NAMED_API_CALL_QUEUES = {}
Esempio n. 4
0
    def test_get_stack(self):
        actor = cloudformation.CloudFormationBaseActor('unittest',
                                                       {'region': 'us-east-1'})

        actor.cf_conn.list_stacks = mock.MagicMock()
        s1 = mock.MagicMock()
        s1.stack_name = 'stack-1'
        s2 = mock.MagicMock()
        s2.stack_name = 'stack-2'
        s3 = mock.MagicMock()
        s3.stack_name = 'stack-3'
        actor.cf_conn.list_stacks.return_value = [s1, s2, s3]

        ret = yield actor._get_stack('stack-1')
        self.assertEquals(ret, s1)

        ret = yield actor._get_stack('stack-5')
        self.assertEquals(ret, None)
Esempio n. 5
0
    def test_create_parameters(self):
        params = {
            'Key1': 'Value1',
            'Key2': 'Value2',
        }

        expected = [
            {'ParameterKey': 'Key1',
             'ParameterValue': 'Value1'},
            {'ParameterKey': 'Key2',
             'ParameterValue': 'Value2'}
        ]

        actor = cloudformation.CloudFormationBaseActor(
            'unittest', {'region': 'us-east-1'})

        ret = actor._create_parameters(params)
        self.assertEquals(ret, expected)
Esempio n. 6
0
    def test_wait_until_state(self):
        create_in_progress = mock.MagicMock(name='create_in_progress')
        create_in_progress.stack_status = 'CREATE_IN_PROGRESS'
        create_in_progress.stack_name = 'unittest'

        create_complete = mock.MagicMock(name='CREATE_COMPLETE')
        create_complete.stack_status = 'CREATE_COMPLETE'
        create_complete.stack_name = 'unittest'

        rollback_complete = mock.MagicMock(name='ROLLBACK_COMPLETE')
        rollback_complete.stack_status = 'ROLLBACK_COMPLETE'
        rollback_complete.stack_name = 'unittest'

        actor = cloudformation.CloudFormationBaseActor('unittest',
                                                       {'region': 'us-east-1'})
        actor._get_stack = mock.MagicMock()

        # Make _get_stack() yield back 2 in-progress states, then yield a
        # successfull execution.
        actor._get_stack.side_effect = [
            tornado_value(create_in_progress),
            tornado_value(create_in_progress),
            tornado_value(create_complete)
        ]
        ret = yield actor._wait_until_state(cloudformation.COMPLETE, sleep=0.1)
        self.assertEquals(ret, None)

        # Make sure a cloudformationerror is raised if we ask for a deleted
        # state rather than a created one.
        actor._get_stack.side_effect = [
            tornado_value(create_in_progress),
            tornado_value(create_in_progress),
            tornado_value(create_complete)
        ]
        with self.assertRaises(cloudformation.CloudFormationError):
            yield actor._wait_until_state(cloudformation.DELETED, sleep=0.1)

        # Lastly, test that if wait_until_state returns no actor, we bail
        # appropriately.
        actor._get_stack.side_effect = [tornado_value(None)]
        with self.assertRaises(cloudformation.StackNotFound):
            yield actor._wait_until_state(cloudformation.COMPLETE, sleep=0.1)
Esempio n. 7
0
 def test_init_with_bad_creds(self):
     settings.AWS_ACCESS_KEY_ID = None
     settings.AWS_SECRET_ACCESS_KEY = None
     with self.assertRaises(exceptions.InvalidCredentials):
         cloudformation.CloudFormationBaseActor('unittest',
                                                {'region': 'us-east-1'})