-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add Workflow module to Wazuh-qa repository #4990
Merged
davidjiglesias
merged 7 commits into
4.9.0
from
4989-dtt1-iteration-3-workflow-engine-module-release-workflow-module
Mar 4, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6a13894
Add Workflow module to Wazuh-qa repository
fcaffieri a9a815f
Remove unused dependency from remote_requirements
fcaffieri 6941f08
Fix reviews
fcaffieri 0eb255a
Add Copyright
fcaffieri 29ab9ad
Fix indentation
fcaffieri c9e7911
Fix reviews: fix logguer, setup.py and filter
fcaffieri 39e5f11
Remove filter.py file not used
fcaffieri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pytest>=7.4.2,<8.0.0 | ||
chardet==5.2.0 | ||
chardet==5.2.0 | ||
pytest-tinybird==0.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
ansible_runner==2.3.4 | ||
boto3==1.29.1 | ||
pydantic==2.5.2 | ||
ansible | ||
ruamel.yaml==0.18.5 | ||
ruamel.yaml.clib==0.2.8 | ||
graphlib==0.9.5 | ||
jsonschema==3.2.0 | ||
PyYAML==6.0.1 | ||
colorlog==6.8.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
# Copyright (C) 2015, Wazuh Inc. | ||
# Created by Wazuh, Inc. <info@wazuh.com>. | ||
# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 | ||
import json | ||
from setuptools import setup, find_packages | ||
import os | ||
from pathlib import Path | ||
|
||
def get_files_from_directory(directory): | ||
paths = [] | ||
base_path = Path(__file__) | ||
for (path, directories, filenames) in os.walk(directory): | ||
for filename in filenames: | ||
if filename.endswith(('.yaml', '.json', '.md', '.py')): | ||
paths.append(os.path.join(base_path, path, filename)) | ||
return paths | ||
|
||
def get_version(): | ||
abs_path = Path(__file__).parent.parent / "version.json" | ||
|
||
if not os.path.exists(abs_path): | ||
raise FileNotFoundError(f'File "{abs_path}" not found.') | ||
|
||
with open(abs_path, 'r') as abs_file: | ||
data = json.load(abs_file) | ||
version = data['version'] | ||
return version or None | ||
|
||
package_data_list = get_files_from_directory("workflow_engine") | ||
scripts_list = ['engine=workflow_engine.__main__:main'] | ||
|
||
setup( | ||
name='workflow_engine', | ||
version=get_version(), | ||
description='Wazuh testing utilities to help programmers automate deployment tests', | ||
url='https://github.com/wazuh', | ||
author='Wazuh', | ||
author_email='hello@wazuh.com', | ||
license='GPLv2', | ||
packages=['workflow_engine'], | ||
package_dir={'workflow_engine': 'workflow_engine'}, | ||
package_data={'workflow_engine': package_data_list}, | ||
entry_points={'console_scripts': scripts_list}, | ||
include_package_data=True, | ||
zip_safe=False | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,325 @@ | ||
## Workflow engine | ||
|
||
### User documentation | ||
|
||
The execution of the Workflow is done through the installation of its library. | ||
|
||
Initially, Python libraries must be installed. It is recommended to use virtual environments. Follow the technical documentation at https://docs.python.org/3/library/venv.html. | ||
|
||
1. Activate the environment: | ||
|
||
```bash | ||
source {venv directory}/bin/activate | ||
``` | ||
|
||
2. Clone the `wazuh-qa` repository: | ||
|
||
```bash | ||
git clone {wazuh-qa} | ||
``` | ||
|
||
Navigate to the project directory and switch to the project branch: | ||
|
||
```bash | ||
cd wazuh-qa | ||
git checkout {project-branch} | ||
``` | ||
|
||
3. Install requirements: | ||
|
||
```bash | ||
pip3 install -r deployability/deps/requirements.txt | ||
``` | ||
|
||
4. Install the Workflow engine library and its launcher: | ||
|
||
While in wazuh-qa: | ||
|
||
```bash | ||
cd modules | ||
pip3 uninstall -y workflow_engine && pip3 install . | ||
``` | ||
|
||
5. 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/ | ||
|
||
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-ubuntu-22.04-amd64 | ||
infra-provider: vagrant | ||
working-dir: /tmp/dtt1-poc | ||
|
||
tasks: | ||
# Generic agent test task | ||
- task: "run-agent-tests-{agent}" | ||
description: "Run tests uninstall for the {agent} agent." | ||
do: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/testing/main.py | ||
- inventory: "{working-dir}/agent-{agent}/inventory.yaml" | ||
- dependencies: | ||
- manager: "{working-dir}/manager-{manager-os}/inventory.yaml" | ||
- agent: "{working-dir}/agent-{agent}/inventory.yaml" | ||
- tests: "install,register,stop" | ||
- component: "agent" | ||
- wazuh-version: "4.7.1" | ||
- wazuh-revision: "40709" | ||
depends-on: | ||
- "provision-install-{agent}" | ||
- "provision-manager" | ||
foreach: | ||
- variable: agents-os | ||
as: agent | ||
|
||
# Generic agent test task | ||
- task: "run-agent-tests-uninstall-{agent}" | ||
description: "Run tests uninstall for the {agent} agent." | ||
do: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/testing/main.py | ||
- inventory: "{working-dir}/agent-{agent}/inventory.yaml" | ||
- dependencies: | ||
- manager: "{working-dir}/manager-{manager-os}/inventory.yaml" | ||
- tests: "uninstall" | ||
- component: "agent" | ||
- wazuh-version: "4.7.1" | ||
- wazuh-revision: "40709" | ||
depends-on: | ||
- "run-agent-tests-{agent}" | ||
- "provision-uninstall-{agent}" | ||
foreach: | ||
- variable: agents-os | ||
as: agent | ||
|
||
# Unique manager provision task | ||
- task: "provision-manager" | ||
description: "Provision the manager." | ||
do: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/provision/main.py | ||
- inventory-manager: "{working-dir}/manager-{manager-os}/inventory.yaml" | ||
- install: | ||
- component: wazuh-manager | ||
type: package | ||
depends-on: | ||
- "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 provision task | ||
- task: "provision-install-{agent}" | ||
description: "Provision resources for the {agent} agent." | ||
do: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/provision/main.py | ||
- inventory-agent: "{working-dir}/agent-{agent}/inventory.yaml" | ||
- inventory-manager: "{working-dir}/manager-{manager-os}/inventory.yaml" | ||
- install: | ||
- component: wazuh-agent | ||
type: package | ||
- component: curl | ||
depends-on: | ||
- "allocate-{agent}" | ||
- "provision-manager" | ||
foreach: | ||
- variable: agents-os | ||
as: agent | ||
|
||
# Generic agent provision task | ||
- task: "provision-uninstall-{agent}" | ||
description: "Provision resources for the {agent} agent." | ||
do: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/provision/main.py | ||
- inventory-agent: "{working-dir}/agent-{agent}/inventory.yaml" | ||
- inventory-manager: "{working-dir}/manager-{manager-os}/inventory.yaml" | ||
- uninstall: | ||
- component: wazuh-agent | ||
type: package | ||
depends-on: | ||
- "provision-install-{agent}" | ||
foreach: | ||
- variable: agents-os | ||
as: agent | ||
|
||
# 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. Execution of Command (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 | ||
``` | ||
|
||
> Note The command execution can also be mediated through Jenkins. | ||
|
||
--- | ||
|
||
### Technical documentation | ||
|
||
`Workflow Engine` is the orchestrator of the deployability test architecture. | ||
|
||
Its function is to allow the ordered and structured execution in steps of allocation, provision, and testing. | ||
|
||
`The Workflow Engine` receives instructions through a `YAML document`, the structure of which can be exemplified in tests found in: | ||
`wazuh-qa/deployability/modules/workflow_engine/examples` | ||
|
||
**In these tests**: | ||
- Tasks: define the steps. | ||
- Task: defines a step. | ||
|
||
**Within Task**: | ||
- description: description of the task. | ||
- do: instructions for the task. | ||
- this: nature of the task. | ||
- with: tools with which the task will be executed. | ||
- path: executable. | ||
- args: arguments. it receives the binary or file to execute and the parameters. | ||
- depends-on: steps prior to the execution of that task. | ||
- foreach: loop that executes the task on the previously declared hosts. | ||
|
||
```bash | ||
tasks: | ||
# Generic agent test task | ||
- task: "run-agent-tests-{agent}" | ||
description: "Run tests uninstall for the {agent} agent." | ||
do: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/testing/main.py | ||
- inventory: "{working-dir}/agent-{agent}/inventory.yaml" | ||
- dependencies: | ||
- manager: "{working-dir}/manager-{manager-os}/inventory.yaml" | ||
- agent: "{working-dir}/agent-{agent}/inventory.yaml" | ||
- tests: "install,register,stop" | ||
- component: "agent" | ||
- wazuh-version: "4.7.1" | ||
- wazuh-revision: "40709" | ||
depends-on: | ||
- "provision-install-{agent}" | ||
- "provision-manager" | ||
foreach: | ||
- variable: agents-os | ||
as: agent | ||
``` | ||
|
||
These tasks are executed by the `Workflow Engine` launcher installed as workflow_engine library in your virtual environment. | ||
|
||
This launcher receives the parameters, sets up the test logs, and proceeds with the ordered execution. | ||
|
||
The parameters sent from the launcher are processed by deployability/modules/workflow_engine/models.py, which checks the nature of the parameters sent and filters out incorrect parameters. | ||
|
||
![image](https://github.com/wazuh/wazuh-qa/assets/125690423/32aa77b7-f294-41ac-af93-db8a084dbad1) | ||
|
||
These are then sent to `deployability/modules/workflow_engine/workflow_processor.py`, where using `deployability/modules/schemas`, instructions in YAML are received and the schema of the instructions is checked. | ||
|
||
The commands are executed in the WorkflowProcessor of the same file, which also handles parallel executions and aborts failed executions. | ||
|
||
[WF.drawio.zip](https://github.com/wazuh/wazuh-qa/files/14167559/WF.drawio.zip) | ||
|
||
|
||
### License | ||
|
||
WAZUH Copyright (C) 2015 Wazuh Inc. (License GPLv2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .workflow_processor import WorkflowProcessor |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may lead to including unwanted files (like temporary or binary files) in the distribution package. It's generally better to specify only the types of files we need explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in c9e7911