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

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