Skip to content

Commit 2962b4c

Browse files
Tomer HaskalovitchTomer Haskalovitch
authored andcommitted
mgr/dashboard: add missing fields to subsytem list command
Signed-off-by: Tomer Haskalovitch <[email protected]> add a test
1 parent a3babf1 commit 2962b4c

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/pybind/mgr/dashboard/model/nvmeof.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class Subsystem(NamedTuple):
3939
namespace_count: int
4040
subtype: str
4141
max_namespaces: int
42+
has_dhchap_key: bool
43+
allow_any_host: bool
44+
created_without_key: bool = False
4245

4346

4447
class SubsystemList(NamedTuple):

src/pybind/mgr/dashboard/services/nvmeof_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def _convert(value, field_type, depth, max_depth) -> Generator:
151151

152152
def _lazily_create_namedtuple(data: Any, target_type: Type[NamedTuple],
153153
depth: int, max_depth: int) -> Generator:
154+
# pylint: disable=protected-access
154155
""" Lazily create NamedTuple from a dict """
155156
field_values = {}
156157
for field, field_type in zip(target_type._fields,
@@ -170,8 +171,7 @@ def _lazily_create_namedtuple(data: Any, target_type: Type[NamedTuple],
170171
except StopIteration:
171172
return
172173
else:
173-
# If the field is missing assign None
174-
field_values[field] = None
174+
field_values[field] = target_type._field_defaults.get(field)
175175

176176
namedtuple_instance = target_type(**field_values) # type: ignore
177177
yield namedtuple_instance

src/pybind/mgr/dashboard/tests/test_nvmeof_client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ class EmptyModel(NamedTuple):
301301
pass
302302

303303

304+
class ModelWithDefaultParam(NamedTuple):
305+
a: str
306+
b: str = 'iamdefault'
307+
308+
304309
@pytest.fixture(name="person_func")
305310
def fixture_person_func():
306311
@convert_to_model(Boy)
@@ -355,6 +360,23 @@ def get_adult() -> dict:
355360
result = get_adult()
356361
assert result == {'name': 'Charlie', 'age': 40, "children": [], 'hobby': None}
357362

363+
def test_fields_default_value(self, disable_message_to_dict):
364+
# pylint: disable=unused-argument
365+
@convert_to_model(ModelWithDefaultParam)
366+
def get() -> dict:
367+
return {"a": "bla"}
368+
369+
result = get()
370+
assert result == {'a': 'bla', 'b': "iamdefault"}
371+
372+
# pylint: disable=unused-argument
373+
@convert_to_model(ModelWithDefaultParam)
374+
def get2() -> dict:
375+
return {"a": "bla", "b": 'notdefault'}
376+
377+
result = get2()
378+
assert result == {'a': 'bla', 'b': "notdefault"}
379+
358380
def test_nested_fields(self, disable_message_to_dict):
359381
# pylint: disable=unused-argument
360382
@convert_to_model(Adult)

0 commit comments

Comments
 (0)