]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: add missing fields to subsytem list command 63308/head
authorTomer Haskalovitch <il033030@Tomers-MBP.lan>
Tue, 13 May 2025 23:40:59 +0000 (02:40 +0300)
committerTomer Haskalovitch <il033030@Tomers-MBP.lan>
Sat, 17 May 2025 16:55:41 +0000 (19:55 +0300)
Signed-off-by: Tomer Haskalovitch <il033030@Tomers-MBP.lan>
add a test

src/pybind/mgr/dashboard/model/nvmeof.py
src/pybind/mgr/dashboard/services/nvmeof_client.py
src/pybind/mgr/dashboard/tests/test_nvmeof_client.py

index 268106247a8bd1c797446d45c7d08b5f2dc4c480..ec5bbc344c947317177f5ba1ea598ebf077d0053 100644 (file)
@@ -39,6 +39,9 @@ class Subsystem(NamedTuple):
     namespace_count: int
     subtype: str
     max_namespaces: int
+    has_dhchap_key: bool
+    allow_any_host: bool
+    created_without_key: bool = False
 
 
 class SubsystemList(NamedTuple):
index 79b4a607ecf2c001662ff86da033100feb67a5f0..b461755948dfe82245142be1de325ace75816b0d 100644 (file)
@@ -151,6 +151,7 @@ else:
 
     def _lazily_create_namedtuple(data: Any, target_type: Type[NamedTuple],
                                   depth: int, max_depth: int) -> Generator:
+        # pylint: disable=protected-access
         """ Lazily create NamedTuple from a dict """
         field_values = {}
         for field, field_type in zip(target_type._fields,
@@ -170,8 +171,7 @@ else:
                 except StopIteration:
                     return
             else:
-                # If the field is missing assign None
-                field_values[field] = None
+                field_values[field] = target_type._field_defaults.get(field)
 
         namedtuple_instance = target_type(**field_values)  # type: ignore
         yield namedtuple_instance
index 6ffe5c323f762933614b9a5f5bc452f43077fd0c..5744657935470999e32692faec2d5388824f96ac 100644 (file)
@@ -301,6 +301,11 @@ class EmptyModel(NamedTuple):
     pass
 
 
+class ModelWithDefaultParam(NamedTuple):
+    a: str
+    b: str = 'iamdefault'
+
+
 @pytest.fixture(name="person_func")
 def fixture_person_func():
     @convert_to_model(Boy)
@@ -355,6 +360,23 @@ class TestConvertToModel:
         result = get_adult()
         assert result == {'name': 'Charlie', 'age': 40, "children": [], 'hobby': None}
 
+    def test_fields_default_value(self, disable_message_to_dict):
+        # pylint: disable=unused-argument
+        @convert_to_model(ModelWithDefaultParam)
+        def get() -> dict:
+            return {"a": "bla"}
+
+        result = get()
+        assert result == {'a': 'bla', 'b': "iamdefault"}
+
+        # pylint: disable=unused-argument
+        @convert_to_model(ModelWithDefaultParam)
+        def get2() -> dict:
+            return {"a": "bla", "b": 'notdefault'}
+
+        result = get2()
+        assert result == {'a': 'bla', 'b': "notdefault"}
+
     def test_nested_fields(self, disable_message_to_dict):
         # pylint: disable=unused-argument
         @convert_to_model(Adult)