mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
More work on getting integration tests running for v2
This commit is contained in:
@@ -39,6 +39,7 @@ AWS_REGIONS = [
|
||||
'cn-north-1',
|
||||
'eu-central-1',
|
||||
'eu-west-1',
|
||||
'eu-central-1',
|
||||
'sa-east-1',
|
||||
'us-east-1',
|
||||
'us-west-1',
|
||||
@@ -165,6 +166,11 @@ def boto_fix_security_token_in_profile(conn, profile_name):
|
||||
|
||||
def connect_to_aws(aws_module, region, **params):
|
||||
conn = aws_module.connect_to_region(region, **params)
|
||||
if not conn:
|
||||
if region not in [aws_module_region.name for aws_module_region in aws_module.regions()]:
|
||||
raise StandardError("Region %s does not seem to be available for aws module %s. If the region definitely exists, you may need to upgrade boto" % (region, aws_module.__name__))
|
||||
else:
|
||||
raise StandardError("Unknown problem connecting to region %s for aws module %s." % (region, aws_module.__name__))
|
||||
if params.get('profile_name'):
|
||||
conn = boto_fix_security_token_in_profile(conn, params['profile_name'])
|
||||
return conn
|
||||
@@ -180,13 +186,13 @@ def ec2_connect(module):
|
||||
if region:
|
||||
try:
|
||||
ec2 = connect_to_aws(boto.ec2, region, **boto_params)
|
||||
except boto.exception.NoAuthHandlerFound, e:
|
||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
# Otherwise, no region so we fallback to the old connection method
|
||||
elif ec2_url:
|
||||
try:
|
||||
ec2 = boto.connect_ec2_endpoint(ec2_url, **boto_params)
|
||||
except boto.exception.NoAuthHandlerFound, e:
|
||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="Either region or ec2_url must be specified")
|
||||
|
||||
@@ -46,7 +46,7 @@ except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
# --------------------------------------------------------------
|
||||
# timeout function to make sure some fact gathering
|
||||
# timeout function to make sure some fact gathering
|
||||
# steps do not exceed a time limit
|
||||
|
||||
class TimeoutError(Exception):
|
||||
@@ -82,7 +82,8 @@ class Facts(object):
|
||||
subclass Facts.
|
||||
"""
|
||||
|
||||
_I386RE = re.compile(r'i[3456]86')
|
||||
# i86pc is a Solaris and derivatives-ism
|
||||
_I386RE = re.compile(r'i([3456]86|86pc)')
|
||||
# For the most part, we assume that platform.dist() will tell the truth.
|
||||
# This is the fallback to handle unknowns or exceptions
|
||||
OSDIST_LIST = ( ('/etc/redhat-release', 'RedHat'),
|
||||
@@ -274,84 +275,115 @@ class Facts(object):
|
||||
self.facts['distribution_release'] = dist[2] or 'NA'
|
||||
# Try to handle the exceptions now ...
|
||||
for (path, name) in Facts.OSDIST_LIST:
|
||||
if os.path.exists(path) and os.path.getsize(path) > 0:
|
||||
if self.facts['distribution'] in ('Fedora', ):
|
||||
# Once we determine the value is one of these distros
|
||||
# we trust the values are always correct
|
||||
break
|
||||
elif name == 'RedHat':
|
||||
data = get_file_content(path)
|
||||
if 'Red Hat' in data:
|
||||
if os.path.exists(path):
|
||||
if os.path.getsize(path) > 0:
|
||||
if self.facts['distribution'] in ('Fedora', ):
|
||||
# Once we determine the value is one of these distros
|
||||
# we trust the values are always correct
|
||||
break
|
||||
elif name == 'RedHat':
|
||||
data = get_file_content(path)
|
||||
if 'Red Hat' in data:
|
||||
self.facts['distribution'] = name
|
||||
else:
|
||||
self.facts['distribution'] = data.split()[0]
|
||||
break
|
||||
elif name == 'OtherLinux':
|
||||
data = get_file_content(path)
|
||||
if 'Amazon' in data:
|
||||
self.facts['distribution'] = 'Amazon'
|
||||
self.facts['distribution_version'] = data.split()[-1]
|
||||
break
|
||||
elif name == 'OpenWrt':
|
||||
data = get_file_content(path)
|
||||
if 'OpenWrt' in data:
|
||||
self.facts['distribution'] = name
|
||||
version = re.search('DISTRIB_RELEASE="(.*)"', data)
|
||||
if version:
|
||||
self.facts['distribution_version'] = version.groups()[0]
|
||||
release = re.search('DISTRIB_CODENAME="(.*)"', data)
|
||||
if release:
|
||||
self.facts['distribution_release'] = release.groups()[0]
|
||||
break
|
||||
elif name == 'Alpine':
|
||||
data = get_file_content(path)
|
||||
self.facts['distribution'] = name
|
||||
else:
|
||||
self.facts['distribution'] = data.split()[0]
|
||||
break
|
||||
elif name == 'OtherLinux':
|
||||
data = get_file_content(path)
|
||||
if 'Amazon' in data:
|
||||
self.facts['distribution'] = 'Amazon'
|
||||
self.facts['distribution_version'] = data.split()[-1]
|
||||
self.facts['distribution_version'] = data
|
||||
break
|
||||
elif name == 'OpenWrt':
|
||||
data = get_file_content(path)
|
||||
if 'OpenWrt' in data:
|
||||
self.facts['distribution'] = name
|
||||
version = re.search('DISTRIB_RELEASE="(.*)"', data)
|
||||
if version:
|
||||
self.facts['distribution_version'] = version.groups()[0]
|
||||
release = re.search('DISTRIB_CODENAME="(.*)"', data)
|
||||
if release:
|
||||
self.facts['distribution_release'] = release.groups()[0]
|
||||
break
|
||||
elif name == 'Alpine':
|
||||
data = get_file_content(path)
|
||||
self.facts['distribution'] = name
|
||||
self.facts['distribution_version'] = data
|
||||
break
|
||||
elif name == 'Solaris':
|
||||
data = get_file_content(path).split('\n')[0]
|
||||
if 'Solaris' in data:
|
||||
ora_prefix = ''
|
||||
if 'Oracle Solaris' in data:
|
||||
data = data.replace('Oracle ','')
|
||||
ora_prefix = 'Oracle '
|
||||
self.facts['distribution'] = data.split()[0]
|
||||
self.facts['distribution_version'] = data.split()[1]
|
||||
self.facts['distribution_release'] = ora_prefix + data
|
||||
break
|
||||
elif name == 'SuSE':
|
||||
data = get_file_content(path)
|
||||
if 'suse' in data.lower():
|
||||
if path == '/etc/os-release':
|
||||
elif name == 'Solaris':
|
||||
data = get_file_content(path).split('\n')[0]
|
||||
if 'Solaris' in data:
|
||||
ora_prefix = ''
|
||||
if 'Oracle Solaris' in data:
|
||||
data = data.replace('Oracle ','')
|
||||
ora_prefix = 'Oracle '
|
||||
self.facts['distribution'] = data.split()[0]
|
||||
self.facts['distribution_version'] = data.split()[1]
|
||||
self.facts['distribution_release'] = ora_prefix + data
|
||||
break
|
||||
|
||||
uname_rc, uname_out, uname_err = module.run_command(['uname', '-v'])
|
||||
distribution_version = None
|
||||
if 'SmartOS' in data:
|
||||
self.facts['distribution'] = 'SmartOS'
|
||||
if os.path.exists('/etc/product'):
|
||||
product_data = dict([l.split(': ', 1) for l in get_file_content('/etc/product').split('\n') if ': ' in l])
|
||||
if 'Image' in product_data:
|
||||
distribution_version = product_data.get('Image').split()[-1]
|
||||
elif 'OpenIndiana' in data:
|
||||
self.facts['distribution'] = 'OpenIndiana'
|
||||
elif 'OmniOS' in data:
|
||||
self.facts['distribution'] = 'OmniOS'
|
||||
distribution_version = data.split()[-1]
|
||||
elif uname_rc == 0 and 'NexentaOS_' in uname_out:
|
||||
self.facts['distribution'] = 'Nexenta'
|
||||
distribution_version = data.split()[-1].lstrip('v')
|
||||
|
||||
if self.facts['distribution'] in ('SmartOS', 'OpenIndiana', 'OmniOS', 'Nexenta'):
|
||||
self.facts['distribution_release'] = data.strip()
|
||||
if distribution_version is not None:
|
||||
self.facts['distribution_version'] = distribution_version
|
||||
elif uname_rc == 0:
|
||||
self.facts['distribution_version'] = uname_out.split('\n')[0].strip()
|
||||
break
|
||||
|
||||
elif name == 'SuSE':
|
||||
data = get_file_content(path)
|
||||
if 'suse' in data.lower():
|
||||
if path == '/etc/os-release':
|
||||
release = re.search("PRETTY_NAME=[^(]+ \(?([^)]+?)\)", data)
|
||||
distdata = get_file_content(path).split('\n')[0]
|
||||
self.facts['distribution'] = distdata.split('=')[1]
|
||||
if release:
|
||||
self.facts['distribution_release'] = release.groups()[0]
|
||||
break
|
||||
elif path == '/etc/SuSE-release':
|
||||
data = data.splitlines()
|
||||
distdata = get_file_content(path).split('\n')[0]
|
||||
self.facts['distribution'] = distdata.split()[0]
|
||||
for line in data:
|
||||
release = re.search('CODENAME *= *([^\n]+)', line)
|
||||
if release:
|
||||
self.facts['distribution_release'] = release.groups()[0].strip()
|
||||
break
|
||||
elif name == 'Debian':
|
||||
data = get_file_content(path)
|
||||
if 'Debian' in data:
|
||||
release = re.search("PRETTY_NAME=[^(]+ \(?([^)]+?)\)", data)
|
||||
if release:
|
||||
self.facts['distribution_release'] = release.groups()[0]
|
||||
break
|
||||
elif path == '/etc/SuSE-release':
|
||||
data = data.splitlines()
|
||||
for line in data:
|
||||
release = re.search('CODENAME *= *([^\n]+)', line)
|
||||
if release:
|
||||
self.facts['distribution_release'] = release.groups()[0].strip()
|
||||
break
|
||||
elif name == 'Debian':
|
||||
data = get_file_content(path)
|
||||
if 'Debian' in data:
|
||||
release = re.search("PRETTY_NAME=[^(]+ \(?([^)]+?)\)", data)
|
||||
if release:
|
||||
self.facts['distribution_release'] = release.groups()[0]
|
||||
break
|
||||
elif name == 'Mandriva':
|
||||
data = get_file_content(path)
|
||||
if 'Mandriva' in data:
|
||||
version = re.search('DISTRIB_RELEASE="(.*)"', data)
|
||||
if version:
|
||||
self.facts['distribution_version'] = version.groups()[0]
|
||||
release = re.search('DISTRIB_CODENAME="(.*)"', data)
|
||||
if release:
|
||||
self.facts['distribution_release'] = release.groups()[0]
|
||||
self.facts['distribution'] = name
|
||||
break
|
||||
break
|
||||
elif name == 'Mandriva':
|
||||
data = get_file_content(path)
|
||||
if 'Mandriva' in data:
|
||||
version = re.search('DISTRIB_RELEASE="(.*)"', data)
|
||||
if version:
|
||||
self.facts['distribution_version'] = version.groups()[0]
|
||||
release = re.search('DISTRIB_CODENAME="(.*)"', data)
|
||||
if release:
|
||||
self.facts['distribution_release'] = release.groups()[0]
|
||||
self.facts['distribution'] = name
|
||||
break
|
||||
else:
|
||||
self.facts['distribution'] = name
|
||||
|
||||
@@ -598,22 +630,49 @@ class LinuxHardware(Hardware):
|
||||
|
||||
def get_cpu_facts(self):
|
||||
i = 0
|
||||
vendor_id_occurrence = 0
|
||||
model_name_occurrence = 0
|
||||
physid = 0
|
||||
coreid = 0
|
||||
sockets = {}
|
||||
cores = {}
|
||||
|
||||
xen = False
|
||||
xen_paravirt = False
|
||||
try:
|
||||
if os.path.exists('/proc/xen'):
|
||||
xen = True
|
||||
elif open('/sys/hypervisor/type').readline().strip() == 'xen':
|
||||
xen = True
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
if not os.access("/proc/cpuinfo", os.R_OK):
|
||||
return
|
||||
self.facts['processor'] = []
|
||||
for line in open("/proc/cpuinfo").readlines():
|
||||
data = line.split(":", 1)
|
||||
key = data[0].strip()
|
||||
|
||||
if xen:
|
||||
if key == 'flags':
|
||||
# Check for vme cpu flag, Xen paravirt does not expose this.
|
||||
# Need to detect Xen paravirt because it exposes cpuinfo
|
||||
# differently than Xen HVM or KVM and causes reporting of
|
||||
# only a single cpu core.
|
||||
if 'vme' not in data:
|
||||
xen_paravirt = True
|
||||
|
||||
# model name is for Intel arch, Processor (mind the uppercase P)
|
||||
# works for some ARM devices, like the Sheevaplug.
|
||||
if key == 'model name' or key == 'Processor' or key == 'vendor_id':
|
||||
if 'processor' not in self.facts:
|
||||
self.facts['processor'] = []
|
||||
self.facts['processor'].append(data[1].strip())
|
||||
if key == 'vendor_id':
|
||||
vendor_id_occurrence += 1
|
||||
if key == 'model name':
|
||||
model_name_occurrence += 1
|
||||
i += 1
|
||||
elif key == 'physical id':
|
||||
physid = data[1].strip()
|
||||
@@ -629,13 +688,23 @@ class LinuxHardware(Hardware):
|
||||
cores[coreid] = int(data[1].strip())
|
||||
elif key == '# processors':
|
||||
self.facts['processor_cores'] = int(data[1].strip())
|
||||
|
||||
if vendor_id_occurrence == model_name_occurrence:
|
||||
i = vendor_id_occurrence
|
||||
|
||||
if self.facts['architecture'] != 's390x':
|
||||
self.facts['processor_count'] = sockets and len(sockets) or i
|
||||
self.facts['processor_cores'] = sockets.values() and sockets.values()[0] or 1
|
||||
self.facts['processor_threads_per_core'] = ((cores.values() and
|
||||
cores.values()[0] or 1) / self.facts['processor_cores'])
|
||||
self.facts['processor_vcpus'] = (self.facts['processor_threads_per_core'] *
|
||||
self.facts['processor_count'] * self.facts['processor_cores'])
|
||||
if xen_paravirt:
|
||||
self.facts['processor_count'] = i
|
||||
self.facts['processor_cores'] = i
|
||||
self.facts['processor_threads_per_core'] = 1
|
||||
self.facts['processor_vcpus'] = i
|
||||
else:
|
||||
self.facts['processor_count'] = sockets and len(sockets) or i
|
||||
self.facts['processor_cores'] = sockets.values() and sockets.values()[0] or 1
|
||||
self.facts['processor_threads_per_core'] = ((cores.values() and
|
||||
cores.values()[0] or 1) / self.facts['processor_cores'])
|
||||
self.facts['processor_vcpus'] = (self.facts['processor_threads_per_core'] *
|
||||
self.facts['processor_count'] * self.facts['processor_cores'])
|
||||
|
||||
def get_dmi_facts(self):
|
||||
''' learn dmi facts from system
|
||||
@@ -1355,7 +1424,7 @@ class HPUX(Hardware):
|
||||
self.facts['memtotal_mb'] = int(data) / 1024
|
||||
except AttributeError:
|
||||
#For systems where memory details aren't sent to syslog or the log has rotated, use parsed
|
||||
#adb output. Unfortunatley /dev/kmem doesn't have world-read, so this only works as root.
|
||||
#adb output. Unfortunately /dev/kmem doesn't have world-read, so this only works as root.
|
||||
if os.access("/dev/kmem", os.R_OK):
|
||||
rc, out, err = module.run_command("echo 'phys_mem_pages/D' | adb -k /stand/vmunix /dev/kmem | tail -1 | awk '{print $2}'", use_unsafe_shell=True)
|
||||
if not err:
|
||||
|
||||
@@ -32,7 +32,7 @@ import pprint
|
||||
USER_AGENT_PRODUCT="Ansible-gce"
|
||||
USER_AGENT_VERSION="v1"
|
||||
|
||||
def gce_connect(module):
|
||||
def gce_connect(module, provider=None):
|
||||
"""Return a Google Cloud Engine connection."""
|
||||
service_account_email = module.params.get('service_account_email', None)
|
||||
pem_file = module.params.get('pem_file', None)
|
||||
@@ -71,8 +71,14 @@ def gce_connect(module):
|
||||
'secrets file.')
|
||||
return None
|
||||
|
||||
# Allow for passing in libcloud Google DNS (e.g, Provider.GOOGLE)
|
||||
if provider is None:
|
||||
provider = Provider.GCE
|
||||
|
||||
try:
|
||||
gce = get_driver(Provider.GCE)(service_account_email, pem_file, datacenter=module.params.get('zone'), project=project_id)
|
||||
gce = get_driver(provider)(service_account_email, pem_file,
|
||||
datacenter=module.params.get('zone', None),
|
||||
project=project_id)
|
||||
gce.connection.user_agent_append("%s/%s" % (
|
||||
USER_AGENT_PRODUCT, USER_AGENT_VERSION))
|
||||
except (RuntimeError, ValueError), e:
|
||||
|
||||
@@ -40,7 +40,7 @@ def add_git_host_key(module, url, accept_hostkey=True, create_dir=True):
|
||||
|
||||
""" idempotently add a git url hostkey """
|
||||
|
||||
fqdn = get_fqdn(module.params['repo'])
|
||||
fqdn = get_fqdn(url)
|
||||
|
||||
if fqdn:
|
||||
known_host = check_hostkey(module, fqdn)
|
||||
|
||||
@@ -252,9 +252,33 @@ class SSLValidationHandler(urllib2.BaseHandler):
|
||||
except:
|
||||
self.module.fail_json(msg='Connection to proxy failed')
|
||||
|
||||
def detect_no_proxy(self, url):
|
||||
'''
|
||||
Detect if the 'no_proxy' environment variable is set and honor those locations.
|
||||
'''
|
||||
env_no_proxy = os.environ.get('no_proxy')
|
||||
if env_no_proxy:
|
||||
env_no_proxy = env_no_proxy.split(',')
|
||||
netloc = urlparse.urlparse(url).netloc
|
||||
|
||||
for host in env_no_proxy:
|
||||
if netloc.endswith(host) or netloc.split(':')[0].endswith(host):
|
||||
# Our requested URL matches something in no_proxy, so don't
|
||||
# use the proxy for this
|
||||
return False
|
||||
return True
|
||||
|
||||
def http_request(self, req):
|
||||
tmp_ca_cert_path, paths_checked = self.get_ca_certs()
|
||||
https_proxy = os.environ.get('https_proxy')
|
||||
|
||||
# Detect if 'no_proxy' environment variable is set and if our URL is included
|
||||
use_proxy = self.detect_no_proxy(req.get_full_url())
|
||||
|
||||
if not use_proxy:
|
||||
# ignore proxy settings for this host request
|
||||
return req
|
||||
|
||||
try:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
if https_proxy:
|
||||
|
||||
Reference in New Issue
Block a user