Skip to content

Commit 11790f9

Browse files
committed
Review comments
1 parent 56bc95a commit 11790f9

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

plugins/httpapi/dcnm.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,6 @@ def login(self, username, password):
125125

126126
# Define login configurations in order of preference
127127
login_configs = [
128-
{
129-
"controller_type": "DCNM",
130-
"version": 11,
131-
"path": "/rest/logon",
132-
"data": "{'expirationTime': %s}" % (self.connection.get_option("persistent_connect_timeout") * 1000),
133-
"force_basic_auth": True,
134-
},
135128
{
136129
"controller_type": "NDFC",
137130
"version": 12,
@@ -146,6 +139,13 @@ def login(self, username, password):
146139
"data": json.dumps({"username": username, "password": password, "domain": login_domain}),
147140
"force_basic_auth": False,
148141
},
142+
{
143+
"controller_type": "DCNM",
144+
"version": 11,
145+
"path": "/rest/logon",
146+
"data": "{'expirationTime': %s}" % (self.connection.get_option("persistent_connect_timeout") * 1000),
147+
"force_basic_auth": True,
148+
},
149149
]
150150

151151
# Try each login method
@@ -279,9 +279,10 @@ def _response_to_json(self, response_text):
279279
"""Convert response_text to json format"""
280280
try:
281281
return json.loads(response_text) if response_text else {}
282-
# JSONDecodeError only available on Python 3.5+
283-
except ValueError:
282+
except json.JSONDecodeError:
284283
return "Invalid JSON response: {0}".format(response_text)
284+
except Exception as e:
285+
return "Error decoding JSON response: {0}".format(str(e))
285286

286287
def _response_to_json12(self, response_text):
287288
"""Convert response_text to json format"""

tests/unit/plugins/httpapi/test_dcnm.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def test_login_success_first_attempt(self, mock_get_option, mock_connection):
400400

401401
# Should call attempt_login once and return
402402
mock_attempt.assert_called_once()
403-
assert mock_attempt.call_args[0][0]["controller_type"] == "DCNM"
403+
assert mock_attempt.call_args[0][0]["controller_type"] == "NDFC"
404404

405405
@patch.object(HttpApi, "get_option")
406406
def test_login_success_second_attempt(self, mock_get_option, mock_connection):
@@ -790,11 +790,10 @@ def test_login_configs_structure(self, mock_connection):
790790

791791
# Get the first call (DCNM config)
792792
nd_config = mock_attempt.call_args_list[0][0][0]
793-
assert nd_config["controller_type"] == "DCNM"
794-
assert nd_config["version"] == 11
795-
assert nd_config["path"] == "/rest/logon"
796-
assert nd_config["force_basic_auth"] is True
797-
assert "'expirationTime': 10000" in nd_config["data"]
793+
assert nd_config["controller_type"] == "NDFC"
794+
assert nd_config["version"] == 12
795+
assert nd_config["path"] == "/login"
796+
assert nd_config["force_basic_auth"] is False
798797

799798
def test_logout_config_selection(self, mock_connection):
800799
"""Test that logout selects correct configuration based on version."""
@@ -888,8 +887,8 @@ def test_full_login_logout_cycle_nd(self, mock_connection):
888887

889888
# Verify login state
890889
assert http_api.login_succeeded is True
891-
assert http_api.version == 11
892-
assert http_api.connection._auth == {"Dcnm-Token": "test-token-123"}
890+
assert http_api.version == 12
891+
assert http_api.connection._auth == {'Authorization': 'Bearer None', 'Cookie': 'AuthCookie=None'}
893892

894893
# Perform logout
895894
http_api.logout()

0 commit comments

Comments
 (0)