Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Test module into DTT1 #5165

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
37de8df
enhacement(#4843): Adding checkfiles to install and uninstall
pro-akim Feb 21, 2024
ef1578a
fixes(#4843): Adding features lost by update
pro-akim Feb 21, 2024
d5e72f0
fix(#4843): Adding deps
pro-akim Feb 21, 2024
fcb1862
fix(#4843): Restore provider
pro-akim Feb 21, 2024
7f1cd7d
fix(#4843): Changes done over actions
pro-akim Feb 21, 2024
02460c1
enhacenment(#4850): Adding README.MD
pro-akim Feb 22, 2024
2c267f9
enhacenment(#4850): Adding relevant notes about order of agent tests
pro-akim Feb 22, 2024
885c88c
enhacenment(#4850): Chaning orders
pro-akim Feb 22, 2024
6d07361
fix(#4843): Merging old branch changes to the updated
pro-akim Feb 22, 2024
8ab1abd
enhancement(#4843): Adding one_line installation, adding waiting time…
pro-akim Feb 23, 2024
cbe5608
enhancement(#4843): Removing some /n
pro-akim Feb 23, 2024
db29c08
fix(#4843): Style improvement
pro-akim Feb 23, 2024
e6f72f2
fix(#4843): main order rollback
pro-akim Feb 23, 2024
bcb7e11
enhancement(#4843): Changing installer and uninstaller object name
pro-akim Feb 26, 2024
a0c447c
enhancement(#4844): Adding Uninstall action
pro-akim Feb 27, 2024
c070392
enhancement(#4843): Error handling checked
pro-akim Feb 27, 2024
b849c65
enhancement(#4843): /n fixes
pro-akim Feb 27, 2024
71ff100
enhancements(#4844): Adding playbooks for step by step installation
pro-akim Feb 29, 2024
465f55e
enhancement(#4844): Python methods for manager, agent hosts
pro-akim Mar 5, 2024
3c2262f
enhancement(#4844): Adding more functions to manager, agent and generics
pro-akim Mar 6, 2024
af46847
enhancement(#4844): Developing tests
pro-akim Mar 6, 2024
691405f
enhancement(#4844): Adding methods to agent, manager and generic
pro-akim Mar 7, 2024
1feb29a
enhancement(#4844): Adding stop, restart, and uninstalled tested
pro-akim Mar 11, 2024
ce9ea13
enhancement(#4844): Changing inputs from the test
pro-akim Mar 11, 2024
c7ce3c1
enhancement(#4844): Code improvements and Checkfile Update (bin, sbin…
pro-akim Mar 12, 2024
dca3507
enhancement(#4844): Adding filters to checkfiles
pro-akim Mar 12, 2024
c71106d
enhancement(#4844): Staticmethods and target added
pro-akim Mar 13, 2024
f4796d1
enhancement(#4844): Changes of vagrant home to pwd
pro-akim Mar 13, 2024
db58f7f
enhancement(#4844): General methods were added + filters from install.sh
pro-akim Mar 14, 2024
0adc8e9
enhancement(#4844): cert creation reversed
pro-akim Mar 15, 2024
29dc0ce
enhancement(#4844): Connection between WF and Tests done
pro-akim Mar 15, 2024
14e7aed
enhancement(#4844): dtt1 poc and uninstall validation upgraded
pro-akim Mar 15, 2024
badcf4b
enhancement(#4843): Adding Api method and layer to test from localhost
pro-akim Mar 18, 2024
080b7a2
enhancement(#4843): Tested version with dynamic waits
pro-akim Mar 19, 2024
11b6ac8
enhancement(#4843): More dynamic waits
pro-akim Mar 19, 2024
33bc706
enhancement(#4843): Removing uninstall at the end, API password and u…
pro-akim Mar 19, 2024
a0ef700
enhancement(#4843): Fixing white spaces
pro-akim Mar 19, 2024
e31b366
enhancement(#4844): Multiple workers can connect
pro-akim Mar 19, 2024
dd818b7
enhancement(#4844): Fixes after review, changing testing.py and metho…
pro-akim Mar 20, 2024
d1837a3
enhancement(#4843): Changes to work with AWS
pro-akim Mar 21, 2024
d05be9a
fix(#4843): Small fixes indentation
pro-akim Mar 21, 2024
a9db1da
fix(#4843): Remove ansible empty variable
pro-akim Mar 21, 2024
da52a2b
Enhancement(#4843): Remove print
pro-akim Mar 21, 2024
d56b35c
fix(#4843): Changing config.yml using private ips
pro-akim Mar 21, 2024
f87b1b5
enhancement(#4843): Updating filters
pro-akim Mar 22, 2024
791df33
enhancement(#4843): Adding filters
pro-akim Mar 22, 2024
2135327
enhancement(#4843): Adding filters
pro-akim Mar 22, 2024
5d76a43
enhancement(#4844): Adding filters and fixing private and public IPs
pro-akim Mar 22, 2024
7fdb170
fix(#4843): Changing if condition for certs creation
pro-akim Mar 22, 2024
fae25f7
fix(#4844): Changing if condition in certs creation
pro-akim Mar 22, 2024
d8a834a
fix(#4843): Fixing certs scp ips
pro-akim Mar 25, 2024
978fe70
Merge pull request #4998 from wazuh/enhancement/4843-dtt1-iteracion3-…
fcaffieri Mar 25, 2024
993a6b5
fix(#4844): Fixes after review
pro-akim Mar 25, 2024
9b7f195
Merge branch 'enhancement/4848-dtt1-iteration-3-test-module' into enh…
pro-akim Mar 25, 2024
c4f62d2
fix(#4844): Making dependencies optional
pro-akim Mar 25, 2024
b4f2d1b
enhancement(#4902): Error handling and logs
pro-akim Mar 25, 2024
b5bbca3
enhancement(#4844): Changing execute_commands methods
pro-akim Mar 26, 2024
431e6dd
Merge pull request #5112 from wazuh/enhancement/4844-dtt1-iteration-3…
QU3B1M Mar 26, 2024
2517e24
Add copyright headers to all test module files
QU3B1M Mar 26, 2024
f6095fc
enhancement(#4902): Changing debug comments to info
pro-akim Mar 26, 2024
98273a5
enhancement(#4902): Changing indentation
pro-akim Mar 26, 2024
b924e8c
fix(#4922): Fixing Manager API request host and adding scp confirmation
pro-akim Mar 26, 2024
f0e95e3
enhancement(#4902): Changing logs of checkfiles)
pro-akim Mar 26, 2024
6730d5f
fix(#4902): Fixing unsupported os message
pro-akim Mar 27, 2024
4d9cd40
Merge pull request #5153 from wazuh/enhancement/5144-test-add-copyrig…
fcaffieri Mar 27, 2024
9c15759
fix(#4902): White spaces
pro-akim Mar 27, 2024
e5ee6f6
enhancement(#4902): Conflicts solved
pro-akim Mar 27, 2024
53c30a4
enhancement(#4902): Conflicts error solved
pro-akim Mar 27, 2024
d443428
fix(#4902): Assertions instead of error messages only
pro-akim Mar 27, 2024
79bc376
enhancement(#4902): Removing repeated test
pro-akim Mar 27, 2024
ca8e6c7
Merge pull request #5148 from wazuh/enhancement/4902-dtt1-iteration-3…
QU3B1M Mar 27, 2024
c752486
Merge branch 'enhancement/4495-DTT1' into enhancement/4848-dtt1-itera…
QU3B1M Mar 27, 2024
103ab4f
Merge branch 'enhancement/4495-DTT1' into enhancement/4848-dtt1-itera…
fcaffieri Mar 27, 2024
76fa92e
Removed unused variable
rauldpm Apr 1, 2024
6698385
fix(#4850): Fixes after review
pro-akim Apr 1, 2024
c37afe8
fix(#4850): Fixes of depends on
pro-akim Apr 1, 2024
9e5f56a
fix(#4850): Fixes of readme.md
pro-akim Apr 1, 2024
af4b19f
fix(#4850): Fixes of readme.md wf
pro-akim Apr 1, 2024
8442103
fix(#4850): removing readme.md wf
pro-akim Apr 1, 2024
19221f5
fix(#4850): removing readme.md wf final
pro-akim Apr 1, 2024
aa4254b
fix(#4850): adding .py
pro-akim Apr 1, 2024
0a77c0c
Merge pull request #5005 from wazuh/enhancement/4850-dtt1-iteration-3…
rauldpm Apr 1, 2024
d02dcd7
Added git clone
rauldpm Apr 1, 2024
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
3 changes: 3 additions & 0 deletions deployability/deps/remote_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ pytest>=7.4.2,<8.0.0
chardet==5.2.0
chardet==5.2.0
pytest-tinybird==0.2.0
requests>=2.31.0
psutil>=5.8.0
colored>=1.4.0,<2.0.0
294 changes: 294 additions & 0 deletions deployability/modules/testing/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
## Testing Module

### User documentation

The test module runs tests on the different components of Wazuh.
It is designed so that you can perform installations, actions on components and uninstallations, performing validations at each step.
This module must receive allocated and provisioned infrastructure. (From Allocation and Provision modules)

This module can be executed as follows:
A. Installing and using Workflow engine
B. Direct execution


#### A. Installing and using Workflow engine

The execution of the workflow is done through the installation of its library.

Initially, Python libraries must be installed. we recommended the use of virtual environments. Follow the technical documentation at https://docs.python.org/3/library/venv.html.

1. Create the python environment:

```bash
python3 -m venv {environment_name}
```


2. Activate the environment:

```bash
source {venv directory}/bin/activate
```

3. Clone the `wazuh-qa` repository:

Navigate to the project directory and switch to the project branch:

```bash
git clone https://github.com/wazuh/wazuh-qa.git
cd wazuh-qa
git checkout {project-branch}
```

4. Install requirements:

```bash
pip3 install -r deployability/deps/requirements.txt
```

5. Install the Workflow engine library and its launcher:

While in wazuh-qa:

```bash
cd modules
pip3 uninstall -y workflow_engine && pip3 install .
```

Run the module by doing the following steps:

6. Test fixture to execute:

It will be necessary to create a fixture (YAML file) where the infrastructure, provisioning, and tests to be executed will be declared.

>Note: It is possible to find some fixture examples in '[deployability/modules/workflow_engine/examples/](https://github.com/wazuh/wazuh-qa/tree/master/deployability/modules/workflow_engine/examples)'

Example:

```bash
version: 0.1
description: This workflow is used to test agents deployment por DDT1 PoC
variables:
agents-os:
- linux-ubuntu-22.04-amd64
manager-os:
- linux-redhat-8-amd64
infra-provider: vagrant
working-dir: /tmp/dtt1-poc

tasks:
# Generic agent test task
- task: "run-agent-tests"
description: "Run tests install for the agent."
do:
this: process
with:
path: python3
args:
- modules/testing/main.py
- targets:
- wazuh-1: "{working-dir}/manager-linux-ubuntu-22.04-amd64/inventory.yaml"
- agent-1: "{working-dir}/agent-linux-redhat-8-amd64/inventory.yaml"
- tests: "install,registration,restart,stop,uninstall"
- component: "agent"
- wazuh-version: "4.7.1"
- wazuh-revision: "40709"
- live: "True"
depends-on:
- "allocate-{agent}"
- "allocate-manager"

# Unique manager allocate task
- task: "allocate-manager"
description: "Allocate resources for the manager."
do:
this: process
with:
path: python3
args:
- modules/allocation/main.py
- action: create
- provider: "{infra-provider}"
- size: large
- composite-name: "{manager-os}"
- inventory-output: "{working-dir}/manager-{manager-os}/inventory.yaml"
- track-output: "{working-dir}/manager-{manager-os}/track.yaml"
cleanup:
this: process
with:
path: python3
args:
- modules/allocation/main.py
- action: delete
- track-output: "{working-dir}/manager-{manager-os}/track.yaml"

# Generic agent allocate task
- task: "allocate-{agent}"
description: "Allocate resources for the {agent} agent."
do:
this: process
with:
path: python3
args:
- modules/allocation/main.py
- action: create
- provider: "{infra-provider}"
- size: small
- composite-name: "{agent}"
- inventory-output: "{working-dir}/agent-{agent}/inventory.yaml"
- track-output: "{working-dir}/agent-{agent}/track.yaml"
cleanup:
this: process
with:
path: python3
args:
- modules/allocation/main.py
- action: delete
- track-output: "{working-dir}/agent-{agent}/track.yaml"
foreach:
- variable: agents-os
as: agent
```

Following the schema of the example:

Configure the following parameters depending on your test case:

```yaml
variables/agent-os
variables/manager-os
infra-provider
working-dir
tasks
```

Pay attention to the tasks:

```yaml
args
depends-on
```

>Note: In args, configure the launcher's path correctly (main.py files in each module), and to fill `depends-on`, consider the steps of your test (allocation, provision, and test)

7. Command execution (local):

Execute the command by referencing the parameters required by the library (launcher).

```bash
python3 -m workflow_engine {.yaml fixture path}
```

Example

```bash
python3 -m workflow_engine modules/workflow_engine/examples/dtt1-agents-poc.yaml
```

#### B. Direct execution

To execute the testing module without installing the Workflow engine, it can be done by using the launcher ('[module/testing/main.py](https://github.com/wazuh/wazuh-qa/tree/master/deployability/modules/testing/main.py)'):

1. Execution

While in 'wazuh-qa/deployability'

```bash
python3 modules/testing/main.py --wazuh-revision '{{ wazuh_revision }}' --wazuh-version '{{ wazuh_version }}' --component {{ component }} --tests 'install,restart,stop,uninstall' --targets '{"wazuh-1":"{{ inventory }}"}' --targets '{"wazuh-2":"{{ inventory }}"}' --live 'True'
```

Examples:
```bash
python3 modules/testing/main.py --wazuh-revision '40714' --wazuh-version '4.7.3' --component 'manager' --tests 'install,restart,stop,uninstall' --targets '{"wazuh-1":"/tmp/dtt1-poc/manager-linux-ubuntu-22.04-amd64/inventory.yml"}' --targets '{"wazuh-2":"/tmp/dtt1-poc/manager-linux-redhat-8-amd64/inventory.yml"}' --live 'True'
```

```bash
python3 modules/testing/main.py --wazuh-revision '40714' --wazuh-version '4.7.3' --component 'agent' --tests 'install,registration,restart,stop,uninstall' --targets '{"wazuh-1":"/tmp/dtt1-poc/manager-linux-ubuntu-22.04-amd64/inventory.yml"}' --targets '{"agent-1":"/tmp/dtt1-poc/agent-linux-redhat-8-amd64/inventory.yml"}' --targets '{"agent-2":"/tmp/dtt1-poc/agent-linux-redhat-9-amd64/inventory.yml"}' --targets '{"agent-3":"/tmp/dtt1-poc/agent-linux-centos-7-amd64/inventory.yml"}' --live 'True'
```

#### To be considered:
wazuh-1: This is the master node
wazuh-{number}: They are the workers
agent-{number}: They are the agents

>If the manager component is tested, 'wazuh-' components must be entered in target.
If the agent component is tested, there must be a master and the rest must be 'agent-'s

---

### Technical documentation

The testing module allows the execution of tests on agents and central components.

Instructions can be received from the fixture and executed through the Workflow Engine or run through commands on an already provisioned infrastructure.

In both cases, the following information will be required:

```bash
- task: "run-agent-tests"
description: "Run tests install for the agent."
do:
this: process
with:
path: python3
args:
- modules/testing/main.py
- targets:
- wazuh-1: "{working-dir}/manager-linux-ubuntu-22.04-amd64/inventory.yaml"
- agent-1: "{working-dir}/agent-linux-redhat-8-amd64/inventory.yaml"
- tests: "install,registration,restart,stop,uninstall"
- component: "agent"
- wazuh-version: "4.7.3"
- wazuh-revision: "40714"
- live: "True"
depends-on:
- "allocate-{agent}"
- "allocate-manager"
```
In the exposed fixture fragment, the execution of the testing module launcher (`testing/main.py`), it is necessary to provide the inventory, dependencies, component, tests to execute, Wazuh version, Wazuh revision, and whether the repository is live or not (if not, it will look for information in packages-dev pre-release).

For manual execution, an example command would be:

```bash
python3 modules/testing/main.py --wazuh-revision '40714' --wazuh-version '4.7.3' --component 'agent' --tests 'install,registration,restart,stop,uninstall' --targets '{"wazuh-1":"/tmp/dtt1-poc/manager-linux-ubuntu-22.04-amd64/inventory.yml"}' --targets '{"agent-1":"/tmp/dtt1-poc/agent-linux-redhat-8-amd64/inventory.yml"}' --live 'True'
```

The module is composed of:

- **Launcher** ('[/wazuh-qa/deployability/modules/testing/main.py](https://github.com/wazuh/wazuh-qa/tree/master/deployability/modules/testing/main.py)'): Entry point for the workflow or the user who wishes to execute a test.

- **Parameter validator** ('[/wazuh-qa/deployability/modules/testing/models.py](https://github.com/wazuh/wazuh-qa/tree/master/deployability/modules/testing/models.py)'): Validator for parameters entered by the Workflow or the user.

- **Module functions** ('[/wazuh-qa/deployability/modules/testing/testing.py](https://github.com/wazuh/wazuh-qa/tree/master/deployability/modules/testing/testing.py)'): Module-specific functions responsible for triggering the test.

- **Executor** ('[/wazuh-qa/deployability/modules/provision/actions.py](https://github.com/wazuh/wazuh-qa/tree/master/deployability/modules/provision/actions.py)'): Executes the provision using Actions in the generic module.

- **Playbooks** ('[/wazuh-qa/deployability/modules/tests/playbooks](https://github.com/wazuh/wazuh-qa/tree/master/deployability/modules/tests/playbooks)'): Contains setup, execution, and post-test cleanup playbooks.

- **Tests** ('[/wazuh-qa/deployability/modules/tests](https://github.com/wazuh/wazuh-qa/tree/master/deployability/modules/tests/)'): Contains the test_agent and test_manager directories where the tests to be executed are located.

- **Helpers** ('[/wazuh-qa/deployability/modules/tests/helpers](https://github.com/wazuh/wazuh-qa/tree/master/deployability/modules/tests/helpers)'): Contains files that enable the execution of the test.

- **Conftest** ('[/wazuh-qa/deployability/modules/tests/conftest.py](https://github.com/wazuh/wazuh-qa/tree/master/deployability/modules/tests/conftest.py)'): Contains information that will be transferred from the parameter validator to the tests.


![image](https://github.com/wazuh/wazuh-qa/assets/125690423/58332378-489a-49da-a73a-4d87d6bed3bc)


The testing module receives the infrastructure generated and provisioned by the allocation and provision modules. The module has the ability to execute actions on the hosts as well as perform the necessary validation.

[Testing.drawio.zip](https://github.com/wazuh/wazuh-qa/files/14372508/Testing.drawio.zip)

The test module must recieve the infrastructure generated and provisioned by the allocation and provision modules. The module can execute actions on the hosts as well as perform the necessary validation.

Testing of the manager component includes:
`install`, `restart`, `stop` and `uninstall`
Install should come at the beginning and uninstall at the end, other tests can change their order

Testing of the agent component includes:
`install`, `registration`, `restart`, `stop` and `uninstall`
Install must come at the beginning followed by registration Uninstall must come at the end and the other tests can change their order

### License

WAZUH Copyright (C) 2015 Wazuh Inc. (License GPLv2)
6 changes: 5 additions & 1 deletion deployability/modules/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
from .testing import Tester
# Copyright (C) 2015, Wazuh Inc.
# Created by Wazuh, Inc. <[email protected]>.
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

from .models import InputPayload, ExtraVars
from .testing import Tester
23 changes: 10 additions & 13 deletions deployability/modules/testing/main.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
# Copyright (C) 2015, Wazuh Inc.
# Created by Wazuh, Inc. <[email protected]>.
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import argparse
import sys
import os
import sys

project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))
sys.path.append(project_root)

from modules.testing import Tester, InputPayload


def parse_arguments():
parser = argparse.ArgumentParser(description="Wazuh testing tool")
parser.add_argument("--inventory", required=True)
parser.add_argument("--targets", action='append', default=[], required=True)
parser.add_argument("--tests", required=True)
parser.add_argument("--component", choices=['manager', 'agent'], required=True)
parser.add_argument("--dependencies", required=False)
parser.add_argument("--dependencies", action='append', default=[], required=False)
parser.add_argument("--cleanup", required=False, default=True)
parser.add_argument("--wazuh-version", required=True)
parser.add_argument("--wazuh-revision", required=True)
parser.add_argument("--wazuh-branch", required=False)
parser.add_argument("--live", required=False)

return parser.parse_args()

if __name__ == "__main__":
Tester.run(InputPayload(**vars(parse_arguments())))



# linux-ubuntu-20.04-amd64:
# hosts:
# VAGRANT-F6FD6643-B41E-4112-A652-3CFF8CC26F51:
# ansible_host: 127.0.0.1
# ansible_port: 2222
# ansible_ssh_private_key_file: C:\tmp\wazuh-qa\VAGRANT-F6FD6643-B41E-4112-A652-3CFF8CC26F51\instance_key
# ansible_user: vagrant
Loading