Skip to content

Instantly share code, notes, and snippets.

@tbielawa
Created July 17, 2017 13:39
Show Gist options
  • Save tbielawa/7276903c31ad3dfb0f2759d72f2c5547 to your computer and use it in GitHub Desktop.
Save tbielawa/7276903c31ad3dfb0f2759d72f2c5547 to your computer and use it in GitHub Desktop.
# Run from here: roles/openshift_facts/library/test_set_proxy_facts.py
"""
Some basic testing of the openshift_facts 'set_proxy_facts' function
"""
from pprint import pprint as pp
import copy
import openshift_facts
BASE_COMMON = {
'hostname': 'control.example.com',
'dns_domain': 'cluster.local',
'generate_no_proxy_hosts': True,
'no_proxy_internal_hostnames': 'master1.example.com,node1.example.com'
}
def build_facts(**kwargs):
"""Provide a dict with some proxy related params to update, and this
will return a new facts-like dict.
Usage: build_facts(**{'param': 'value', ...})
-> {'facts': {'common': {'param': 'value', ....}}}
"""
common = copy.deepcopy(BASE_COMMON)
common.update(kwargs)
return {'common': common}
def show_no_proxy(common_facts):
"""Provide a dict of common facts, print out just the no_proxy line if
it exists.
"""
try:
pp(common_facts['no_proxy'])
except KeyError:
pp("undefined")
######################################################################
# No openshift_*_proxy settings defined
FACTS = build_facts(**{})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
# Same as previous, except with openshift_generate_no_proxy_hosts False
FACTS = build_facts(**{
'generate_no_proxy_hosts': False
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
######################################################################
# openshift_https?_proxy defined
# Just HTTPS
FACTS = build_facts(**{
'https_proxy': 'https://file.schmoo.example.com:3128'
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
# Just HTTP
FACTS = build_facts(**{
'http_proxy': 'https://file.schmoo.example.com:3128'
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
# Both HTTPS and HTTP
FACTS = build_facts(**{
'https_proxy': 'https://file.schmoo.example.com:3128',
'http_proxy': 'https://file.schmoo.example.com:3128'
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
# --------------------------------------------------------------------
# Same as previous, except with openshift_generate_no_proxy_hosts False
# Just HTTPS
FACTS = build_facts(**{
'https_proxy': 'https://file.schmoo.example.com:3128',
'generate_no_proxy_hosts': False,
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
# Just HTTP
FACTS = build_facts(**{
'http_proxy': 'https://file.schmoo.example.com:3128',
'generate_no_proxy_hosts': False,
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
# Both HTTPS and HTTP
FACTS = build_facts(**{
'https_proxy': 'https://file.schmoo.example.com:3128',
'http_proxy': 'https://file.schmoo.example.com:3128',
'generate_no_proxy_hosts': False,
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
######################################################################
# Play with openshift_no_proxy now
######################################################################
# Custom no_proxy hosts
FACTS = build_facts(**{
'no_proxy': 'demo1.example.com,secrets.example.com'
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
# Custom no_proxy and https proxy
FACTS = build_facts(**{
'no_proxy': 'demo1.example.com,secrets.example.com',
'https_proxy': 'https://file.schmoo.example.com:3128'
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
# Custom no_proxy and http proxy
FACTS = build_facts(**{
'no_proxy': 'demo1.example.com,secrets.example.com',
'http_proxy': 'https://file.schmoo.example.com:3128'
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
# Custom no_proxy and http proxy and https proxy
FACTS = build_facts(**{
'no_proxy': 'demo1.example.com,secrets.example.com',
'https_proxy': 'https://file.schmoo.example.com:3128',
'http_proxy': 'https://file.schmoo.example.com:3128'
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
# --------------------------------------------------------------------
# Same as previous, except with openshift_generate_no_proxy_hosts False
# Custom no_proxy hosts
FACTS = build_facts(**{
'no_proxy': 'demo1.example.com,secrets.example.com',
'generate_no_proxy_hosts': False,
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
# Custom no_proxy and https proxy
FACTS = build_facts(**{
'no_proxy': 'demo1.example.com,secrets.example.com',
'https_proxy': 'https://file.schmoo.example.com:3128',
'generate_no_proxy_hosts': False,
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
# Custom no_proxy and http proxy
FACTS = build_facts(**{
'no_proxy': 'demo1.example.com,secrets.example.com',
'http_proxy': 'https://file.schmoo.example.com:3128',
'generate_no_proxy_hosts': False,
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
# Custom no_proxy and http proxy and https proxy
FACTS = build_facts(**{
'no_proxy': 'demo1.example.com,secrets.example.com',
'https_proxy': 'https://file.schmoo.example.com:3128',
'http_proxy': 'https://file.schmoo.example.com:3128',
'generate_no_proxy_hosts': False,
})
show_no_proxy(openshift_facts.set_proxy_facts(FACTS)['common'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment