Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def nginx_installed():
try:
subp.call('/usr/sbin/nginx -V')
return True
except:
return False
def teardown_method(self, method):
# use check=False because sometimes this returns code 123 on test-plus for some reason
subp.call('pgrep nginx | sudo xargs kill -9', check=False)
subp.call('rm -f %s' % self.conf_path, check=False)
super(RealNginxTempFileTestCase, self).teardown_method(method)
def reload_nginx(self):
subp.call('service nginx reload', check=False)
time.sleep(0.5)
def proc_cpuinfo(self):
""" cat /proc/cpuinfo """
proc_cpuinfo_out, _ = subp.call('cat /proc/cpuinfo')
for line in proc_cpuinfo_out:
kv = re.match(self.proc_cpuinfo_re, line)
if kv:
key, value = kv.group(1), kv.group(2)
if key.startswith('model name'):
self.meta['processor']['model'] = value
elif key.startswith('cpu cores'):
self.meta['processor']['cores'] = value
def version_parser(bin_path):
"""
Runs version command and parses verson of mysqld
:param bin_path: str bin path
:return: str version
"""
try:
raw_stdout, _ = subp.call(VERSION_CMD % bin_path)
# also trying to get the first line of output
# here's the line that we are interested in::
# mysqld Ver 5.5.55-0ubuntu0.14.04.1 for debian-linux-gnu on x86_64 ((Ubuntu))
raw_line = raw_stdout[0]
except Exception as e:
exc_name = e.__class__.__name__
# this is being logged as debug only since we will rely on bin_path
# collection error to tip off support as to what is going wrong with
# version detection
context.log.debug(
'failed to get version info from "%s" due to %s' %
(bin_path, exc_name)
)
context.log.debug('additional info:', exc_info=True)
else:
def linux_name():
try:
out, err = subp.call('cat /etc/*-release')
except AmplifySubprocessError:
try:
out, err = subp.call('uname -s')
return out[0].lower()
except AmplifySubprocessError:
return 'unix'
for line in out:
if line.startswith('ID='):
return line[3:].strip('"').lower()
full_output = '\n'.join(out).lower()
if 'oracle linux' in full_output:
return 'rhel'
elif 'red hat' in full_output:
return 'rhel'
elif 'centos' in full_output:
return 'centos'
else:
def linux_name():
try:
out, err = subp.call('cat /etc/*-release')
except AmplifySubprocessError:
try:
out, err = subp.call('uname -s')
return out[0].lower()
except AmplifySubprocessError:
return 'unix'
for line in out:
if line.startswith('ID='):
return line[3:].strip('"').lower()
full_output = '\n'.join(out).lower()
if 'oracle linux' in full_output:
return 'rhel'
elif 'red hat' in full_output:
return 'rhel'
def lscpu(self):
""" lscpu """
lscpu_out, _ = subp.call('lscpu')
for line in lscpu_out:
kv = re.match(self.lscpu_re, line)
if kv:
key, value = kv.group(1), kv.group(2)
if key == 'Architecture':
self.meta['processor']['architecture'] = value
elif key == 'CPU MHz':
self.meta['processor']['mhz'] = value
elif key == 'Hypervisor vendor':
self.meta['processor']['hypervisor'] = value
elif key == 'Virtualization type':
self.meta['processor']['virtualization'] = value
elif key == 'CPU(s)':
self.meta['processor']['cpus'] = value
elif 'cache' in key:
key = key.replace(' cache', '')
def proc_cpuinfo(meta):
""" cat /proc/cpuinfo """
proc_cpuinfo_out, _ = subp.call('cat /proc/cpuinfo')
for line in proc_cpuinfo_out:
kv = re.match('([\w|\s]+):\s*(.+)', line)
if kv:
key, value = kv.group(1), kv.group(2)
if key.startswith('model name'):
meta['processor']['model'] = value
elif key.startswith('cpu cores'):
meta['processor']['cores'] = value