Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Check latest version status before changes
Browse files Browse the repository at this point in the history
If the akamai latest version is in a pending state, the
task execution should not make any changes as they overwrite
properties in akamai.

Change-Id: I46019d8f6a70e63678fab921485069258a3e5a6f
  • Loading branch information
isaacm committed Jun 30, 2016
1 parent 80b4192 commit 552a3c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def execute(self, property_spec):
str(max_version)))
return max_version
else:
# else now we need to create a new version (bump up a version)
# retrieve the latest version from akamai
resp = self.akamai_driver.akamai_papi_api_client.get(
self.akamai_driver.akamai_papi_api_base_url.format(
middle_part='properties/%s/versions/%s' % (
Expand All @@ -77,8 +77,26 @@ def execute(self, property_spec):
if resp.status_code != 200:
raise RuntimeError('PAPI API request failed.'
'Exception: %s' % resp.text)

# if the latest version is pending state, stop execution
production_status = \
json.loads(resp.text)['versions']['items'][0][
'productionStatus']

if production_status.upper() == 'PENDING':
err_message = (
'Aborting task/flow execution.'
'Akamai property version {0} is in {1} status.'.format(
max_version,
production_status
)
)
LOG.error(err_message)
raise ValueError(err_message)

etag = json.loads(resp.text)['versions']['items'][0]['etag']
# create a new version

# now we need to create a new version (bump up a version)
resp = self.akamai_driver.akamai_papi_api_client.post(
self.akamai_driver.akamai_papi_api_base_url.format(
middle_part='properties/%s/versions' % (
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/provider/akamai/background_jobs/akamai_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ def get(self, url):
"versions": {
"items": [{
"propertyVersion": 1,
"etag": str(uuid.uuid4())
"etag": str(uuid.uuid4()),
"productionStatus": "ACTIVE",
}]
}
})
Expand Down

0 comments on commit 552a3c9

Please sign in to comment.