Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
aa87d55
Revert "sles16: adding dependencies" (#353)
spoorthys1303 Mar 11, 2025
4464a64
Adding a new section for sles16 (#354)
bskjois Mar 12, 2025
bd4f6ec
Fix pip based installation in helper
AYUSHJAIN951 Mar 27, 2025
69d1c6d
Merge pull request #355 from AYUSHJAIN951/pip_version_patch
narasimhan-v Apr 10, 2025
c680e42
Fix branch checkout for tests
bssrikanth Apr 11, 2025
99288df
Fix tests file path from test cfg
AYUSHJAIN951 Apr 11, 2025
354665b
Print final count summary after test run
AYUSHJAIN951 Apr 12, 2025
48076f4
Add summary of testsuites ran
AYUSHJAIN951 Apr 12, 2025
3e028bf
Use Testsuite_status enum instead of hardcoded status strings
AYUSHJAIN951 Apr 12, 2025
da24e77
Fix tests repo handling
AYUSHJAIN951 Apr 11, 2025
3983340
Add helper comments to env.conf
AYUSHJAIN951 Apr 10, 2025
0cc1cc2
Merge pull request #357 from AYUSHJAIN951/envconf
narasimhan-v Apr 21, 2025
d419378
Merge pull request #356 from bssrikanth/fix_branchcheckout
narasimhan-v Apr 21, 2025
61804ff
Merge pull request #359 from AYUSHJAIN951/fixtestpath
narasimhan-v Apr 21, 2025
53dda2d
Merge pull request #360 from AYUSHJAIN951/testsummary
narasimhan-v Apr 21, 2025
f0222dd
Merge pull request #361 from AYUSHJAIN951/branchbugfix
narasimhan-v Apr 21, 2025
5b35429
Add config option for env and norun configurations
AYUSHJAIN951 Mar 28, 2025
f8d46c5
Update README
AYUSHJAIN951 Apr 5, 2025
3753885
Merge pull request #358 from AYUSHJAIN951/configupdate
narasimhan-v Apr 29, 2025
2b595c4
script runs the WCA_CLI commands and can also generate test code for …
yeswanth6096 Jun 10, 2025
6141a0e
Merge pull request #362 from yeswanth6096/WCA-CLI-CodeGen
PraveenPenguin Jun 11, 2025
cdf8acc
Fix package install
AYUSHJAIN951 May 27, 2025
67b11f1
Merge pull request #363 from AYUSHJAIN951/fix_package_install
narasimhan-v Jun 27, 2025
7643e11
Fix package install in tests for non ubuntu system
AYUSHJAIN951 Jun 27, 2025
e8c67e9
Merge pull request #364 from AYUSHJAIN951/fix_package_install
narasimhan-v Jul 9, 2025
a4eabe9
Move paths to env.conf to make it configurable
Jul 28, 2025
177cc18
Merge pull request #365 from narasimhan-v/env_configurable
narasimhan-v Sep 18, 2025
0c617a2
Updated the pci_passthrough.cfg test bucket with the latest configs (…
TasmiyaNalatwad Sep 22, 2025
b21e859
Enable prerequisite pip packages installation
bssrikanth Aug 12, 2025
59ae97d
Merge pull request #366 from bssrikanth/pip_prereq
narasimhan-v Sep 26, 2025
0e8c8e2
Add branch/tag handling for tests
bssrikanth Sep 26, 2025
91efb42
Merge pull request #368 from bssrikanth/tagcheckout_tests
narasimhan-v Sep 29, 2025
13b3242
correcting extra charecter added in the code (#367)
TasmiyaNalatwad Oct 14, 2025
a57168d
Removing 16M hugepages tests from memory test bucket (#369)
TasmiyaNalatwad Oct 14, 2025
af8cdca
Adding P1, P2 and P3 priority config files for CPU Test Bucket
Nov 3, 2025
9bb4988
Adding P1, P2 and P3 priority config files for MIGRATION Test Bucket!…
Anushree-Mathur Nov 6, 2025
74c11be
Merge pull request #377 from Anushree-Mathur/priority_CPU
spoorthys1303 Nov 6, 2025
0c1a92e
libvirt-mem:Fixing hotplug attach device tests
Sep 19, 2024
a58bd68
Update backuprestore.cfg to fix parameter
Nov 26, 2024
2f9c2eb
Update env.conf file to add nfs-utils for Fedora
aniket-sahu-ibmx Nov 23, 2025
a95313b
Merge pull request #379 from aniket-sahu-ibmx/fix_dep
PraveenPenguin Nov 24, 2025
20eb56e
Adding P1, P2 and P3 priority config files for Memory Test Bucket
TasmiyaNalatwad Oct 21, 2025
3b8cf6a
Adding P1, P2 and P3 priority config files for PCI-Passthrough Test B…
TasmiyaNalatwad Oct 21, 2025
e957f9a
Adding P1, P2 and P3 priority config files for Storage Test Bucket
TasmiyaNalatwad Oct 21, 2025
e918b1b
Adding P1, P2 and P3 priority config files for RAS Test Bucket
misanjumn Oct 21, 2025
025516b
Adding P1, P2 and P3 priority config files for Network Bucket
misanjumn Jan 5, 2026
bc7f68e
Removing allocate capacity test from raw & qcow2 format
sneh-3 Dec 18, 2025
5f1612d
Merge branch 'KVMCI' into changesfrommerge
spoorthys1303 Jan 6, 2026
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
146 changes: 146 additions & 0 deletions Gentest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/usr/bin/env python3

"""
Gentest.py
This script runs the WCA_CLI commands and can also generate test code for the patch.

Usage:
./Gentest.py PATCH_NAME

Example:
./Gentest.py fs-patch

Description:
- Takes the patch file name as an argument in the same location.
- User can pass CLI commands to history argument
- Generates a test code file for the patch using avocado-misc-tests style.
- Extracts only the relevant Python code (like import statements, function and class blocks)
from the generated output file and writes it to a final Python file.

Author:
Tellakula Yeswanth Krishna - yeswanth@ibm.com

"""
import os
import sys
import subprocess
import argparse

patch_file = sys.argv[1]
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"

def run_wca_cli_commands(patch_file, data_file):

#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.
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.
history = [
"What specific issues does this patch address",
"Are there any prerequisites or dependencies for applying this patch"
]

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")


def extract_python_code(input_file, output_file):
"""
Extract only Python code (imports, def/class blocks, comments) from the generated file.
"""
with open(input_file, 'r') as infile, open(output_file, 'w') as outfile:
in_code_block = False
current_indent_level = None

for line in infile:
stripped_line = line.lstrip()

# Keep import statements at top level
if stripped_line.startswith('import ') or stripped_line.startswith('from '):
outfile.write(line)
continue

# Start of function or class block
if stripped_line.startswith('def ') or stripped_line.startswith('class '):
in_code_block = True
current_indent_level = len(line) - len(stripped_line)
outfile.write(line)
continue

if in_code_block:
indent_level = len(line) - len(stripped_line)

# Keep blank lines and comments
if not stripped_line or stripped_line.startswith('#'):
outfile.write(line)
continue

# If line is still part of block
if indent_level >= current_indent_level:
outfile.write(line)
else:
# Outside block
in_code_block = False

def main():

parser = argparse.ArgumentParser(
description=(
"Please export APIKEY it by -> export IAM_APIKEY=your_api_key_here and make sure having python3.13+ Environment.\n"
"Have the clone repo: https://github.ibm.com/code-assistant/wca-api.git,If not script handle to clone the Repo.\n"
"Gentest.py: Execute WCA CLI Prompts about patch and Generate Python test code/unit-test for a patch using WCA_CLI and "
"extract relevant code to a final Python file.\n\n"
"Example usage:\n"
" ./Gentest.py fs-patch\n"
"This will create test_fs-patch.py from the WCA_CLI-generated output.\n"
),
formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument(
"patch_name",
help="Patch name or file to process (example: fs-patch)"
)
args = parser.parse_args()

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)
extract_python_code(data_file, final_py_file)


if __name__ == "__main__":
main()
86 changes: 49 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,47 +61,48 @@ It is highly recommended for users to execute the following command as root when

```
$ ./avocado-setup.py -h
usage: avocado-setup.py [-h] [--bootstrap] [--run-suite RUN_SUITE]
[--output-dir OUTPUTDIR] [--use-test-dir]
[--input-file INPUTFILE]
[--interval-time INTERVAL] [--verbose]
[--only-filter ONLY_FILTER] [--no-filter NO_FILTER]
[--additional-args ADD_ARGS] [--guest-os GUEST_OS]
[--vt {qemu,libvirt}] [--install] [--no-download]
[--no-deps-check] [--install-deps] [--clean]
[--enable-kvm]

optional arguments:
-h, --help show this help message and exit
--bootstrap Prepare the environment for test
--run-suite RUN_SUITE
usage: avocado-setup.py [-h] [--bootstrap] [--run-suite RUN_SUITE] [--output-dir OUTPUTDIR]
[--use-test-dir] [--input-file INPUTFILE] [--interval-time INTERVAL]
[--verbose] [--only-filter ONLY_FILTER] [--no-filter NO_FILTER]
[--additional-args ADD_ARGS] [--guest-os GUEST_OS] [--vt {qemu,libvirt}]
[--install] [--no-download] [--no-deps-check] [--install-deps] [--clean]
[--enable-kvm] [--nrunner] [--run-tests RUN_TESTS] [--config-env CONFIG_PATH]
[--config-norun NORUNTEST_PATH]

options:
-h, --help show this help message and exit
--bootstrap Prepare the environment for test
--run-suite RUN_SUITE
Indicate which test suite(s) to run
--output-dir OUTPUTDIR
--output-dir OUTPUTDIR
Specify the custom test results directory
--use-test-dir Use corresponding test-name dir for storing job results
--input-file INPUTFILE
Specify input file for custom mux values for host
tests
--interval-time INTERVAL
--use-test-dir Use corresponding test-name dir for storing job results
--input-file INPUTFILE
Specify input file for custom mux values for host tests
--interval-time INTERVAL
Specify the interval time between tests
--verbose Enable verbose output on the console
--only-filter ONLY_FILTER
Add filters to include specific avocado tests,features
from the guest test suite
--no-filter NO_FILTER
Add filters to exclude specific avocado tests,features
from the guest test suite
--additional-args ADD_ARGS
--verbose Enable verbose output on the console
--only-filter ONLY_FILTER
Add filters to include specific avocado tests,features from the guest test suite
--no-filter NO_FILTER
Add filters to exclude specific avocado tests,features from the guest test suite
--additional-args ADD_ARGS
Pass additional arguments to the command
--guest-os GUEST_OS Provide Guest os: Default: JeOS.27.ppc64le
--vt {qemu,libvirt} Provide VT: qemu or libvirt Default: libvirt
--install Install the Guest VM, if needed.
--no-download To download the preinstalled guest image
--no-deps-check To force wrapper not to check for dependancy packages
--install-deps To force wrapper to install dependancy packages (Only
for Ubuntu, SLES and yum based OS)
--clean To remove/uninstall autotest, avocado from system
--enable-kvm enable bootstrap kvm tests
--guest-os GUEST_OS Provide Guest os: Default: JeOS.27.ppc64le
--vt {qemu,libvirt} Provide VT: qemu or libvirt Default: libvirt
--install Install the Guest VM, if needed.
--no-download To download the preinstalled guest image
--no-deps-check To force wrapper not to check for dependancy packages
--install-deps To force wrapper to install dependancy packages (Only for Ubuntu, SLES and yum based OS)
--clean To remove/uninstall autotest, avocado from system
--enable-kvm enable bootstrap kvm tests
--nrunner enable Parallel run
--run-tests RUN_TESTS
To run the host tests provided in the option and publish result [Note: test names(full path) and separated by comma]
--config-env CONFIG_PATH
Specify env config path
--config-norun NORUNTEST_PATH
Specify no run tests config path

```

Expand Down Expand Up @@ -249,6 +250,17 @@ $ ./avocado-setup.py -h
15. `--enable-kvm`:
> By default kvm(guest VM) tests environment is not bootstrapped, enable this flag to bootstrap KVM (guest VM) tests.

16. `--nrunner`:
> To enable Parallel run through avocado

17. `--run-tests`:
> To run the host tests provided in the option and publish result [Note: test names(full path) and separated by comma]

18. `--config-env`:
> Path to a custom environment config file for Avocado setup.

19. `--config-norun`:
> Path to a custom NORUNTEST File path

### Customizing Test Suites:

Expand Down
Loading
Loading