Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit db57b13

Browse files
committedMar 28, 2021
fix(k8scluster): better err handling
Signed-off-by: Chris Snow <[email protected]>
1 parent 6abb8b7 commit db57b13

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed
 

‎hpecp/cli/k8scluster.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ def create(
104104
:param addons: list of required addons. See:
105105
`hpecp k8scluster get-available-addons`
106106
:param external_identity_server: dict
107-
Example {
108-
"bind_pwd":"password",
107+
Example '{"bind_pwd":"password",
109108
"user_attribute":"CN",
110109
"bind_type":"search_bind",
111110
"bind_dn":"cn=Administrator,CN=Users,DC=samdom,DC=example,DC=com",
@@ -115,25 +114,25 @@ def create(
115114
"base_dn":"CN=Users,DC=samdom,DC=example,DC=com",
116115
"verify_peer":false,
117116
"type":"Active Directory",
118-
"port":636}
117+
"port":636}'
119118
"""
120119
host_config = [
121120
K8sClusterHostConfig.create_from_list(h.split(":"))
122121
for h in k8shosts_config.split(",")
123122
]
124123

125-
if external_identity_server:
126-
try:
127-
external_identity_server = json.loads(external_identity_server)
128-
except ValueError:
129-
print(
130-
(
131-
"could not parse 'external_identity_server' parameter"
132-
" - is it valid json?"
133-
),
134-
file=sys.stderr,
135-
)
136-
sys.exit(1)
124+
if external_identity_server and not isinstance(
125+
external_identity_server, dict
126+
):
127+
print(
128+
(
129+
"Could not parse 'external_identity_server' parameter"
130+
" - is it valid json?\n"
131+
"Received: " + external_identity_server + "\n"
132+
),
133+
file=sys.stderr,
134+
)
135+
sys.exit(1)
137136

138137
print(
139138
base.get_client().k8s_cluster.create(

‎tests/k8s_cluster_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ def test_k8scluster_create_valid_external_identity_server_json(
11081108
hpecp.k8scluster.create(
11091109
name="mycluster",
11101110
k8shosts_config="/api/v2/worker/k8shost/1:master,/api/v2/worker/k8shost/2:worker",
1111-
external_identity_server='{"valid_json": true}',
1111+
external_identity_server={"valid_json": True},
11121112
)
11131113

11141114
output = self.out.getvalue().strip()
@@ -1136,7 +1136,10 @@ def test_k8scluster_create_invalid_external_identity_server_json(
11361136
error = self.err.getvalue().strip()
11371137
self.assertEqual(
11381138
error,
1139-
"could not parse 'external_identity_server' parameter - is it valid json?",
1139+
(
1140+
"Could not parse 'external_identity_server' parameter - is it valid json?\n"
1141+
'Received: {\\"not_valid_json\\": true}'
1142+
),
11401143
)
11411144

11421145
self.assertEqual(cm.exception.code, 1)

0 commit comments

Comments
 (0)
Please sign in to comment.