Skip to content

Commit

Permalink
fixup! ⬆️(dependencies) update python dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaupetit committed Oct 4, 2021
1 parent 66dff78 commit e94717b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
38 changes: 18 additions & 20 deletions filter_plugins/deploy.py
Expand Up @@ -8,58 +8,56 @@

def blue_green_host(host, prefix=None):
"""
Add next/previous prefix to the base host, if prefix is empty or equals
to 'current', the host is left unchanged.
Add next/previous prefix to the base host, if prefix is empty or equals
to 'current', the host is left unchanged.
Example usage:
Example usage:
{{ "foo.bar.com" | blue_green_host("previous") }}
# Should return: previous.foo.bar.com
{{ "foo.bar.com" | blue_green_host("previous") }}
# Should return: previous.foo.bar.com
{{ "foo.bar.com" | blue_green_host() }}
# Should return: foo.bar.com
{{ "foo.bar.com" | blue_green_host() }}
# Should return: foo.bar.com
{{ "foo.bar.com" | blue_green_host("current") }}
# Should return: foo.bar.com
{{ "foo.bar.com" | blue_green_host("current") }}
# Should return: foo.bar.com
"""

if prefix is None or not prefix:
return host

if prefix not in BLUE_GREEN_PREFIXES:
raise AnsibleFilterError(
"prefix '{}' is not allowed (must be in {})".format(
prefix, BLUE_GREEN_PREFIXES
)
f"prefix '{prefix}' is not allowed (must be in {BLUE_GREEN_PREFIXES})"
)

return "{}.{}".format(prefix, host) if prefix != "current" else host
return f"{prefix}.{host}" if prefix != "current" else host


def blue_green_hosts(host):
"""
Add next/current/previous prefix to the base host, and return that list
of possible hosts.
Add next/current/previous prefix to the base host, and return that list
of possible hosts.
Example usage:
Example usage:
{{ "foo.bar.com" | blue_green_hosts }}
# Should return: previous.foo.bar.com, foo.bar.com, next.foo.bar.com
{{ "foo.bar.com" | blue_green_hosts }}
# Should return: previous.foo.bar.com, foo.bar.com, next.foo.bar.com
"""

if not host:
raise AnsibleFilterError("host cannot be empty")

return ",".join(
[
"{}.{}".format(prefix, host) if prefix != "current" else host
f"{prefix}.{host}" if prefix != "current" else host
for prefix in BLUE_GREEN_PREFIXES
]
)


# pylint: disable=no-self-use,too-few-public-methods
class FilterModule():
class FilterModule:
"""Filters used for deployments"""

def filters(self):
Expand Down
6 changes: 5 additions & 1 deletion lookup_plugins/apps.py
Expand Up @@ -4,6 +4,7 @@
"""
from __future__ import absolute_import, division, print_function

from locale import getpreferredencoding
from pathlib import Path

import yaml
Expand Down Expand Up @@ -162,7 +163,10 @@ def __init__(self, loader=None, templar=None, **kwargs):
def _yaml_load(file_path):
"""Syntactic sugar to get yaml content with a simpler line of code"""

return yaml.load(Path(file_path).read_text(), Loader=yaml.FullLoader)
return yaml.load(
Path(file_path).read_text(encoding=getpreferredencoding()),
Loader=yaml.FullLoader,
)

def _get_app_service(self, service_path):
"""Explore an application service"""
Expand Down
4 changes: 2 additions & 2 deletions tests/units/plugins/filter/test_deploy.py
Expand Up @@ -44,8 +44,8 @@ def test_with_next_previous_prefix(self):

host = "foo.com"

self.assertEqual(blue_green_host(host, "previous"), "previous.{}".format(host))
self.assertEqual(blue_green_host(host, "next"), "next.{}".format(host))
self.assertEqual(blue_green_host(host, "previous"), f"previous.{host}")
self.assertEqual(blue_green_host(host, "next"), f"next.{host}")


class TestBlueGreenHostsFilter(unittest.TestCase):
Expand Down

0 comments on commit e94717b

Please sign in to comment.