mirror of
https://github.com/Telecominfraproject/wlan-testing.git
synced 2025-11-01 19:37:54 +00:00
310 lines
9.6 KiB
Python
310 lines
9.6 KiB
Python
# import files in the current directory
|
|
import datetime
|
|
import sys
|
|
import os
|
|
import time
|
|
import allure
|
|
|
|
sys.path.append(
|
|
os.path.dirname(
|
|
os.path.realpath(__file__)
|
|
)
|
|
)
|
|
if "libs" not in sys.path:
|
|
sys.path.append(f'../libs')
|
|
for folder in 'py-json', 'py-scripts':
|
|
if folder not in sys.path:
|
|
sys.path.append(f'../lanforge/lanforge-scripts/{folder}')
|
|
|
|
sys.path.append(f"../lanforge/lanforge-scripts/py-scripts/tip-cicd-sanity")
|
|
|
|
sys.path.append(f'../libs')
|
|
sys.path.append(f'../libs/lanforge/')
|
|
|
|
from LANforge.LFUtils import *
|
|
|
|
if 'py-json' not in sys.path:
|
|
sys.path.append('../py-scripts')
|
|
from apnos.apnos import APNOS
|
|
from controller.controller import Controller
|
|
from controller.controller import ProfileUtility
|
|
from controller.controller import FirmwareUtility
|
|
import pytest
|
|
import logging
|
|
from configuration import RADIUS_SERVER_DATA
|
|
from configuration import TEST_CASES
|
|
from configuration import CONFIGURATION
|
|
from configuration import FIRMWARE
|
|
from testrails.testrail_api import APIClient
|
|
from testrails.reporting import Reporting
|
|
import sta_connect2
|
|
from sta_connect2 import StaConnect2
|
|
|
|
|
|
def pytest_addoption(parser):
|
|
parser.addini("tr_url", "Test Rail URL")
|
|
parser.addini("tr_prefix", "Test Rail Prefix (Generally Testbed_name_)")
|
|
parser.addini("tr_user", "Testrail Username")
|
|
parser.addini("tr_pass", "Testrail Password")
|
|
parser.addini("tr_project_id", "Testrail Project ID")
|
|
parser.addini("milestone", "milestone Id")
|
|
|
|
parser.addini("num_stations", "Number of Stations/Clients for testing")
|
|
|
|
# change behaviour
|
|
parser.addoption(
|
|
"--skip-upgrade",
|
|
action="store_true",
|
|
default=False,
|
|
help="skip updating firmware on the AP (useful for local testing)"
|
|
)
|
|
# change behaviour
|
|
parser.addoption(
|
|
"--force-upgrade",
|
|
action="store_true",
|
|
default=False,
|
|
help="force Upgrading Firmware even if it is already latest version"
|
|
)
|
|
parser.addoption(
|
|
"--force-upload",
|
|
action="store_true",
|
|
default=False,
|
|
help="force Uploading Firmware even if it is already latest version"
|
|
)
|
|
# this has to be the last argument
|
|
# example: --access-points ECW5410 EA8300-EU
|
|
parser.addoption(
|
|
"--testbed",
|
|
# nargs="+",
|
|
default="basic-01",
|
|
help="AP Model which is needed to test"
|
|
)
|
|
parser.addoption(
|
|
"--skip-testrail",
|
|
action="store_true",
|
|
default=False,
|
|
help="Stop using Testrails"
|
|
)
|
|
|
|
|
|
"""
|
|
Test session base fixture
|
|
"""
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def testbed(request):
|
|
var = request.config.getoption("--testbed")
|
|
allure.attach(body=str(var),
|
|
name="Testbed Selected : ")
|
|
yield var
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def should_upload_firmware(request):
|
|
yield request.config.getoption("--force-upload")
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def should_upgrade_firmware(request):
|
|
yield request.config.getoption("--force-upgrade")
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def radius_info():
|
|
allure.attach(body=str(RADIUS_SERVER_DATA), name="Radius server Info: ")
|
|
yield RADIUS_SERVER_DATA
|
|
|
|
|
|
# Get Configuration data f
|
|
@pytest.fixture(scope="session")
|
|
def get_configuration(testbed):
|
|
allure.attach(body=str(testbed), name="Testbed Selected: ")
|
|
yield CONFIGURATION[testbed]
|
|
|
|
|
|
# APNOS Library
|
|
@pytest.fixture(scope="session")
|
|
def get_apnos():
|
|
yield APNOS
|
|
|
|
|
|
# Controller Fixture
|
|
@pytest.fixture(scope="session")
|
|
def setup_controller(request, get_configuration):
|
|
try:
|
|
sdk_client = Controller(controller_data=get_configuration["controller"])
|
|
allure.attach(body=str(get_configuration["controller"]), name="Controller Instantiated: ")
|
|
|
|
def teardown_controller():
|
|
print("\nTest session Completed")
|
|
allure.attach(body=str(get_configuration["controller"]), name="Controller Teardown: ")
|
|
sdk_client.disconnect_Controller()
|
|
|
|
request.addfinalizer(teardown_controller)
|
|
except Exception as e:
|
|
print(e)
|
|
allure.attach(body=str(e), name="Controller Instantiation Failed: ")
|
|
sdk_client = False
|
|
yield sdk_client
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def instantiate_firmware(controller_instance, instantiate_jFrog, get_configuration):
|
|
firmware_client_obj = []
|
|
for access_point_info in get_configuration['access_point']:
|
|
firmware_client = FirmwareUtility(jfrog_credentials=instantiate_jFrog, sdk_client=controller_instance,
|
|
model=access_point_info["model"],
|
|
version=access_point_info["version"])
|
|
firmware_client_obj.append(firmware_client)
|
|
yield firmware_client_obj
|
|
|
|
|
|
"""
|
|
Instantiate Reporting
|
|
"""
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def instantiate_reporting(request, testbed, get_latest_firmware):
|
|
if request.config.getoption("--skip-testrail"):
|
|
tr_client = Reporting()
|
|
else:
|
|
tr_client = APIClient(request.config.getini("tr_url"), request.config.getini("tr_user"),
|
|
request.config.getini("tr_pass"), request.config.getini("tr_project_id"))
|
|
if request.config.getoption("--skip-testrail"):
|
|
tr_client.rid = "skip testrails"
|
|
else:
|
|
projId = tr_client.get_project_id(project_name=request.config.getini("tr_project_id"))
|
|
test_run_name = request.config.getini("tr_prefix") + testbed + "_" + str(
|
|
datetime.date.today()) + "_" + get_latest_firmware
|
|
tr_client.create_testrun(name=test_run_name, case_ids=list(TEST_CASES.values()), project_id=projId,
|
|
milestone_id=request.config.getini("milestone"),
|
|
description="Automated Nightly Sanity test run for new firmware build")
|
|
rid = tr_client.get_run_id(test_run_name=test_run_name)
|
|
tr_client.rid = rid
|
|
yield tr_client
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def instantiate_jFrog():
|
|
yield FIRMWARE["JFROG"]
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def check_lanforge_connectivity(testbed):
|
|
# Check port
|
|
yield True
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def setup_perfecto_devices(request):
|
|
yield True
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def test_cases():
|
|
yield TEST_CASES
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def instantiate_access_point(testbed):
|
|
APNOS(CONFIGURATION[testbed]['access_point'][0], pwd="../libs/apnos/")
|
|
yield True
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def test_access_point(testbed, instantiate_access_point):
|
|
ap_ssh = APNOS(CONFIGURATION[testbed]['access_point'][0])
|
|
ap_ssh.reboot()
|
|
time.sleep(100)
|
|
status = ap_ssh.get_manager_state()
|
|
if "ACTIVE" not in status:
|
|
time.sleep(30)
|
|
ap_ssh = APNOS(CONFIGURATION[testbed]['access_point'][0])
|
|
status = ap_ssh.get_manager_state()
|
|
yield status
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def setup_profile_data(testbed):
|
|
model = CONFIGURATION[testbed]["access_point"][0]["model"]
|
|
profile_data = {}
|
|
for mode in "BRIDGE", "NAT", "VLAN":
|
|
profile_data[mode] = {}
|
|
for security in "OPEN", "WPA", "WPA2_P", "WPA2_E", "WEP":
|
|
profile_data[mode][security] = {}
|
|
for radio in "2G", "5G":
|
|
profile_data[mode][security][radio] = {}
|
|
name_string = f"{'Sanity'}-{testbed}-{model}-{radio}_{security}_{mode}"
|
|
ssid_name = f"{'Sanity'}-{model}-{radio}_{security}_{mode}"
|
|
passkey_string = f"{radio}-{security}_{mode}"
|
|
profile_data[mode][security][radio]["profile_name"] = name_string
|
|
profile_data[mode][security][radio]["ssid_name"] = ssid_name
|
|
if mode == "VLAN":
|
|
profile_data[mode][security][radio]["vlan"] = 100
|
|
else:
|
|
profile_data[mode][security][radio]["vlan"] = 1
|
|
if mode != "NAT":
|
|
profile_data[mode][security][radio]["mode"] = "BRIDGE"
|
|
else:
|
|
profile_data[mode][security][radio]["mode"] = "NAT"
|
|
if security != "OPEN":
|
|
profile_data[mode][security][radio]["security_key"] = passkey_string
|
|
else:
|
|
profile_data[mode][security][radio]["security_key"] = "[BLANK]"
|
|
yield profile_data
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def get_security_flags():
|
|
security = ["open", "wpa", "wpa2_personal", "wpa2_enterprise", "wpa3_enterprise", "twog", "fiveg", "radius"]
|
|
yield security
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def get_markers(request, get_security_flags):
|
|
session = request.node
|
|
markers = list()
|
|
security = get_security_flags
|
|
security_dict = dict().fromkeys(security)
|
|
for item in session.items:
|
|
for j in item.iter_markers():
|
|
markers.append(j.name)
|
|
# print(set(markers))
|
|
for i in security:
|
|
if set(markers).__contains__(i):
|
|
security_dict[i] = True
|
|
else:
|
|
security_dict[i] = False
|
|
# print(security_dict)
|
|
allure.attach(body=str(security_dict), name="Test Cases Requires: ")
|
|
yield security_dict
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def get_latest_firmware(instantiate_firmware):
|
|
try:
|
|
latest_firmware = instantiate_firmware.get_fw_version()
|
|
except Exception as e:
|
|
print(e)
|
|
latest_firmware = False
|
|
yield latest_firmware
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def check_ap_firmware_ssh(testbed):
|
|
try:
|
|
ap_ssh = APNOS(CONFIGURATION[testbed]['access_point'][0])
|
|
active_fw = ap_ssh.get_active_firmware()
|
|
print(active_fw)
|
|
except Exception as e:
|
|
print(e)
|
|
active_fw = False
|
|
yield active_fw
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def client_connectivity():
|
|
yield StaConnect2
|