Merge "Removal of netloc filters"

This commit is contained in:
Zuul 2019-04-24 18:58:48 +00:00 committed by Gerrit Code Review
commit 6c80d69bdd
4 changed files with 6 additions and 106 deletions

View File

@ -80,33 +80,6 @@ user after removing any duplicates found within the second list.
{{ ['a', 'b'] | filtered_list(['b', 'c']) }}
# => [ "a" ]
netloc
~~~~~~
This filter will return the netloc from a given URL.
.. code-block:: yaml
{{ 'https://172.29.236.100:5000/v3/auth/tokens' | netloc }}
# => "172.29.236.100:5000"
netloc_no_port
~~~~~~~~~~~~~~
This filter will return the netloc, without a port, from a given URL.
.. code-block:: yaml
{{ 'https://172.29.236.100:5000/v3/auth/tokens' | netloc_no_port }}
# => "172.29.236.100"
netorigin
~~~~~~~~~
This filter will return the scheme and netloc from a given URL.
.. code-block:: yaml
{{ 'https://172.29.236.100:5000/v3/auth/tokens' | netorigin }}
# => "https://172.29.236.100:5000"
pip_constraint_update
~~~~~~~~~~~~~~~~~~~~~
This filter will return a merged list from a given list of pip packages and a

View File

@ -152,68 +152,6 @@ def bit_length_power_of_2(value):
"""
return 2**(int(value)-1).bit_length()
def get_netloc(url):
"""Return the netloc from a URL.
If the input value is not a value URL the method will raise an Ansible
filter exception.
:param url: the URL to parse
:type url: ``str``
:returns: ``str``
"""
try:
netloc = urlparse(url).netloc
except Exception as exp:
raise errors.AnsibleFilterError(
'Failed to return the netloc of: "%s"' % str(exp)
)
else:
return netloc
def get_netloc_no_port(url):
"""Return the netloc without a port from a URL.
If the input value is not a value URL the method will raise an Ansible
filter exception.
:param url: the URL to parse
:type url: ``str``
:returns: ``str``
"""
try:
hostname = urlparse(url).hostname
except Exception as exp:
raise errors.AnsibleFilterError(
'Failed to return the hostname of: "%s"' % str(exp)
)
else:
return hostname
def get_netorigin(url):
"""Return the netloc from a URL.
If the input value is not a value URL the method will raise an Ansible
filter exception.
:param url: the URL to parse
:type url: ``str``
:returns: ``str``
"""
try:
parsed_url = urlparse(url)
netloc = parsed_url.netloc
scheme = parsed_url.scheme
except Exception as exp:
raise errors.AnsibleFilterError(
'Failed to return the netorigin of: "%s"' % str(exp)
)
else:
return '%s://%s' % (scheme, netloc)
def string_2_int(string):
"""Return the an integer from a string.
@ -331,9 +269,6 @@ class FilterModule(object):
def filters():
return {
'bit_length_power_of_2': bit_length_power_of_2,
'netloc': get_netloc,
'netloc_no_port': get_netloc_no_port,
'netorigin': get_netorigin,
'string_2_int': string_2_int,
'pip_requirement_names': pip_requirement_names,
'pip_constraint_update': pip_constraint_update,

View File

@ -0,0 +1,6 @@
---
deprecations:
- |
Removal of the netloc, netloc_no_port and netorigin filters.
Please use the urlsplit filter instead.
All usages of the deprecated filters in openstack repos have been updated.

View File

@ -26,20 +26,6 @@
- "{{ 1024 | bit_length_power_of_2 }} == 1024"
- "{{ 9600 | bit_length_power_of_2 }} == 16384"
- name: Set net filter facts
set_fact:
url_netloc: "{{ 'http://review.openstack.org:29418/something' | netloc }}"
url_netloc_no_port: "{{ 'http://review.openstack.org:29418/something' | netloc_no_port }}"
url_netloc_no_port_with_auth: "{{ 'http://user:secrete@review.openstack.org:29418/something' | netloc_no_port }}"
url_netorigin: "{{ 'http://review.openstack.org:29418/something' | netorigin }}"
- name: Validate net filters
assert:
that:
- "url_netloc == 'review.openstack.org:29418'"
- "url_netloc_no_port == 'review.openstack.org'"
- "url_netloc_no_port_with_auth == 'review.openstack.org'"
- "url_netorigin == 'http://review.openstack.org:29418'"
- name: Validate string_2_int filter
assert:
that: