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 workflow engine into main DTT1 branch #4981

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e4a8be0
Implement logger to workflow_engine and improve log messages
QU3B1M Feb 6, 2024
43206e5
Apply logger to the workflow_engine files
QU3B1M Feb 6, 2024
32aaa80
Update deployability/modules/workflow_engine/logging/logger.py
QU3B1M Feb 7, 2024
dc17294
Update deployability/modules/workflow_engine/logging/logger.py
QU3B1M Feb 7, 2024
a60c1a5
Update deployability/modules/workflow_engine/logging/logger.py
QU3B1M Feb 7, 2024
9700d3e
Merge pull request #4919 from wazuh/enhancement/4907-dtt1-iteration-3…
fcaffieri Feb 7, 2024
506d315
enhacement(#4909): Changes in playbooks dir, setup.py and launchers
pro-akim Feb 7, 2024
e40a2c9
fix(#4909): Changes in script_list in setup
pro-akim Feb 7, 2024
5767f63
enhancement(#4909): Chaning logging directory name
pro-akim Feb 7, 2024
b8c54da
fix(#4909): Fixing paths
pro-akim Feb 7, 2024
0c156f8
fix(#4909): Fixing paths and restoring dtt-1-agents-poc-yaml
pro-akim Feb 8, 2024
af65f61
fix(#4909): Fixing path testing.py
pro-akim Feb 8, 2024
b281a01
fix(#4909): Fixing path testing
pro-akim Feb 8, 2024
f658807
fix(#4909): Fixing path in dtt1-agents-poc.yaml
pro-akim Feb 8, 2024
9b87195
Merge pull request #4925 from wazuh/enhancement/4909-Install-module-a…
fcaffieri Feb 8, 2024
f0d42a9
enhacement(#4906): Adding documentation
pro-akim Feb 8, 2024
5a4f1f6
Merge pull request #4944 from wazuh/enhancement/4906-dtt1-iteration-3…
QU3B1M Feb 8, 2024
a43bda4
Merge branch 'enhancement/4905-dtt1-iteration-3-workflow' of https://…
fcaffieri Feb 9, 2024
2bdf001
Improve error handling, add sigterm handle improve logging
fcaffieri Feb 14, 2024
d865900
Improve error handling, add sigterm handle improve logging
fcaffieri Feb 15, 2024
ebce158
Fix review comments
fcaffieri Feb 15, 2024
63b1206
Fix review comments
fcaffieri Feb 15, 2024
229b2ab
Merge pull request #4960 from wazuh/4908-dtt1-workflow-engine-error-h…
rauldpm Feb 15, 2024
8be5569
fix(#4910): Changing Readme and dtt-agents-poc file
pro-akim Feb 19, 2024
88b4f9b
fix(#4910): Fixing Readme and dtt-agents-poc file
pro-akim Feb 19, 2024
a405f83
fix(#4910): Changing Tecnical documentation path
pro-akim Feb 19, 2024
d266ffd
Merge pull request #4974 from wazuh/enhancement/4910-dtt1-Perform-tests
QU3B1M Feb 19, 2024
a457798
Remove duplicated examples
QU3B1M Feb 19, 2024
2f6d5dc
Merge pull request #4979 from wazuh/enhancement/hotfix-dtt1-workflow-…
fcaffieri Feb 19, 2024
690c624
Merge branch 'enhancement/4495-DTT1' into enhancement/4905-dtt1-itera…
QU3B1M Feb 19, 2024
e649993
Update README.md
QU3B1M Feb 19, 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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ ansible.log
key

#Python
__pycache__/
__pycache__/

#Python setup
*.egg-info/
build/
5 changes: 2 additions & 3 deletions deployability/Jenkinsfiles/Launcher.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

String jenkins_reference = params.getOrDefault('JENKINS_REFERENCE', 'enhancement/4751-dtt1-iteration-2-poc')
String launcher_path = "launchers"
String task_flow_launcher = "provision.py"
String launcher_path = "modules/provision"
String task_flow_launcher = "main.py"
String workflow = "modules/workflow_engine/examples/dtt1-managers.yaml"
String schema = "modules/workflow_engine/schema.json"

Expand Down
6 changes: 2 additions & 4 deletions deployability/Jenkinsfiles/Provision.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@


String provision_path = "${WORKSPACE}/scripts/provision"
String provision_script = "provision.py"
String provision_path = "${WORKSPACE}/modules/provision"
String provision_script = "main.py"
String inventory = "inventory.yaml"
String jenkins_reference = params.getOrDefault('JENKINS_REFERENCE', 'enhancement/4665-dtt1-poc')

Expand Down
2 changes: 1 addition & 1 deletion deployability/modules/allocation/allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __delete(cls, payload: models.DeletionPayload) -> None:

Args:
payload (DeletionPayload): The payload containing the parameters
for instance deletion.
for instance deletion.
"""
payload = models.DeletionPayload(**dict(payload))
# Read the data from the track file.
Expand Down
6 changes: 3 additions & 3 deletions deployability/modules/allocation/aws/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def ssh_connection_info(self) -> ConnectionInfo:
ConnectionInfo: SSH connection information.
"""
return ConnectionInfo(hostname=self._instance.public_dns_name,
user=self._user,
port=22,
private_key=str(self.credentials.key_path))
user=self._user,
port=22,
private_key=str(self.credentials.key_path))

def __get_credentials(self) -> AWSCredentials:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import sys

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

from modules.allocation import Allocator
Expand Down
5 changes: 3 additions & 2 deletions deployability/modules/generic/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class Inventory(BaseModel):
class Ansible:
def __init__(self, ansible_data: dict | Inventory, path: str | Path = None):
self.path = path
self.playbooks_path = Path(__file__).parents[2] / 'playbooks'
self.modules_path = Path(__file__).parents[1]
self.provision_playbook_path = self.modules_path / 'provision/playbooks'
self.ansible_data = Inventory(**dict(ansible_data))
self.inventory = self.generate_inventory()
self.logger = Logger(Path(__file__).stem).get_logger()
Expand All @@ -32,7 +33,7 @@ def render_playbooks(self, rendering_variables: dict) -> list[str]:
rendering_variables (dict): Extra variables to render the playbooks.
"""
tasks = []
path_to_render_playbooks = self.playbooks_path / rendering_variables.get("templates_path")
path_to_render_playbooks = self.provision_playbook_path / rendering_variables.get("templates_path")
template_loader = jinja2.FileSystemLoader(searchpath=path_to_render_playbooks)
template_env = jinja2.Environment(loader=template_loader)

Expand Down
8 changes: 4 additions & 4 deletions deployability/modules/provision/componentType.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Package(ComponentType):
"""
Class to define the type of package to be provisioned
"""
TEMPLATE_BASE_PATH = 'provision/wazuh'
TEMPLATE_BASE_PATH = 'wazuh'

def __init__(self, component_info, action):
super().__init__(component_info)
Expand All @@ -58,7 +58,7 @@ class AIO(ComponentType):
"""
Class to define the type of AIO to be provisioned
"""
TEMPLATE_BASE_PATH = 'provision/wazuh'
TEMPLATE_BASE_PATH = 'wazuh'

def __init__(self, component_info, action):
super().__init__(component_info)
Expand All @@ -73,7 +73,7 @@ class Generic(ComponentType):
"""
Class to define the type of generic component to be provisioned
"""
TEMPLATE_BASE_PATH = 'provision/generic'
TEMPLATE_BASE_PATH = 'generic'

def __init__(self, component_info, action):
super().__init__(component_info)
Expand All @@ -88,7 +88,7 @@ class Dependencies(ComponentType):
"""
Class to define the type of dependencies to be provisioned
"""
TEMPLATE_BASE_PATH = 'provision/deps'
TEMPLATE_BASE_PATH = 'deps'

def __init__(self, component_info, action):
super().__init__(component_info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# ---------------- Vars ------------------------

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

from modules.provision import Provision, models
Expand Down
42 changes: 42 additions & 0 deletions deployability/modules/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# Copyright (C) 2015-2024, Wazuh Inc.
# Created by Wazuh, Inc. <[email protected]>.
# 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

def get_files_from_directory(directory):
paths = []
for (path, directories, filenames) in os.walk(directory):
for filename in filenames:
paths.append(os.path.join('..', path, filename))
return paths

def get_version():
script_path = os.path.dirname(__file__)
rel_path = "../version.json"
abs_file_path = os.path.join(script_path, rel_path)
f = open(abs_file_path)
data = json.load(f)
version = data['version']
return version

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='[email protected]',
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
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import os

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

from modules.testing import Tester, InputPayload
Expand Down
11 changes: 5 additions & 6 deletions deployability/modules/testing/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
from .models import InputPayload, ExtraVars
from .utils import logger


class Tester:
_playbooks_dir = Path('tests')
_playbooks_dir = Path(__file__).parent / 'playbooks'
_setup_playbook = _playbooks_dir / 'setup.yml'
_cleanup_playbook = _playbooks_dir / 'cleanup.yml'
_test_template = _playbooks_dir / 'test.yml'
Expand Down Expand Up @@ -77,7 +76,7 @@ def _run_tests(cls, test_list: list[str], ansible: Ansible, extra_vars: ExtraVar
"""
for test in test_list:
rendering_var = {**extra_vars, 'test': test}
template = str(ansible.playbooks_path / cls._test_template)
template = str(cls._test_template)
playbook = ansible.render_playbook(template, rendering_var)
if not playbook:
logger.warning(f"Test {test} not found. Skipped.")
Expand All @@ -95,7 +94,7 @@ def _setup(cls, ansible: Ansible, remote_working_dir: str = '/tmp') -> None:
"""
extra_vars = {'local_path': str(Path(__file__).parent / 'tests'),
'working_dir': remote_working_dir}
playbook = str(ansible.playbooks_path / cls._setup_playbook)
playbook = str(cls._setup_playbook)
ansible.run_playbook(playbook, extra_vars)

@classmethod
Expand All @@ -108,5 +107,5 @@ def _cleanup(cls, ansible: Ansible, remote_working_dir: str = '/tmp') -> None:
remote_working_dir (str): The remote working directory.
"""
extra_vars = {'working_dir': remote_working_dir}
playbook = str(ansible.playbooks_path / cls._cleanup_playbook)
ansible.run_playbook(playbook, extra_vars)
playbook = str(cls._cleanup_playbook)
ansible.run_playbook(playbook, extra_vars)
Loading