예제 #1
0
    def test_destroy_stack_step_statuses(self):
        mock_provider = mock.MagicMock()
        stacks_dict = self.context.get_stacks_dict()

        def get_stack(stack_name):
            return stacks_dict.get(stack_name)

        plan = self.action._generate_plan()
        step = plan.steps[0]
        # we need the AWS provider to generate the plan, but swap it for
        # the mock one to make the test easier
        self.action.provider = mock_provider

        # simulate stack doesn't exist and we haven't submitted anything for
        # deletion
        mock_provider.get_stack.side_effect = StackDoesNotExist("mock")
        status = step.run()
        self.assertEqual(status, SKIPPED)

        # simulate stack getting successfully deleted
        mock_provider.get_stack.side_effect = get_stack
        mock_provider.is_stack_destroyed.return_value = False
        mock_provider.is_stack_in_progress.return_value = False
        status = step._run_once()
        self.assertEqual(status, SUBMITTED)
        mock_provider.is_stack_destroyed.return_value = False
        mock_provider.is_stack_in_progress.return_value = True
        status = step._run_once()
        self.assertEqual(status, SUBMITTED)
        mock_provider.is_stack_destroyed.return_value = True
        mock_provider.is_stack_in_progress.return_value = False
        status = step._run_once()
        self.assertEqual(status, COMPLETE)
예제 #2
0
        def get_stack(name, *args, **kwargs):
            if name != self.stack.name or not self.stack_status:
                raise StackDoesNotExist(name)

            return {'StackName': self.stack.name,
                    'StackStatus': self.stack_status,
                    'Tags': []}
예제 #3
0
 def test_destroy_stack_complete_if_state_submitted(self):
     # Simulate the provider not being able to find the stack (a result of
     # it being successfully deleted)
     self.action.provider = mock.MagicMock()
     self.action.provider.get_stack.side_effect = StackDoesNotExist('mock')
     status = self.action._destroy_stack(MockStack('vpc'), status=PENDING)
     # if we haven't processed the step (ie. has never been SUBMITTED, should be skipped)
     self.assertEqual(status, SKIPPED)
     status = self.action._destroy_stack(MockStack('vpc'), status=SUBMITTED)
     # if we have processed the step and then can't find the stack, it means
     # we successfully deleted it
     self.assertEqual(status, COMPLETE)
예제 #4
0
 def get_stack_staggered(stack_name):
     count['_count'] += 1
     if not count['_count'] % 2:
         raise StackDoesNotExist(stack_name)
     return stacks_dict.get(stack_name)