Skip to content

Commit

Permalink
enhacement(#4909): Changes in playbooks dir, setup.py and launchers
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-akim committed Feb 7, 2024
1 parent 9700d3e commit 506d315
Show file tree
Hide file tree
Showing 37 changed files with 123 additions and 24 deletions.
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
Empty file.
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
6 changes: 4 additions & 2 deletions deployability/modules/generic/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ 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[2]
self.provision_playbook_path = self.modules_path / 'provision/playbooks'
self.testing_playbook_path = self.modules_path / 'testing/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 +34,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
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
49 changes: 49 additions & 0 deletions deployability/modules/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

# 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

scripts_list = [
'models=workflow_engine.models:main',
'schema_validator=workflow_engine.schema_validator:main',
'task=workflow_engine.task:main',
'workflow_processor=workflow_engine.workflow_processor:main',
'main=workflow_engine.main:main'
]

package_data_list = get_files_from_directory("workflow_engine")

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.
6 changes: 3 additions & 3 deletions deployability/modules/testing/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,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(ansible.testing_playbook_path / 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 +95,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(ansible.testing_playbook_path / cls._setup_playbook)
ansible.run_playbook(playbook, extra_vars)

@classmethod
Expand All @@ -108,5 +108,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)
playbook = str(ansible.testing_playbook_path / cls._cleanup_playbook)
ansible.run_playbook(playbook, extra_vars)
8 changes: 8 additions & 0 deletions deployability/modules/workflow_engine.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Metadata-Version: 2.1
Name: workflow_engine
Version: 1.0
Summary: Wazuh testing utilities to help programmers automate deployment tests
Home-page: https://github.com/wazuh
Author: Wazuh
Author-email: [email protected]
License: GPLv2
29 changes: 29 additions & 0 deletions deployability/modules/workflow_engine.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
setup.py
workflow_engine/README.md
workflow_engine/__init__.py
workflow_engine/main.py
workflow_engine/models.py
workflow_engine/schema_validator.py
workflow_engine/task.py
workflow_engine/workflow_processor.py
workflow_engine.egg-info/PKG-INFO
workflow_engine.egg-info/SOURCES.txt
workflow_engine.egg-info/dependency_links.txt
workflow_engine.egg-info/entry_points.txt
workflow_engine.egg-info/not-zip-safe
workflow_engine.egg-info/top_level.txt
workflow_engine/__pycache__/__init__.cpython-310.pyc
workflow_engine/__pycache__/models.cpython-310.pyc
workflow_engine/__pycache__/schema_validator.cpython-310.pyc
workflow_engine/__pycache__/task.cpython-310.pyc
workflow_engine/__pycache__/utils.cpython-310.pyc
workflow_engine/__pycache__/workflow_processor.cpython-310.pyc
workflow_engine/examples/dtt1-agents-poc.yaml
workflow_engine/examples/dtt1-agents.yaml
workflow_engine/examples/dtt1-managers.yaml
workflow_engine/logging/__init__.py
workflow_engine/logging/config.yaml
workflow_engine/logging/filter.py
workflow_engine/logging/logger.py
workflow_engine/logging/__pycache__/__init__.cpython-310.pyc
workflow_engine/schemas/schema_v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[console_scripts]
main = workflow_engine.main:main
models = workflow_engine.models:main
schema_validator = workflow_engine.schema_validator:main
task = workflow_engine.task:main
utils = workflow_engine.utils:main
workflow_processor = workflow_engine.workflow_processor:main
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workflow_engine
2 changes: 1 addition & 1 deletion deployability/modules/workflow_engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .workflow_processor import WorkflowProcessor
#from .workflow_processor import WorkflowProcessor
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import sys
import argparse

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.workflow_engine.workflow_processor import WorkflowProcessor
from modules.workflow_engine.models import InputPayload
from workflow_engine.workflow_processor import WorkflowProcessor
from workflow_engine.models import InputPayload


def parse_arguments() -> argparse.Namespace:
Expand Down
2 changes: 1 addition & 1 deletion deployability/modules/workflow_engine/schema_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path
from ruamel.yaml import YAML

from .logging.logger import logger
from workflow_engine.logging.logger import logger


class SchemaValidator:
Expand Down
2 changes: 1 addition & 1 deletion deployability/modules/workflow_engine/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import time

from abc import ABC, abstractmethod
from .logging.logger import logger
from workflow_engine.logging.logger import logger


class Task(ABC):
Expand Down
6 changes: 3 additions & 3 deletions deployability/modules/workflow_engine/workflow_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from pathlib import Path
from itertools import product

from .logging.logger import logger
from .schema_validator import SchemaValidator
from .task import Task, TASKS_HANDLERS
from workflow_engine.logging.logger import logger
from workflow_engine.schema_validator import SchemaValidator
from workflow_engine.task import Task, TASKS_HANDLERS


class WorkflowFile:
Expand Down
4 changes: 4 additions & 0 deletions deployability/version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "1.0",
"revision": "1"
}

0 comments on commit 506d315

Please sign in to comment.