aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2020-04-13 17:02:44 -0400
committerJake Hunsaker <jhunsake@redhat.com>2020-04-22 10:01:01 -0400
commita6c227d143a9b988e5a3594a1097b338e1a0a871 (patch)
tree5296881178cc84ceba88213184b95a5b72649824
parent0a9baa41928b58b76b533cac362e41fd123910c3 (diff)
downloadsos-a6c227d143a9b988e5a3594a1097b338e1a0a871.tar.gz
[linters] PEP8, PEP257, flake8 fixes
Various fixups for PEP8, PEP257, and unused imports as highlighted by flake8. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/collector/__init__.py77
-rw-r--r--sos/collector/clusters/__init__.py55
-rw-r--r--sos/collector/sosnode.py116
-rw-r--r--sos/policies/__init__.py20
-rw-r--r--sos/report/__init__.py8
5 files changed, 136 insertions, 140 deletions
diff --git a/sos/collector/__init__.py b/sos/collector/__init__.py
index 131bb006..f2ada569 100644
--- a/sos/collector/__init__.py
+++ b/sos/collector/__init__.py
@@ -11,13 +11,10 @@
import fnmatch
import inspect
import json
-import logging
import os
import random
import re
import string
-import tarfile
-import tempfile
import socket
import shutil
import subprocess
@@ -296,7 +293,7 @@ class SoSCollector(SoSComponent):
help="Encrypt the archive using a password")
def _check_for_control_persist(self):
- '''Checks to see if the local system supported SSH ControlPersist.
+ """Checks to see if the local system supported SSH ControlPersist.
ControlPersist allows OpenSSH to keep a single open connection to a
remote host rather than building a new session each time. This is the
@@ -312,7 +309,7 @@ class SoSCollector(SoSComponent):
Returns
True if ControlPersist is supported, else raise Exception.
- '''
+ """
ssh_cmd = ['ssh', '-o', 'ControlPersist']
cmd = subprocess.Popen(ssh_cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
@@ -323,7 +320,7 @@ class SoSCollector(SoSComponent):
return True
def _exit(self, msg, error=1):
- '''Used to safely terminate if sos-collector encounters an error'''
+ """Used to safely terminate if sos-collector encounters an error"""
self.log_error(msg)
try:
self.close_all_connections()
@@ -378,13 +375,13 @@ class SoSCollector(SoSComponent):
% (opt.cluster, opt.name))
def _validate_option(self, default, cli):
- '''Checks to make sure that the option given on the CLI is valid.
+ """Checks to make sure that the option given on the CLI is valid.
Valid in this sense means that the type of value given matches what a
cluster profile expects (str for str, bool for bool, etc).
For bool options, this will also convert the string equivalent to an
actual boolean value
- '''
+ """
if not default.opt_type == bool:
if not default.opt_type == cli.opt_type:
msg = "Invalid option type for %s. Expected %s got %s"
@@ -403,25 +400,25 @@ class SoSCollector(SoSComponent):
return False
def log_info(self, msg):
- '''Log info messages to both console and log file'''
+ """Log info messages to both console and log file"""
self.soslog.info(msg)
def log_warn(self, msg):
- '''Log warn messages to both console and log file'''
+ """Log warn messages to both console and log file"""
self.soslog.warn(msg)
def log_error(self, msg):
- '''Log error messages to both console and log file'''
+ """Log error messages to both console and log file"""
self.soslog.error(msg)
def log_debug(self, msg):
- '''Log debug message to both console and log file'''
+ """Log debug message to both console and log file"""
caller = inspect.stack()[1][3]
msg = '[sos_collector:%s] %s' % (caller, msg)
self.soslog.debug(msg)
def list_options(self):
- '''Display options for available clusters'''
+ """Display options for available clusters"""
sys.stdout.write('\nThe following clusters are supported by this '
'installation\n')
@@ -465,11 +462,11 @@ class SoSCollector(SoSComponent):
'"pacemaker.offline=False"\n')
def delete_tmp_dir(self):
- '''Removes the temp directory and all collected sosreports'''
+ """Removes the temp directory and all collected sosreports"""
shutil.rmtree(self.tmpdir)
def _get_archive_name(self):
- '''Generates a name for the tarball archive'''
+ """Generates a name for the tarball archive"""
nstr = 'sos-collector'
if self.opts.label:
nstr += '-%s' % self.opts.label
@@ -486,9 +483,9 @@ class SoSCollector(SoSComponent):
return '%s-%s-%s' % (nstr, dt, rand)
def _get_archive_path(self):
- '''Returns the path, including filename, of the tarball we build
+ """Returns the path, including filename, of the tarball we build
that contains the collected sosreports
- '''
+ """
self.arc_name = self._get_archive_name()
compr = 'gz'
return self.tmpdir + '/' + self.arc_name + '.tar.' + compr
@@ -501,7 +498,7 @@ class SoSCollector(SoSComponent):
return _fmt
def _load_group_config(self):
- '''
+ """
Attempts to load the host group specified on the command line.
Host groups are defined via JSON files, typically saved under
/var/lib/sos-collector/, although users can specify a full filepath
@@ -509,7 +506,7 @@ class SoSCollector(SoSComponent):
Host groups define a list of nodes and/or regexes and optionally the
master and cluster-type options.
- '''
+ """
if os.path.exists(self.opts.group):
fname = self.opts.group
elif os.path.exists(
@@ -533,13 +530,13 @@ class SoSCollector(SoSComponent):
self.opts.nodes.extend(_group['nodes'])
def write_host_group(self):
- '''
+ """
Saves the results of this run of sos-collector to a host group file
on the system so it can be used later on.
The host group will save the options master, cluster_type, and nodes
as determined by sos-collector prior to execution of sosreports.
- '''
+ """
cfg = {
'name': self.opts.save_group,
'master': self.opts.master,
@@ -671,7 +668,7 @@ class SoSCollector(SoSComponent):
self.ui_log.info('')
def configure_sos_cmd(self):
- '''Configures the sosreport command that is run on the nodes'''
+ """Configures the sosreport command that is run on the nodes"""
self.sos_cmd = 'sosreport --batch'
if self.opts.sos_opt_line:
filt = ['&', '|', '>', '<', ';']
@@ -706,9 +703,9 @@ class SoSCollector(SoSComponent):
self.commons['sos_cmd'] = self.sos_cmd
def connect_to_master(self):
- '''If run with --master, we will run cluster checks again that
+ """If run with --master, we will run cluster checks again that
instead of the localhost.
- '''
+ """
try:
self.master = SosNode(self.opts.master, self.commons)
self.ui_log.info('Connected to %s, determining cluster type...'
@@ -718,14 +715,14 @@ class SoSCollector(SoSComponent):
self._exit('Could not connect to master node. Aborting...', 1)
def determine_cluster(self):
- '''This sets the cluster type and loads that cluster's cluster.
+ """This sets the cluster type and loads that cluster's cluster.
If no cluster type is matched and no list of nodes is provided by
the user, then we abort.
If a list of nodes is given, this is not run, however the cluster
can still be run if the user sets a --cluster-type manually
- '''
+ """
self.cluster = None
checks = list(self.clusters.values())
for cluster in self.clusters.values():
@@ -757,15 +754,15 @@ class SoSCollector(SoSComponent):
break
def get_nodes_from_cluster(self):
- '''Collects the list of nodes from the determined cluster cluster'''
+ """Collects the list of nodes from the determined cluster cluster"""
if self.cluster_type:
nodes = self.cluster._get_nodes()
self.log_debug('Node list: %s' % nodes)
return nodes
def reduce_node_list(self):
- '''Reduce duplicate entries of the localhost and/or master node
- if applicable'''
+ """Reduce duplicate entries of the localhost and/or master node
+ if applicable"""
if (self.hostname in self.node_list and self.opts.no_local):
self.node_list.remove(self.hostname)
for i in self.ip_addrs:
@@ -781,8 +778,8 @@ class SoSCollector(SoSComponent):
self.log_debug('Node list reduced to %s' % self.node_list)
def compare_node_to_regex(self, node):
- '''Compares a discovered node name to a provided list of nodes from
- the user. If there is not a match, the node is removed from the list'''
+ """Compares a discovered node name to a provided list of nodes from
+ the user. If there is not a match, the node is removed from the list"""
for regex in self.opts.nodes:
try:
regex = fnmatch.translate(regex)
@@ -794,7 +791,7 @@ class SoSCollector(SoSComponent):
return False
def get_nodes(self):
- ''' Sets the list of nodes to collect sosreports from '''
+ """ Sets the list of nodes to collect sosreports from """
if not self.master and not self.cluster:
msg = ('Could not determine a cluster type and no list of '
'nodes or master node was provided.\nAborting...'
@@ -840,13 +837,13 @@ class SoSCollector(SoSComponent):
self.commons['hostlen'] = len(self.opts.master)
def _connect_to_node(self, node):
- '''Try to connect to the node, and if we can add to the client list to
+ """Try to connect to the node, and if we can add to the client list to
run sosreport on
Positional arguments
node - a tuple specifying (address, password). If no password, set
to None
- '''
+ """
try:
client = SosNode(node[0], self.commons, password=node[1])
client.set_cluster(self.cluster)
@@ -909,8 +906,8 @@ this utility or remote systems that it connects to.
self.cleanup()
def collect(self):
- ''' For each node, start a collection thread and then tar all
- collected sosreports '''
+ """ For each node, start a collection thread and then tar all
+ collected sosreports """
if self.master.connected:
self.client_list.append(self.master)
@@ -966,7 +963,7 @@ this utility or remote systems that it connects to.
self._exit(msg, 1)
def _collect(self, client):
- '''Runs sosreport on each node'''
+ """Runs sosreport on each node"""
try:
if not client.local:
client.sosreport()
@@ -979,14 +976,14 @@ this utility or remote systems that it connects to.
self.log_error("Error running sosreport: %s" % err)
def close_all_connections(self):
- '''Close all ssh sessions for nodes'''
+ """Close all ssh sessions for nodes"""
for client in self.client_list:
self.log_debug('Closing SSH connection to %s' % client.address)
client.close_ssh_session()
def create_cluster_archive(self):
- '''Calls for creation of tar archive then cleans up the temporary
- files created by sos-collector'''
+ """Calls for creation of tar archive then cleans up the temporary
+ files created by sos-collector"""
self.log_info('Creating archive of sosreports...')
try:
for host in self.client_list:
diff --git a/sos/collector/clusters/__init__.py b/sos/collector/clusters/__init__.py
index d66cb139..01abfdcc 100644
--- a/sos/collector/clusters/__init__.py
+++ b/sos/collector/clusters/__init__.py
@@ -9,7 +9,6 @@
# See the LICENSE file in the source distribution for further information.
import logging
-import subprocess
class Cluster():
@@ -22,7 +21,7 @@ class Cluster():
cluster_name = None
def __init__(self, commons):
- '''This is the class that cluster profile should subclass in order to
+ """This is the class that cluster profile should subclass in order to
add support for different clustering technologies and environments to
sos-collector.
@@ -30,7 +29,7 @@ class Cluster():
configured for the type of cluster the profile is intended to serve and
then additionall be able to return a list of enumerated nodes via the
get_nodes() method
- '''
+ """
self.master = None
self.cluster_ssh_key = None
@@ -48,14 +47,14 @@ class Cluster():
@classmethod
def name(cls):
- '''Returns the cluster's name as a string.
- '''
+ """Returns the cluster's name as a string.
+ """
if cls.cluster_name:
return cls.cluster_name
return cls.__name__.lower()
def _get_options(self):
- '''Loads the options defined by a cluster and sets the default value'''
+ """Loads the options defined by a cluster and sets the default value"""
for opt in self.option_list:
option = ClusterOption(name=opt[0], opt_type=opt[1].__class__,
value=opt[1], cluster=self.cluster_type,
@@ -66,25 +65,25 @@ class Cluster():
return '[%s] %s' % (self.cluster_type, msg)
def log_info(self, msg):
- '''Used to print info messages'''
+ """Used to print info messages"""
self.soslog.info(self._fmt_msg(msg))
def log_error(self, msg):
- '''Used to print error messages'''
+ """Used to print error messages"""
self.soslog.error(self._fmt_msg(msg))
def log_debug(self, msg):
- '''Used to print debug messages'''
+ """Used to print debug messages"""
self.soslog.debug(self._fmt_msg(msg))
def log_warn(self, msg):
- '''Used to print warning messages'''
+ """Used to print warning messages"""
self.soslog.warn(self._fmt_msg(msg))
def get_option(self, option):
- '''This is used to by clusters to check if a cluster option was
+ """This is used to by clusters to check if a cluster option was
supplied to sos-collector.
- '''
+ """
# check CLI before defaults
for opt in self.opts.cluster_options:
if opt.name == option and opt.cluster in self.cluster_type:
@@ -107,38 +106,38 @@ class Cluster():
self.cluster_ssh_key = key
def exec_master_cmd(self, cmd, need_root=False):
- '''Used to retrieve output from a (master) node in a cluster'''
+ """Used to retrieve output from a (master) node in a cluster"""
res = self.master.run_command(cmd, get_pty=True, need_root=need_root)
if res['stdout']:
res['stdout'] = res['stdout'].replace('Password:', '')
return res
def setup(self):
- '''This MAY be used by a cluster to do prep work in case there are
+ """This MAY be used by a cluster to do prep work in case there are
extra commands to be run even if a node list is given by the user, and
thus get_nodes() would not be called
- '''
+ """
pass
def check_enabled(self):
- '''This may be overridden by clusters
+ """This may be overridden by clusters
This is called by sos-collector on each cluster type that exists, and
is meant to return True when the cluster type matches a criteria
that indicates that is the cluster type is in use.
Only the first cluster type to determine a match is run
- '''
+ """
for pkg in self.packages:
if self.master.is_installed(pkg):
return True
return False
def get_nodes(self):
- '''This MUST be overridden by a cluster.
+ """This MUST be overridden by a cluster.
A cluster should use this method to return a list or string that
contains all the nodes that a report should be collected from
- '''
+ """
pass
def _get_nodes(self):
@@ -149,23 +148,23 @@ class Cluster():
return []
def get_node_label(self, node):
- '''Used by SosNode() to retrieve the appropriate label from the cluster
+ """Used by SosNode() to retrieve the appropriate label from the cluster
as set by set_node_label() in the cluster profile.
- '''
+ """
return self.set_node_label(node)
def set_node_label(self, node):
- '''This may be overridden by clusters.
+ """This may be overridden by clusters.
If there is a distinction between masters and nodes, or types of nodes,
then this can be used to label the sosreport archive differently.
- '''
+ """
return ''
def format_node_list(self):
- '''Format the returned list of nodes from a cluster into a known
+ """Format the returned list of nodes from a cluster into a known
format. This being a list that contains no duplicates
- '''
+ """
try:
nodes = self.get_nodes()
except Exception as e:
@@ -183,11 +182,11 @@ class Cluster():
return node_list
def _run_extra_cmd(self):
- '''Ensures that any files returned by a cluster's run_extra_cmd()
+ """Ensures that any files returned by a cluster's run_extra_cmd()
method are properly typed as a list for iterative collection. If any
of the files are an additional sosreport (e.g. the ovirt db dump) then
the md5 sum file is automatically added to the list
- '''
+ """
files = []
try:
res = self.run_extra_cmd()
@@ -205,7 +204,7 @@ class Cluster():
class ClusterOption():
- '''Used to store/manipulate options for cluster profiles.'''
+ """Used to store/manipulate options for cluster profiles."""
def __init__(self, name, value, opt_type, cluster, description=None):
self.name = name
diff --git a/sos/collector/sosnode.py b/sos/collector/sosnode.py
index 09561f7f..9a2a8fd6 100644
--- a/sos/collector/sosnode.py
+++ b/sos/collector/sosnode.py
@@ -77,7 +77,7 @@ class SosNode():
self._load_sos_info()
def _create_ssh_command(self):
- '''Build the complete ssh command for this node'''
+ """Build the complete ssh command for this node"""
cmd = "ssh -oControlPath=%s " % self.control_path
cmd += "%s@%s " % (self.opts.ssh_user, self.address)
return cmd
@@ -86,9 +86,9 @@ class SosNode():
return '{:<{}} : {}'.format(self._hostname, self.hostlen + 1, msg)
def check_in_container(self):
- '''
+ """
Tries to identify if we are currently running in a container or not.
- '''
+ """
if os.path.exists('/run/.containerenv'):
self.log_debug('Found /run/.containerenv. Running in container.')
return True
@@ -98,8 +98,8 @@ class SosNode():
return False
def create_sos_container(self):
- '''If the host is containerized, create the container we'll be using
- '''
+ """If the host is containerized, create the container we'll be using
+ """
if self.host.containerized:
res = self.run_command(self.host.create_sos_container())
if res['status'] in [0, 125]: # 125 means container exists
@@ -118,12 +118,12 @@ class SosNode():
raise Exception
def file_exists(self, fname):
- '''Checks for the presence of fname on the remote node'''
+ """Checks for the presence of fname on the remote node"""
if not self.local:
try:
res = self.run_command("stat %s" % fname)
return res['status'] == 0
- except Exception as err:
+ except Exception:
return False
else:
try:
@@ -140,54 +140,54 @@ class SosNode():
@property
def control_socket_exists(self):
- '''Check if the SSH control socket exists
+ """Check if the SSH control socket exists
The control socket is automatically removed by the SSH daemon in the
event that the last connection to the node was greater than the timeout
set by the ControlPersist option. This can happen for us if we are
collecting from a large number of nodes, and the timeout expires before
we start collection.
- '''
+ """
return os.path.exists(self.control_path)
def _sanitize_log_msg(self, msg):
- '''Attempts to obfuscate sensitive information in log messages such as
- passwords'''
+ """Attempts to obfuscate sensitive information in log messages such as
+ passwords"""
reg = r'(?P<var>(pass|key|secret|PASS|KEY|SECRET).*?=)(?P<value>.*?\s)'
return re.sub(reg, r'\g<var>****** ', msg)
def log_info(self, msg):
- '''Used to print and log info messages'''
+ """Used to print and log info messages"""
caller = inspect.stack()[1][3]
lmsg = '[%s:%s] %s' % (self._hostname, caller, msg)
self.soslog.info(lmsg)
self.ui_log.info(self._fmt_msg(msg))
def log_error(self, msg):
- '''Used to print and log error messages'''
+ """Used to print and log error messages"""
caller = inspect.stack()[1][3]
lmsg = '[%s:%s] %s' % (self._hostname, caller, msg)
self.soslog.error(lmsg)
self.ui_log.error(self._fmt_msg(msg))
def log_debug(self, msg):
- '''Used to print and log debug messages'''
+ """Used to print and log debug messages"""
msg = self._sanitize_log_msg(msg)
caller = inspect.stack()[1][3]
msg = '[%s:%s] %s' % (self._hostname, caller, msg)
self.soslog.debug(msg)
def get_hostname(self):
- '''Get the node's hostname'''
+ """Get the node's hostname"""
sout = self.run_command('hostname')
self.hostname = sout['stdout'].strip()
self.log_debug(
'Hostname set to %s' % self.hostname)
def _format_cmd(self, cmd):
- '''If we need to provide a sudo or root password to a command, then
+ """If we need to provide a sudo or root password to a command, then
here we prefix the command with the correct bits
- '''
+ """
if self.opts.become_root:
return "su -c %s" % quote(cmd)
if self.need_sudo:
@@ -195,7 +195,7 @@ class SosNode():
return cmd
def _fmt_output(self, output=None, rc=0):
- '''Formats the returned output from a command into a dict'''
+ """Formats the returned output from a command into a dict"""
if rc == 0:
stdout = output
stderr = ''
@@ -208,8 +208,8 @@ class SosNode():
return res
def _load_sos_info(self):
- '''Queries the node for information about the installed version of sos
- '''
+ """Queries the node for information about the installed version of sos
+ """
pkg = self.host.package_manager.pkg_version(self.host.sos_pkg_name)
if pkg:
ver = '.'.join(pkg['version'])
@@ -266,7 +266,7 @@ class SosNode():
return res
def read_file(self, to_read):
- '''Reads the specified file and returns the contents'''
+ """Reads the specified file and returns the contents"""
try:
self.log_debug("Reading file %s" % to_read)
if not self.local:
@@ -289,9 +289,9 @@ class SosNode():
return ''
def determine_host_policy(self):
- '''Attempts to identify the host installation against supported
+ """Attempts to identify the host installation against supported
distributions
- '''
+ """
host = load(cache={}, sysroot=self.opts.sysroot, init=InitSystem(),
probe_runtime=False, remote_exec=self.ssh_cmd,
remote_check=self.read_file('/etc/os-release'))
@@ -302,19 +302,19 @@ class SosNode():
raise UnsupportedHostException
def check_sos_version(self, ver):
- '''Checks to see if the sos installation on the node is AT LEAST the
+ """Checks to see if the sos installation on the node is AT LEAST the
given ver. This means that if the installed version is greater than
ver, this will still return True
- '''
+ """
return LooseVersion(self.sos_info['version']) >= ver
def is_installed(self, pkg):
- '''Checks if a given package is installed on the node'''
+ """Checks if a given package is installed on the node"""
return self.host.package_manager.pkg_by_name(pkg) is not None
def run_command(self, cmd, timeout=180, get_pty=False, need_root=False,
force_local=False, use_container=False):
- '''Runs a given cmd, either via the SSH session or locally
+ """Runs a given cmd, either via the SSH session or locally
Arguments:
cmd - the full command to be run
@@ -327,7 +327,7 @@ class SosNode():
force_local - force a command to run locally. Mainly used for scp.
use_container - Run this command in a container *IF* the host is
containerized
- '''
+ """
if not self.control_socket_exists and not self.local:
self.log_debug('Control socket does not exist, attempting to '
're-create')
@@ -375,7 +375,7 @@ class SosNode():
raise CommandTimeoutException(cmd)
def sosreport(self):
- '''Run a sosreport on the node, then collect it'''
+ """Run a sosreport on the node, then collect it"""
self.finalize_sos_cmd()
self.log_debug('Final sos command set to %s' % self.sos_cmd)
try:
@@ -391,7 +391,7 @@ class SosNode():
self.cleanup()
def _create_ssh_session(self):
- '''
+ """
Using ControlPersist, create the initial connection to the node.
This will generate an OpenSSH ControlPersist socket within the tmp
@@ -408,7 +408,7 @@ class SosNode():
Returns
True if session is successfully opened, else raise Exception
- '''
+ """
# Don't use self.ssh_cmd here as we need to add a few additional
# parameters to establish the initial connection
self.log_debug('Opening SSH session to create control socket')
@@ -478,7 +478,7 @@ class SosNode():
return False
def close_ssh_session(self):
- '''Remove the control socket to effectively terminate the session'''
+ """Remove the control socket to effectively terminate the session"""
if self.local:
return True
try:
@@ -494,27 +494,27 @@ class SosNode():
return False
def _preset_exists(self, preset):
- '''Verifies if the given preset exists on the node'''
+ """Verifies if the given preset exists on the node"""
return preset in self.sos_info['presets']
def _plugin_exists(self, plugin):
- '''Verifies if the given plugin exists on the node'''
+ """Verifies if the given plugin exists on the node"""
return any(plugin in s for s in [self.sos_info['enabled'],
self.sos_info['disabled']])
def _check_enabled(self, plugin):
- '''Checks to see if the plugin is default enabled on node'''
+ """Checks to see if the plugin is default enabled on node"""
return plugin in self.sos_info['enabled']
def _check_disabled(self, plugin):
- '''Checks to see if the plugin is default disabled on node'''
+ """Checks to see if the plugin is default disabled on node"""
return plugin in self.sos_info['disabled']
def _plugin_option_exists(self, opt):
- '''Attempts to verify that the given option is available on the node.
+ """Attempts to verify that the given option is available on the node.
Note that we only get available options for enabled plugins, so if a
plugin has been force-enabled we cannot validate if the plugin option
- is correct or not'''
+ is correct or not"""
plug = opt.split('.')[0]
if not self._plugin_exists(plug):
return False
@@ -528,8 +528,8 @@ class SosNode():
return True
def _fmt_sos_opt_list(self, opts):
- '''Returns a comma delimited list for sos plugins that are confirmed
- to exist on the node'''
+ """Returns a comma delimited list for sos plugins that are confirmed
+ to exist on the node"""
return ','.join(o for o in opts if self._plugin_exists(o))
def set_cluster(self, cluster):
@@ -539,13 +539,13 @@ class SosNode():
self.cluster = cluster
def update_cmd_from_cluster(self):
- '''This is used to modify the sosreport command run on the nodes.
+ """This is used to modify the sosreport command run on the nodes.
By default, sosreport is run without any options, using this will
allow the profile to specify what plugins to run or not and what
options to use.
This will NOT override user supplied options.
- '''
+ """
if self.cluster.sos_preset:
if not self.opts.preset:
self.opts.preset = self.cluster.sos_preset
@@ -566,8 +566,8 @@ class SosNode():
self.opts.plugin_options.append(option)
def finalize_sos_cmd(self):
- '''Use host facts and compare to the cluster type to modify the sos
- command if needed'''
+ """Use host facts and compare to the cluster type to modify the sos
+ command if needed"""
self.sos_cmd = self.sos_info['sos_cmd']
label = self.determine_sos_label()
if label:
@@ -628,7 +628,7 @@ class SosNode():
'not exist on node' % self.opts.preset)
def determine_sos_label(self):
- '''Determine what, if any, label should be added to the sosreport'''
+ """Determine what, if any, label should be added to the sosreport"""
label = ''
label += self.cluster.get_node_label(self)
@@ -648,8 +648,8 @@ class SosNode():
return '%s=%s' % (lcmd, label)
def finalize_sos_path(self, path):
- '''Use host facts to determine if we need to change the sos path
- we are retrieving from'''
+ """Use host facts to determine if we need to change the sos path
+ we are retrieving from"""
pstrip = self.host.sos_path_strip
if pstrip:
path = path.replace(pstrip, '')
@@ -672,7 +672,7 @@ class SosNode():
return 'sos exited with code %s' % rc
def execute_sos_command(self):
- '''Run sosreport and capture the resulting file path'''
+ """Run sosreport and capture the resulting file path"""
self.log_info("Generating sosreport...")
try:
path = False
@@ -699,7 +699,7 @@ class SosNode():
raise
def retrieve_file(self, path):
- '''Copies the specified file from the host to our temp dir'''
+ """Copies the specified file from the host to our temp dir"""
destdir = self.tmpdir + '/'
dest = destdir + path.split('/')[-1]
try:
@@ -729,9 +729,9 @@ class SosNode():
return False
def remove_file(self, path):
- '''Removes the spciefied file from the host. This should only be used
+ """Removes the spciefied file from the host. This should only be used
after we have retrieved the file already
- '''
+ """
path = ''.join(path.split())
try:
if len(path) <= 2: # ensure we have a non '/' path
@@ -752,7 +752,7 @@ class SosNode():
return False
def retrieve_sosreport(self):
- '''Collect the sosreport archive from the node'''
+ """Collect the sosreport archive from the node"""
if self.sos_path:
if self.need_sudo or self.opts.become_root:
try:
@@ -789,8 +789,8 @@ class SosNode():
return False
def remove_sos_archive(self):
- '''Remove the sosreport archive from the node, since we have
- collected it and it would be wasted space otherwise'''
+ """Remove the sosreport archive from the node, since we have
+ collected it and it would be wasted space otherwise"""
if self.sos_path is None:
return
if 'sosreport' not in self.sos_path:
@@ -802,7 +802,7 @@ class SosNode():
self.log_error('Failed to remove sosreport')
def cleanup(self):
- '''Remove the sos archive from the node once we have it locally'''
+ """Remove the sos archive from the node once we have it locally"""
self.remove_sos_archive()
if self.hash_retrieved:
self.remove_file(self.sos_path + '.md5')
@@ -811,7 +811,7 @@ class SosNode():
self.run_command(cleanup)
def collect_extra_cmd(self, filenames):
- '''Collect the file created by a cluster outside of sos'''
+ """Collect the file created by a cluster outside of sos"""
for filename in filenames:
try:
if self.need_sudo or self.opts.become_root:
@@ -833,11 +833,11 @@ class SosNode():
self.log_error(msg)
def make_archive_readable(self, filepath):
- '''Used to make the given archive world-readable, which is slightly
+ """Used to make the given archive world-readable, which is slightly
better than changing the ownership outright.
This is only used when we're not connecting as root.
- '''
+ """
cmd = 'chmod o+r %s' % filepath
res = self.run_command(cmd, timeout=10, need_root=True)
if res['status'] == 0:
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 1ddc4fc3..ffd6086e 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -1384,46 +1384,46 @@ class LinuxPolicy(Policy):
raise Exception("could not open archive file")
def set_sos_prefix(self):
- '''If sosreport commands need to always be prefixed with something,
+ """If sosreport commands need to always be prefixed with something,
for example running in a specific container image, then it should be
defined here.
If no prefix should be set, return an empty string instead of None.
- '''
+ """
return ''
def set_cleanup_cmd(self):
- '''If a host requires additional cleanup, the command should be set and
+ """If a host requires additional cleanup, the command should be set and
returned here
- '''
+ """
return ''
def create_sos_container(self):
- '''Returns the command that will create the container that will be
+ """Returns the command that will create the container that will be
used for running commands inside a container on hosts that require it.
This will use the container runtime defined for the host type to
launch a container. From there, we use the defined runtime to exec into
the container's namespace.
- '''
+ """
return ''
def restart_sos_container(self):
- '''Restarts the container created for sos-collector if it has stopped.
+ """Restarts the container created for sos-collector if it has stopped.
This is called immediately after create_sos_container() as the command
to create the container will exit and the container will stop. For
current container runtimes, subsequently starting the container will
default to opening a bash shell in the container to keep it running,
thus allowing us to exec into it again.
- '''
+ """
return "%s start %s" % (self.container_runtime,
self.sos_container_name)
def format_container_command(self, cmd):
- '''Returns the command that allows us to exec into the created
+ """Returns the command that allows us to exec into the created
container for sos-collector.
- '''
+ """
if self.container_runtime:
return '%s exec %s %s' % (self.container_runtime,
self.sos_container_name,
diff --git a/sos/report/__init__.py b/sos/report/__init__.py
index aaa3bee2..a4c462da 100644
--- a/sos/report/__init__.py
+++ b/sos/report/__init__.py
@@ -296,11 +296,11 @@ class SoSReport(SoSComponent):
# TODO: enumerate network devices, preferably with devtype info
def get_fibre_devs(self):
- '''Enumerate a list of fibrechannel devices on this system so that
+ """Enumerate a list of fibrechannel devices on this system so that
plugins can iterate over them
These devices are used by add_fibredev_cmd() in the Plugin class.
- '''
+ """
try:
devs = []
devdirs = [
@@ -317,11 +317,11 @@ class SoSReport(SoSComponent):
return []
def get_block_devs(self):
- '''Enumerate a list of block devices on this system so that plugins
+ """Enumerate a list of block devices on this system so that plugins
can iterate over them
These devices are used by add_blockdev_cmd() in the Plugin class.
- '''
+ """
try:
return os.listdir('/sys/block/')
except Exception as err: