def _import_stacks_per_client(clients, uid, project_name, tests): # pylint: disable=too-many-locals stacks = Stacks() client, region = clients for page in client.get_paginator("describe_stacks").paginate(): for stack_props in page["Stacks"]: if stack_props.get("ParentId"): continue match = False project = "" test = "" for tag in stack_props["Tags"]: k, v = (tag["Key"], tag["Value"]) if k == "taskcat-id" and v == uid.hex: match = True elif k == "taskcat-test-name" and v in tests: test = v elif k == "taskcat-project-name" and v == project_name: project = v if match and test and project: stack = Stack.import_existing(stack_props, tests[test].template, region[0], test, uid) stacks.append(stack) return stacks
def from_existing( cls, uid: uuid.UUID, project_name: str, tests: Dict[str, TestObj], include_deleted=False, 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
def __init__( self, config: Config, uid: uuid.UUID = NULL_UUID, stack_name_prefix: str = "tCaT", tags: list = None, ): self.config = config self.project_name = config.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()
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()