How to use the taskcat._cfn.threaded.Stacker function in taskcat

To help you get started, we’ve selected a few taskcat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws-quickstart / taskcat / tests / test_cfn_threaded.py View on Github external
def test_resources(self):
        test_proj = (Path(__file__).parent / "./data/nested-fail").resolve()
        project_name, tests = get_tests(test_proj)
        stacker = Stacker(project_name=project_name, tests=tests)
        stacker.create_stacks()
        resources = stacker.resources()
        self.assertEqual(2, len(resources))
github aws-quickstart / taskcat / tests / test_cfn_threaded.py View on Github external
def test_create_stacks(self):
        test_proj = (Path(__file__).parent / "./data/nested-fail").resolve()
        project_name, tests = get_tests(test_proj)
        stacker = Stacker(project_name=project_name, tests=tests)
        stacker.create_stacks()
        self.assertEqual(2, len(stacker.stacks))
github aws-quickstart / taskcat / tests / test_cfn_threaded.py View on Github external
def test_delete_stacks(self):
        test_proj = (Path(__file__).parent / "./data/nested-fail").resolve()
        project_name, tests = get_tests(test_proj)
        stacker = Stacker(project_name=project_name, tests=tests)
        stacker.create_stacks()
        stacker.delete_stacks()
        stacker.stacks[0].delete.assert_called_once()
github aws-quickstart / taskcat / taskcat / _cli_modules / list.py View on Github external
if isinstance(profiles, str):
            profiles = profiles.split(",")
        if regions == "ALL":
            region_set: set = set()
            for profile in profiles:
                region_set = region_set.union(
                    set(
                        boto3.Session(profile_name=profile).get_available_regions(
                            "cloudformation"
                        )
                    )
                )
            regions = list(region_set)
        else:
            regions = regions.split(",")
        stacks = Stacker.list_stacks(profiles, regions)
        jobs: dict = {}
        for stack in stacks:
            stack_key = stack["taskcat-id"].hex + "-" + stack["region"]
            if stack_key not in jobs:
                name = stack.get("taskcat-installer")
                if _stack_type == "test" and not name:
                    name = stack["taskcat-project-name"]
                    jobs[stack_key] = {
                        "name": name,
                        "id": stack["taskcat-id"].hex,
                        "project_name": stack["taskcat-project-name"],
                        "active_stacks": 1,
                        "region": stack["region"],
                    }
                elif name and _stack_type == "package":
                    jobs[stack_key] = {
github aws-quickstart / taskcat / taskcat / _cli_modules / delete.py View on Github external
region="default",
        _stack_type="package",
    ):
        """
        :param package: installed package to delete, can be an install name or uuid
        :param aws_profile: aws profile to use for deletion
        :param region: region to delete from, default will use aws cli configured
        default
        """
        LOG.warning("delete is in alpha feature, use with caution")
        boto3_cache = Boto3Cache()
        if region == "default":
            region = boto3_cache.get_default_region(aws_profile)
        if isinstance(region, str):
            region = [region]
        stacks = Stacker.list_stacks([aws_profile], region)
        jobs = []
        for stack in stacks:
            name = stack.get("taskcat-installer", stack["taskcat-project-name"])
            job = {
                "name": name,
                "project_name": stack["taskcat-project-name"],
                "test_name": stack["taskcat-test-name"],
                "taskcat_id": stack["taskcat-id"].hex,
                "region": stack["region"],
                "type": "package" if stack.get("taskcat-installer") else "test",
                "stack_id": stack["stack-id"],
            }
            if _stack_type == job["type"]:
                if package in [job["name"], job["taskcat_id"], "ALL"]:
                    jobs.append(job)
        # TODO: concurrency and wait for complete
github aws-quickstart / taskcat / taskcat / _cfn / threaded.py View on Github external
if recurse:
            raise NotImplementedError("recurse not implemented")
        clients: Dict[boto3.client, List[TestRegion]] = {}
        for test in tests.values():
            for region in test.regions:
                client = region.client("cloudformation")
                if client not in clients:
                    clients[client] = []
                clients[client].append(region)
        results = fan_out(
            Stacker._import_stacks_per_client,
            {"uid": uid, "project_name": project_name, "tests": tests},
            clients.items(),
            threads,
        )
        stacker = Stacker(project_name, tests, uid)
        stacker.stacks = Stacks([item for sublist in results for item in sublist])
        return stacker
github aws-quickstart / taskcat / taskcat / _cfn / threaded.py View on Github external
def __init__(
        self,
        project_name: str,
        tests: Dict[str, TestObj],
        uid: uuid.UUID = NULL_UUID,
        stack_name_prefix: str = "tCaT",
        tags: list = None,
    ):
        self.tests = tests
        self.project_name = project_name
        self.stack_name_prefix = stack_name_prefix
        self.tags = tags if tags else []
        self.uid = uuid.uuid4() if uid == Stacker.NULL_UUID else uid
        self.stacks: Stacks = Stacks()
github aws-quickstart / taskcat / taskcat / _cfn / threaded.py View on Github external
recurse=False,
        threads=32,
    ):
        if include_deleted:
            raise NotImplementedError("including deleted stacks not implemented")
        if recurse:
            raise NotImplementedError("recurse not implemented")
        clients: Dict[boto3.client, List[TestRegion]] = {}
        for test in tests.values():
            for region in test.regions:
                client = region.client("cloudformation")
                if client not in clients:
                    clients[client] = []
                clients[client].append(region)
        results = fan_out(
            Stacker._import_stacks_per_client,
            {"uid": uid, "project_name": project_name, "tests": tests},
            clients.items(),
            threads,
        )
        stacker = Stacker(project_name, tests, uid)
        stacker.stacks = Stacks([item for sublist in results for item in sublist])
        return stacker
github aws-quickstart / taskcat / taskcat / _cli_modules / deploy.py View on Github external
if "default" not in config.config.tests:
            config.config.tests["default"] = config.config.tests[
                list(config.config.tests.keys())[0]
            ]
        # until install offers a way to run different "plans" we only need one test
        for test_name in list(config.config.tests.keys()):
            if test_name != "default":
                del config.config.tests[test_name]
        buckets = config.get_buckets(boto3_cache)
        stage_in_s3(buckets, config.config.project.name, path)
        regions = config.get_regions(boto3_cache)
        templates = config.get_templates(project_root=path)
        parameters = config.get_rendered_parameters(buckets, regions, templates)
        tests = config.get_tests(path, templates, regions, buckets, parameters)
        tags = [Tag({"Key": "taskcat-installer", "Value": name})]
        stacks = Stacker(config.config.project.name, tests, tags=tags)
        stacks.create_stacks()
        LOG.error(
            f" {stacks.uid.hex}",
            extra={"nametag": "\x1b[0;30;47m[INSTALL_ID  ]\x1b[0m"},
        )
        LOG.error(f" {name}", extra={"nametag": "\x1b[0;30;47m[INSTALL_NAME]\x1b[0m"})
        if wait:
            LOG.info(
                f"waiting for stack {stacks.stacks[0].name} to complete in "
                f"{stacks.stacks[0].region_name}"
            )
            while stacks.status()["IN_PROGRESS"]:
                sleep(5)
        if stacks.status()["FAILED"]:
            LOG.error("Install failed:")
            for error in stacks.stacks[0].error_events():