Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
name: Pylint

on: [push]
on:
push:
branches: [master ]

pull_request:
branches: [ master ]
types: [ opened, synchronize, reopened ]


jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7","3.8", "3.9", "3.10"]
python-version: ["3.9", "3.10", "3.11", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
57 changes: 29 additions & 28 deletions Gentest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,27 @@
import argparse

patch_file = sys.argv[1]
final_py_file = 'test_'+sys.argv[1]+'.py'
data_file= 'sudocode.txt'
final_py_file = 'test_' + sys.argv[1] + '.py'
data_file = 'sudocode.txt'
WCA_CLI_PATH = 'wca-api/WCA_CLI'
WCA_CLI_REPO_URL="https://github.ibm.com/code-assistant/wca-api.git"
WCA_CLI_REPO_URL = "https://github.ibm.com/code-assistant/wca-api.git"


def run_wca_cli_commands(patch_file, data_file):

#Check APIKEY exist in enviroment
# Check APIKEY exist in enviroment
if not os.getenv("IAM_APIKEY"):
print("Error: IAM_APIKEY is not set. Please export it by -> export IAM_APIKEY=your_api_key_here and make sure having python3.13+ Environment")
sys.exit(1)
#Ensure WCA_CLI repo exists locally. If not, automatically clone it.

# Ensure WCA_CLI repo exists locally. If not, automatically clone it.
if not os.path.isdir(WCA_CLI_PATH):
print("The '{WCA_CLI_PATH}' directory does not exist.")
print("Cloning repository from {WCA_CLI_REPO_URL}...")
subprocess.run(["git", "clone", WCA_CLI_REPO_URL])
print("Repository cloned successfully!")

#Run WCA_CLI commands to gather explanations and generate test code.
# Run WCA_CLI commands to gather explanations and generate test code.
history = [
"What specific issues does this patch address",
"Are there any prerequisites or dependencies for applying this patch"
Expand All @@ -55,26 +56,25 @@ def run_wca_cli_commands(patch_file, data_file):
history1 = [
"generate a python py unitest for the patch using the avocado-misc-tests style",
]

for i,prompt in enumerate(history,start=1):
command = [
"python", "wca-api/WCA_CLI/wca_cli.py", "prompt", prompt,
"--source-file", patch_file
]
print(f"Executing {i}: {prompt}")
subprocess.run(command)
print("\n")

for i, prompt1 in enumerate(history1, start=1):
with open(data_file, "w") as outfile:
command = [
"python", "wca-api/WCA_CLI/wca_cli.py", "unit-test", "--using", "avacado framework",
patch_file

]
print(f"Executing {i}: {prompt1}")
subprocess.run(command, stdout=outfile)
print("\n")
for i, prompt in enumerate(history, start=1):
command = [
"python", "wca-api/WCA_CLI/wca_cli.py", "prompt", prompt,
"--source-file", patch_file
]
print(f"Executing {i}: {prompt}")
subprocess.run(command)
print("\n")

for i, prompt1 in enumerate(history1, start=1):
with open(data_file, "w") as outfile:
command = [
"python", "wca-api/WCA_CLI/wca_cli.py", "unit-test", "--using", "avacado framework",
patch_file
]
print(f"Executing {i}: {prompt1}")
subprocess.run(command, stdout=outfile)
print("\n")


def extract_python_code(input_file, output_file):
Expand Down Expand Up @@ -115,6 +115,7 @@ def extract_python_code(input_file, output_file):
# Outside block
in_code_block = False


def main():

parser = argparse.ArgumentParser(
Expand All @@ -135,10 +136,10 @@ def main():
)
args = parser.parse_args()

print("Running WCA_CLI commands for patch:",patch_file)
print("Running WCA_CLI commands for patch:", patch_file)
run_wca_cli_commands(patch_file, data_file)

print("Extracting Python code from "+data_file+" to "+ final_py_file)
print("Extracting Python code from " + data_file + " to " + final_py_file)
extract_python_code(data_file, final_py_file)


Expand Down
51 changes: 28 additions & 23 deletions avocado-setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
# pylint: disable=E0602
# Copyright (C) IBM Corp. 2016.
#
# This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -50,16 +51,19 @@ class Result(Enum):
Failures = "failures"
Skip = "skip"
Warn = "warn"
Interrupt ="interrupt"
Interrupt = "interrupt"


class Testsuite_status(Enum):
Total = "Total"
Run = "Run"
Not_Run = "Not_Run"
Cant_Run = "Cant_Run"

count_result = { _.value : 0 for _ in Result}
count_testsuites_status = { _.value : 0 for _ in Testsuite_status}

count_result = {_.value: 0 for _ in Result}
count_testsuites_status = {_.value: 0 for _ in Testsuite_status}


class TestSuite():
"""
Expand Down Expand Up @@ -146,9 +150,9 @@ def env_check(enable_kvm):
if packages != '':
env_deps = packages.split(',')
for dep in env_deps:
if(dep[-1] == "$"):
#Substrings
formatted_dep=dep[:-1]
if dep[-1] == "$":
# Substrings
formatted_dep = dep[:-1]
original_dep = formatted_dep
else:
#Absoulute strings
Expand Down Expand Up @@ -439,6 +443,7 @@ def run_test(testsuite, avocado_bin, runner, linux_src_path):
test_bucket = "_".join([out[1], out[2]])
logger.info("Capturing the Gcov data.....")
if test_bucket.startswith("io_"):
driver_name = None
with open(input_file, 'r') as file:
for line in file:
if line.startswith("module"):
Expand Down Expand Up @@ -712,11 +717,11 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm, runner):
default=None,
help="To run the host tests provided in the option and publish result [Note: test names(full path) and separated by comma]")
parser.add_argument('--config-env', dest='CONFIG_PATH',
action='store', default=CONFIG_PATH,
help='Specify env config path')
action='store', default=CONFIG_PATH,
help='Specify env config path')
parser.add_argument('--config-norun', dest='NORUNTEST_PATH',
action='store', default=NORUNTEST_PATH,
help='Specify no run tests config path')
action='store', default=NORUNTEST_PATH,
help='Specify no run tests config path')

args = parser.parse_args()

Expand All @@ -742,19 +747,19 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm, runner):
logger.error(f"No Run Config Path: {args.NORUNTEST_PATH} not defined")
sys.exit(1)

globals() ['TEST_CONF_PATH'] = os.path.join(BASE_PATH, eval(CONFIGFILE.get('paths', 'test_cfg_dir')))
globals() ['LOG_DIR'] = os.path.join(BASE_PATH, eval(CONFIGFILE.get('paths', 'results_dir')))
globals() ['TEST_DIR'] = os.path.join(BASE_PATH, eval(CONFIGFILE.get('paths', 'test_dir')))
globals() ['DATA_DIR'] = os.path.join(BASE_PATH, eval(CONFIGFILE.get('paths', 'data_dir')))
globals() ['prescript'] = os.path.join(BASE_PATH, eval(CONFIGFILE.get('paths', 'pre_script_dir')))
globals() ['postscript'] = os.path.join(BASE_PATH, eval(CONFIGFILE.get('paths', 'post_script_dir')))
globals() ['BASE_FRAMEWORK'] = eval(CONFIGFILE.get('framework', 'base'))
globals() ['KVM_FRAMEWORK'] = eval(CONFIGFILE.get('framework', 'kvm'))
globals() ['OPTIONAL_FRAMEWORK'] = eval(CONFIGFILE.get('framework', 'optional'))
globals() ['TEST_REPOS'] = eval(CONFIGFILE.get('tests', 'name'))
globals() ['prescript_dir'] = CONFIGFILE.get('script-dir', 'prescriptdir')
globals() ['postscript_dir'] = CONFIGFILE.get('script-dir', 'postscriptdir')
globals() ['PIP_PACKAGES'] = eval(CONFIGFILE.get('pip-package', 'package'))
globals()['TEST_CONF_PATH'] = os.path.join(BASE_PATH, eval(CONFIGFILE.get('paths', 'test_cfg_dir')))
globals()['LOG_DIR'] = os.path.join(BASE_PATH, eval(CONFIGFILE.get('paths', 'results_dir')))
globals()['TEST_DIR'] = os.path.join(BASE_PATH, eval(CONFIGFILE.get('paths', 'test_dir')))
globals()['DATA_DIR'] = os.path.join(BASE_PATH, eval(CONFIGFILE.get('paths', 'data_dir')))
globals()['prescript'] = os.path.join(BASE_PATH, eval(CONFIGFILE.get('paths', 'pre_script_dir')))
globals()['postscript'] = os.path.join(BASE_PATH, eval(CONFIGFILE.get('paths', 'post_script_dir')))
globals()['BASE_FRAMEWORK'] = eval(CONFIGFILE.get('framework', 'base'))
globals()['KVM_FRAMEWORK'] = eval(CONFIGFILE.get('framework', 'kvm'))
globals()['OPTIONAL_FRAMEWORK'] = eval(CONFIGFILE.get('framework', 'optional'))
globals()['TEST_REPOS'] = eval(CONFIGFILE.get('tests', 'name'))
globals()['prescript_dir'] = CONFIGFILE.get('script-dir', 'prescriptdir')
globals()['postscript_dir'] = CONFIGFILE.get('script-dir', 'postscriptdir')
globals()['PIP_PACKAGES'] = eval(CONFIGFILE.get('pip-package', 'package'))

if helper.get_machine_type() == 'pHyp':
args.enable_kvm = False
Expand Down
7 changes: 3 additions & 4 deletions lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def remove_file(src, dest):


class PipMagager:
def __init__(self, base_fw=[], opt_fw=[], kvm_fw=[],pip_packages=[], enable_kvm=False):
def __init__(self, base_fw=[], opt_fw=[], kvm_fw=[], pip_packages=[], enable_kvm=False):
"""
helper class to parse, install, uninstall pip package from user config
"""
Expand Down Expand Up @@ -254,7 +254,7 @@ def install(self):
for package in self.install_packages:
cmd = '%s %s' % (pip_installcmd, package)
if (self.pip_vmajor > 23) or (self.pip_vmajor == 23 and self.pip_vminor >= 1):
cmd = cmd + ' --break-system-packages' # --break-system-packages introduced in pip 23.1
cmd = cmd + ' --break-system-packages' # --break-system-packages introduced in pip 23.1
runcmd(cmd,
err_str='Package installation via pip failed: package %s' % package,
debug_str='Installing python package %s using pip' % package)
Expand All @@ -263,13 +263,12 @@ def uninstall(self):
for package in self.uninstall_packages:
cmd = '%s uninstall %s -y --disable-pip-version-check' % (self.pip_cmd, package)
if (self.pip_vmajor > 23) or (self.pip_vmajor == 23 and self.pip_vminor >= 1):
cmd = cmd + ' --break-system-packages' # --break-system-packages introduced in pip 23.1
cmd = cmd + ' --break-system-packages' # --break-system-packages introduced in pip 23.1
runcmd(cmd, ignore_status=True,
err_str="Error in removing package: %s" % package,
debug_str="Uninstalling %s" % package)



class RemoteRunner:
"""
SSH-based remote command runner using ``sshpass`` + the system ``ssh``
Expand Down
4 changes: 2 additions & 2 deletions lib/hmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def get_vios_info(self, managed_system):
continue
# Format: "ltcden7-vios1,vioserver"
parts = line.split(',')
name = parts[0].strip()
name = parts[0].strip()
lpar_env = parts[1].strip() if len(parts) > 1 else ''
# Match on lpar_env containing "vio" OR partition name containing "vios"
if ('vio' in lpar_env.lower() or 'vios' in name.lower()) and name:
Expand All @@ -419,7 +419,7 @@ def get_vios_info(self, managed_system):
if len(names) == 1:
names = names * 2
vios_names = ' '.join(names)
vios_ip = ' '.join(v['ip'] for v in vios_list if v['ip'])
vios_ip = ' '.join(v['ip'] for v in vios_list if v['ip'])
logger.info("VIOS on '%s': names=%s ips=%s", managed_system, vios_names, vios_ip)
return {'vios_names': vios_names, 'vios_ip': vios_ip, 'vios_list': vios_list}

Expand Down
11 changes: 9 additions & 2 deletions lib/pci.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
import platform
from .helper import runcmd, is_rhel8
from lib.logger import logger_init


class NWException(Exception):
"""Exception for network/PCI related errors."""


BASE_PATH = os.path.dirname(os.path.abspath(__file__))
logger = logger_init(filepath=BASE_PATH).getlogger()

Expand Down Expand Up @@ -307,8 +313,8 @@ def get_interfaces_in_pci_address(pci_address, pci_class):
if not pci_class or not os.path.isdir(pci_class_path):
return ""
return [interface for interface in os.listdir(pci_class_path)
if os.path.islink(os.path.join(pci_class_path, interface)) and pci_address \
in os.readlink(os.path.join(pci_class_path, interface))]
if os.path.islink(os.path.join(pci_class_path, interface)) and pci_address
in os.readlink(os.path.join(pci_class_path, interface))]


def get_pci_class_name(pci_address):
Expand Down Expand Up @@ -633,6 +639,7 @@ def get_secondary_ioa(primary_ioa):
return ioa_detail['ioa']
return ''


def is_sriov(pci_address):
"""
Check if interface is a SRIOV virtual interface.
Expand Down
3 changes: 1 addition & 2 deletions lib/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import re
import os
import platform

from .helper import runcmd
from lib.logger import logger_init
Expand Down Expand Up @@ -211,4 +210,4 @@ def virtual_info(interface, runner=None):
virtual_dict['adapter_type'] = 'hnv'

virtual_list.append(virtual_dict)
return virtual_list
return virtual_list
Loading
Loading