Blame SOURCES/sos-bz1882368-upload-functionality-issues.patch

bffc8a
From a3b493a8accc338158faa53b9e221067323b75f5 Mon Sep 17 00:00:00 2001
bffc8a
From: Jake Hunsaker <jhunsake@redhat.com>
bffc8a
Date: Thu, 24 Sep 2020 10:06:17 -0400
bffc8a
Subject: [PATCH] [redhat] Ease upload url determination logic
bffc8a
bffc8a
The logic for determining if an archive should be uploaded to the
bffc8a
Customer Portal was too strict, ease it to now properly only block on a
bffc8a
missing case number since username and passwords may now be provided via
bffc8a
env vars.
bffc8a
bffc8a
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
bffc8a
---
bffc8a
 sos/policies/__init__.py | 6 ++++--
bffc8a
 sos/policies/redhat.py   | 8 ++++++--
bffc8a
 2 files changed, 10 insertions(+), 4 deletions(-)
bffc8a
bffc8a
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
bffc8a
index 9a1aac07..215739bd 100644
bffc8a
--- a/sos/policies/__init__.py
bffc8a
+++ b/sos/policies/__init__.py
bffc8a
@@ -1427,8 +1427,8 @@ class LinuxPolicy(Policy):
bffc8a
         """Should be overridden by policies to determine if a password needs to
bffc8a
         be provided for upload or not
bffc8a
         """
bffc8a
-        if ((not self.upload_password and not self._upload_password) and
bffc8a
-                self.upload_user):
bffc8a
+        if not self.get_upload_password() and (self.get_upload_user() !=
bffc8a
+                                               self._upload_user):
bffc8a
             msg = (
bffc8a
                 "Please provide the upload password for %s: "
bffc8a
                 % self.upload_user
bffc8a
@@ -1472,7 +1473,8 @@ class LinuxPolicy(Policy):
bffc8a
             Print a more human-friendly string than vendor URLs
bffc8a
         """
bffc8a
         self.upload_archive = archive
bffc8a
-        self.upload_url = self.get_upload_url()
bffc8a
+        if not self.upload_url:
bffc8a
+            self.upload_url = self.get_upload_url()
bffc8a
         if not self.upload_url:
bffc8a
             raise Exception("No upload destination provided by policy or by "
bffc8a
                             "--upload-url")
bffc8a
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
bffc8a
index 34b421f3..f2f847a5 100644
bffc8a
--- a/sos/policies/redhat.py
bffc8a
+++ b/sos/policies/redhat.py
bffc8a
@@ -320,12 +320,16 @@ support representative.
bffc8a
                 "Enter your Red Hat Customer Portal username (empty to use "
bffc8a
                 "public dropbox): ")
bffc8a
             )
bffc8a
+            if not self.upload_user:
bffc8a
+                self.upload_url = RH_FTP_HOST
bffc8a
+                self.upload_user = self._upload_user
bffc8a
 
bffc8a
     def get_upload_url(self):
bffc8a
+        if self.upload_url:
bffc8a
+            return self.upload_url
bffc8a
         if self.commons['cmdlineopts'].upload_url:
bffc8a
             return self.commons['cmdlineopts'].upload_url
bffc8a
-        if (not self.case_id or not self.upload_user or not
bffc8a
-                self.upload_password):
bffc8a
+        if not self.case_id:
bffc8a
             # Cannot use the RHCP. Use anonymous dropbox
bffc8a
             self.upload_user = self._upload_user
bffc8a
             self.upload_directory = self._upload_directory
bffc8a
-- 
bffc8a
2.26.2
bffc8a
bffc8a
From 11cc6f478a9b41ce81b5b74faab5ca42930262ee Mon Sep 17 00:00:00 2001
bffc8a
From: Jake Hunsaker <jhunsake@redhat.com>
bffc8a
Date: Thu, 24 Sep 2020 10:17:25 -0400
bffc8a
Subject: [PATCH] [policy] Use user-provided FTP directory if specified
bffc8a
bffc8a
Fixes an issue whereby we ignore a user-provided FTP directory.
bffc8a
bffc8a
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
bffc8a
---
bffc8a
 sos/policies/__init__.py | 2 +-
bffc8a
 sos/policies/redhat.py   | 3 ++-
bffc8a
 2 files changed, 3 insertions(+), 2 deletions(-)
bffc8a
bffc8a
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
bffc8a
index 215739bd..32f271d9 100644
bffc8a
--- a/sos/policies/__init__.py
bffc8a
+++ b/sos/policies/__init__.py
bffc8a
@@ -1677,7 +1677,7 @@ class LinuxPolicy(Policy):
bffc8a
             password = self.get_upload_password()
bffc8a
 
bffc8a
         if not directory:
bffc8a
-            directory = self._upload_directory
bffc8a
+            directory = self.upload_directory or self._upload_directory
bffc8a
 
bffc8a
         try:
bffc8a
             session = ftplib.FTP(url, user, password)
bffc8a
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
bffc8a
index f2f847a5..d079406f 100644
bffc8a
--- a/sos/policies/redhat.py
bffc8a
+++ b/sos/policies/redhat.py
bffc8a
@@ -332,7 +332,8 @@ support representative.
bffc8a
         if not self.case_id:
bffc8a
             # Cannot use the RHCP. Use anonymous dropbox
bffc8a
             self.upload_user = self._upload_user
bffc8a
-            self.upload_directory = self._upload_directory
bffc8a
+            if self.upload_directory is None:
bffc8a
+                self.upload_directory = self._upload_directory
bffc8a
             self.upload_password = None
bffc8a
             return RH_FTP_HOST
bffc8a
         else:
bffc8a
-- 
bffc8a
2.26.2
bffc8a
bffc8a
From caa9a2f2a511689080d019ffab61a4de5787d8be Mon Sep 17 00:00:00 2001
bffc8a
From: Jake Hunsaker <jhunsake@redhat.com>
bffc8a
Date: Thu, 24 Sep 2020 10:25:00 -0400
bffc8a
Subject: [PATCH] [policy] Handle additional failure conditions for FTP uploads
bffc8a
bffc8a
Adds a timeout and a timeout handler for FTP connections, rather than
bffc8a
letting the connection attempt continue indefinitely.
bffc8a
bffc8a
Second, adds exception handling for an edge case where the connection to
bffc8a
the FTP server fails, but does not generate an exception from the ftplib
bffc8a
module.
bffc8a
bffc8a
Additionally, correct the type-ing of the error numbers being checked so
bffc8a
that we actually match them.
bffc8a
bffc8a
Resolves: #2245
bffc8a
bffc8a
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
bffc8a
---
bffc8a
 sos/policies/__init__.py | 11 ++++++++---
bffc8a
 1 file changed, 8 insertions(+), 3 deletions(-)
bffc8a
bffc8a
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
bffc8a
index 32f271d9..826d022e 100644
bffc8a
--- a/sos/policies/__init__.py
bffc8a
+++ b/sos/policies/__init__.py
bffc8a
@@ -1680,15 +1680,20 @@ class LinuxPolicy(Policy):
bffc8a
             directory = self.upload_directory or self._upload_directory
bffc8a
 
bffc8a
         try:
bffc8a
-            session = ftplib.FTP(url, user, password)
bffc8a
+            session = ftplib.FTP(url, user, password, timeout=15)
bffc8a
+            if not session:
bffc8a
+                raise Exception("connection failed, did you set a user and "
bffc8a
+                                "password?")
bffc8a
             session.cwd(directory)
bffc8a
+        except socket.timeout:
bffc8a
+            raise Exception("timeout hit while connecting to %s" % url)
bffc8a
         except socket.gaierror:
bffc8a
             raise Exception("unable to connect to %s" % url)
bffc8a
         except ftplib.error_perm as err:
bffc8a
             errno = str(err).split()[0]
bffc8a
-            if errno == 503:
bffc8a
+            if errno == '503':
bffc8a
                 raise Exception("could not login as '%s'" % user)
bffc8a
-            if errno == 550:
bffc8a
+            if errno == '550':
bffc8a
                 raise Exception("could not set upload directory to %s"
bffc8a
                                 % directory)
bffc8a
 
bffc8a
-- 
bffc8a
2.26.2
bffc8a
bffc8a
From 21720a0f8c9cf6739e26470b2280e005f0f3e3f1 Mon Sep 17 00:00:00 2001
bffc8a
From: Pavel Moravec <pmoravec@redhat.com>
bffc8a
Date: Thu, 15 Oct 2020 13:45:37 +0200
bffc8a
Subject: [PATCH] [policy] Use FTP server when user isnt set in batch mode
bffc8a
bffc8a
Caling "sos report --upload --case-id=123 --batch" should fallback
bffc8a
to uploading to FTP server as the upload user is unknown and can't
bffc8a
be prompted in batch mode.
bffc8a
bffc8a
Resolves: #2276
bffc8a
bffc8a
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
bffc8a
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
bffc8a
---
bffc8a
 sos/policies/redhat.py | 12 ++++++++++--
bffc8a
 1 file changed, 10 insertions(+), 2 deletions(-)
bffc8a
bffc8a
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
bffc8a
index d079406f..3a65b9fa 100644
bffc8a
--- a/sos/policies/redhat.py
bffc8a
+++ b/sos/policies/redhat.py
bffc8a
@@ -324,13 +324,21 @@ support representative.
bffc8a
                 self.upload_url = RH_FTP_HOST
bffc8a
                 self.upload_user = self._upload_user
bffc8a
 
bffc8a
+    def _upload_user_set(self):
bffc8a
+        user = self.get_upload_user()
bffc8a
+        return user and (user != 'anonymous')
bffc8a
+
bffc8a
     def get_upload_url(self):
bffc8a
         if self.upload_url:
bffc8a
             return self.upload_url
bffc8a
         if self.commons['cmdlineopts'].upload_url:
bffc8a
             return self.commons['cmdlineopts'].upload_url
bffc8a
-        if not self.case_id:
bffc8a
-            # Cannot use the RHCP. Use anonymous dropbox
bffc8a
+        # anonymous FTP server should be used as fallback when either:
bffc8a
+        # - case id is not set, or
bffc8a
+        # - upload user isn't set AND batch mode prevents to prompt for it
bffc8a
+        if (not self.case_id) or \
bffc8a
+           ((not self._upload_user_set()) and
bffc8a
+               self.commons['cmdlineopts'].batch):
bffc8a
             self.upload_user = self._upload_user
bffc8a
             if self.upload_directory is None:
bffc8a
                 self.upload_directory = self._upload_directory
bffc8a
-- 
bffc8a
2.26.2
bffc8a