diff --git a/py-scripts/tip-cicd-sanity/Nightly_Sanity.py b/py-scripts/tip-cicd-sanity/Nightly_Sanity.py index 0dd069a7..5015ba8b 100755 --- a/py-scripts/tip-cicd-sanity/Nightly_Sanity.py +++ b/py-scripts/tip-cicd-sanity/Nightly_Sanity.py @@ -58,7 +58,7 @@ from cloudsdk import CloudSDK import ap_ssh from ap_ssh import ssh_cli_active_fw from ap_ssh import iwinfo_status -import cluster_version + ### Set CloudSDK URL ### cloudSDK_url=os.getenv('CLOUD_SDK_URL') @@ -265,40 +265,14 @@ test_cases = [ 5250, 5251, 5252, - 5253 + 5253, + 5540 ] ##AP models for jfrog ap_models = ["ec420","ea8300","ecw5211","ecw5410"] #ap_models = ["ecw5410"] -############################################################################# -##################### CloudSDK Version ############################### -print("Getting CloudSDK version information...") -try: - cluster_ver = cluster_version.main() - - print("CloudSDK Version Information:") - print("-------------------------------------------") - print(cluster_ver) - print("-------------------------------------------") - - logger.info('CloudSDK version info:'+cluster_ver) - cloudsdk_cluster_info = {} - for line in cluster_ver.splitlines(): - (key, val) = line.split("=") - cloudsdk_cluster_info[key] = val - -except: - cluster_ver = 'error' - print("ERROR: CloudSDK Version Unavailable") - logger.info('CloudSDK version Unavailable') - cloudsdk_cluster_info = { - "date" : "unknown", - "commitId" : "unknown", - "projectVersion" : "unknown" - } - ############################################################################ #################### Create Report ######################################### ############################################################################ @@ -325,7 +299,12 @@ except: tc_results = dict.fromkeys(test_cases, "not run") report_data = dict() -report_data['cloud_sdk'] = cloudsdk_cluster_info +report_data['cloud_sdk'] = { + "ea8300" : "", + "ecw5211": "", + "ecw5410": "", + "ec420": "" + } report_data["fw_available"] = dict.fromkeys(ap_models,"Unknown") report_data["fw_under_test"] = dict.fromkeys(ap_models,"N/A") report_data['pass_percent'] = dict.fromkeys(ap_models,"") @@ -406,10 +385,6 @@ for key in equipment_id_dict: ##Get Bearer Token to make sure its valid (long tests can require re-auth) bearer = CloudSDK.get_bearer(cloudSDK_url) - # create dictionary to track test case pass/fail - #tc_results = dict.fromkeys(test_cases, "Not Run") - #print(tc_results) - ###Get Current AP Firmware and upgrade customer_id = "2" equipment_id = equipment_id_dict[key] @@ -439,6 +414,13 @@ for key in equipment_id_dict: print('FW does not require updating') report_data['fw_available'][key] = "No" logger.info(fw_model + " does not require upgrade. Not performing sanity tests for this AP variant") + cloudsdk_cluster_info = { + "date": "N/A", + "commitId": "N/A", + "projectVersion": "N/A" + } + report_data['cloud_sdk'][key] = cloudsdk_cluster_info + else: print('FW needs updating') report_data['fw_available'][key] = "Yes" @@ -447,10 +429,46 @@ for key in equipment_id_dict: ###Create Test Run today = str(date.today()) test_run_name = "Daily_Sanity_" + fw_model + "_" + today + "_" + latest_ap_image - client.create_testrun(name=test_run_name, case_ids=test_cases, project_id=projId, milestone_id=milestoneId, description='CloudSDK version info:\n'+cluster_ver) + client.create_testrun(name=test_run_name, case_ids=test_cases, project_id=projId, milestone_id=milestoneId, description="Automated Nightly Sanity test run for new firmware build") rid = client.get_run_id(test_run_name="Daily_Sanity_" + fw_model + "_" + today + "_" + latest_ap_image) print("TIP run ID is:", rid) + ###GetCloudSDK Version + print("Getting CloudSDK version information...") + try: + cluster_ver = CloudSDK.get_cloudsdk_version(cloudSDK_url, bearer) + print("CloudSDK Version Information:") + print("-------------------------------------------") + print(cluster_ver) + print("-------------------------------------------") + + cloudsdk_cluster_info = {} + cloudsdk_cluster_info['date'] = cluster_ver['commitDate'] + cloudsdk_cluster_info['commitId'] = cluster_ver['commitID'] + cloudsdk_cluster_info['projectVersion'] = cluster_ver['projectVersion'] + report_data['cloud_sdk'][key] = cloudsdk_cluster_info + logger.info('CloudSDK version info: ',cluster_ver) + client.update_testrail(case_id="5540", run_id=rid, status_id=1, msg='Read CloudSDK version from API successfully') + report_data['tests'][key][5540] = "passed" + + except: + cluster_ver = 'error' + print("ERROR: CloudSDK Version Unavailable") + logger.info('CloudSDK version Unavailable') + cloudsdk_cluster_info = { + "date": "unknown", + "commitId": "unknown", + "projectVersion": "unknown" + } + client.update_testrail(case_id="5540", run_id=rid, status_id=5, msg='Could not read CloudSDK version from API') + report_data['cloud_sdk'][key] = cloudsdk_cluster_info + report_data['tests'][key][5540] = "failed" + + with open(report_path + today + '/report_data.json', 'w') as report_json_file: + json.dump(report_data, report_json_file) + + time.sleep(60) + # Upgrade AP firmware upgrade_fw = CloudSDK.update_firmware(equipment_id, latest_firmware_id, cloudSDK_url, bearer) logger.info("Lab "+fw_model+" Requires FW update") @@ -467,9 +485,6 @@ for key in equipment_id_dict: logger.warning('Firmware upgrade API failed to send') continue - print("Wait for AP Upgrade") - time.sleep(300) - # Check if upgrade success is displayed on CloudSDK cloud_ap_fw = CloudSDK.ap_firmware(customer_id, equipment_id, cloudSDK_url, bearer) print('Current AP Firmware from CloudSDK:', cloud_ap_fw) diff --git a/py-scripts/tip-cicd-sanity/cloudsdk.py b/py-scripts/tip-cicd-sanity/cloudsdk.py index 597d27ab..3e31fbcd 100755 --- a/py-scripts/tip-cicd-sanity/cloudsdk.py +++ b/py-scripts/tip-cicd-sanity/cloudsdk.py @@ -157,3 +157,16 @@ class CloudSDK: response = requests.request("PUT", url, headers=headers, data=json.dumps(equipment_info)) #print(response) + + def get_cloudsdk_version(cloudSDK_url, bearer): + #print(latest_ap_image) + fw_id_url = cloudSDK_url+"/ping" + + payload = {} + headers = { + 'Authorization': 'Bearer ' + bearer + } + response = requests.request("GET", fw_id_url, headers=headers, data=payload) + cloud_sdk_version = response.json() + return cloud_sdk_version + diff --git a/py-scripts/tip-cicd-sanity/cluster_version.py b/py-scripts/tip-cicd-sanity/cluster_version.py deleted file mode 100644 index 68e1a355..00000000 --- a/py-scripts/tip-cicd-sanity/cluster_version.py +++ /dev/null @@ -1,74 +0,0 @@ -################################################################################## -# Used to login to AWS and determine current CloudSDK version -# Requires user to install chromedriver and specify path -# -# Used by Nightly_Sanity ######################################################### -################################################################################## - -import time -from threading import Thread - -from selenium import webdriver -from selenium.webdriver.common.by import By -from selenium.webdriver.common.keys import Keys - -import os -import subprocess - -user=os.getenv('AWS_USER') -password=os.getenv('AWS_PWD') -chromedriver_dir=os.getenv('CHROMEDRIVER_PATH') - -def main(): - chrome_options = webdriver.ChromeOptions() - chrome_options.add_argument("--headless") - driver = webdriver.Chrome(executable_path=chromedriver_dir, options=chrome_options) - driver.get("https://telecominfraproject.awsapps.com/start#") - time.sleep(10); - elem = driver.find_element_by_xpath('//*[@id="awsui-input-0"]') - elem.send_keys(user); - elem.send_keys(Keys.ENTER) - - time.sleep(5); - elem2 = driver.find_element_by_xpath('//*[@id="awsui-input-1"]') - elem2.send_keys(password) - elem2.send_keys(Keys.ENTER) - - time.sleep(10); - driver.find_element_by_xpath("//*[@id=\"app-03e8643328913682\"]").click() - time.sleep(2); - driver.find_element_by_xpath("//*[@id=\"ins-9f89e35be3e67abf\"]/div/div/img").click() - time.sleep(5); - - driver.find_element_by_xpath("//*[@id=\"temp-credentials-button\"]").click() - time.sleep(2); - AWS_ACCESS_KEY_ID = driver.find_element_by_xpath("//*[@id=\"env-var-linux\"]/div[1]").text - AWS_ACCESS_KEY_ID = AWS_ACCESS_KEY_ID[26:-1] - AWS_SECRET_ACCESS_KEY = driver.find_element_by_xpath("//*[@id=\"env-var-linux\"]/div[2]").text - AWS_SECRET_ACCESS_KEY = AWS_SECRET_ACCESS_KEY[30:-1] - AWS_SESSION_TOKEN = driver.find_element_by_xpath("//*[@id=\"env-var-linux\"]/div[3]").text - AWS_SESSION_TOKEN = AWS_SESSION_TOKEN[26:-1] - driver.close() - - #print (AWS_ACCESS_KEY_ID) - #print(AWS_SECRET_ACCESS_KEY) - #print(AWS_SESSION_TOKEN) - # //*[@id="env-var-linux"]/div[2]/text() - # //*[@id="env-var-linux"]/div[3]/text() - - os.environ['AWS_ACCESS_KEY_ID'] = AWS_ACCESS_KEY_ID - os.environ['AWS_SECRET_ACCESS_KEY'] = AWS_SECRET_ACCESS_KEY - os.environ['AWS_SESSION_TOKEN'] = AWS_SESSION_TOKEN - - get_pods = subprocess.check_output("kubectl -n tip get pods | grep tip-wlan-opensync-gw-cloud", shell=True, universal_newlines=True) - #print(get_pods) - - opensync = str(get_pods.split()[0]) - #print(opensync) - - version_info = subprocess.check_output("kubectl exec -it -n tip "+opensync+" -- cat commit.properties", shell=True, universal_newlines=True) - return version_info - - - - diff --git a/py-scripts/tip-cicd-sanity/reports/report_template.php b/py-scripts/tip-cicd-sanity/reports/report_template.php index 0601f798..1ed08906 100755 --- a/py-scripts/tip-cicd-sanity/reports/report_template.php +++ b/py-scripts/tip-cicd-sanity/reports/report_template.php @@ -6,8 +6,8 @@
@@ -75,16 +75,52 @@ $json = json_decode($results, true);