Skip to content

Commit

Permalink
Merge pull request #4981 from wazuh/enhancement/4905-dtt1-iteration-3…
Browse files Browse the repository at this point in the history
…-workflow

Merge workflow engine into main DTT1 branch
  • Loading branch information
QU3B1M authored Feb 19, 2024
2 parents 336e2f7 + e649993 commit eca6527
Show file tree
Hide file tree
Showing 44 changed files with 587 additions and 384 deletions.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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

0 comments on commit eca6527

Please sign in to comment.