Exemplo n.º 1
0
    def test_generate_plan_persist_destroy(self, mock_graph_tags):
        """Test generate plan persist destroy."""
        mock_graph_tags.return_value = {}
        context = self._get_context(
            extra_config_args={'persistent_graph_key': 'test.json'})
        context._persistent_graph = Graph.from_steps(
            [Step.from_stack_name('removed', context)])
        build_action = build.Action(context=context)
        plan = build_action._Action__generate_plan()

        self.assertIsInstance(plan, Plan)
        self.assertEqual(build.Action.DESCRIPTION, plan.description)
        mock_graph_tags.assert_called_once()
        # order is different between python2/3 so can't compare dicts
        result_graph_dict = plan.graph.to_dict()
        self.assertEqual(5, len(result_graph_dict))
        self.assertEqual(set(), result_graph_dict['other'])
        self.assertEqual(set(), result_graph_dict['removed'])
        self.assertEqual(set(), result_graph_dict['vpc'])
        self.assertEqual(set(['vpc']), result_graph_dict['bastion'])
        self.assertEqual(set(['bastion', 'vpc']), result_graph_dict['db'])
        self.assertEqual(build_action._destroy_stack,
                         plan.graph.steps['removed'].fn)
        self.assertEqual(build_action._launch_stack,
                         plan.graph.steps['vpc'].fn)
        self.assertEqual(build_action._launch_stack,
                         plan.graph.steps['bastion'].fn)
        self.assertEqual(build_action._launch_stack, plan.graph.steps['db'].fn)
        self.assertEqual(build_action._launch_stack,
                         plan.graph.steps['other'].fn)
Exemplo n.º 2
0
 def setUp(self):
     """Run before tests."""
     self.context = Context(config=Config({"namespace": "namespace"}))
     self.provider = MockProvider()
     self.build_action = build.Action(self.context,
                                      provider_builder=MockProviderBuilder(
                                          self.provider))
Exemplo n.º 3
0
 def test_execute_plan_when_outline_not_specified(self):
     """Test execute plan when outline not specified."""
     context = self._get_context()
     build_action = build.Action(context, cancel=MockThreadingEvent())
     with patch.object(build_action, "_generate_plan") as \
             mock_generate_plan:
         build_action.run(outline=False)
         self.assertEqual(mock_generate_plan().execute.call_count, 1)
Exemplo n.º 4
0
    def setUp(self):
        """Run before tests."""
        self.context = self._get_context()
        self.session = get_session(region=None)
        self.provider = Provider(self.session,
                                 interactive=False,
                                 recreate_failed=False)
        provider_builder = MockProviderBuilder(self.provider)
        self.build_action = build.Action(self.context,
                                         provider_builder=provider_builder,
                                         cancel=MockThreadingEvent())

        self.stack = MagicMock()
        self.stack.region = None
        self.stack.name = 'vpc'
        self.stack.fqn = 'vpc'
        self.stack.blueprint.rendered = '{}'
        self.stack.locked = False
        self.stack_status = None

        plan = self.build_action._Action__generate_plan()
        self.step = plan.steps[0]
        self.step.stack = self.stack

        def patch_object(*args, **kwargs):
            mock_object = patch.object(*args, **kwargs)
            self.addCleanup(mock_object.stop)
            mock_object.start()

        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,
                'Outputs': [],
                'Tags': []
            }

        def get_events(name, *args, **kwargs):
            return [{
                'ResourceStatus': 'ROLLBACK_IN_PROGRESS',
                'ResourceStatusReason': 'CFN fail'
            }]

        patch_object(self.provider, 'get_stack', side_effect=get_stack)
        patch_object(self.provider, 'update_stack')
        patch_object(self.provider, 'create_stack')
        patch_object(self.provider, 'destroy_stack')
        patch_object(self.provider, 'get_events', side_effect=get_events)

        patch_object(self.build_action, "s3_stack_push")
Exemplo n.º 5
0
 def test_generate_plan(self):
     """Test generate plan."""
     context = self._get_context()
     build_action = build.Action(context, cancel=MockThreadingEvent())
     plan = build_action._Action__generate_plan()
     self.assertEqual(
         {
             'db': set(['bastion', 'vpc']),
             'bastion': set(['vpc']),
             'other': set([]),
             'vpc': set([])
         }, plan.graph.to_dict())
Exemplo n.º 6
0
    def setUp(self):
        """Run before tests."""
        self.context = self._get_context()
        self.session = get_session(region=None)
        self.provider = Provider(self.session,
                                 interactive=False,
                                 recreate_failed=False)
        provider_builder = MockProviderBuilder(self.provider)
        self.build_action = build.Action(self.context,
                                         provider_builder=provider_builder,
                                         cancel=MockThreadingEvent())

        self.stack = MagicMock()
        self.stack.region = None
        self.stack.name = "vpc"
        self.stack.fqn = "vpc"
        self.stack.blueprint.rendered = "{}"
        self.stack.locked = False
        self.stack_status = None

        plan = self.build_action._Action__generate_plan()
        self.step = plan.steps[0]
        self.step.stack = self.stack

        def patch_object(*args, **kwargs):
            mock_object = patch.object(*args, **kwargs)
            self.addCleanup(mock_object.stop)
            mock_object.start()

        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,
                "Outputs": [],
                "Tags": [],
            }

        def get_events(name, *args, **kwargs):
            return [{
                "ResourceStatus": "ROLLBACK_IN_PROGRESS",
                "ResourceStatusReason": "CFN fail",
            }]

        patch_object(self.provider, "get_stack", side_effect=get_stack)
        patch_object(self.provider, "update_stack")
        patch_object(self.provider, "create_stack")
        patch_object(self.provider, "destroy_stack")
        patch_object(self.provider, "get_events", side_effect=get_events)

        patch_object(self.build_action, "s3_stack_push")
Exemplo n.º 7
0
 def test_generate_plan(self):
     """Test generate plan."""
     context = self._get_context()
     build_action = build.Action(context, cancel=MockThreadingEvent())
     plan = build_action._Action__generate_plan()
     self.assertEqual(
         {
             "db": set(["bastion", "vpc"]),
             "bastion": set(["vpc"]),
             "other": set([]),
             "vpc": set([]),
         },
         plan.graph.to_dict(),
     )
Exemplo n.º 8
0
    def test_run_persist(self, mock_execute, mock_unlock, mock_lock,
                         mock_graph_tags):
        """Test run persist."""
        mock_graph_tags.return_value = {}
        context = self._get_context(
            extra_config_args={'persistent_graph_key': 'test.json'})
        context._persistent_graph = Graph.from_steps(
            [Step.from_stack_name('removed', context)])
        build_action = build.Action(context=context)
        build_action.run()

        mock_graph_tags.assert_called_once()
        mock_lock.assert_called_once()
        mock_execute.assert_called_once()
        mock_unlock.assert_called_once()