예제 #1
0
    def test_generate_plan_with_persist_no_lock_req(self, mock_stack_action,
                                                    mock_tags):
        """Test generate plan with persist no lock req."""
        mock_stack_action.return_value = MagicMock()
        mock_tags.return_value = {}
        context = mock_context(namespace="test",
                               extra_config_args=self.config_persist,
                               region=self.region)
        persist_step = Step.from_stack_name("removed", context)
        context._persistent_graph = Graph.from_steps([persist_step])
        action = BaseAction(
            context=context,
            provider_builder=MockProviderBuilder(self.provider,
                                                 region=self.region),
        )

        plan = action._generate_plan(include_persistent_graph=True,
                                     require_unlocked=False)

        self.assertIsInstance(plan, Plan)
        mock_tags.assert_called_once()
        # order is different between python2/3 so can't compare dicts
        result_graph_dict = plan.graph.to_dict()
        self.assertEqual(3, len(result_graph_dict))
        self.assertEqual(set(), result_graph_dict["stack1"])
        self.assertEqual(set(["stack1"]), result_graph_dict["stack2"])
        self.assertEqual(set(), result_graph_dict["removed"])
        self.assertEqual(BaseAction.DESCRIPTION, plan.description)
        self.assertFalse(plan.require_unlocked)
예제 #2
0
    def test_generate_plan_persist_destroy(
            self, mock_graph_tags: PropertyMock) -> None:
        """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)])
        deploy_action = deploy.Action(context=context)
        plan = cast(Plan,
                    deploy_action._Action__generate_plan())  # type: ignore

        self.assertIsInstance(plan, Plan)
        self.assertEqual(deploy.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(deploy_action._destroy_stack,
                         plan.graph.steps["removed"].fn)
        self.assertEqual(deploy_action._launch_stack,
                         plan.graph.steps["vpc"].fn)
        self.assertEqual(deploy_action._launch_stack,
                         plan.graph.steps["bastion"].fn)
        self.assertEqual(deploy_action._launch_stack,
                         plan.graph.steps["db"].fn)
        self.assertEqual(deploy_action._launch_stack,
                         plan.graph.steps["other"].fn)
예제 #3
0
    def test_from_stack_name(self):
        """Return step from step name."""
        context = mock_context()
        stack_name = "test-stack"
        result = Step.from_stack_name(stack_name, context)

        self.assertIsInstance(result, Step)
        self.assertEqual(stack_name, result.stack.name)