Example #1
0
    def test_existing_dependency(
        self, filepaths, dependency
    ):
        project_path, config_dir = self.create_project()

        for rel_path in filepaths:
            # Set up config with reference to an existing stack
            config = {
                "project_code": "project_code",
                "region": "region",
                "template_path": rel_path,
                "dependencies": [dependency]
            }

            abs_path = os.path.join(config_dir, rel_path)
            self.write_config(abs_path, config)

        self.context.project_path = project_path
        try:
            config_reader = ConfigReader(self.context)
            all_stacks, command_stacks = config_reader.construct_stacks()
        except Exception:
            raise
        else:
            assert True
Example #2
0
    def test_missing_dependency(
        self, filepaths, dependency
    ):
        project_path, config_dir = self.create_project()

        for rel_path in filepaths:
            # Set up config with reference to non-existing stack
            config = {
                "project_code": "project_code",
                "region": "region",
                "template_path": rel_path,
                "dependencies": [dependency]
            }

            abs_path = os.path.join(config_dir, rel_path)
            self.write_config(abs_path, config)

        self.context.project_path = project_path
        try:
            config_reader = ConfigReader(self.context)
            all_stacks, command_stacks = config_reader.construct_stacks()
        except DependencyDoesNotExistError as e:
            # Test that the missing dependency is reported.
            assert dependency in str(e)
        except Exception:
            raise
        else:
            assert False
Example #3
0
    def test_missing_attr(
        self, filepaths, del_key
    ):
        project_path, config_dir = self.create_project()

        for rel_path in filepaths:

            config = {
                "project_code": "project_code",
                "region": "region",
                "template_path": rel_path
            }
            # Delete the mandatory key to be tested.
            del config[del_key]

            abs_path = os.path.join(config_dir, rel_path)
            self.write_config(abs_path, config)

        self.context.project_path = project_path
        try:
            config_reader = ConfigReader(self.context)
            all_stacks, command_stacks = config_reader.construct_stacks()
        except InvalidConfigFileError as e:
            # Test that the missing key is reported.
            assert del_key in str(e)
        except Exception:
            raise
        else:
            assert False
Example #4
0
    def test_construct_stacks_with_valid_config(
        self, filepaths, expected_stacks
    ):
        with self.runner.isolated_filesystem():
            project_path = os.path.abspath('./example')
            config_dir = os.path.join(project_path, "config")
            os.makedirs(config_dir)

            for rel_path in filepaths:
                abs_path = os.path.join(config_dir, rel_path)
                dir_path = abs_path
                if abs_path.endswith(".yaml"):
                    dir_path = os.path.split(abs_path)[0]
                if not os.path.exists(dir_path):
                    try:
                        os.makedirs(dir_path)
                    except OSError as exc:
                        if exc.errno != errno.EEXIST:
                            raise

                config = {
                    "region": "region",
                    "project_code": "project_code",
                    "template_path": rel_path
                }
                with open(abs_path, 'w') as config_file:
                    yaml.safe_dump(
                        config, stream=config_file, default_flow_style=False
                    )

            self.context.project_path = project_path
            config_reader = ConfigReader(self.context)
            all_stacks, command_stacks = config_reader.construct_stacks()
            assert {str(stack) for stack in all_stacks} == expected_stacks
Example #5
0
    def test_construct_stacks_with_valid_config(self, command_path, filepaths,
                                                expected_stacks,
                                                expected_command_stacks,
                                                full_scan):
        project_path, config_dir = self.create_project()

        for rel_path in filepaths:

            config = {
                "region": "region",
                "project_code": "project_code",
                "template_path": rel_path
            }

            abs_path = os.path.join(config_dir, rel_path)
            self.write_config(abs_path, config)

        self.context.project_path = project_path
        self.context.command_path = command_path
        self.context.full_scan = full_scan
        config_reader = ConfigReader(self.context)
        all_stacks, command_stacks = config_reader.construct_stacks()
        assert {str(stack) for stack in all_stacks} == expected_stacks
        assert {str(stack)
                for stack in command_stacks} == expected_command_stacks
Example #6
0
    def __init__(self, context):
        """
        Intialises a SceptrePlan and generates the Stacks, StackGraph and
        launch order of required.

        :param context: A SceptreContext
        :type sceptre.context.SceptreContext:
        """
        self.context = context
        self.command = None
        self.reverse = None
        self.launch_order = None

        config_reader = ConfigReader(context)
        all_stacks, command_stacks = config_reader.construct_stacks()
        self.graph = StackGraph(all_stacks)
        self.command_stacks = command_stacks
Example #7
0
    def test_missing_attr(
        self, filepaths, target, del_key
    ):
        with self.runner.isolated_filesystem():
            project_path = os.path.abspath('./example')
            config_dir = os.path.join(project_path, "config")
            os.makedirs(config_dir)

            self.context.project_path = project_path

            for rel_path in filepaths:
                abs_path = os.path.join(config_dir, rel_path)
                dir_path = abs_path
                if abs_path.endswith(".yaml"):
                    dir_path = os.path.split(abs_path)[0]
                if not os.path.exists(dir_path):
                    try:
                        os.makedirs(dir_path)
                    except OSError as exc:
                        if exc.errno != errno.EEXIST:
                            raise

                config = {
                    "project_code": "project_code",
                    "region": "region",
                    "template_path": rel_path
                }

                # Delete the mandatory key to be tested.
                del config[del_key]

                with open(abs_path, 'w') as config_file:
                    yaml.safe_dump(
                        config, stream=config_file, default_flow_style=False
                    )

            try:
                config_reader = ConfigReader(self.context)
                all_stacks, command_stacks = config_reader.construct_stacks()
            except InvalidConfigFileError as e:
                # Test that the missing key is reported.
                assert del_key in str(e)
            except Exception:
                raise
            else:
                assert False