Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sos] Add 'upload' component to upload existing reports and files #3746

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

jcastill
Copy link
Member

@jcastill jcastill commented Aug 9, 2024

This commit marks the beginning of the addition of a new 'upload' component for sos, which can be used to upload already created sos reports, collects, or other files like logs or vmcores to a policy defined location.

The user needs to specify a file location, and can make use of any of the options that exist nowadays for the --upload option.

This first commit includes:

  • The initial framework for the 'upload' component.
  • The new man page for 'sos upload'.
  • The code in the component 'help' to show information about the component.
  • The code in sos/init.py to deal with the component.
  • And modifications to setup.py to build the man pages.

Related: RHEL-23032, SUPDEV-138, CLIOT-481


Please place an 'X' inside each '[]' to confirm you adhere to our Contributor Guidelines

  • Is the commit message split over multiple lines and hard-wrapped at 72 characters?
  • Is the subject and message clear and concise?
  • Does the subject start with [plugin_name] if submitting a plugin patch or a [section_name] if part of the core sosreport code?
  • Does the commit contain a Signed-off-by: First Lastname email@example.com?
  • Are any related Issues or existing PRs properly referenced via a Closes (Issue) or Resolved (PR) line?
  • Are all passwords or private data gathered by this PR obfuscated?

@jcastill
Copy link
Member Author

jcastill commented Aug 9, 2024

Huge thanks to @pmoravec for all the help reviewing this, suggesting improvements, and finding bugs.
This is a first implementation of the 'upload' component, that can help users to upload already created sos or other files that support organizations can find useful.
In the future, the idea is to hook 'report' and 'collector' components to this one if the maintainers think is a good idea.

Copy link

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo yum install -y dnf-plugins-core on RHEL 8
  • sudo dnf install -y dnf-plugins-core on Fedora
  • dnf copr enable packit/sosreport-sos-3746
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

Copy link
Member

@arif-ali arif-ali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea

Some initial comments

man/en/sos-upload.1 Outdated Show resolved Hide resolved
man/en/sos-upload.1 Outdated Show resolved Hide resolved
sos/upload/__init__.py Outdated Show resolved Hide resolved
sos/upload/__init__.py Outdated Show resolved Hide resolved
@jcastill
Copy link
Member Author

jcastill commented Aug 9, 2024

@arif-ali about these ones:

sos/upload/init.py:103:0: C0325: Unnecessary parens after '=' keyword (superfluous-parens)
Fixed
sos/upload/init.py:141:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens)
Fixed
sos/upload/init.py:142:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens)
Fixed

************* Module sos.upload
sos/upload/init.py:47:8: R1725: Consider using Python 3 style super() without arguments (super-with-arguments)
Do I need to fix this one? Are we doing the same in the rest of the code, or is a nice-thing to have but not necessary?

sos/upload/init.py:42:46: W0613: Unused argument 'in_place' (unused-argument)
This is there to help with hooking report and others in the future, but can remove it now.

sos/upload/init.py:43:17: W0613: Unused argument 'hook_commons' (unused-argument)
Same as above as far as I know.

sos/upload/init.py:155:24: R1722: Consider using 'sys.exit' instead (consider-using-sys-exit)
I'll make this change now.

@jcastill jcastill force-pushed the jcastillo-add-upload-subsystem branch from d5b6c64 to 0e6bc72 Compare August 9, 2024 12:42
@arif-ali
Copy link
Member

arif-ali commented Aug 9, 2024

With R1725, I made the changes a few months back, and hence enabled the check, so let's do this here too.

With the unused variable. If your 100% sure you're going to be using them then potentially you could add the following before the line

#pylint: disable=unused-argument

@jcastill jcastill force-pushed the jcastillo-add-upload-subsystem branch from 0e6bc72 to 9c60d66 Compare August 9, 2024 13:46
@jcastill
Copy link
Member Author

jcastill commented Aug 9, 2024

With R1725, I made the changes a few months back, and hence enabled the check, so let's do this here too.

Done, should be in the version I just pushed.

With the unused variable. If your 100% sure you're going to be using them then potentially you could add the following before the line

#pylint: disable=unused-argument

Nice one! But I ended up removing it. I'll re-add them in the future when I have ready the code for hooking report etc.

@jcastill jcastill requested review from pmoravec and arif-ali August 13, 2024 10:51

.PP
.SH DESCRIPTION
upload is an sos subcommand to upload sos reports, logs, vmcores, or other files to a policy defined remote location, or an user defined one.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: s/an user/a user/.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is 'an' because 'user' starts with a vowel, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule is "first sound of word", not first letter :) E.g. https://english.stackexchange.com/questions/105116/is-it-a-user-or-an-user (though I am not sure how authoritative that source is).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, TIL. Fixed in the next push.

man/en/sos-upload.1 Outdated Show resolved Hide resolved
sos/help/__init__.py Outdated Show resolved Hide resolved
@@ -298,7 +298,7 @@ def get_upload_url(self):
self.ui_log.info("No case id provided, uploading to SFTP")
return RH_SFTP_HOST
rh_case_api = "/support/v1/cases/%s/attachments"
return RH_API_HOST + rh_case_api % self.case_id
return RH_API_HOST + rh_case_api % self.commons['cmdlineopts'].case_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? AFAIK self.case_id might be blank (and common's case_id set) only in scenario "case id not in cmdline, batch not in cmdline" - should not upload query for case_id, then? (or am I wrong here with my assumption)?

(that concern is valid for sure (while I can be wrong on its impact to this code change):

# python3 bin/sos upload /var/tmp/sosreport-pmoravec-rhel8-012345678-2024-08-13-gbiatgg.tar.xz

sos upload (version 4.7.2)
This utility is used to upload files to a policy-default location.

The archive to be uploaded may contain data considered sensitive and its content
should be reviewed by the originating organization before being passed to any
third party.

No configuration changes will be made to the system running this utility.


Press ENTER to continue, or CTRL-C to quit


Attempting to upload file /var/tmp/sosreport-pmoravec-rhel8-012345678-2024-08-13-gbiatgg.tar.xz to case 
No case id provided, uploading to SFTP
No case id provided, uploading to SFTP
Attempting upload to Red Hat Secure FTP
..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the things we talked about internally when I first started playing with 'upload'. If you remember, the issue was that without this change, we were getting 'None' on the case_id and it was failing to build the url, and so failed to upload. I have the feeling that I've done something wrong on the upload side and I'm not passing the case_id correctly.
My hope is that more experienced eyes, or at least fresher, can tell me where I'm failing.

@pmoravec
Copy link
Contributor

When I run:

python3 bin/sos upload /var/tmp/sosreport-pmoravec-rhel8-01234567-2024-08-13-gbiatgg.tar.xz

and "Press ENTER to continue", and then nothing, then I get a final error:

..
Attempting to upload file /var/tmp/sosreport-pmoravec-rhel8-01234567-2024-08-13-gbiatgg.tar.xz to case 
No case id provided, uploading to SFTP
No case id provided, uploading to SFTP
Attempting upload to Red Hat Secure FTP
Please visit the following URL to authenticate this device: https://sso.redhat.com/device?user_code=SOME-CODE
User anonUser used for anonymous upload. Please inform your support engineer so they may retrieve the data.
Upload attempt failed: 'RHELPolicy' object has no attribute 'upload_directory'

I think the upload did not succeed at the end..

defined location. These files can be either sos reports,
sos collections, or other kind of files like: vmcores,
application cores, logs, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line..?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this has been addressed, we could just remove the extra line

@pmoravec
Copy link
Contributor

When pressing Ctrl+C on ress ENTER to continue, or CTRL-C to quit prompt, I get backtrace:

Press ENTER to continue, or CTRL-C to quit
^CTraceback (most recent call last):
  File "/root/sos-main/sos/upload/__init__.py", line 120, in intro
    input(prompt)
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bin/sos", line 22, in <module>
    sos.execute()
  File "/root/sos-main/sos/__init__.py", line 187, in execute
    self._component.execute()
  File "/root/sos-main/sos/upload/__init__.py", line 137, in execute
    self.intro()
  File "/root/sos-main/sos/upload/__init__.py", line 123, in intro
    self.exit("Exiting on user cancel", 130)
AttributeError: 'SoSUpload' object has no attribute 'exit'

@jcastill
Copy link
Member Author

@pmoravec thank you for finding this, I thought we solved these issues:

When I run:

python3 bin/sos upload /var/tmp/sosreport-pmoravec-rhel8-01234567-2024-08-13-gbiatgg.tar.xz

and "Press ENTER to continue", and then nothing, then I get a final error:

..
Attempting to upload file /var/tmp/sosreport-pmoravec-rhel8-01234567-2024-08-13-gbiatgg.tar.xz to case 
No case id provided, uploading to SFTP
No case id provided, uploading to SFTP

I'll check the double messaging here, looks horrible.

Attempting upload to Red Hat Secure FTP
Please visit the following URL to authenticate this device: https://sso.redhat.com/device?user_code=SOME-CODE
User anonUser used for anonymous upload. Please inform your support engineer so they may retrieve the data.
Upload attempt failed: 'RHELPolicy' object has no attribute 'upload_directory'


I'll check this one as well, I remember we had a similar issue with a previous implementation.

I think the upload did not succeed at the end..

No, it should not succeed in that case.

@jcastill
Copy link
Member Author

When pressing Ctrl+C on ress ENTER to continue, or CTRL-C to quit prompt, I get backtrace:

Press ENTER to continue, or CTRL-C to quit
^CTraceback (most recent call last):
  File "/root/sos-main/sos/upload/__init__.py", line 120, in intro
    input(prompt)
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bin/sos", line 22, in <module>
    sos.execute()
  File "/root/sos-main/sos/__init__.py", line 187, in execute
    self._component.execute()
  File "/root/sos-main/sos/upload/__init__.py", line 137, in execute
    self.intro()
  File "/root/sos-main/sos/upload/__init__.py", line 123, in intro
    self.exit("Exiting on user cancel", 130)
AttributeError: 'SoSUpload' object has no attribute 'exit'

I'll check this, should be easy to fix.

@jcastill
Copy link
Member Author

When pressing Ctrl+C on ress ENTER to continue, or CTRL-C to quit prompt, I get backtrace:

Press ENTER to continue, or CTRL-C to quit
^CTraceback (most recent call last):
  File "/root/sos-main/sos/upload/__init__.py", line 120, in intro
    input(prompt)
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bin/sos", line 22, in <module>
    sos.execute()
  File "/root/sos-main/sos/__init__.py", line 187, in execute
    self._component.execute()
  File "/root/sos-main/sos/upload/__init__.py", line 137, in execute
    self.intro()
  File "/root/sos-main/sos/upload/__init__.py", line 123, in intro
    self.exit("Exiting on user cancel", 130)
AttributeError: 'SoSUpload' object has no attribute 'exit'

Fixed. I used exit() instead of _exit(), which is the one implemented in Soscomponent.

Copy link
Member

@TurboTurtle TurboTurtle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a bare minimum, a new component should be implementing all the abstractions that it needs to operate solo, not acting as a wrapper to existing functionality.

This means the upload logic needs to be separated from its current location in Policy, and implemented as a discrete unit. Policy should then control the default setting, and users should be able to direct sos to chose an upload target/profile/whatever we want to call it as an override. E.G. if I have an sos report locally on my Fedora workstation that was taken from a RHEL box, and I am unable due to some network policy to directly upload from the RHEL box, then on my Fedora system I should be able to send that sos report to Red Hat.

Further, any current or future usage of the component's functionality should go through the actual component code. Much like we do with sos clean, when --clean is used for a report being generated. We hook into the component from within report, to ensure we use the exact code flow for cleaning the archive as we would by running a clean after-the-fact.

@jcastill jcastill force-pushed the jcastillo-add-upload-subsystem branch from 9c60d66 to 72dd27c Compare August 13, 2024 15:16
@jcastill
Copy link
Member Author

At a bare minimum, a new component should be implementing all the abstractions that it needs to operate solo, not acting as a wrapper to existing functionality.

This means the upload logic needs to be separated from its current location in Policy, and implemented as a discrete unit. Policy should then control the default setting, and users should be able to direct sos to chose an upload target/profile/whatever we want to call it as an override. E.G. if I have an sos report locally on my Fedora workstation that was taken from a RHEL box, and I am unable due to some network policy to directly upload from the RHEL box, then on my Fedora system I should be able to send that sos report to Red Hat.

Further, any current or future usage of the component's functionality should go through the actual component code. Much like we do with sos clean, when --clean is used for a report being generated. We hook into the component from within report, to ensure we use the exact code flow for cleaning the archive as we would by running a clean after-the-fact.

I agree with everything above, but the idea behind this PR is to be a first implementation to get the upload component started, and then move things carefully from policy to upload. Could this approach be acceptable?

@pmoravec
Copy link
Contributor

I support this initial implementation of the feature to let enhance sos capabilities for a low cost. The discussion about refactorization (what precisely should be moved to some new *Upload* classes) can be lengthy, while we can already offer this feature as is.

I was thinking to raise the same concern, but I realized I would see beneficial for the discussion about refactorization if we already has some implementation in hand. With the current code, it is hard for me to specify "cut this away from here and put it (there)", if we have no "(there)". With the SosUpload class, I have better description of the "(there)". So having this initial implementation merged, it will be much more easier to have tat conversation - at least for me, this can be subjective.

If somebody sees as a potential threat "we accept this initial implementation, but will never refactor the code as needed, and we dont want that technical debt here", then I can make a commitment: once there will be an agreement about the refactorisation and if nobody(*) will have time to implement it, I will work on such PR.

(*) nobody including Jose as the primary person to implement. I assume he will be the primary person to make his own feature to make it complete. On the other side, there can be various reasons he won't be able to do the refactorisation (time, other work on sos, willingness, whatever). And then anybody else (with me as the volunteer with above commitment) can contribute that way.

@jcastill
Copy link
Member Author

If somebody sees as a potential threat "we accept this initial implementation, but will never refactor the code as needed, and we dont want that technical debt here", then I can make a commitment: once there will be an agreement about the refactorisation and if nobody(*) will have time to implement it, I will work on such PR.

(*) nobody including Jose as the primary person to implement. I assume he will be the primary person to make his own feature to make it complete. On the other side, there can be various reasons he won't be able to do the refactorisation (time, other work on sos, willingness, whatever). And then anybody else (with me as the volunteer with above commitment) can contribute that way.

On this note, I already started moving things around from policies/distros just after I sent this PR - this is not something I want to leave abandoned, or done in six months time or more, but as soon as possible. But also I want to make sure I cover all the possible cases, and the upload code in policies has been there for a long time, working perfectly, so want to be extra careful while refactoring.

Comment on lines +7 to +14
[--case-id id]\fR
[--upload-url url]\fR
[--upload-user user]\fR
[--upload-pass pass]\fR
[--upload-directory dir]\fR
[--upload-method]\fR
[--upload-no-ssl-verify]\fR
[--upload-protocol protocol]\fR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcastill Could the --upload-protocol s3 flags be included in this work? Unfortunately, it contains unique flags that made S3 easier to implement at the time.

  [--upload-s3-endpoint endpoint]
  [--upload-s3-region region]
  [--upload-s3-bucket bucket]
  [--upload-s3-access-key access_key]
  [--upload-s3-secret-key secret_key]
  [--upload-s3-object-prefix object_prefix]

The existing flags and how the provided values were used were not well aligned for S3, even though valid for FTP, HTTP, etc. protocols. I didn't want to cause any breakage for existing upload protocols while trying to make them work for all protocols, so S3 ended up with unique flags.

I planned to attempt a refactor at some point (sos v5?) where the original protocols and s3 overlap. For example, allowing synonymous flags:

  • --upload-user ~ --upload-s3-access-key
  • --upload-pass ~ --upload-s3-secret-key
  • --upload-directory ~ --upload-s3-object-prefix
  • --upload-url ~ --upload-s3-endpoint

However, I haven't been able to dedicate the time yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the --upload-protocol s3 flags be included in this work? Unfortunately, it contains unique flags that made S3 easier to implement at the time.

Yes, I'll make sure I include them in the next iteration of this PR.

I planned to attempt a refactor at some point (sos v5?) where the original protocols and s3 overlap. For example, allowing synonymous flags:

--upload-user ~ --upload-s3-access-key
--upload-pass ~ --upload-s3-secret-key
--upload-directory ~ --upload-s3-object-prefix
--upload-url ~ --upload-s3-endpoint

However, I haven't been able to dedicate the time yet.

Let me know if I can help. My original idea was to have this PR as a starting point and then move stuff out of the generic policy and the OS-specific ones in a second PR, but that was rejected, so I'm working on the full change now. As soon as I finish with that, we can start working on the refactor of S3 it that's OK with you. In fact we need to do some work with S3 uploads for the RH customer portal, so we could do both things in parallel.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if I can help. My original idea was to have this PR as a starting point and then move stuff out of the generic policy and the OS-specific ones in a second PR, but that was rejected, so I'm working on the full change now. As soon as I finish with that, we can start working on the refactor of S3 it that's OK with you. In fact we need to do some work with S3 uploads for the RH customer portal, so we could do both things in parallel.

When you have a branch published for public view and somewhat functional let me know. I'll branch off of it and start migrating the s3 portions in then submit a PR targeting your branch for you to review.


As for the s3 refactoring, we can look into it and I'd be more than happy to try and make some time. I believe a few lend themselves easily, or at least I don't immediately recall any issues with using them, like URL, user, and password. One I do recall bringing up some questions is the --upload-directory. For example, should this be only the prefixes inside the bucket? Or should it split the directory like {bucket}/{prefix} on only the first slash? There may have been others, but I would have to review the LinuxPolicy.get_upload_xxxx() functions and internal self._vars again.

Without some "group think" I decided not to implement something I (or others) may have been unhappy with later but stuck with unless making breaking changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be less to refactor than I first thought as I haven't reviewed the code in almost a year. I guess ended up implementing some of it already. Hope I'm still happy with my choices after a year 😄

def get_upload_s3_bucket(self):
"""Helper function to determine if we should use the policy default
upload bucket or one provided by the user
:returns: The S3 bucket to use for upload
:rtype: ``str``
"""
if self.upload_url and self.upload_url.startswith('s3://'):
bucket_and_prefix = self.upload_url[5:].split('/', 1)
self.upload_s3_bucket = bucket_and_prefix[0]
if len(bucket_and_prefix) > 1:
self.upload_s3_object_prefix = bucket_and_prefix[1]
if not self.upload_s3_bucket:
self.prompt_for_upload_s3_bucket()
return self.upload_s3_bucket or self._upload_s3_bucket

@arif-ali arif-ali added the Status/Need More Info Feedback is required to reproduce issue or to continue work label Nov 20, 2024
@jcastill
Copy link
Member Author

Latest push:

  • Removed unnecessary reference to skip_plugins.
  • Added a new function prompt_for_case_id() in line with what we have for user and password on the Red Hat Upload target code.

Copy link
Contributor

@pmoravec pmoravec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. Seems every test is passing (again), code reviewd as well. s3 uploads is worth to test, if possible.

@TrevorBenson
Copy link
Member

ACK. Seems every test is passing (again), code reviewd as well. s3 uploads is worth to test, if possible.

Apologies for delay, I was travelling to the EU when the comments on s3 were made. I'll try to test this PR for s3 uploads later today, or before Monday at the latest.

@jcastill
Copy link
Member Author

Thank you so much @TrevorBenson . I think we can wait until Monday, so you can enjoy your trip to Europe :)

@jcastill
Copy link
Member Author

jcastill commented Feb 5, 2025

Tests from Fedora:

# python bin/sos upload  --upload-target RHELUpload --upload-protocol s3 --upload-s3-endpoint https://sosreport.example.com --upload-s3-bucket projectb-sosreports /var/tmp/sosreport-test-upload-S3-from-fedora.tar.xz

sos upload (version 4.8.2)
This utility is used to upload files to a target location based either on a
command line option or detecting the local distribution.

The archive to be uploaded may contain data considered sensitive and its content
should be reviewed by the originating organization before being passed to any
third party.

No configuration changes will be made to the system running this utility.


Press ENTER to continue, or CTRL-C to quit


Optionally, please enter the case id that you are generating this report for: 03093474
Please provide the upload access key for bucket projectb-sosreports via endpoint https://sosreport.example.com: testtesttest
Please provide the upload secret key for bucket projectb-sosreports via endpoint https://sosreport.example.com: 

Attempting upload to Red Hat Customer Portal
Upload to Red Hat Customer Portal failed due to Failed to upload to S3: Could not connect to the endpoint URL: "https://sosreport.example.com/projectb-sosreports/sosreport-test-upload-S3-from-fedora.tar.xz?uploads". Trying sftp://sftp.access.redhat.com

And from RHEL:

# python bin/sos upload  --upload-protocol s3 --upload-s3-endpoint https://sosreport.example.com --upload-s3-bucket projectb-sosreports /var/tmp/sosreport-test-use-S3-protocol.tar.xz 

sos upload (version 4.8.2)
This utility is used to upload files to a target location based either on a
command line option or detecting the local distribution.

The archive to be uploaded may contain data considered sensitive and its content
should be reviewed by the originating organization before being passed to any
third party.

No configuration changes will be made to the system running this utility.


Press ENTER to continue, or CTRL-C to quit


Upload target set to Red Hat Upload Target
Optionally, please enter the case id that you are generating this report for: 03093474
Please provide the upload access key for bucket projectb-sosreports via endpoint https://sosreport.example.com: testtesttest
Please provide the upload secret key for bucket projectb-sosreports via endpoint https://sosreport.example.com: 

Attempting upload to Red Hat Customer Portal
Upload to Red Hat Customer Portal failed due to Failed to upload to S3: Could not connect to the endpoint URL: "https://sosreport.example.com/projectb-sosreports/sosreport-test-use-S3-protocol.tar.xz". Trying sftp://sftp.access.redhat.com
Attempting upload to Red Hat Secure FTP

Both fail as expected because I didn't have the right credentials, but I wanted to check that the actual code flow was working.

@TrevorBenson
Copy link
Member

I had some issues after installing dnf-plugins-core, trying to enable packit/sosreport-sos-3746 fails

$ sudo dnf copr enable packit/sosreport-sos-37464
 https://copr.fedorainfracloud.org/api_3/rpmrepo/packit/sosreport-sos-37464/fedora-41/                                                                                                               100% |  28.0   B/s |  59.0   B |  00m02s
>>> Status code: 404 for https://copr.fedorainfracloud.org/api_3/rpmrepo/packit/sosreport-sos-37464/fedora-41/ (IP: 3.225.109.36) - https://copr.fedorainfracloud.org/api_3/rpmrepo/packit/sosreport-sos-37464/fedora-41/
>>> Status code: 404 for https://copr.fedorainfracloud.org/api_3/rpmrepo/packit/sosreport-sos-37464/fedora-41/ (IP: 3.225.109.36) - https://copr.fedorainfracloud.org/api_3/rpmrepo/packit/sosreport-sos-37464/fedora-41/
>>> Status code: 404 for https://copr.fedorainfracloud.org/api_3/rpmrepo/packit/sosreport-sos-37464/fedora-41/ (IP: 3.225.109.36) - https://copr.fedorainfracloud.org/api_3/rpmrepo/packit/sosreport-sos-37464/fedora-41/
>>> Status code: 404 for https://copr.fedorainfracloud.org/api_3/rpmrepo/packit/sosreport-sos-37464/fedora-41/ (IP: 3.225.109.36) - https://copr.fedorainfracloud.org/api_3/rpmrepo/packit/sosreport-sos-37464/fedora-41/
>>> Status code: 404 for https://copr.fedorainfracloud.org/api_3/rpmrepo/packit/sosreport-sos-37464/fedora-41/ (IP: 3.225.109.36)Failed to download files
 Librepo error: Status code: 404 for https://copr.fedorainfracloud.org/api_3/rpmrepo/packit/sosreport-sos-37464/fedora-41/ (IP: 3.225.109.36)

I meant to get back to looking into this sooner, but had not had much free time. I'll give it another shot this evening to see if I can isolate why the Fedora 41 system is failing to install the packit RPM.

@pmoravec
Copy link
Contributor

pmoravec commented Feb 6, 2025

It seems we set up just rawhide? Since I fail the same also on F40 , while I see https://download.copr.fedorainfracloud.org/results/packit/sosreport-sos-3746/ exists.

And indeed, commands from https://dashboard.packit.dev/jobs/copr/2168507 do work:

sudo dnf install -y 'dnf*-command(copr)'
sudo dnf copr enable packit/sosreport-sos-3746 fedora-rawhide-x86_64
sudo dnf install -y sos-4.8.2-1.20250129125335854695.pr3746.13.g6e884c61.fc42.noarch

@TrevorBenson
Copy link
Member

sos upload: error: argument --upload-target: invalid choice: 'generic' (choose from 'RHELUpload', 'UbuntuUpload', 'local')

Is the --upload-target local supposed to work without presuming any defaults from Ubuntu or Red Hat? It seems to error out as if there was no --upload-target specified.

$ sos upload --upload-target local --upload-s3-bucket testilluminatus  --upload-s3-object-prefix XXXXXXXXXX/2025/01 --upload-protocol s3 /var/tmp/sosreport-fedora-2025-02-06-ymyzzom.tar.xz

sos upload (version 4.8.2)
This utility is used to upload files to a target location based either on a
command line option or detecting the local distribution.

The archive to be uploaded may contain data considered sensitive and its content
should be reviewed by the originating organization before being passed to any
third party.

No configuration changes will be made to the system running this utility.


Press ENTER to continue, or CTRL-C to quit


No upload target set via command line options or autodetected.
Please specify one using the option --upload-target.
Exiting.

@jcastill
Copy link
Member Author

jcastill commented Feb 6, 2025

sos upload: error: argument --upload-target: invalid choice: 'generic' (choose from 'RHELUpload', 'UbuntuUpload', 'local')

Is the --upload-target local supposed to work without presuming any defaults from Ubuntu or Red Hat? It seems to error out as if there was no --upload-target specified.

No upload target set via command line options or autodetected.
Please specify one using the option --upload-target.
Exiting.

I think this may be a consecuence of my change of target names. Let me fix it and push a new commit

@jcastill jcastill force-pushed the jcastillo-add-upload-subsystem branch from 6e884c6 to 06245ce Compare February 6, 2025 11:29
@jcastill
Copy link
Member Author

jcastill commented Feb 6, 2025

@TrevorBenson Try with target GenericUpload, i.e.:

bin/sos upload /var/tmp/sosreport-test-upload-S3-from-fedora.tar.xz --upload-s3-endpoint https://redhat.com --upload-s3-region <region> --upload-s3-bucket rh-cases --upload-protocol s3 --upload-target GenericUpload

Changing whatever you need from there.

I added GenericUpload explicitly, so 'local' will be used when the person running the command wants to detect the local target (and that is the default).

@TurboTurtle
Copy link
Member

TurboTurtle commented Feb 6, 2025

Wait...clarify something for me, as I don't have a RHEL box handy to explicitly test this with at the moment. Is the current design in this PR:

  1. Using just sos report --upload will determine the policy default target
    or
  2. Users are expected to now use sos report --upload-target rhel (or redhat edit: or local) explicitly each time?

Side note - I'd like it if, regardless of the answer to the above, users don't specify --upload-target RHELUpload but instead simply --upload-target rhel (or redhat)

@jcastill
Copy link
Member Author

jcastill commented Feb 6, 2025

Wait...clarify something for me, as I don't have a RHEL box handy to explicitly test this with at the moment. Is the current design in this PR:

1. Using just `sos report --upload` will determine the policy default target
   or

2. Users are expected to now use `sos report --upload-target rhel` (or `redhat` edit: or `local`) explicitly each time?

First option. So users can do:

a- Upload from RHEL, either:
a.1- Don't specify RHEL, it will be auto-determined.
a.2- Specify RHEL (if they want) or other, be it now generic or Ubuntu.
b- From Ubuntu, the same - either:
b.1- Don't specify Ubuntu, so it will be auto-determined, or
b.2- Specify Ubuntu (if they want) or other, be it generic or RHEL at the moment.

So when I tested uploads from RHEL I did an "implicit target" upload, i.e. not specifying; or specifying the others (so, weirdcase but still, upload to Ubuntu target from RHEL).
Same when I tested Ubuntu, I tested "implicit target", so Ubuntu target (that's what @arif-ali checked) and upload to RHEL target, that we verified in the portal.

Side note - I'd like it if, regardless of the answer to the above, users don't specify --upload-target RHELUpload but instead simply --upload-target rhel (or redhat)

I dislike *Upload (RHELUpload, UbuntuUpload, GenericUpload) as target names inmensely, so happy to change that as soon as possible to something that makes sense and doesn't get users' fingers exhausted. I imagine "redhat", "ubuntu", "generic", "local" could be better.

@pmoravec
Copy link
Contributor

pmoravec commented Feb 6, 2025

ACK to Jose's comment. Targets work like presets, automatically loaded but can be overriden, I verified that as well.

ACK to the rename of targets to e.g. redhat / ubuntu / generic / local (I suggest those strings in particular, all lowercase that is easier to type while e.g. RedHat or Redhat or Ubuntu strings suggest they are something "better" than local which would not be fair)

@jcastill
Copy link
Member Author

jcastill commented Feb 6, 2025

Actually, self selection of profile works well for existing profiles but not for non-explicit ones, so when @TrevorBenson ran his tests in Fedora, it wasn't selecting any,, and it has to do with one of the changes I did when moved from static to dynamic class selection for upload.
So in the next push I'll move the options to lowercase and simple names, and add a fix for generic uploads (i.e. so Fedora goes through the generic target).

@TrevorBenson
Copy link
Member

@TrevorBenson Try with target GenericUpload, i.e.:

bin/sos upload /var/tmp/sosreport-test-upload-S3-from-fedora.tar.xz --upload-s3-endpoint https://redhat.com --upload-s3-region <region> --upload-s3-bucket rh-cases --upload-protocol s3 --upload-target GenericUpload

Changing whatever you need from there.

I added GenericUpload explicitly, so 'local' will be used when the person running the command wants to detect the local target (and that is the default).

👍🏼

I've got a 6 hour layover in Munich tomorrow where I can focus on this testing.

@TurboTurtle
Copy link
Member

TurboTurtle commented Feb 6, 2025

ACK to the rename of targets

I dislike *Upload (RHELUpload, UbuntuUpload, GenericUpload) as target names inmensely

What I'm suggesting is that the class names are fine, but the strings the end users leverage should be friendlier. Like we do with plugins with the plugin_name class attr; we don't change the plugin name that users use with various options based on the class that gets instantiated. We could simply have a class attr added to the target class e.g. target_name, and that string is what gets referenced for whatever a user selects.

Like Pavel I prefer redhat to rhel for the upload. For consistency I would say canonical instead of ubuntu, but I'll defer to @arif-ali on that one.

@jcastill
Copy link
Member Author

jcastill commented Feb 7, 2025

ACK to the rename of targets

I dislike *Upload (RHELUpload, UbuntuUpload, GenericUpload) as target names inmensely

What I'm suggesting is that the class names are fine, but the strings the end users leverage should be friendlier. Like we do with plugins with the plugin_name class attr; we don't change the plugin name that users use with various options based on the class that gets instantiated. We could simply have a class attr added to the target class e.g. target_name, and that string is what gets referenced for whatever a user selects.

Yes, I meant the same, only user-facing options, I should have been clearer. This is how it looks now:

# bin/sos upload --help 
usage: sos upload FILE [options]

[...]
  --upload-no-ssl-verify
                        Disable SSL verification for upload url
  --upload-target {redhat,ubuntu,generic,local}
                        Manually specify vendor-specific target for uploads. Supported options are: redhat, ubuntu, generic, local


Like Pavel I prefer redhat to rhel for the upload. For consistency I would say canonical instead of ubuntu, but I'll defer to @arif-ali on that one.

This next version I'm trying to push at the moment still has 'ubuntu', but I can change it to 'canonical' pretty quickly.
@arif-ali which name do you prefer for the option?

@jcastill jcastill force-pushed the jcastillo-add-upload-subsystem branch from 06245ce to ace6660 Compare February 7, 2025 10:38
@jcastill
Copy link
Member Author

jcastill commented Feb 7, 2025

@TrevorBenson Try with target GenericUpload, i.e.:
bin/sos upload /var/tmp/sosreport-test-upload-S3-from-fedora.tar.xz --upload-s3-endpoint https://redhat.com --upload-s3-region <region> --upload-s3-bucket rh-cases --upload-protocol s3 --upload-target GenericUpload
Changing whatever you need from there.
I added GenericUpload explicitly, so 'local' will be used when the person running the command wants to detect the local target (and that is the default).

👍🏼

I've got a 6 hour layover in Munich tomorrow where I can focus on this testing.

@TrevorBenson thank you so much for testing this, I really appreciate you taking the time to do it.
I'm sorry I cannot test a proper S3 upload, I can only go as far as my tests above for now.

@TrevorBenson
Copy link
Member

TrevorBenson commented Feb 7, 2025

I tested RPM sos-4.8.2-1.20250207103936406048.pr3746.19.gace66602.fc43.noarch and uploads are successful. Using sos upload, both with and without defining --upload-target generic, on both an F41 container & F41 VM worked and the file was properly sent to the bucket. I also tested sos report --upload and confirmed it was still working as well.

@jcastill LGTM from my side on S3 protocol uploads.


All tests were using amazon AWS S3. I did find on bug while testing. However, I went ahead and went through comparisons to version 8 and 9 enterprise distributions to make sure they were still working as intended.

I've opened #3921 for tracking purposes to try and work out a fix before the packages make it into enterprise and the error is observed.


FWIW, I didn't find a CentOS Stream 9 container to perform testing with and downloading the Stream 9 ISO was a bit slow in the airport. So I skipped testing for this PR except for F41.

Given a packit repository for centos-stream-8, to go along with stream 9, I would test under both stream versions as well as F41 for any future s3, saltstack or other major changes I provide testing for. As sos has approval to be upgraded after Enhancements are no longer being applied to other packages in RHEL 8 it would be my preference to test thoroughly since they have diverged packages versions and when sos is updated, python3-boto3, botocore, etc. may not be getting updated as well, so creates a small possibility of testing only on rhel9/f41 in missing something that could impact rhel8.

@arif-ali
Copy link
Member

Like Pavel I prefer redhat to rhel for the upload. For consistency I would say canonical instead of ubuntu, but I'll defer to @arif-ali on that one.

This next version I'm trying to push at the moment still has 'ubuntu', but I can change it to 'canonical' pretty quickly. @arif-ali which name do you prefer for the option?

I think canonical makes more sense here in my opinion

"""

desc = """
Upload a file (can be a sos report, a must-gather, or others) to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super minor nit that I'm only highlighting since this string can be user facing: this should be "an sos report", as it is officially "ess oh ess" and not "sauce".

This commit marks the beginning of the addition of a new 'upload'
component for sos, which can be used to upload already created
sos reports, collects, or other files like logs or vmcores to
a policy defined location.

The user needs to specify a file location, and can make use of any
of the options that exist nowadays for the --upload option.

This first commit includes:
- The initial framework for the 'upload' component.
- The new man page for 'sos upload'.
- The code in the component 'help' to show information about
the component.
- The code in sos/__init__.py to deal with the component.
- The code for uploads to Red Hat and Ubuntu systems.
- The code to allow uploads specifying remote destination, called
targets in this implementation. For example, you could generate
a sos report in a CentOS system and specify a target defined as
'redhat' or 'RedHatUpload' to upload to the Red Hat Customer Portal.
- And modifications to setup.py to build the man pages.

Related: RHEL-23032, SUPDEV-138, CLIOT-481

Co-authored-by: Jose Castillo <jcastillo@redhat.com>
Co-authored-by: Pavel Moravec <pmoravec@redhat.com>
Co-authored-by: Trevor Benson <trevor.benson@gmail.com>
Signed-off-by: Jose Castillo <jcastillo@redhat.com>
@jcastill jcastill force-pushed the jcastillo-add-upload-subsystem branch from ace6660 to ab15651 Compare February 11, 2025 10:24
@jcastill
Copy link
Member Author

Thank you so much everyone for reviewing this PR and for all your suggestions. I moved the option name from 'ubuntu' to 'canonical' and fixed the 'a sos to 'an sos'. If there's nothing else, can you merged this PR?

@TurboTurtle TurboTurtle merged commit d75cef3 into sosreport:main Feb 11, 2025
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Kind/RedHat RedHat related item Kind/Ubuntu Ubuntu related item Status/Canonical Eng Canonical Engineering has been requested to review Status/Need More Info Feedback is required to reproduce issue or to continue work Status/RedHat Eng RedHat Engineering has been requested to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants