Update asb_script for better error handling

Signed-off-by: bhargavi-ct <bhargavimamidipaka@candelatech.com>
This commit is contained in:
bhargavi-ct
2025-07-22 10:57:31 +05:30
parent aa1ac5eab8
commit 9ed541b786
2 changed files with 14 additions and 2 deletions

View File

@@ -955,7 +955,17 @@ class Controller(ConfigureController):
payload = json.dumps(payload)
resp = requests.post(uri, data=payload, headers=self.make_headers(), verify=False, timeout=120)
logging.info("resp:- " + str(resp))
resp = resp.json()
# Check if response status is OK (200)
if resp.status_code != 200:
pytest.fail(f"Request to {uri} failed with status code {resp.status_code}: {resp.text}")
# Try parsing JSON
try:
resp = resp.json()
except ValueError:
pytest.fail(f"Response from {uri} is not valid JSON: {resp.text}")
if 'UUID' not in resp:
pytest.fail(f"'UUID' not found in response JSON from {uri}: {resp}")
resp = resp['UUID']
return resp

View File

@@ -1052,10 +1052,11 @@ class TestUcentralGatewayService(object):
"deferred": True,
"uri": ""
}
resp = resp = get_target_object.controller_library_object.check_restrictions(device_name)
resp = get_target_object.controller_library_object.check_restrictions(device_name)
if not resp:
logging.info("AP is in not restricted and we can trigger script")
uuid = get_target_object.controller_library_object.asb_script(device_name, payload)
logging.info(f"uuid:{uuid}")
resp = get_target_object.controller_library_object.get_file(device_name, uuid)
assert resp.status_code == 200
else:
@@ -1100,6 +1101,7 @@ class TestUcentralGatewayService(object):
if resp:
logging.info("From GW it's confirmed that AP is restricted now")
uuid = get_target_object.controller_library_object.asb_script(device_name, payload)
logging.info(f"uuid:{uuid}")
resp = get_target_object.controller_library_object.get_file(device_name, uuid)
assert resp.status_code == 200
else: