cloudsdk: better handle when test cases are not configured.

For instance when using helper tools to call into the querysdk
logic, when test cases are not relavent.

Fix sdk upgrade tool to use latest API.

Signed-off-by: Ben Greear <greearb@candelatech.com>
This commit is contained in:
Ben Greear
2021-02-10 12:07:27 -08:00
parent ae80bc92a5
commit a734432fc9
4 changed files with 72 additions and 57 deletions

View File

@@ -15,7 +15,11 @@ class GetBuild:
self.jfrog_url = 'https://tip.jfrog.io/artifactory/tip-wlan-ap-firmware/'
self.build = build
def get_latest_image(self, model):
def get_latest_image(self, model, for_build=None):
build_name = self.build
if for_build:
build_name = for_build
url = self.jfrog_url + model + "/dev/"
@@ -35,7 +39,7 @@ class GetBuild:
soup = BeautifulSoup(html, features="html.parser")
# find the last pending link on dev
last_link = soup.find_all('a', href=re.compile(self.build))[-1]
last_link = soup.find_all('a', href=re.compile(build_name))[-1]
latest_file = last_link['href']
latest_fw = latest_file.replace('.tar.gz', '')
return latest_fw

View File

@@ -189,14 +189,15 @@ class CloudSDK:
if "success" in upgrade_fw:
if upgrade_fw["success"] == True:
print("CloudSDK Upgrade Request Success")
if report_data:
if report_data and test_cases:
report_data['tests'][key][test_cases["upgrade_api"]] = "passed"
client.update_testrail(case_id=self.test_cases["upgrade_api"], run_id=rid, status_id=1, msg='Upgrade request using API successful')
client.update_testrail(case_id=test_cases["upgrade_api"], run_id=rid, status_id=1, msg='Upgrade request using API successful')
logger.info('Firmware upgrade API successfully sent')
else:
print("Cloud SDK Upgrade Request Error!")
# mark upgrade test case as failed with CloudSDK error
client.update_testrail(case_id=self.test_cases["upgrade_api"], run_id=rid, status_id=5, msg='Error requesting upgrade via API')
if test_cases:
client.update_testrail(case_id=test_cases["upgrade_api"], run_id=rid, status_id=5, msg='Error requesting upgrade via API')
if report_data:
report_data['tests'][key][test_cases["upgrade_api"]] = "failed"
logger.warning('Firmware upgrade API failed to send')
@@ -204,7 +205,8 @@ class CloudSDK:
else:
print("Cloud SDK Upgrade Request Error!")
# mark upgrade test case as failed with CloudSDK error
client.update_testrail(case_id=self.test_cases["upgrade_api"], run_id=rid, status_id=5,msg='Error requesting upgrade via API')
if test_cases:
client.update_testrail(case_id=test_cases["upgrade_api"], run_id=rid, status_id=5,msg='Error requesting upgrade via API')
if report_data:
report_data['tests'][key][test_cases["upgrade_api"]] = "failed"
logger.warning('Firmware upgrade API failed to send')
@@ -214,6 +216,7 @@ class CloudSDK:
for i in range(10):
time.sleep(30)
# Check if upgrade success is displayed on CloudSDK
if test_cases:
test_id_cloud = test_cases["cloud_fw"]
cloud_ap_fw = self.ap_firmware(customer_id, equipment_id, cloudSDK_url, bearer)
print('Current AP Firmware from CloudSDK: %s requested-image: %s'%(cloud_ap_fw, ap_image))
@@ -233,6 +236,7 @@ class CloudSDK:
if sdk_ok:
for i in range(10):
# Check if upgrade successful on AP CLI
if test_cases:
test_id_cli = test_cases["ap_upgrade"]
try:
ap_cli_info = ssh_cli_active_fw(command_line_args)
@@ -251,6 +255,7 @@ class CloudSDK:
logging.error(logging.traceback.format_exc())
print("Cannot Reach AP CLI to confirm upgrade!")
logger.warning('Cannot Reach AP CLI to confirm upgrade!')
if test_cases:
client.update_testrail(case_id=test_id_cli, run_id=rid, status_id=4,
msg='Cannot reach AP after upgrade to check CLI - re-test required')
continue
@@ -265,6 +270,7 @@ class CloudSDK:
# Check status
if cloud_ap_fw == ap_image and ap_cli_fw == ap_image:
print("CloudSDK and AP CLI both show upgrade success, passing upgrade test case")
if test_cases:
client.update_testrail(case_id=test_id_cli, run_id=rid, status_id=1,
msg='Upgrade to ' + ap_image + ' successful')
client.update_testrail(case_id=test_id_cloud, run_id=rid, status_id=1,
@@ -278,6 +284,7 @@ class CloudSDK:
elif cloud_ap_fw != ap_image and ap_cli_fw == ap_image:
print("AP CLI shows upgrade success - CloudSDK reporting error!")
##Raise CloudSDK error but continue testing
if test_cases:
client.update_testrail(case_id=test_id_cli, run_id=rid, status_id=1,
msg='Upgrade to ' + ap_image + ' successful.')
client.update_testrail(case_id=test_id_cloud, run_id=rid, status_id=5,
@@ -291,6 +298,7 @@ class CloudSDK:
elif cloud_ap_fw == ap_image and ap_cli_fw != ap_image:
print("AP CLI shows upgrade failed - CloudSDK reporting error!")
# Testrail TC fail
if test_cases:
client.update_testrail(case_id=test_id_cli, run_id=rid, status_id=5,
msg='AP failed to download or apply new FW. Upgrade to ' + ap_image + ' Failed')
client.update_testrail(case_id=test_id_cloud, run_id=rid, status_id=5,
@@ -304,6 +312,7 @@ class CloudSDK:
elif cloud_ap_fw != ap_image and ap_cli_fw != ap_image:
print("Upgrade Failed! Confirmed on CloudSDK and AP CLI. Upgrade test case failed.")
##fail TR testcase and exit
if test_cases:
client.update_testrail(case_id=test_id_cli, run_id=rid, status_id=5,
msg='AP failed to download or apply new FW. Upgrade to ' + ap_image + ' Failed')
if report_data:
@@ -314,6 +323,7 @@ class CloudSDK:
else:
print("Unable to determine upgrade status. Skipping AP variant")
# update TR testcase as error
if test_cases:
client.update_testrail(case_id=test_id_cli, run_id=rid, status_id=4,
msg='Cannot determine upgrade status - re-test required')
if report_data:

View File

@@ -97,7 +97,7 @@ from lab_ap_info import radius_info
class UnitTestBase:
def __init__(self, log_name, args, reporting):
def __init__(self, log_name, args, reporting=None):
self.parser = argparse.ArgumentParser(description="Sanity Testing on Firmware Build", parents=[args])
self.parser.add_argument("-b", "--build-id", type=str,
@@ -239,7 +239,11 @@ class UnitTestBase:
self.build = self.command_line_args.build_id
self.logger = logging.getLogger(log_name)
if not reporting:
self.hdlr = logging.FileHandler("./logs/test_run.log")
else:
self.hdlr = logging.FileHandler(reporting.report_path + "/test_run.log")
self.formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
self.hdlr.setFormatter(self.formatter)

View File

@@ -138,15 +138,12 @@ ap_image = command_line_args.ap_image
apModel = model_id
cloudModel = cloud_sdk_models[apModel]
build = command_line_args.build_id # ie, pending
if not ap_image:
# then get latest from jfrog
# print(cloudModel)
jfrog_url = 'https://tip.jfrog.io/artifactory/tip-wlan-ap-firmware/'
url = jfrog_url + apModel + "/dev/"
Build: GetBuild = GetBuild(jfrog_user, jfrog_pwd)
latest_image = Build.get_latest_image(url, build)
print(apModel, "Latest FW on jFrog:", latest_image)
ap_image = latest_image
Build: GetBuild = GetBuild(jfrog_user, jfrog_pwd, build)
ap_image = Build.get_latest_image(apModel)
##Get Bearer Token to make sure its valid (long tests can require re-auth)
bearer = cloud.get_bearer(cloudSDK_url, cloud_type)