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
mgr/dashboard: Add backend support for changing dashboard configuration settings via the REST API #22457
Conversation
try: | ||
default, data_type = getattr(Options, attr) | ||
except AttributeError: | ||
raise cherrypy.HTTPError(404) |
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.
Consider to use DashboardException(http_status_code=404)
here.
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'd use cherrypy.NotFound()
try: | ||
setattr(Settings, self._to_native(name), value) | ||
except AttributeError: | ||
raise cherrypy.HTTPError(404) |
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.
Consider to use DashboardException(http_status_code=404)
here.
try: | ||
delattr(Settings, self._to_native(name)) | ||
except AttributeError: | ||
raise cherrypy.HTTPError(404) |
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.
Consider to use DashboardException(http_status_code=404)
here.
for name, value in kwargs.items(): | ||
setattr(Settings, self._to_native(name), value) | ||
except AttributeError: | ||
raise cherrypy.HTTPError(404) |
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.
Consider to use DashboardException(http_status_code=404)
here.
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.
does it make sense to refactor this into a separate method or function?
try: | ||
default, data_type = getattr(Options, attr) | ||
except AttributeError: | ||
raise cherrypy.HTTPError(404) |
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'd use cherrypy.NotFound()
def _to_native(setting): | ||
return setting.upper().replace('-', '_') | ||
|
||
def list(self): |
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.
def list(self):
return [self.get(name) for name in Options.__dict__]
??
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.
return [
json.loads(self.get(name)) for name in Options.__dict__
if name.isupper() and not name.startswith('_')
]
That would work, but it requires to unserialize the result of get
as the result is automatically serialized. Do you prefer this solution?
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.
why do you need to run json.loads
?
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.
The list
method of the RESTController
class is being modified at initialization, so that it returns the serialized version of the output of list
. I resolved this by creating a _get
method, like you proposed in our call.
for name, value in kwargs.items(): | ||
setattr(Settings, self._to_native(name), value) | ||
except AttributeError: | ||
raise cherrypy.HTTPError(404) |
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.
does it make sense to refactor this into a separate method or function?
9695fcf
to
8be01b6
Compare
c286808
to
20d3218
Compare
jenkins retest this please |
jenkins retest this please |
1 similar comment
jenkins retest this please |
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.
Please add integration (QA) tests for testing the Settings controller.
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've added some suggestions to improve the swagger API documentation.
with self._attribute_handler(name) as sname: | ||
delattr(Settings, self._to_native(sname)) | ||
|
||
def bulk_set(self, **kwargs): |
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.
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've looked into it and yes, I think it can be fixed but it's a general issue with generating the API documentation (or how the Endpoints are generated) for the bulk_set
method of the RestController
. Hence, I'd say it shouldn't be fixed in this PR.
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.
Thanks for the info. Agree, this should be fixed in a separate PR.
|
||
|
||
@ApiController('/settings', Scope.CONFIG_OPT) | ||
class SettingsController(RESTController): |
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.
Enables to change (set/unset) values of settings of the dashboard using the REST API. Fixes: https://tracker.ceph.com/issues/24273 Signed-off-by: Patrick Nawracay <pnawracay@suse.com>
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.
Lgtm
I don't have the feeling that the error is related to this pull request:
|
Enables to change (set/unset) values of settings of the dashboard using the REST API.
Fixes: https://tracker.ceph.com/issues/24273
Signed-off-by: Patrick Nawracay pnawracay@suse.com