Skip to content

Commit

Permalink
[ubuntu|Policy] Fix exception when attempting upload
Browse files Browse the repository at this point in the history
Fixes an issue where an upload attempt on Ubuntu systems would fail with
a traceback due to the upload archive's name not being available when we
first check to make sure we have an upload location, since the Ubuntu
default location requires an archive/file name.

Related to this, stop clobbering `upload_archive` and assign the archive
name to an `upload_archive_name` variable instead.

Closes: #2472
Resolves: #2479

Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
  • Loading branch information
TurboTurtle committed Apr 9, 2021
1 parent 297011d commit 3c90f65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions sos/policies/distros/__init__.py
Expand Up @@ -149,6 +149,7 @@ def pre_work(self):
self.upload_user = cmdline_opts.upload_user
self.upload_directory = cmdline_opts.upload_directory
self.upload_password = cmdline_opts.upload_pass
self.upload_archive_name = ''

if not cmdline_opts.batch and not \
cmdline_opts.quiet:
Expand Down Expand Up @@ -237,7 +238,7 @@ def upload_archive(self, archive):
`get_upload_url_string()`
Print a more human-friendly string than vendor URLs
"""
self.upload_archive = archive
self.upload_archive_name = archive
if not self.upload_url:
self.upload_url = self.get_upload_url()
if not self.upload_url:
Expand Down Expand Up @@ -384,7 +385,7 @@ def upload_https(self):
raise Exception("Unable to upload due to missing python requests "
"library")

with open(self.upload_archive, 'rb') as arc:
with open(self.upload_archive_name, 'rb') as arc:
if not self._use_https_streaming:
r = self._upload_https_no_stream(arc)
else:
Expand Down Expand Up @@ -467,9 +468,9 @@ def upload_ftp(self, url=None, directory=None, user=None, password=None):
% str(err))

try:
with open(self.upload_archive, 'rb') as _arcfile:
with open(self.upload_archive_name, 'rb') as _arcfile:
session.storbinary(
"STOR %s" % self.upload_archive.split('/')[-1],
"STOR %s" % self.upload_archive_name.split('/')[-1],
_arcfile
)
session.quit()
Expand Down
4 changes: 3 additions & 1 deletion sos/policies/distros/ubuntu.py
Expand Up @@ -74,7 +74,9 @@ def get_upload_url_string(self):

def get_upload_url(self):
if not self.upload_url or self.upload_url.startswith(self._upload_url):
fname = os.path.basename(self.upload_archive)
if not self.upload_archive_name:
return self._upload_url
fname = os.path.basename(self.upload_archive_name)
return self._upload_url + fname
super(UbuntuPolicy, self).get_upload_url()

Expand Down

0 comments on commit 3c90f65

Please sign in to comment.