Changes to use API to check CloudSDK version. cluster_version.py is now obsolete and is deleted

This commit is contained in:
bealler
2020-11-27 15:39:23 -05:00
parent d2792d1294
commit dcc2c23ee5
4 changed files with 109 additions and 119 deletions

View File

@@ -58,7 +58,7 @@ from cloudsdk import CloudSDK
import ap_ssh import ap_ssh
from ap_ssh import ssh_cli_active_fw from ap_ssh import ssh_cli_active_fw
from ap_ssh import iwinfo_status from ap_ssh import iwinfo_status
import cluster_version
### Set CloudSDK URL ### ### Set CloudSDK URL ###
cloudSDK_url=os.getenv('CLOUD_SDK_URL') cloudSDK_url=os.getenv('CLOUD_SDK_URL')
@@ -265,40 +265,14 @@ test_cases = [
5250, 5250,
5251, 5251,
5252, 5252,
5253 5253,
5540
] ]
##AP models for jfrog ##AP models for jfrog
ap_models = ["ec420","ea8300","ecw5211","ecw5410"] ap_models = ["ec420","ea8300","ecw5211","ecw5410"]
#ap_models = ["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 ######################################### #################### Create Report #########################################
############################################################################ ############################################################################
@@ -325,7 +299,12 @@ except:
tc_results = dict.fromkeys(test_cases, "not run") tc_results = dict.fromkeys(test_cases, "not run")
report_data = dict() 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_available"] = dict.fromkeys(ap_models,"Unknown")
report_data["fw_under_test"] = dict.fromkeys(ap_models,"N/A") report_data["fw_under_test"] = dict.fromkeys(ap_models,"N/A")
report_data['pass_percent'] = dict.fromkeys(ap_models,"") 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) ##Get Bearer Token to make sure its valid (long tests can require re-auth)
bearer = CloudSDK.get_bearer(cloudSDK_url) 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 ###Get Current AP Firmware and upgrade
customer_id = "2" customer_id = "2"
equipment_id = equipment_id_dict[key] equipment_id = equipment_id_dict[key]
@@ -439,6 +414,13 @@ for key in equipment_id_dict:
print('FW does not require updating') print('FW does not require updating')
report_data['fw_available'][key] = "No" report_data['fw_available'][key] = "No"
logger.info(fw_model + " does not require upgrade. Not performing sanity tests for this AP variant") 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: else:
print('FW needs updating') print('FW needs updating')
report_data['fw_available'][key] = "Yes" report_data['fw_available'][key] = "Yes"
@@ -447,10 +429,46 @@ for key in equipment_id_dict:
###Create Test Run ###Create Test Run
today = str(date.today()) today = str(date.today())
test_run_name = "Daily_Sanity_" + fw_model + "_" + today + "_" + latest_ap_image 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) rid = client.get_run_id(test_run_name="Daily_Sanity_" + fw_model + "_" + today + "_" + latest_ap_image)
print("TIP run ID is:", rid) 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 AP firmware
upgrade_fw = CloudSDK.update_firmware(equipment_id, latest_firmware_id, cloudSDK_url, bearer) upgrade_fw = CloudSDK.update_firmware(equipment_id, latest_firmware_id, cloudSDK_url, bearer)
logger.info("Lab "+fw_model+" Requires FW update") 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') logger.warning('Firmware upgrade API failed to send')
continue continue
print("Wait for AP Upgrade")
time.sleep(300)
# Check if upgrade success is displayed on CloudSDK # Check if upgrade success is displayed on CloudSDK
cloud_ap_fw = CloudSDK.ap_firmware(customer_id, equipment_id, cloudSDK_url, bearer) cloud_ap_fw = CloudSDK.ap_firmware(customer_id, equipment_id, cloudSDK_url, bearer)
print('Current AP Firmware from CloudSDK:', cloud_ap_fw) print('Current AP Firmware from CloudSDK:', cloud_ap_fw)

View File

@@ -157,3 +157,16 @@ class CloudSDK:
response = requests.request("PUT", url, headers=headers, data=json.dumps(equipment_info)) response = requests.request("PUT", url, headers=headers, data=json.dumps(equipment_info))
#print(response) #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

View File

@@ -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

View File

@@ -6,8 +6,8 @@
<head> <head>
<?php <?php
error_reporting(E_ALL); //error_reporting(E_ALL);
ini_set('display_errors', '1'); //ini_set('display_errors', '1');
$results = file_get_contents('report_data.json'); $results = file_get_contents('report_data.json');
$json = json_decode($results, true); $json = json_decode($results, true);
?> ?>
@@ -75,16 +75,52 @@ $json = json_decode($results, true);
<TD style="font-size:12px"><?php echo print_r($json['fw_under_test']['ecw5410'],true) ?></TD> <TD style="font-size:12px"><?php echo print_r($json['fw_under_test']['ecw5410'],true) ?></TD>
<TD style="font-size:12px"><?php echo print_r($json['fw_under_test']['ec420'],true) ?></TD> <TD style="font-size:12px"><?php echo print_r($json['fw_under_test']['ec420'],true) ?></TD>
</TR> </TR>
<TR ALIGN="CENTER" style="font-weight:bold">
<TD></TD>
<TD ALIGN="LEFT" >CloudSDK Commit Date</TD>
<TD style="font-size:12px"><?php echo print_r($json['cloud_sdk']['ea8300']['date'],true) ?></TD>
<TD style="font-size:12px"><?php echo print_r($json['cloud_sdk']['ecw5211']['date'],true) ?></TD>
<TD style="font-size:12px"><?php echo print_r($json['cloud_sdk']['ecw5410']['date'],true) ?></TD>
<TD style="font-size:12px"><?php echo print_r($json['cloud_sdk']['ec420']['date'],true) ?></TD>
</TR>
<TR ALIGN="CENTER" style="font-weight:bold">
<TD></TD>
<TD ALIGN="LEFT" >CloudSDK Commit ID</TD>
<TD style="font-size:10px"><?php echo print_r($json['cloud_sdk']['ea8300']['commitId'],true) ?></TD>
<TD style="font-size:10px"><?php echo print_r($json['cloud_sdk']['ecw5211']['commitId'],true) ?></TD>
<TD style="font-size:10px"><?php echo print_r($json['cloud_sdk']['ecw5410']['commitId'],true) ?></TD>
<TD style="font-size:10px"><?php echo print_r($json['cloud_sdk']['ec420']['commitId'],true) ?></TD>
</TR>
<TR ALIGN="CENTER" style="font-weight:bold">
<TD></TD>
<TD ALIGN="LEFT" >CloudSDK Project Version</TD>
<TD style="font-size:12px"><?php echo print_r($json['cloud_sdk']['ea8300']['projectVersion'],true) ?></TD>
<TD style="font-size:12px"><?php echo print_r($json['cloud_sdk']['ecw5211']['projectVersion'],true) ?></TD>
<TD style="font-size:12px"><?php echo print_r($json['cloud_sdk']['ecw5410']['projectVersion'],true) ?></TD>
<TD style="font-size:12px"><?php echo print_r($json['cloud_sdk']['ec420']['projectVersion'],true) ?></TD>
</TR>
<TR ALIGN="CENTER" style="font-weight:bold"> <TR ALIGN="CENTER" style="font-weight:bold">
<TD></TD> <TD></TD>
<TD ALIGN="LEFT">Test Pass Rate</TD> <TD ALIGN="LEFT">Test Pass Rate</TD>
<TD style="font-size:14px"><?php echo print_r($json['pass_percent']['ea8300'],true) ?>%</TD> <TD style="font-size:14px"><?php echo print_r($json['pass_percent']['ea8300'],true) ?></TD>
<TD style="font-size:14px"><?php echo print_r($json['pass_percent']['ecw5211'],true) ?>%</TD> <TD style="font-size:14px"><?php echo print_r($json['pass_percent']['ecw5211'],true) ?></TD>
<TD style="font-size:14px"><?php echo print_r($json['pass_percent']['ecw5410'],true) ?>%</TD> <TD style="font-size:14px"><?php echo print_r($json['pass_percent']['ecw5410'],true) ?></TD>
<TD style="font-size:14px"><?php echo print_r($json['pass_percent']['ec420'],true) ?>%</TD> <TD style="font-size:14px"><?php echo print_r($json['pass_percent']['ec420'],true) ?></TD>
</TR> </TR>
<TR ALIGN="CENTER">
<TD>5540</TD>
<TD ALIGN="LEFT">Get CloudSDK Version with API</TD>
<TD><?php echo print_r($json['tests']['ea8300']['5540'],true) ?></TD>
<TD><?php echo print_r($json['tests']['ecw5211']['5540'],true) ?></TD>
<TD><?php echo print_r($json['tests']['ecw5410']['5540'],true) ?></TD>
<TD><?php echo print_r($json['tests']['ec420']['5540'],true) ?></TD>
</TR>
<TR ALIGN="CENTER"> <TR ALIGN="CENTER">
<TD>2233</TD> <TD>2233</TD>
<TD ALIGN="LEFT">AP Upgrade Successful</TD> <TD ALIGN="LEFT">AP Upgrade Successful</TD>