From: Stephan Müller Date: Mon, 2 Mar 2020 09:57:16 +0000 (+0100) Subject: mgr/dashboard: Moves ECP info endpoint to UI-API X-Git-Tag: v15.1.1~39^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3e400f6a0b6bc4747923099c2ae1cf83e35f0806;p=ceph.git mgr/dashboard: Moves ECP info endpoint to UI-API Moves the "_info" endpoint of erasure code profile into an equivalent UI-API call with the name "info". The serialization of the profile was outsourced into "ceph-service" as it's used somewhere else (follow up commit). Removed unused methods in angular service and REST controller. Fixed path in angular service. Fixes: https://tracker.ceph.com/issues/44371 Signed-off-by: Stephan Müller --- diff --git a/qa/tasks/mgr/dashboard/test_erasure_code_profile.py b/qa/tasks/mgr/dashboard/test_erasure_code_profile.py index 9fcce30f6192..111e37c7e3e6 100644 --- a/qa/tasks/mgr/dashboard/test_erasure_code_profile.py +++ b/qa/tasks/mgr/dashboard/test_erasure_code_profile.py @@ -99,7 +99,7 @@ class ECPTest(DashboardTestCase): self.assertStatus(204) def test_ecp_info(self): - self._get('/api/erasure_code_profile/_info') + self._get('/ui-api/erasure_code_profile/info') self.assertSchemaBody(JObj({ 'names': JList(six.string_types), 'failure_domains': JList(six.string_types), diff --git a/src/pybind/mgr/dashboard/controllers/erasure_code_profile.py b/src/pybind/mgr/dashboard/controllers/erasure_code_profile.py index 34c9f651b3ea..ca63ba286a4b 100644 --- a/src/pybind/mgr/dashboard/controllers/erasure_code_profile.py +++ b/src/pybind/mgr/dashboard/controllers/erasure_code_profile.py @@ -3,24 +3,12 @@ from __future__ import absolute_import from cherrypy import NotFound -from . import ApiController, RESTController, Endpoint, ReadPermission +from . import ApiController, RESTController, Endpoint, ReadPermission, UiApiController from ..security import Scope from ..services.ceph_service import CephService from .. import mgr -def _serialize_ecp(name, ecp): - def serialize_numbers(key): - value = ecp.get(key) - if value is not None: - ecp[key] = int(value) - - ecp['name'] = name - serialize_numbers('k') - serialize_numbers('m') - return ecp - - @ApiController('/erasure_code_profile', Scope.POOL) class ErasureCodeProfile(RESTController): ''' @@ -29,17 +17,14 @@ class ErasureCodeProfile(RESTController): ''' def list(self): - ret = [] - for name, ecp in mgr.get('osd_map').get('erasure_code_profiles', {}).items(): - ret.append(_serialize_ecp(name, ecp)) - return ret + return CephService.get_erasure_code_profiles() def get(self, name): - try: - ecp = mgr.get('osd_map')['erasure_code_profiles'][name] - return _serialize_ecp(name, ecp) - except KeyError: - raise NotFound('No such erasure code profile') + profiles = CephService.get_erasure_code_profiles() + for p in profiles: + if p['name'] == name: + return p + raise NotFound('No such erasure code profile') def create(self, name, **kwargs): profile = ['{}={}'.format(key, value) for key, value in kwargs.items()] @@ -49,9 +34,12 @@ class ErasureCodeProfile(RESTController): def delete(self, name): CephService.send_command('mon', 'osd erasure-code-profile rm', name=name) + +@UiApiController('/erasure_code_profile', Scope.POOL) +class ErasureCodeProfileUi(ErasureCodeProfile): @Endpoint() @ReadPermission - def _info(self): + def info(self): '''Used for profile creation and editing''' config = mgr.get('config') osd_map_crush = mgr.get('osd_map_crush') diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/erasure-code-profile.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/erasure-code-profile.service.spec.ts index 227af54c43c8..c2a90c27fb81 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/erasure-code-profile.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/erasure-code-profile.service.spec.ts @@ -41,27 +41,15 @@ describe('ErasureCodeProfileService', () => { expect(req.request.method).toBe('POST'); }); - it('should call update', () => { - service.update(testProfile).subscribe(); - const req = httpTesting.expectOne(`${apiPath}/test`); - expect(req.request.method).toBe('PUT'); - }); - it('should call delete', () => { service.delete('test').subscribe(); const req = httpTesting.expectOne(`${apiPath}/test`); expect(req.request.method).toBe('DELETE'); }); - it('should call get', () => { - service.get('test').subscribe(); - const req = httpTesting.expectOne(`${apiPath}/test`); - expect(req.request.method).toBe('GET'); - }); - it('should call getInfo', () => { service.getInfo().subscribe(); - const req = httpTesting.expectOne(`${apiPath}/_info`); + const req = httpTesting.expectOne(`ui-${apiPath}/info`); expect(req.request.method).toBe('GET'); }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/erasure-code-profile.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/erasure-code-profile.service.ts index df7527727aab..a8c414f3c06b 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/erasure-code-profile.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/erasure-code-profile.service.ts @@ -14,7 +14,7 @@ export class ErasureCodeProfileService { apiPath = 'api/erasure_code_profile'; formTooltips = { - // Copied from /srv/cephmgr/ceph-dev/doc/rados/operations/erasure-code.*.rst + // Copied from /doc/rados/operations/erasure-code.*.rst k: this.i18n(`Each object is split in data-chunks parts, each stored on a different OSD.`), m: this.i18n(`Compute coding chunks for each object and store them on different OSDs. @@ -89,19 +89,11 @@ export class ErasureCodeProfileService { return this.http.post(this.apiPath, ecp, { observe: 'response' }); } - update(ecp: ErasureCodeProfile) { - return this.http.put(`${this.apiPath}/${ecp.name}`, ecp, { observe: 'response' }); - } - delete(name: string) { return this.http.delete(`${this.apiPath}/${name}`, { observe: 'response' }); } - get(name: string) { - return this.http.get(`${this.apiPath}/${name}`); - } - getInfo() { - return this.http.get(`${this.apiPath}/_info`); + return this.http.get(`ui-${this.apiPath}/info`); } } diff --git a/src/pybind/mgr/dashboard/services/ceph_service.py b/src/pybind/mgr/dashboard/services/ceph_service.py index f43304ac095a..e0d583d8c01e 100644 --- a/src/pybind/mgr/dashboard/services/ceph_service.py +++ b/src/pybind/mgr/dashboard/services/ceph_service.py @@ -118,6 +118,24 @@ class CephService(object): pools_w_stats.append(pool) return pools_w_stats + @classmethod + def get_erasure_code_profiles(cls): + def _serialize_ecp(name, ecp): + def serialize_numbers(key): + value = ecp.get(key) + if value is not None: + ecp[key] = int(value) + + ecp['name'] = name + serialize_numbers('k') + serialize_numbers('m') + return ecp + + ret = [] + for name, ecp in mgr.get('osd_map').get('erasure_code_profiles', {}).items(): + ret.append(_serialize_ecp(name, ecp)) + return ret + @classmethod def get_pool_name_from_id(cls, pool_id): pool_list = cls.get_pool_list() diff --git a/src/pybind/mgr/dashboard/tests/test_erasure_code_profile.py b/src/pybind/mgr/dashboard/tests/test_erasure_code_profile.py index 88575c0a35c5..557b7c1061b1 100644 --- a/src/pybind/mgr/dashboard/tests/test_erasure_code_profile.py +++ b/src/pybind/mgr/dashboard/tests/test_erasure_code_profile.py @@ -29,8 +29,3 @@ class ErasureCodeProfileTest(ControllerTestCase): self._get('/api/erasure_code_profile') self.assertStatus(200) self.assertJsonBody([{'k': 2, 'm': 1, 'name': 'test'}]) - - def test_get(self): - self._get('/api/erasure_code_profile/test') - self.assertStatus(200) - self.assertJsonBody({'k': 2, 'm': 1, 'name': 'test'})