Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ni_measurementlink_service/_drivers/_niswitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ def __call__(self, session_info: SessionInformation) -> niswitch.Session:
initialization_behavior=self._initialization_behavior,
)

# Initializing a nonexistent switch module returns
# NISWITCH_ERROR_INVALID_RESOURCE_DESCRIPTOR, even if simulate=True.
resource_name = "" if self._simulate else session_info.resource_name

return niswitch.Session(
resource_name=session_info.resource_name,
resource_name=resource_name,
topology=self._topology,
simulate=self._simulate,
reset_device=self._reset_device,
Expand Down
18 changes: 10 additions & 8 deletions ni_measurementlink_service/session_management/_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,13 +1421,14 @@ def create_niswitch_session(
Args:
topology: Specifies the switch topology. If this argument is not
specified, the default value is "Configured Topology", which you
may override by setting ``NISWITCH_TOPOLOGY`` in the
configuration file (``.env``).
may override by setting ``MEASUREMENTLINK_NISWITCH_TOPOLOGY`` in
the configuration file (``.env``).

simulate: Enables or disables simulation of the switch module. If
this argument is not specified, the default value is ``False``,
which you may override by setting ``NISWITCH_SIMULATE`` in the
configuration file (``.env``).
which you may override by setting
``MEASUREMENTLINK_NISWITCH_SIMULATE`` in the configuration file
(``.env``).

reset_device: Specifies whether to reset the switch module during
the initialization procedure.
Expand Down Expand Up @@ -1471,13 +1472,14 @@ def create_niswitch_sessions(
Args:
topology: Specifies the switch topology. If this argument is not
specified, the default value is "Configured Topology", which you
may override by setting ``NISWITCH_TOPOLOGY`` in the
configuration file (``.env``).
may override by setting ``MEASUREMENTLINK_NISWITCH_TOPOLOGY`` in
the configuration file (``.env``).

simulate: Enables or disables simulation of the switch module. If
this argument is not specified, the default value is ``False``,
which you may override by setting ``NISWITCH_SIMULATE`` in the
configuration file (``.env``).
which you may override by setting
``MEASUREMENTLINK_NISWITCH_SIMULATE`` in the configuration file
(``.env``).

reset_device: Specifies whether to reset the switch module during
the initialization procedure.
Expand Down
12 changes: 8 additions & 4 deletions tests/unit/_drivers/test_niswitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ def test___multiple_session_infos___create_niswitch_sessions___sessions_created(
)


# For NI-SWITCH, we set resource_name to "" when simulate is True.
@pytest.mark.parametrize("simulate,expected_resource_name", [(False, "Dev0"), (True, "")])
def test___optional_args___create_niswitch_session___optional_args_passed(
simulate: bool,
expected_resource_name: str,
session_new: Mock,
session_management_client: Mock,
) -> None:
Expand All @@ -97,17 +101,17 @@ def test___optional_args___create_niswitch_session___optional_args_passed(

with reservation.create_niswitch_session(
topology="2567/Independent",
simulate=True,
simulate=simulate,
reset_device=True,
initialization_behavior=SessionInitializationBehavior.INITIALIZE_SERVER_SESSION,
):
pass

session_new.assert_called_once_with(
niswitch.Session,
resource_name="Dev0",
resource_name=expected_resource_name,
topology="2567/Independent",
simulate=True,
simulate=simulate,
reset_device=True,
grpc_options=ANY,
)
Expand All @@ -134,7 +138,7 @@ def test___simulation_configured___create_niswitch_session___simulation_options_

session_new.assert_called_once_with(
niswitch.Session,
resource_name="Dev0",
resource_name="",
topology="2567/Independent",
simulate=True,
reset_device=False,
Expand Down