-
Notifications
You must be signed in to change notification settings - Fork 991
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
fixes #5896 - unable to set compute-resource's 'Console passwords' option in API #1471
Conversation
👍 I think it'd be necessary to include a validation of |
@elobato, If I force
Any reason why? It seems a bug in |
It's not a bug, but it's certainly weird behavior. Force it to 0 instead which is apparently what submitting the form with it disabled does and seems to be the convention. |
@elobato, I refactored to remove the strange behavior when |
end | ||
|
||
def set_console_password=(setpw) | ||
self.attrs[:setpw] = setpw.to_i |
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.
This will cause an error if somebody passes a boolean into the API (which is what the API doc says), as to_i isn't defined on true/falseclass.
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.
This isn't called through API calls, update_attributes
updates self.attrs
directly without calling this setter method.
I tested this and it works well in the UI, however since API calls won't call to the setter method you wrote*, you need to either make API calls check that setpw is 0 or 1 (and change it in the docs) or only use true/false, and convert the 0/1 coming from the checkbox to true/false. I think the latter would be cleaner and we would get rid of the getter/setter.
|
@elobato, I submitted a new commit (to be squashed) that addresses your commits and added functional api tests. A user can pass |
def set_console_password? | ||
!(attrs[:setpw] == 0) # return true unless attrs[:setpw] is set to 0 | ||
end | ||
alias_method :set_console_password, :set_console_password? |
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.
alias_method
was also needed in STI class to work correctly, even though it appears in compute_resource.rb
Thanks, I tested it and this way it works well both through the API and the UI. One thing that concerns me is the duplication of code between libvirt.rb and vmware.rb. |
@elobato, I re-committed with the common code re-factored in a mixin (need to squash commit) |
Thanks, this is looking and working well. I meant to put a bit more shared stuff in mixins but that's for another PR. Merging in 3.. 2.. 1.. |
Merged as 553a0be , thanks @isratrade ! |
No description provided.