Skip to content

Commit

Permalink
Added binary executable creation scripts for CTAM + Added versioning …
Browse files Browse the repository at this point in the history
…(-v to print version)
  • Loading branch information
jitendra-nvi authored and afsanac-nv committed Feb 14, 2024
1 parent 074b7c6 commit c26a733
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 25 deletions.
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) NVIDIA CORPORATION
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
# Docker file making ctam build
#

FROM ubuntu:22.04

RUN apt-get update && apt-get install -y software-properties-common

RUN add-apt-repository ppa:deadsnakes/ppa

RUN apt-get update

RUN apt-get install python3-pip zlib1g-dev scons -y

ARG LOCAL_DIR

ENV LOCAL_DIR_ENV=$LOCAL_DIR

WORKDIR /app

COPY . /app

RUN pip3 install --no-cache-dir --upgrade -r pip-requirements.txt

RUN pip3 install --no-cache-dir --upgrade pyinstaller staticx patchelf-wrapper

COPY build_scripts/build_script.sh .

ENTRYPOINT ["/bin/sh", "build_script.sh"]
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) NVIDIA CORPORATION
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
# Makes a executable build of the ctam directory
#

DOCKER_IMAGE_TAG=pyinstaller-ctam
DOCKER_CONTAINER_NAME=build-ctam

build_image:
docker build --tag $(DOCKER_IMAGE_TAG) --build-arg LOCAL_DIR=$(PWD) .
docker run -it --name $(DOCKER_CONTAINER_NAME) $(DOCKER_IMAGE_TAG)
docker cp $(DOCKER_CONTAINER_NAME):/app/dist ./dist
docker rm -f $(DOCKER_CONTAINER_NAME)
docker rmi $(DOCKER_IMAGE_TAG) --force

clean:
rm -rf build ctam.spec dist
docker rm -f $(DOCKER_CONTAINER_NAME)
docker rmi $(DOCKER_IMAGE_TAG) --force
103 changes: 86 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,140 @@ This project is part of [OCPTV](https://github.com/opencomputeproject/ocp-diag-c

## Getting Started

### Prerequisites
Before you begin, ensure you have met the following requirements:

- Python 3.9 or higher is installed
- Python virtualenv and pip is installed
- Install some key libraries:
sudo apt-get install python3-tk sshpass jq
- Docker is installed (Skip unless you want to create a binary)


### Setup

1. Clone the repo,

```https://github.com/opencomputeproject/ocp-diag-ctam```

### Setting up the workspace

1. Sample workspace files are present inside `json_spec` directory. Modify these file as per your infra details.

1. `input` dir inside `json_spec` contains sample input file that ctam require to run

1. Create a workspace directory and copy the configuration files from `json_spec/input` directory into `workspace` dir.

- `.netrc` - contains bmc ipaddress, username and password
- `dut_config.json` - contains various params for running the test cases
- `package_info.json` - contains details about the firmware
- `redfish_uri_config.json` - redfish config file
- `test_runner.json` - config file for test run, can be overridden by cli flags

### Flag description


| CLI Argument | Type | Definition |
| :--- | :--- | :--- |
| `-t` or `--testcase` | string | Runs a single test case. Overrides test_runner.json in the workspace
| `-test_seq` or `--testcase_sequence` | string | Runs a single test case. Overrides test_runner.json in the workspace
| `-group_seq` or `--group_sequence` | string | Runs no of groups with given sequence
| `-s` or `--Suite` | | Run full ACT Suite
| `-g` or `--group` | | Run tests for a single group. Overrides test_runner.json in the workspace
| `-d` or `--Discovery` | | Path to workspace directory that contains test run files
| `-l` or `--list` | string | List all test cases. If combined with -G then list all cases of the chosen group
| `-v` or `--version` | | Lists the current version



### Running the tool locally

1. Optional: create python [virtual environment](https://docs.python.org/3/library/venv.html) and activate.
```
python -m venv venv
source ./venv/bin/activate
```
2. Run
1. Install dependencies
```
python -m pip install -r pip-requirements.txt
```
3. For full documentation, from `/docs` directory, run
1. For full documentation, from `/docs` directory, run
```
./make html
``````
Open `docs/build/html/index.html` for full documentation including architecture and test case details
4. To run suite,
1. To run suite,
```
cd ctam
python ctam.py -w ..\example_workspace
```
Logs will be created under `example_workspace\TestRuns`
5. To list all test cases
1. To list all test cases
```
cd ctam
python ctam.py -l
```
6. To run a specific test case
1. To run a specific test case
```
cd ctam
python ctam.py -w ..\example_workspace -t <test case id>
```
Logs will be created under `example_workspace\TestRuns`
7. To run test cases of a specifc test group
1. To run test cases of a specifc test group
```
cd ctam
python ctam.py -w ..\example_workspace -g <test group name>
```
Logs will be created under `example_workspace\TestRuns`
8. To run test cases with sequence
1. To run test cases with sequence
```
cd ctam
python ctam.py -w ..\example_workspace -test_seq <test case name or id> <test case name or id>
```
Logs will be created under `example_workspace\TestRuns`
9. To run groups with sequence
1. To run groups with sequence
```
cd ctam
python ctam.py -w ..\example_workspace -group_seq <group name or id> <group name or id>
```
Logs will be created under `example_workspace\TestRuns`
10. Choose test cases to run by using tags and specifying the tags to include/exclude in test_runner.json
11. Choose test sequence in test_runner.json if you want to run it from test runner config.
1. Choose test cases to run by using tags and specifying the tags to include/exclude in test_runner.json
1. Choose test sequence in test_runner.json if you want to run it from test runner config.
### Binary
1. One file Binary executable can be created using Makefile, to create binary run following command. This will create binary and sample workspace dir inside the dist folder.
`make build_image`
1. You can run the binary the same way running the python file. Just that now python file replaced by binary executalbe. Sample command to list all test cases.
Note: Please move your workspace directory inside dist directory before running the binary.
`cd dist && ./ctam -l`
1. To clear build files, run:
```make clean```
## Log Files created
1. OCPTV Log file - All logs in OCPTV defined logging format.
2. Test_Score_<>.json - All test cases result + Final score.
3. Test_Report_<>.log - Tabulated report of test run
4. Test_Info_<>.json - Optional log file used by test interfaces (for debug)
5. RedfishCommandDetails/RedfishCommandDetails_<Test_ID>_ <Test_Name>_<>.json - Redfish Commands used & return values (for debug)
1. Test_Score_<>.json - All test cases result + Final score.
1. Test_Report_<>.log - Tabulated report of test run
1. Test_Info_<>.json - Optional log file used by test interfaces (for debug)
1. RedfishCommandDetails/RedfishCommandDetails_<Test_ID>_ <Test_Name>_<>.json - Redfish Commands used & return values (for debug)
## Test Runner Knobs
Test runner knobs can be modified in `test_runner.json` to enable different logging mode.
1. debug_mode - True/False (for debug logs)
2. console_log - True/False (for console logs)
3. progress_bar - True/False (for progress bar idicator)
| Variable | Type | Definition |
| :--- | :--- | :--- |
| `debug_mode` | boolean | For debug logs
| `console_mode` | boolean | For console logs
| `progress_bar` | boolean | For for progress bar indicator
## Tags
Expand Down Expand Up @@ -126,3 +194,4 @@ steps manually to ensure the consistency of the code base.
Feel free to start a new [discussion](https://github.com/opencomputeproject/ocp-diag-ctam/discussions), or otherwise post an [issue/request](https://github.com/opencomputeproject/ocp-diag-ctam/issues).
An email contact is also available at: [email protected]
32 changes: 32 additions & 0 deletions build_scripts/build_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) NVIDIA CORPORATION
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

# get current directory
export current_dir="$LOCAL_DIR_ENV"

# path to binary
dist_dir="${current_dir}/dist"

# pyinstaller command to make binary
pyinstaller_cmd="pyinstaller --add-data=/app/ctam:. --name ctam.build --paths=/app/ctam --onefile ctam/ctam.py --runtime-tmpdir ${dist_dir}"

# static to make one executable
staticx_cmd="staticx ./dist/ctam.build ./dist/ctam"

# clear stale files
clean_cmd="rm /app/dist/ctam.build"

# create sample workspace
create_workspace_cmd="cp -r /app/json_spec/input /app/dist/workspace"

# execute commands

$pyinstaller_cmd

$staticx_cmd

$create_workspace_cmd

$clean_cmd
23 changes: 19 additions & 4 deletions ctam/ctam.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) Microsoft Corporation
# Copyright (c) NVIDIA CORPORATION
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
Expand All @@ -17,6 +17,9 @@
from test_hierarchy import TestHierarchy
from test_runner import TestRunner

from sys import exit
from version import __version__


def parse_args():
"""
Expand Down Expand Up @@ -58,7 +61,7 @@ def parse_args():
parser.add_argument(
"-w",
"--workspace",
required="-l" not in sys.argv and "--list" not in sys.argv,
required=not any(arg in sys.argv for arg in ["-l", "--list", "-v", "--version"]),
help="Path to workspace directory that contains test run files",
)

Expand All @@ -69,6 +72,13 @@ def parse_args():
action="store_true",
)

parser.add_argument(
"-v",
"--version",
help="Display current version of ctam",
action="store_true",
)

return parser.parse_args()

def get_exception_details(exec: Exception = ""):
Expand Down Expand Up @@ -107,7 +117,6 @@ def get_exception_details(exec: Exception = ""):

def main():
args = parse_args()

try:
# builds hierarchy of test groups and associated test cases
test_root_dir = os.path.join(os.path.dirname(__file__), "tests")
Expand All @@ -117,10 +126,15 @@ def main():
if args.list:
test_hierarchy.print_test_groups_test_cases(args.group)
return 0, None, "List of tests is printed"


if args.version:
print(f"CTAM - version {__version__}")
exit()

if not os.path.isdir(args.workspace):
print("Invalid workspace specified")
return 1, None, "Invalid workspace specified"

required_workspace_files = [
"dut_info.json",
"redfish_uri_config.json",
Expand All @@ -135,6 +149,7 @@ def main():
for file_name in missing_files:
print(f"The required file {file_name} does not exist in the workspace.")
return 1, None, "Missing required files"
print(f"Version : {__version__}")
print(f"WorkSpace : {args.workspace}")
test_runner_json = os.path.join(args.workspace, "test_runner.json")
dut_info_json = os.path.join(args.workspace, "dut_info.json")
Expand Down
7 changes: 4 additions & 3 deletions ctam/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
)
from interfaces.comptool_dut import CompToolDut

from version import __version__


class TestRunner:
"""
Expand Down Expand Up @@ -293,7 +295,7 @@ def _start(self, testrun_name="initialization"):
)
tv.config(writer=self.writer)

self.active_run = tv.TestRun(name="CTAM Test Runner", version="1.0")
self.active_run = tv.TestRun(name="CTAM Test Runner", version=__version__)
# FIXME: This needs to be fixed after system details
# if status_code:
# self.active_run.add_log(LogSeverity.INFO, "{}".format(self.system_details))
Expand Down Expand Up @@ -351,7 +353,6 @@ def run(self):
group_instance,
test_case_instances,
) = self.test_hierarchy.instantiate_obj_for_testcase(test)

group_inc_tags = group_instance.tags
print("Group tags ", group_instance.tags)
# group_exc_tags = group_instance.exclude_tags
Expand Down Expand Up @@ -713,7 +714,7 @@ def generate_test_report(self):
"""
t = PrettyTable(["Test ID", "Test Name", "Execution Time", "TestCase Weight", "Test Score", "Test Result"])
t.title = "Test Result"
t.title = f"Test Result - V {__version__}"
t.add_rows(self.test_result_data[:len(self.test_result_data) - 1:])
t.add_row(["", "", "", "", "", ""], divider=True)
t.add_row(self.test_result_data[-1], divider=True)
Expand Down
10 changes: 10 additions & 0 deletions ctam/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
Copyright (c) NVIDIA CORPORATION
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
:Description: Follows versioning as Major.Minor release eg: 1.1
"""

__version__ = '0.1'
2 changes: 1 addition & 1 deletion docs/source/usage/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Set-up
- Pre-requisites for using SSH tunneling to connect to HMC:

#. Install sshpass. In Ubuntu machine, run the following:
``sudo apt-get install python3-tk sshpass``
``sudo apt-get install python3-tk sshpass jq``
#. Enable port-forwarding in HostBMC.

1. On the HostBmc, there is file /etc/ssh/sshd_config. In this file, set the AllowTcpForwarding to yes.
Expand Down
5 changes: 5 additions & 0 deletions release-notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feburary 16, 2024
==============

Version: 0.1
- Initial release

0 comments on commit c26a733

Please sign in to comment.