Skip to content

Commit

Permalink
fix: optimising and fixing boto3 task (#509)
Browse files Browse the repository at this point in the history
* chore: preparing for release

* fix: no longer waiting 10s between accounts when verifying spoke execution mode was successful in spokes.  now using filter and arguments within the boto3 task to decide if a task is a dupe
  • Loading branch information
eamonnfaherty committed Apr 26, 2022
1 parent f3248a8 commit cd33458
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[tool.poetry]
name = "aws-service-catalog-puppet"
version = "0.166.1"
version = "0.167.0"
description = "Making it easier to deploy ServiceCatalog products"
classifiers = ["Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Programming Language :: Python :: 3", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Natural Language :: English"]
homepage = "https://service-catalog-tools-workshop.com/"
Expand Down
9 changes: 9 additions & 0 deletions servicecatalog_puppet/workflow/general/boto3_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
import luigi
from deepmerge import always_merger
import jmespath
import json

from servicecatalog_puppet.workflow import tasks
from servicecatalog_puppet.workflow import dependency

remove_punctuation_map = dict((ord(char), None) for char in '\/*?:"<>|\n')


def hash(what):
return json.dumps(tasks.unwrap(what), indent=0).translate(remove_punctuation_map)


class Boto3Task(tasks.PuppetTask):
account_id = luigi.Parameter()
Expand Down Expand Up @@ -34,6 +41,8 @@ def params_for_results_display(self):
"client": self.client,
"use_paginator": self.use_paginator,
"call": self.call,
"arguments": hash(self.arguments),
"filter": hash(self.filter),
"requester_task_id": self.requester_task_id,
"requester_task_family": self.requester_task_family,
"cache_invalidator": self.cache_invalidator,
Expand Down
10 changes: 6 additions & 4 deletions servicecatalog_puppet/workflow/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ def get_build_status_for_in(build_id, spoke_account_id):
build = response.get("builds")[0]
status = build.get("buildStatus")
has_failed = status not in ["IN_PROGRESS", "SUCCEEDED"]
is_running = status == "IN_PROGRESS"
logger.info(
f"Checking for status of {build_id} in {spoke_account_id}. status: {status}, has failed: {has_failed}"
f"Checking for status of {build_id} in {spoke_account_id}. status: {status}, has failed: {has_failed}, is running: {is_running}"
)
return status, build, has_failed
return status, build, has_failed, is_running


def run_tasks(
Expand Down Expand Up @@ -161,8 +162,7 @@ def run_tasks(
status = "IN_PROGRESS"

while status == "IN_PROGRESS":
time.sleep(10)
status, build, has_failed = get_build_status_for_in(
status, build, has_failed, is_running = get_build_status_for_in(
build_id, spoke_account_id
)
if has_failed:
Expand All @@ -186,6 +186,8 @@ def run_tasks(
f"results/failure/RunDeployInSpokeTask-{spoke_account_id}.json",
"w",
).write(json.dumps(failure))
elif is_running:
time.sleep(10)

dry_run_tasks = (
glob(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

setup_kwargs = {
'name': 'aws-service-catalog-puppet',
'version': '0.166.1',
'version': '0.167.0',
'description': 'Making it easier to deploy ServiceCatalog products',
'long_description': '# aws-service-catalog-puppet\n\n![logo](./docs/logo.png) \n\n## Badges\n\n[![codecov](https://codecov.io/gh/awslabs/aws-service-catalog-puppet/branch/master/graph/badge.svg?token=e8M7mdsmy0)](https://codecov.io/gh/awslabs/aws-service-catalog-puppet)\n\n\n## What is it?\nThis is a python3 framework that makes it easier to share multi region AWS Service Catalog portfolios and makes it \npossible to provision products into accounts declaratively using a metadata based rules engine.\n\nWith this framework you define your accounts in a YAML file. You give each account a set of tags, a default region and \na set of enabled regions.\n\nOnce you have done this you can define portfolios should be shared with each set of accounts using the tags and you \ncan specify which regions the shares occur in.\n\nIn addition to this, you can also define products that should be provisioned into accounts using the same tag based \napproach. The framework will assume role into the target account and provision the product on your behalf.\n\n\n## Getting started\n\nYou can read the [installation how to](https://service-catalog-tools-workshop.com/30-how-tos/10-installation/30-service-catalog-puppet.html)\nor you can read through the [every day use](https://service-catalog-tools-workshop.com/30-how-tos/50-every-day-use.html)\nguides.\n\nYou can read the [documentation](https://aws-service-catalog-puppet.readthedocs.io/en/latest/) to understand the inner \nworkings. \n\n\n## Going further\n\nThe framework is one of a pair. The other is [aws-service-catalog-factory](https://github.com/awslabs/aws-service-catalog-factory).\nWith Service Catalog Factory you can create pipelines that deploy multi region portfolios very easily. \n\n## License\n\nThis library is licensed under the Apache 2.0 License. \n \n',
'author': 'Eamonn Faherty',
Expand Down

0 comments on commit cd33458

Please sign in to comment.