diff --git a/senza/templates/__init__.py b/senza/templates/__init__.py index ed25ecb1..3b6334b5 100644 --- a/senza/templates/__init__.py +++ b/senza/templates/__init__.py @@ -1,13 +1,22 @@ +""" +Modules and functions for senza component templates +""" + from types import ModuleType, FunctionType import pkg_resources -def get_template_description(name, module: ModuleType): +def get_template_description(name, module: ModuleType) -> str: + """ + Gets the human-readable template description based on the name of the + component and the component's module docstring + """ return '{}: {}'.format(name, (module.__doc__ or "").strip()) def has_functions(module, names): - return all(isinstance(getattr(module, function_name, None), FunctionType) for function_name in names) + return all(isinstance(getattr(module, function_name, None), FunctionType) + for function_name in names) def get_templates() -> dict: @@ -16,15 +25,15 @@ def get_templates() -> dict: """ entry_points = pkg_resources.iter_entry_points('senza.templates') template_modules = {} - for e in entry_points: # type: pkg_resources.EntryPoint + for entry_point in entry_points: # type: pkg_resources.EntryPoint try: - module = e.resolve() + module = entry_point.resolve() except ImportError: # ignore bad entry points continue else: # make sure the entry point resolves to a module with the essential interface functions if (isinstance(module, ModuleType) and - has_functions(module, ('gather_user_variables', 'generate_definition'))): - template_modules[e.name] = module + has_functions(module, ('gather_user_variables', 'generate_definition'))): + template_modules[entry_point.name] = module return template_modules diff --git a/senza/templates/postgresapp.py b/senza/templates/postgresapp.py index 17e9367e..a1781015 100644 --- a/senza/templates/postgresapp.py +++ b/senza/templates/postgresapp.py @@ -398,7 +398,7 @@ def gather_user_variables(variables, region, account_info): prompt(variables, 'instance_type', 'EC2 instance type', default='t2.medium') variables['hosted_zone'] = account_info.Domain or defaults['hosted_zone'] - if (variables['hosted_zone'][-1:] != '.'): + if variables['hosted_zone'][-1:] != '.': variables['hosted_zone'] += '.' prompt(variables, 'discovery_domain', 'ETCD Discovery Domain', default='postgres.' + variables['hosted_zone'][:-1]) @@ -503,11 +503,14 @@ def get_latest_image(registry_domain='registry.opensource.zalan.do', team='acid' Gets the full name of latest image for an artifact """ try: - r = requests.get('https://{0}/teams/{1}/artifacts/{2}/tags'.format(registry_domain, team, artifact)) - if r.ok: + url = 'https://{0}/teams/{1}/artifacts/{2}/tags'.format(registry_domain, + team, + artifact) + response = requests.get(url) + if response.ok: # sort the tags by creation date latest = None - for entry in sorted(r.json(), key=lambda t: t['created'], reverse=True): + for entry in sorted(response.json(), key=lambda t: t['created'], reverse=True): tag = entry['name'] # try to avoid snapshots if possible if 'SNAPSHOT' not in tag: diff --git a/senza/templates/redisnode.py b/senza/templates/redisnode.py index 2683be73..c2ab8c03 100644 --- a/senza/templates/redisnode.py +++ b/senza/templates/redisnode.py @@ -1,6 +1,6 @@ -''' +""" Elasticache node running redis, without replication / HA (for caching) -''' +""" from clickclick import warning from senza.utils import pystache_render @@ -28,7 +28,10 @@ ''' -def gather_user_variables(variables, region, account_info): +def gather_user_variables(variables, region, account_info): # pylint: disable=locally-disabled, unused-argument + """ + Gather all the variables needed to create the redis node + """ # maximal 32 characters because of the loadbalancer-name prompt(variables, 'application_id', 'Application ID', default='hello-world', value_proc=check_value(18, '^[a-zA-Z][-a-zA-Z0-9]*$')) @@ -38,12 +41,15 @@ def gather_user_variables(variables, region, account_info): rules_missing = check_security_group(sg_name, [('tcp', 6379)], region, allow_from_self=True) if ('tcp', 6379) in rules_missing: - warning('Security group {} does not allow tcp/6379 access, you will not be able to access your redis'.format( - sg_name)) + warning('Security group {} does not allow tcp/6379 access, ' + 'you will not be able to access your redis'.format(sg_name)) return variables def generate_definition(variables): + """ + Generates the redis node definition yaml from template + """ definition_yaml = pystache_render(TEMPLATE, variables) return definition_yaml