]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: add missing fields to subsytem list command 64232/head
authorTomer Haskalovitch <il033030@Tomers-MBP.lan>
Tue, 13 May 2025 23:40:59 +0000 (02:40 +0300)
committerTomer Haskalovitch <tomer.haska@ibm.com>
Tue, 1 Jul 2025 06:29:39 +0000 (09:29 +0300)
Signed-off-by: Tomer Haskalovitch <tomer.haska@ibm.com>
(cherry picked from commit 2962b4c02610a8445d34ca16961188250f3a2274)

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 49b175a02e1ec06dd43291f35fc0f34935801eb2..59136ddd252d8c7a25f3e54ec0a322d504824eec 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 556b59eb3655444e740a12deb738bf14af8f1e96..36b8d0c8e09e3f26f2c76691c9f29dab7947a73d 100644 (file)
@@ -205,6 +205,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,
@@ -224,8 +225,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 76fcd63f7cf506c28aa93649018c14037db463cf..6df2ec3e0f95176820762f45114274b48fc1407e 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)