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

feat: add GetEnvironments method to DBus register #3462

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

rverdile
Copy link
Contributor

@rverdile rverdile commented Oct 1, 2024

Card-ID: CCT-764

This implements the functionality requested in the card, but I would like to get guidance on how to architect the implementation. Perhaps I should be implementing an environments class? The get_environments method I created makes multiple calls to the candlepin API, which I don't see precedence for looking at the other DBus methods.

@rverdile rverdile force-pushed the 764 branch 4 times, most recently from f438b2e to 3c6b79b Compare October 4, 2024 17:08
@rverdile
Copy link
Contributor Author

rverdile commented Oct 4, 2024

tested using this script, a modified example from: https://github.com/jirihnidek/rhsm-dbus-examples/tree/main

#!/bin/bash

source ./library.sh

start_register_server
export username="admin"
export password="admin"
export org_id="content-sources-test"



echo "Trying to get list of organizations using dbus-send..."
dbus-send --address=${my_addr} --print-reply --dest='com.redhat.RHSM1.Register' \
       '/com/redhat/RHSM1/Register' \
       com.redhat.RHSM1.Register.GetEnvironments string:${username} \
       string:${password} \
       string:${org_id} \
       dict:string:string:"","" \
       string:""


stop_register_server

@rverdile rverdile marked this pull request as ready for review October 4, 2024 17:11
Copy link
Contributor

@ptoscano ptoscano left a comment

Choose a reason for hiding this comment

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

Thanks for this PR, and sorry for the wait.

I added a couple of notes of things I noticed so far; will give a better try later on.

src/rhsmlib/dbus/objects/register.py Outdated Show resolved Hide resolved
src/rhsmlib/dbus/objects/register.py Outdated Show resolved Hide resolved
src/rhsm/connection.py Outdated Show resolved Hide resolved
Copy link
Contributor

@jirihnidek jirihnidek left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I have few requests.

src/rhsmlib/dbus/objects/register.py Outdated Show resolved Hide resolved
@@ -181,6 +181,32 @@ def get_organizations(self, options: dict) -> List[dict]:
owners: List[dict] = uep.getOwnerList(options["username"])
return owners

def get_environments(self, options: dict) -> List[dict]:
Copy link
Contributor

Choose a reason for hiding this comment

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

This method should not be in rhsmlib.dbus.objects.register module. This module should contain only methods related to D-Bus. This proposed method should be in new rhsmlib.services.environment module, because you can see that subscription-manager CLI already has environments sub-command. Thus, there will be potential to share new code.

This method should have optional argument uep (basic auth connection to candlepin) to be able to pass existing connection instance to this method.

I this method had another argument typed_environments: bool = True, then we could list not only typed environments. If typed_environments is False, then we could skip detection for that capability on server.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding of the card is that the GetEnvironments() method is intended to be a DBus method. With that said, I moved the actual list call to candlepin to a newly created EnvironmentService class. I then instantiated that in the DBus method and used it to call to candlepin. Is that okay?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I'm misunderstanding your request, I'm happy to make more changes :)

src/rhsmlib/dbus/objects/register.py Outdated Show resolved Hide resolved
src/rhsmlib/dbus/objects/register.py Outdated Show resolved Hide resolved
src/rhsmlib/dbus/objects/register.py Outdated Show resolved Hide resolved
"type": "content-template"
}
]
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add more environments to this list. You will see that new unit test will start to fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added more environments to this list (10 more), but I don't see an issue. If you're seeing something else, what else can I do to reproduce?

Copy link
Contributor

Choose a reason for hiding this comment

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

If the old code was used, then the unit test would fail.

@rverdile rverdile force-pushed the 764 branch 2 times, most recently from 6926ca2 to af0d114 Compare October 9, 2024 20:12
@rverdile
Copy link
Contributor Author

rverdile commented Oct 9, 2024

Thank you guys for the reviews! I addressed most of the feedback, and left some questions where I'm not sure.

My team usually squashes commits before merging, so I just added a new commit for the feedback. Please let me know if I should organize my commits differently :)

I also still need to work on the tests a bit and fix the linting

src/rhsmlib/dbus/objects/register.py Outdated Show resolved Hide resolved
src/rhsmlib/dbus/objects/register.py Outdated Show resolved Hide resolved
src/rhsmlib/services/environment.py Outdated Show resolved Hide resolved
test/rhsmlib/dbus/test_register.py Outdated Show resolved Hide resolved
@rverdile
Copy link
Contributor Author

updated, thanks for the review!

Copy link
Contributor

@ptoscano ptoscano left a comment

Choose a reason for hiding this comment

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

Thanks for the updates! It seems to work fine, so I'm leaving a last round of miscellaneous minor changes to do the final polishing to this from my POV.

src/rhsmlib/services/environment.py Outdated Show resolved Hide resolved
src/rhsmlib/services/environment.py Outdated Show resolved Hide resolved
src/rhsmlib/services/environment.py Outdated Show resolved Hide resolved
src/rhsmlib/services/environment.py Outdated Show resolved Hide resolved
src/rhsmlib/services/environment.py Outdated Show resolved Hide resolved
test/rhsmlib/services/test_environment.py Outdated Show resolved Hide resolved
src/rhsmlib/dbus/objects/register.py Outdated Show resolved Hide resolved
src/rhsmlib/dbus/objects/register.py Outdated Show resolved Hide resolved
@rverdile
Copy link
Contributor Author

updated, thanks!

Copy link
Contributor

@ptoscano ptoscano left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! The code now LGTM, and it works well too.

Since @jirihnidek had notes/reviews, I'll approve leaving it to him for an additional review.

One small last thing from me (a forgotten previous comment from you, sorry):

My team usually squashes commits before merging, so I just added a new commit for the feedback. Please let me know if I should organize my commits differently :)

We generally don't squash commits on merging; would you please squash them in this PR, and provide a commit message that explains the changes done?

    * Card-ID: CCT-764
    * Method lists environments of the given org and returns a subset of the
      fields from candlepin
    * Provides a way to get the names of environments before registering
      in support of content templates
Copy link
Contributor

@jirihnidek jirihnidek left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks for updates

@jirihnidek jirihnidek merged commit 05870c4 into candlepin:main Nov 27, 2024
16 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants