]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
python-common: add `service_name` to `ServiceSpec.to_json`
authorSebastian Wagner <sebastian.wagner@suse.com>
Fri, 20 Mar 2020 10:25:35 +0000 (11:25 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Thu, 26 Mar 2020 11:02:56 +0000 (12:02 +0100)
To make it compatible to `Orchestrator.describe_service`.
Otherwise we have the awkward situation that users need to
pass `service_name` to `describe_service`, but `service_id` to apply

Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/cephadm/tests/test_cephadm.py
src/python-common/ceph/deployment/drive_group.py
src/python-common/ceph/deployment/service_spec.py

index a0be9a1426382b1079c32d7e3c4f3db02950a419..49bcafbce4aa9164b62b21b10e8e55e9aedb0c09 100644 (file)
@@ -102,6 +102,7 @@ class TestCephadm(object):
                 {
                     'placement': {'hosts': [{'hostname': 'test', 'name': '', 'network': ''}]},
                     'service_id': 'name',
+                    'service_name': 'mds.name',
                     'service_type': 'mds',
                     'status': {'running': 1, 'size': 0},
                     'unmanaged': True
@@ -114,6 +115,7 @@ class TestCephadm(object):
                     'rgw_realm': 'r',
                     'rgw_zone': 'z',
                     'service_id': 'r.z',
+                    'service_name': 'rgw.r.z',
                     'service_type': 'rgw',
                     'status': {'running': 0, 'size': 1}
                 }
index 0f25afd0b392acaf891d57d2bb553277e7c9a332..595428a2778c9cb890986f0581812f12e6444c6e 100644 (file)
@@ -282,6 +282,7 @@ class DriveGroupSpec(ServiceSpec):
             c['db_devices'] = self.db_devices.to_json()
         if self.wal_devices:
             c['wal_devices'] = self.wal_devices.to_json()
+        c['service_name'] = self.service_name()
         return c
 
     def __eq__(self, other):
index b94be2549d84d00c2c45b15406aa98f2bdb0332e..13bc2dd5426780736b72ecb853e9a8df008f1e04 100644 (file)
@@ -395,10 +395,22 @@ class ServiceSpec(object):
         :param json_spec: A valid dict with ServiceSpec
         """
 
-        service_type = json_spec.get('service_type', '')
+        c = json_spec.copy()
+
+        # kludge to make `from_json` compatible to `Orchestrator.describe_service`
+        # Open question: Remove `service_id` form to_json?
+        if c.get('service_name', ''):
+            service_type_id = c['service_name'].split('.', 1)
+
+            if not c.get('service_type', ''):
+                c['service_type'] = service_type_id[0]
+            if not c.get('service_id', '') and len(service_type_id) > 1:
+                c['service_id'] = service_type_id[1]
+            del c['service_name']
+
+        service_type = c.get('service_type', '')
         _cls = cls._cls(service_type)
 
-        c = json_spec.copy()
         if 'status' in c:
             del c['status']  # kludge to make us compatible to `ServiceDescription.to_json()`
 
@@ -430,6 +442,8 @@ class ServiceSpec(object):
                 val = val.to_json()
             if val:
                 c[key] = val
+
+        c['service_name'] = self.service_name()
         return c
 
     def validate(self):