Skip to content

Commit

Permalink
small changes, refactor into new env_utils method and test
Browse files Browse the repository at this point in the history
  • Loading branch information
willronchetti committed May 20, 2020
1 parent 55a60c3 commit 6b4fc37
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
48 changes: 20 additions & 28 deletions dcicutils/deployment_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def main():

from dcicutils.env_utils import (
get_standard_mirror_env, data_set_for_env, get_bucket_env, INDEXER_ENVS, is_fourfront_env, is_cgap_env,
FF_ENV_INDEXER, CGAP_ENV_INDEXER, is_indexer_env
FF_ENV_INDEXER, CGAP_ENV_INDEXER, is_indexer_env, indexer_env_for_env
)
from dcicutils.misc_utils import PRINT

Expand Down Expand Up @@ -237,17 +237,17 @@ def verify_template_creation(cls, client, template_name):
:returns: True if template can be acquired
:raises: Exception if one is encountered
"""
try:
client.describe_configuration_settings(
ApplicationName=cls.EB_APPLICATION,
TemplateName=template_name
)
except Exception: # catch all exceptions here
time.sleep(10) # wait 10 seconds, try again (and raise exception if it fails)
client.describe_configuration_settings(
ApplicationName=cls.EB_APPLICATION,
TemplateName=template_name
)
for retrying in (True, False):
try:
client.describe_configuration_settings(
ApplicationName=cls.EB_APPLICATION,
TemplateName=template_name
)
except Exception:
if not retrying:
raise
else:
time.sleep(10)
return True

@classmethod
Expand Down Expand Up @@ -287,22 +287,14 @@ def create_indexer_configuration_template(cls, env_name, size=None):
configuration))

# upload the template
if is_cgap_env(env_name):
eb_client.create_configuration_template(
ApplicationName=cls.EB_APPLICATION,
TemplateName=CGAP_ENV_INDEXER,
OptionSettings=configuration,
EnvironmentId=cls.extract_environment_id(env_name)
)
return cls.verify_template_creation(eb_client, CGAP_ENV_INDEXER)
else:
eb_client.create_configuration_template(
ApplicationName=cls.EB_APPLICATION,
TemplateName=FF_ENV_INDEXER,
OptionSettings=configuration,
EnvironmentId=cls.extract_environment_id(env_name)
)
return cls.verify_template_creation(eb_client, FF_ENV_INDEXER)
indexer_env = indexer_env_for_env(env_name)
eb_client.create_configuration_template(
ApplicationName=cls.EB_APPLICATION,
TemplateName=indexer_env,
OptionSettings=configuration,
EnvironmentId=cls.extract_environment_id(env_name)
)
return cls.verify_template_creation(eb_client, indexer_env)

@classmethod
def create_indexer_environment(cls, env_name, app_version):
Expand Down
14 changes: 14 additions & 0 deletions dcicutils/env_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ def is_indexer_env(envname):
return envname in [FF_ENV_INDEXER, CGAP_ENV_INDEXER]


def indexer_env_for_env(envname):
""" Returns the corresponding indexer-env name for the given env.
:param envname: envname we want to determine the indexer for
:returns: either FF_ENV_INDEXER or CGAP_ENV_INDEXER or None
"""
if is_fourfront_env(envname):
return FF_ENV_INDEXER
elif is_cgap_env(envname):
return CGAP_ENV_INDEXER
else:
return None


def data_set_for_env(envname, default=None):
"""
This relates to which data set to load.
Expand Down
20 changes: 19 additions & 1 deletion test/test_env_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
get_mirror_env_from_context, is_test_env, is_hotseat_env, guess_mirror_env, get_standard_mirror_env,
prod_bucket_env, public_url_mappings, CGAP_PUBLIC_URLS, FF_PUBLIC_URLS, FF_PROD_BUCKET_ENV, CGAP_PROD_BUCKET_ENV,
infer_repo_from_env, data_set_for_env, get_bucket_env, infer_foursight_from_env, FF_PRODUCTION_IDENTIFIER,
FF_STAGING_IDENTIFIER, FF_PUBLIC_DOMAIN_PRD, FF_PUBLIC_DOMAIN_STG, CGAP_ENV_DEV
FF_STAGING_IDENTIFIER, FF_PUBLIC_DOMAIN_PRD, FF_PUBLIC_DOMAIN_STG, CGAP_ENV_DEV, indexer_env_for_env,
FF_ENV_INDEXER, CGAP_ENV_INDEXER,
)
from unittest import mock

Expand Down Expand Up @@ -432,3 +433,20 @@ def mock_request(domain=None): # build a dummy request with the 'domain' member
assert infer_foursight_from_env(mock_request(), CGAP_ENV_MASTERTEST) == 'cgaptest'
assert infer_foursight_from_env(mock_request(), CGAP_ENV_WOLF) == 'cgapwolf'
assert infer_foursight_from_env(mock_request(), CGAP_ENV_WEBPROD) == 'cgap'


def test_indexer_env_for_env():
assert indexer_env_for_env('fourfront-mastertest') == FF_ENV_INDEXER
assert indexer_env_for_env('fourfront-blue') == FF_ENV_INDEXER
assert indexer_env_for_env('fourfront-green') == FF_ENV_INDEXER
assert indexer_env_for_env('fourfront-webdev') == FF_ENV_INDEXER
assert indexer_env_for_env('fourfront-hotseat') == FF_ENV_INDEXER

assert indexer_env_for_env('fourfront-cgap') == CGAP_ENV_INDEXER
assert indexer_env_for_env('fourfront-cgapdev') == CGAP_ENV_INDEXER
assert indexer_env_for_env('fourfront-cgaptest') == CGAP_ENV_INDEXER
assert indexer_env_for_env('fourfront-cgapwolf') == CGAP_ENV_INDEXER

assert indexer_env_for_env('fourfront-indexer') is None
assert indexer_env_for_env('cgap-indexer') is None
assert indexer_env_for_env('blah-env') is None

0 comments on commit 6b4fc37

Please sign in to comment.