How to use the taskcat._amiupdater.RegionalCodename 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_amiupdater.py View on Github external
def test_regional_codename__hash__(self):
        rc = RegionalCodename(
            region="us-east-1",
            cn="AMZNLINUXHVM",
            filters=[
                EC2FilterValue("name", ["amzn-ami-hvm-????.??.?.*-x86_64-gp2"]),
                EC2FilterValue("owner-alias", ["amazon"]),
                EC2FilterValue("state", ["available"]),
            ],
        )
        self.assertTrue(isinstance(rc.__hash__(), int))
github aws-quickstart / taskcat / tests / test_amiupdater.py View on Github external
def test_build_codenames(self):
        example_tc_template = self.create_ephemeral_template_object()
        au_template = Template(example_tc_template["taskcat-json"], ["us-east-1"])
        example_config_obj = AUConfig
        example_config_obj.raw_dict = {
            "global": {
                "AMIs": {
                    "AMZNLINUXHVM": {
                        "name": "amzn-ami-hvm-????.??.?.*-x86_64-gp2",
                        "owner-alias": "amazon",
                    }
                }
            }
        }
        expected = [
            RegionalCodename(
                region="us-east-1",
                cn="AMZNLINUXHVM",
                filters=[
                    EC2FilterValue("name", ["amzn-ami-hvm-????.??.?.*-x86_64-gp2"]),
                    EC2FilterValue("owner-alias", ["amazon"]),
                    EC2FilterValue("state", ["available"]),
                ],
            )
        ]
        actual = build_codenames(au_template, example_config_obj)
        _mocked_dt = datetime.now()
        for r1 in expected:
            r1._creation_dt = _mocked_dt
        for r2 in actual:
            r2._creation_dt = _mocked_dt
        self.assertEqual(expected, actual)
github aws-quickstart / taskcat / taskcat / _amiupdater.py View on Github external
def _generate_regional_codenames(self):
        for region in self._regions:
            if region == "AMI":
                continue
            if self.filter_metadata:
                for k in self.filter_metadata.keys():
                    RegionalCodename(
                        cn=k, region=region, filters=self.filter_metadata[k]
                    )
            else:
                # Region Name, Latest AMI Name in Template
                # - We instantiate them in the RegionalCodename class
                #   because it allows us to access the attributes as an object.
                #   It also generates the Filters needed in each API call.
                #   - This is done in the Codenames class, so check that out.
                try:
                    for k in self._mapping_root[region].keys():
                        RegionalCodename(cn=k, region=region)
                except KeyError:
                    pass
github aws-quickstart / taskcat / taskcat / _amiupdater.py View on Github external
def __init__(self, cn, region, filters=None, *args, **kwargs):
        self.region = region
        self.results = None
        self._filters = filters
        super(RegionalCodename, self).__init__(cn, region, *args, **kwargs)
github aws-quickstart / taskcat / taskcat / _amiupdater.py View on Github external
if not REGION_REGEX.search(region):
            LOG.error(f"[{region}] is not a valid region. Please check your template!")
            raise AMIUpdaterFatalException
        if region in tobj.regions_without_creds:
            continue
        for cnname in cndata.keys():
            _filters = _construct_filters(cnname, config)
            if not _filters:
                if cnname not in _missing_filters:
                    _missing_filters.add(cnname)
                    LOG.warning(
                        f"No query parameters were found for: {cnname.upper()}.",
                        f"(Results for this codename are not possible.",
                    )
                continue
            region_cn = RegionalCodename(region=region, cn=cnname, filters=_filters)
            built_cn.append(region_cn)
    return built_cn
github aws-quickstart / taskcat / taskcat / _amiupdater.py View on Github external
if region == "AMI":
                continue
            if self.filter_metadata:
                for k in self.filter_metadata.keys():
                    RegionalCodename(
                        cn=k, region=region, filters=self.filter_metadata[k]
                    )
            else:
                # Region Name, Latest AMI Name in Template
                # - We instantiate them in the RegionalCodename class
                #   because it allows us to access the attributes as an object.
                #   It also generates the Filters needed in each API call.
                #   - This is done in the Codenames class, so check that out.
                try:
                    for k in self._mapping_root[region].keys():
                        RegionalCodename(cn=k, region=region)
                except KeyError:
                    pass
github aws-quickstart / taskcat / taskcat / _amiupdater.py View on Github external
def fetch_latest_amis(cls):
        """Fetches AMI IDs from AWS"""
        # This is a wrapper for the threaded run.
        # Create a ThreadPool, size is the number of regions.

        if len(RegionalCodename.objects()) == 0:
            raise AMIUpdaterException(
                "No AMI filters were found. Nothing to fetch from the EC2 API."
            )

        pool = ThreadPool(len(TemplateClass.regions()))
        # For reach RegionalCodename that we've generated....
        pool.map(cls._per_rcn_ami_fetch, RegionalCodename.objects())