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

mgr/dashboard: Add backend support for changing dashboard configuration settings via the REST API #22457

Merged
merged 1 commit into from Aug 14, 2018

Conversation

p-se
Copy link
Contributor

@p-se p-se commented Jun 7, 2018

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

try:
default, data_type = getattr(Options, attr)
except AttributeError:
raise cherrypy.HTTPError(404)
Copy link
Member

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.

Copy link
Contributor

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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.

Copy link
Contributor

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)
Copy link
Contributor

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):
Copy link
Contributor

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__]

??

Copy link
Contributor Author

@p-se p-se Jun 11, 2018

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

@LenzGr LenzGr changed the title mgr/dashboard: Add support for changing configuration settings via the UI mgr/dashboard: Add support for changing dashboard configuration settings via the UI Jun 11, 2018
@p-se p-se force-pushed the dash-settings branch 2 times, most recently from 9695fcf to 8be01b6 Compare June 11, 2018 12:47
@LenzGr LenzGr changed the title mgr/dashboard: Add support for changing dashboard configuration settings via the UI mgr/dashboard: Add backend support for changing dashboard configuration settings via the REST API Jun 15, 2018
@p-se p-se removed the needs-rebase label Jul 24, 2018
@p-se p-se force-pushed the dash-settings branch 2 times, most recently from c286808 to 20d3218 Compare July 25, 2018 12:32
@p-se
Copy link
Contributor Author

p-se commented Jul 26, 2018

jenkins retest this please

@p-se
Copy link
Contributor Author

p-se commented Jul 26, 2018

jenkins retest this please

1 similar comment
@s0nea
Copy link
Member

s0nea commented Jul 30, 2018

jenkins retest this please

rjfd
rjfd previously requested changes Aug 1, 2018
Copy link
Contributor

@rjfd rjfd left a 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.

@callithea
Copy link
Member

Copy link
Contributor

@ricardoasmarques ricardoasmarques left a 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):
Copy link
Contributor

Choose a reason for hiding this comment

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

The swagger API docs generator doesn't play well with this **kargs parameter (documentation says there is not parameters):

screenshot_20180809_160044

Is this something that can be fixed?

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'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.

Copy link
Contributor

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):
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we rename this controller to Settings, for consistency in the API documentation?

screenshot_20180809_160142

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>
Copy link
Contributor

@ricardoasmarques ricardoasmarques left a comment

Choose a reason for hiding this comment

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

Lgtm

@ricardoasmarques
Copy link
Contributor

@s0nea
Copy link
Member

s0nea commented Aug 13, 2018

I don't have the feeling that the error is related to this pull request:

2018-08-10T14:25:46.695 INFO:tasks.cephfs_test_runner:======================================================================
2018-08-10T14:25:46.696 INFO:tasks.cephfs_test_runner:FAIL: test_list (tasks.mgr.dashboard.test_rgw.RgwUserTest)
2018-08-10T14:25:46.696 INFO:tasks.cephfs_test_runner:----------------------------------------------------------------------
2018-08-10T14:25:46.696 INFO:tasks.cephfs_test_runner:Traceback (most recent call last):
2018-08-10T14:25:46.696 INFO:tasks.cephfs_test_runner:  File "/home/teuthworker/src/git.ceph.com_ceph-c_wip-lpaduano-testing-22457-2/qa/tasks/mgr/dashboard/test_rgw.py", line 260, in test_list
2018-08-10T14:25:46.696 INFO:tasks.cephfs_test_runner:    self.assertStatus(200)
2018-08-10T14:25:46.696 INFO:tasks.cephfs_test_runner:  File "/home/teuthworker/src/git.ceph.com_ceph-c_wip-lpaduano-testing-22457-2/qa/tasks/mgr/dashboard/helper.py", line 325, in assertStatus
2018-08-10T14:25:46.696 INFO:tasks.cephfs_test_runner:    self.assertEqual(self._resp.status_code, status)
2018-08-10T14:25:46.696 INFO:tasks.cephfs_test_runner:AssertionError: 500 != 200
2018-08-10T14:25:46.696 INFO:tasks.cephfs_test_runner:
2018-08-10T14:25:46.696 INFO:tasks.cephfs_test_runner:----------------------------------------------------------------------
2018-08-10T14:25:46.697 INFO:tasks.cephfs_test_runner:Ran 62 tests in 753.519s
2018-08-10T14:25:46.697 INFO:tasks.cephfs_test_runner:
2018-08-10T14:25:46.697 INFO:tasks.cephfs_test_runner:FAILED (failures=1)
2018-08-10T14:25:46.697 INFO:tasks.cephfs_test_runner:
2018-08-10T14:25:46.697 INFO:tasks.cephfs_test_runner:======================================================================
2018-08-10T14:25:46.697 INFO:tasks.cephfs_test_runner:FAIL: test_list (tasks.mgr.dashboard.test_rgw.RgwUserTest)
2018-08-10T14:25:46.697 INFO:tasks.cephfs_test_runner:----------------------------------------------------------------------
2018-08-10T14:25:46.697 INFO:tasks.cephfs_test_runner:Traceback (most recent call last):
2018-08-10T14:25:46.697 INFO:tasks.cephfs_test_runner:  File "/home/teuthworker/src/git.ceph.com_ceph-c_wip-lpaduano-testing-22457-2/qa/tasks/mgr/dashboard/test_rgw.py", line 260, in test_list
2018-08-10T14:25:46.697 INFO:tasks.cephfs_test_runner:    self.assertStatus(200)
2018-08-10T14:25:46.697 INFO:tasks.cephfs_test_runner:  File "/home/teuthworker/src/git.ceph.com_ceph-c_wip-lpaduano-testing-22457-2/qa/tasks/mgr/dashboard/helper.py", line 325, in assertStatus
2018-08-10T14:25:46.697 INFO:tasks.cephfs_test_runner:    self.assertEqual(self._resp.status_code, status)
2018-08-10T14:25:46.698 INFO:tasks.cephfs_test_runner:AssertionError: 500 != 200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants