-
Notifications
You must be signed in to change notification settings - Fork 119
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
Allow to call RegisterWithActivationKeys() with enable_content #3488
Allow to call RegisterWithActivationKeys() with enable_content #3488
Conversation
* When D-Bus method Register() was called with enable_content option and the value was "false" or "0", then code evaluated this value as True. * Fixed this issue, because previous behavior was very confusing * Refactored code a little bit. * The method is static method * It is possible to set default value, when enable_content was not set at all.
* Converted method to static method * Deleted dead code * Deleted empty lines
Coverage (computed on Fedora latest) •
|
54329a3
to
cb97911
Compare
In case the implementation is done- I tried using this subman build on rhel 10 with rhc copr builds that support this feature. I hit the same error as before when using activation key. Sharing the logs from rhsm.log- |
@Archana-PandeyM Did you manually restart |
I can confirm that it works as expected, when service is restarted. |
Thanks George! I checked too it works after the service is restarted. |
To test this change you can use #!/bin/bash
source ./library.sh
export org_id="donaldduck"
export activation_key="awesome_os_pool"
start_register_server
# Try to register using activation key and org
echo "Registering using activation key and org..."
dbus-send --address=${my_addr} --print-reply --dest='com.redhat.RHSM1.Register' \
'/com/redhat/RHSM1/Register' \
com.redhat.RHSM1.Register.RegisterWithActivationKeys \
string:"${org_id}" \
array:string:"${activation_key}" \
dict:string:string:"enable_content","0" \
dict:string:string:"","" \
string:"" | gawk '/string/{ $1 = ""; print $0; }' | sed 's/\"//' | sed 's/\(.*\)\"/\1/' > /root/register_output.json
print_registration_result $?
stop_register_server
# unregister |
I was able to reproduce that without this patch, the Now, I’m going to verify that argument does what it’s intended to do. Also, I‘ll check the code. Tampering with the
Subscription Manager should probably handle missing DBus parameter more gracefully. |
The error was raised from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I can approve. I was not successful with running the DBus command, but Archana confirmed that part. I don’t want to block the PR for too long. I looked at the code and it makes sense. I only nitpicked a few boolean expressions, but they are non-blocking comments.
src/rhsmlib/dbus/objects/register.py
Outdated
ent_cert_lib = EntCertActionInvoker() | ||
ent_cert_lib.update() | ||
# When consumer is created, we can try to enable content, if requested. | ||
if enable_content is True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enable_content
is bool
, so if enable_content
means effectively the same.
if enable_content is True: | |
if enable_content: |
src/rhsmlib/dbus/objects/register.py
Outdated
if is_true_value(enable_content): | ||
return True | ||
else: | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if is_true_value(enable_content): | |
return True | |
else: | |
return False | |
return is_true_value(enable_content): |
* Allow to call D-Bus method RegisterWithActivationKeys() with register option enable_content. When this option is not set, then behavior is still the same. It means that content is enabled by default, when system is registered with this D-Bus method. * Added two unit tests
cb97911
to
b5bf151
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a look at the new tests. I didn’t examine them to the detail, but they make sense to me. I tried to run them and they succeed. Suggested a parametrization, but that’s not necessary. The other changes look perfect.
Two unrelated tests fail when run with a non-en_US
locale. I‘ll file tickets for those.
def test_RegisterWithActivationKeys__with_enable_content_option(self): | ||
expected = json.loads(CONSUMER_CONTENT_JSON_SCA) | ||
self.patches["is_registered"].return_value = False | ||
self.patches["register"].return_value = expected | ||
|
||
result = self.impl.register_with_activation_keys( | ||
"username", | ||
{"keys": ["key1", "key2"], "enable_content": "true"}, | ||
{"host": "localhost", "port": "8443", "handler": "/candlepin"}, | ||
) | ||
self.assertEqual(expected, result) | ||
|
||
def test_RegisterWithActivationKeys__with_disable_content_option(self): | ||
expected = json.loads(CONSUMER_CONTENT_JSON_SCA) | ||
self.patches["is_registered"].return_value = False | ||
self.patches["register"].return_value = expected | ||
|
||
result = self.impl.register_with_activation_keys( | ||
"username", | ||
{"keys": ["key1", "key2"], "enable_content": "false"}, | ||
{"host": "localhost", "port": "8443", "handler": "/candlepin"}, | ||
) | ||
self.assertEqual(expected, result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two tests only differ in the "enable_content"
value. They can be parametrized.
def test_RegisterWithActivationKeys__with_enable_content_option(self): | |
expected = json.loads(CONSUMER_CONTENT_JSON_SCA) | |
self.patches["is_registered"].return_value = False | |
self.patches["register"].return_value = expected | |
result = self.impl.register_with_activation_keys( | |
"username", | |
{"keys": ["key1", "key2"], "enable_content": "true"}, | |
{"host": "localhost", "port": "8443", "handler": "/candlepin"}, | |
) | |
self.assertEqual(expected, result) | |
def test_RegisterWithActivationKeys__with_disable_content_option(self): | |
expected = json.loads(CONSUMER_CONTENT_JSON_SCA) | |
self.patches["is_registered"].return_value = False | |
self.patches["register"].return_value = expected | |
result = self.impl.register_with_activation_keys( | |
"username", | |
{"keys": ["key1", "key2"], "enable_content": "false"}, | |
{"host": "localhost", "port": "8443", "handler": "/candlepin"}, | |
) | |
self.assertEqual(expected, result) | |
@pytest.mark.parametrize(("enable_content",), [("true",), ("false",)]) | |
def test_RegisterWithActivationKeys__with_enable_content_option(self, enable_content): | |
expected = json.loads(CONSUMER_CONTENT_JSON_SCA) | |
self.patches["is_registered"].return_value = False | |
self.patches["register"].return_value = expected | |
result = self.impl.register_with_activation_keys( | |
"username", | |
{"keys": ["key1", "key2"], "enable_content": enable_content}, | |
{"host": "localhost", "port": "8443", "handler": "/candlepin"}, | |
) | |
self.assertEqual(expected, result) |
RegisterWithActivationKeys()
withregister option
enable_content
. When this option is not set,then behavior is still the same. It means that content is
enabled by default, when system is registered with this D-Bus
method.