]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Moves ECP info endpoint to UI-API
authorStephan Müller <smueller@suse.com>
Mon, 2 Mar 2020 09:57:16 +0000 (10:57 +0100)
committerStephan Müller <smueller@suse.com>
Mon, 9 Mar 2020 11:35:57 +0000 (12:35 +0100)
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 <smueller@suse.com>
qa/tasks/mgr/dashboard/test_erasure_code_profile.py
src/pybind/mgr/dashboard/controllers/erasure_code_profile.py
src/pybind/mgr/dashboard/frontend/src/app/shared/api/erasure-code-profile.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/erasure-code-profile.service.ts
src/pybind/mgr/dashboard/services/ceph_service.py
src/pybind/mgr/dashboard/tests/test_erasure_code_profile.py

index 9fcce30f61920365b5a5b29fddd30325d56d1e49..111e37c7e3e66dfdc71017341122de5bcb67cb53 100644 (file)
@@ -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),
index 34c9f651b3eaa00b3dcc6f1afbaff8a9e8bfad5a..ca63ba286a4b1a3c7bee597a21ff12d1e2e70b05 100644 (file)
@@ -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')
index 227af54c43c80565f9ef8e9b91ea2735d80fdf35..c2a90c27fb8106e500d7a654888725a2d5b83116 100644 (file)
@@ -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');
   });
 });
index df7527727aab038a66316bb5840637e333777e0e..a8c414f3c06be389866074d15c1cf6a5f752d80b 100644 (file)
@@ -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`);
   }
 }
index f43304ac095a9b357c78b307daf1598917da55ed..e0d583d8c01e78f90f8b40a16c00f7ba14de3671 100644 (file)
@@ -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()
index 88575c0a35c54ff34c1ea9c787f7fd8a743415bf..557b7c1061b166c245be08582d28cfe3a7e4b1cb 100644 (file)
@@ -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'})