2021-01-08 13:41:50 +01:00
|
|
|
From 8c7ee66166b9b5a47cdd5150a0db35052e5afbac Mon Sep 17 00:00:00 2001
|
2019-01-17 10:18:02 +01:00
|
|
|
From: Bo Maryniuk <bo@suse.de>
|
|
|
|
Date: Wed, 17 Oct 2018 14:10:47 +0200
|
|
|
|
Subject: [PATCH] Support-config non-root permission issues fixes
|
|
|
|
(U#50095)
|
|
|
|
|
|
|
|
Do not crash if there is no configuration available at all
|
|
|
|
|
|
|
|
Handle CLI and log errors
|
|
|
|
|
|
|
|
Catch overwriting exiting archive error by other users
|
|
|
|
|
|
|
|
Suppress excessive tracebacks on error log level
|
|
|
|
---
|
2021-01-08 13:41:50 +01:00
|
|
|
salt/cli/support/collector.py | 43 +++++++++++++++++++++++++++++++----
|
2019-01-17 10:18:02 +01:00
|
|
|
salt/utils/parsers.py | 2 +-
|
2021-01-08 13:41:50 +01:00
|
|
|
2 files changed, 39 insertions(+), 6 deletions(-)
|
2019-01-17 10:18:02 +01:00
|
|
|
|
|
|
|
diff --git a/salt/cli/support/collector.py b/salt/cli/support/collector.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index bfbf491f5b..a08a0b8c6e 100644
|
2019-01-17 10:18:02 +01:00
|
|
|
--- a/salt/cli/support/collector.py
|
|
|
|
+++ b/salt/cli/support/collector.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -124,6 +124,31 @@ class SupportDataCollector:
|
2019-01-17 10:18:02 +01:00
|
|
|
self.__current_section = []
|
|
|
|
self.__current_section_name = name
|
|
|
|
|
|
|
|
+ def _printout(self, data, output):
|
2021-01-08 13:41:50 +01:00
|
|
|
+ """
|
2019-01-17 10:18:02 +01:00
|
|
|
+ Use salt outputter to printout content.
|
|
|
|
+
|
|
|
|
+ :return:
|
2021-01-08 13:41:50 +01:00
|
|
|
+ """
|
|
|
|
+ opts = {"extension_modules": "", "color": False}
|
2019-01-17 10:18:02 +01:00
|
|
|
+ try:
|
|
|
|
+ printout = salt.output.get_printout(output, opts)(data)
|
|
|
|
+ if printout is not None:
|
|
|
|
+ return printout.rstrip()
|
|
|
|
+ except (KeyError, AttributeError, TypeError) as err:
|
|
|
|
+ log.debug(err, exc_info=True)
|
|
|
|
+ try:
|
2021-01-08 13:41:50 +01:00
|
|
|
+ printout = salt.output.get_printout("nested", opts)(data)
|
2019-01-17 10:18:02 +01:00
|
|
|
+ if printout is not None:
|
|
|
|
+ return printout.rstrip()
|
|
|
|
+ except (KeyError, AttributeError, TypeError) as err:
|
|
|
|
+ log.debug(err, exc_info=True)
|
2021-01-08 13:41:50 +01:00
|
|
|
+ printout = salt.output.get_printout("raw", opts)(data)
|
2019-01-17 10:18:02 +01:00
|
|
|
+ if printout is not None:
|
|
|
|
+ return printout.rstrip()
|
|
|
|
+
|
|
|
|
+ return salt.output.try_printout(data, output, opts)
|
|
|
|
+
|
|
|
|
def write(self, title, data, output=None):
|
2021-01-08 13:41:50 +01:00
|
|
|
"""
|
2019-01-17 10:18:02 +01:00
|
|
|
Add a data to the current opened section.
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -137,9 +162,7 @@ class SupportDataCollector:
|
2019-01-17 10:18:02 +01:00
|
|
|
try:
|
2021-01-08 13:41:50 +01:00
|
|
|
if isinstance(data, dict) and "return" in data:
|
|
|
|
data = data["return"]
|
|
|
|
- content = salt.output.try_printout(
|
|
|
|
- data, output, {"extension_modules": "", "color": False}
|
|
|
|
- )
|
2019-01-17 10:18:02 +01:00
|
|
|
+ content = self._printout(data, output)
|
|
|
|
except Exception: # Fall-back to just raw YAML
|
|
|
|
content = None
|
|
|
|
else:
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -436,7 +459,11 @@ class SaltSupport(salt.utils.parsers.SaltSupportOptionParser):
|
|
|
|
and os.path.exists(self.config["support_archive"])
|
|
|
|
):
|
|
|
|
self.out.warning("Terminated earlier, cleaning up")
|
|
|
|
- os.unlink(self.config["support_archive"])
|
2019-01-17 10:18:02 +01:00
|
|
|
+ try:
|
2021-01-08 13:41:50 +01:00
|
|
|
+ os.unlink(self.config["support_archive"])
|
2019-01-17 10:18:02 +01:00
|
|
|
+ except Exception as err:
|
|
|
|
+ log.debug(err)
|
2021-01-08 13:41:50 +01:00
|
|
|
+ self.out.error("{} while cleaning up.".format(err))
|
2019-01-17 10:18:02 +01:00
|
|
|
|
|
|
|
def _check_existing_archive(self):
|
2021-01-08 13:41:50 +01:00
|
|
|
"""
|
|
|
|
@@ -452,7 +479,13 @@ class SaltSupport(salt.utils.parsers.SaltSupportOptionParser):
|
|
|
|
self.config["support_archive"]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
- os.unlink(self.config["support_archive"])
|
2019-01-17 10:18:02 +01:00
|
|
|
+ try:
|
2021-01-08 13:41:50 +01:00
|
|
|
+ os.unlink(self.config["support_archive"])
|
2019-01-17 10:18:02 +01:00
|
|
|
+ except Exception as err:
|
|
|
|
+ log.debug(err)
|
2021-01-08 13:41:50 +01:00
|
|
|
+ self.out.error(
|
|
|
|
+ "{} while trying to overwrite existing archive.".format(err)
|
|
|
|
+ )
|
2019-01-17 10:18:02 +01:00
|
|
|
ret = True
|
|
|
|
else:
|
2021-01-08 13:41:50 +01:00
|
|
|
self.out.warning(
|
2019-01-17 10:18:02 +01:00
|
|
|
diff --git a/salt/utils/parsers.py b/salt/utils/parsers.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index c1422a9556..cea59b387e 100644
|
2019-01-17 10:18:02 +01:00
|
|
|
--- a/salt/utils/parsers.py
|
|
|
|
+++ b/salt/utils/parsers.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -2157,7 +2157,7 @@ class SaltSupportOptionParser(
|
|
|
|
"""
|
2019-01-17 10:18:02 +01:00
|
|
|
_opts, _args = optparse.OptionParser.parse_args(self)
|
|
|
|
configs = self.find_existing_configs(_opts.support_unit)
|
|
|
|
- if cfg not in configs:
|
|
|
|
+ if configs and cfg not in configs:
|
|
|
|
cfg = configs[0]
|
|
|
|
|
|
|
|
return config.master_config(self.get_config_file_path(cfg))
|
|
|
|
--
|
2021-01-08 13:41:50 +01:00
|
|
|
2.29.2
|
2019-01-17 10:18:02 +01:00
|
|
|
|
|
|
|
|