Skip to content

Commit

Permalink
fix(#5197): Fixing provision logs
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-akim committed Apr 12, 2024
1 parent 0272962 commit 643a24c
Show file tree
Hide file tree
Showing 43 changed files with 82 additions and 44 deletions.
1 change: 1 addition & 0 deletions deployability/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 .provision import Provision
from .generic import Ansible
from .allocation import Allocator
1 change: 1 addition & 0 deletions deployability/modules/allocation/generic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from .credentials import Credentials
from .instance import Instance
from .provider import Provider
from ...generic.logger import Logger
4 changes: 2 additions & 2 deletions deployability/modules/allocation/generic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# 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 modules.generic.logger import Logger
from modules.generic.logger.logger import Logger

logger = Logger("allocator").get_logger()
logger = Logger("allocation-module").get_logger()
1 change: 1 addition & 0 deletions deployability/modules/generic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# 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 .ansible import Ansible, Inventory
1 change: 1 addition & 0 deletions deployability/modules/generic/ansible.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 ansible_runner
import jinja2
import yaml
Expand Down
1 change: 1 addition & 0 deletions deployability/modules/generic/logger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# 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 .logger import Logger
3 changes: 2 additions & 1 deletion deployability/modules/generic/logger/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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

version: 1
formatters:
simple:
Expand All @@ -23,7 +24,7 @@ handlers:
class: logging.FileHandler
level: DEBUG
formatter: simple
filename: /tmp/workflow.log
filename: /tmp/workflow2.log
filters: [uppercase]
root:
level: DEBUG
Expand Down
1 change: 1 addition & 0 deletions deployability/modules/generic/logger/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 logging


Expand Down
1 change: 1 addition & 0 deletions deployability/modules/generic/logger/logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 logging
import logging.config
import yaml
Expand Down
1 change: 1 addition & 0 deletions deployability/modules/generic/logger/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .logger import Logger
1 change: 1 addition & 0 deletions deployability/modules/generic/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 pydantic import BaseModel, IPvAnyAddress


Expand Down
1 change: 1 addition & 0 deletions deployability/modules/generic/parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 argparse import ArgumentParser
from pydantic import BaseModel

Expand Down
1 change: 1 addition & 0 deletions deployability/modules/generic/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 os
import yaml

Expand Down
4 changes: 4 additions & 0 deletions deployability/modules/provision/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 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 .actions import Action
from .handler import ProvisionHandler
from .models import InputPayload, InputPayload
from .provision import Provision
9 changes: 5 additions & 4 deletions deployability/modules/provision/actions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# 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 modules.generic import Ansible

from modules.provision.handler import ProvisionHandler
from modules.provision.models import ComponentInfo
from modules.provision.utils import logger
from ..generic import Ansible

from .handler import ProvisionHandler
from .models import ComponentInfo
from .utils import logger


class Action:
Expand Down
1 change: 1 addition & 0 deletions deployability/modules/provision/handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 pathlib import Path

from modules.provision.models import ComponentInfo
Expand Down
8 changes: 6 additions & 2 deletions deployability/modules/provision/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 os
import sys
Expand All @@ -9,9 +10,11 @@
sys.path.append(project_root)

from modules.provision import Provision, models
from modules.generic.logger.logger import Logger

# ---------------- Methods ---------------------

logger = Logger('provision-module').get_logger()
# ---------------- Methods ---------------------

def parse_arguments():
parser = argparse.ArgumentParser(
Expand All @@ -24,8 +27,9 @@ def parse_arguments():


if __name__ == "__main__":
logger.info(f'Initiating provisionment.')
try:
provision = Provision(models.InputPayload(**vars(parse_arguments())))
provision.run()
except Exception as e:
sys.exit(f"Error while provisioning: {e}")
logger.error(f"Error while provisioning: {e}")
1 change: 1 addition & 0 deletions deployability/modules/provision/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 pathlib import Path
from typing import List, Union
from pydantic import BaseModel, validator, model_validator
Expand Down
14 changes: 7 additions & 7 deletions deployability/modules/provision/provision.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# 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 pathlib import Path

from modules.generic.utils import Utils
from modules.provision.actions import Action
from modules.provision.utils import logger
from modules.provision.models import InputPayload, ComponentInfo
from pathlib import Path

from ..generic.utils import Utils
from .actions import Action
from .models import InputPayload, ComponentInfo
from .utils import logger

PATH_BASE_DIR = Path(__file__).parents[2]



class Provision:
"""
Provision class to install and uninstall components.
Expand All @@ -35,12 +36,11 @@ def __init__(self, payload: InputPayload):
self.components = self.get_components(payload)
self.ansible_data = self.__load_ansible_data(payload.inventory)


def run(self) -> None:
"""
Run the provision.
"""
logger.info(f'Initiating provisionment.')

logger.debug(f'Running action {self.action} for components: {self.components}')
for component in self.components:
try:
Expand Down
5 changes: 3 additions & 2 deletions deployability/modules/provision/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# 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

"""Common unit test fixtures."""
from unittest.mock import patch
import pytest

from modules.provision.models import InputPayload
from modules.provision.provision import Provision
from ..models import InputPayload
from ..provision import Provision


@pytest.fixture
Expand Down
9 changes: 5 additions & 4 deletions deployability/modules/provision/tests/test_actions.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# 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

"""Unit Tests for the Action class"""

from unittest.mock import patch, MagicMock, call
import pytest

from modules.generic import Ansible
from modules.provision.actions import Action
from modules.provision.models import ComponentInfo
from modules.provision.handler import ProvisionHandler
from ...generic import Ansible
from ..actions import Action
from ..models import ComponentInfo
from ..handler import ProvisionHandler


@pytest.mark.parametrize('action, component_type',
Expand Down
5 changes: 3 additions & 2 deletions deployability/modules/provision/tests/test_handler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# 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

"""Unit Tests for the ProvisionHandler class."""
from unittest.mock import patch, MagicMock
import pytest

from modules.provision.handler import ProvisionHandler
from modules.provision.models import ComponentInfo
from ..handler import ProvisionHandler
from ..models import ComponentInfo

@pytest.mark.parametrize('component, action, method',
[('wazuh-manager', 'install', 'package'),
Expand Down
3 changes: 2 additions & 1 deletion deployability/modules/provision/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# 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

"""modules.provision.models Unit tests."""
from pathlib import Path
import pytest

from modules.provision.models import InputPayload, ComponentInfo
from ..models import InputPayload, ComponentInfo


@pytest.mark.parametrize('install', [(True), (False)])
Expand Down
5 changes: 3 additions & 2 deletions deployability/modules/provision/tests/test_provision.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# 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

"""Unit Tests for the Provision class"""

from typing import List
from unittest.mock import patch, MagicMock, call
import pytest

from modules.provision.models import InputPayload, ComponentInfo
from modules.provision.provision import Provision
from ..models import InputPayload, ComponentInfo
from ..provision import Provision


def test_provision_constructor():
Expand Down
3 changes: 2 additions & 1 deletion deployability/modules/provision/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 modules.generic.logger import Logger

from modules.generic.logger.logger import Logger

logger = Logger("provisioner").get_logger()
1 change: 1 addition & 0 deletions deployability/modules/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 json
import os

Expand Down
1 change: 1 addition & 0 deletions deployability/modules/testing/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 typing import Literal

from pydantic import BaseModel, field_validator
Expand Down
1 change: 0 additions & 1 deletion deployability/modules/testing/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from .models import InputPayload, ExtraVars
from .utils import logger


class Tester:
_playbooks_dir = Path(__file__).parent / 'playbooks'
_setup_playbook = _playbooks_dir / 'setup.yml'
Expand Down
1 change: 1 addition & 0 deletions deployability/modules/testing/tests/helpers/agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 requests
import yaml

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ handlers:
class: logging.FileHandler
level: DEBUG
formatter: simple
filename: /tmp/workflow.log
filename: /tmp/workflow2.log
root:
level: DEBUG
handlers: [console, file]
3 changes: 1 addition & 2 deletions deployability/modules/testing/tests/helpers/logger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import logging.config
from pathlib import Path
import threading

import yaml

Expand All @@ -21,4 +20,4 @@ def _load_config() -> None:

_load_config()

logger = logging.getLogger("Testing")
logger = logging.getLogger("TEST-MODULE")
1 change: 0 additions & 1 deletion deployability/modules/testing/tests/helpers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import requests
import socket

from .constants import CLUSTER_CONTROL, AGENT_CONTROL, WAZUH_CONF, WAZUH_ROOT
from .executor import Executor, WazuhAPI
Expand Down
2 changes: 1 addition & 1 deletion deployability/modules/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

from modules.generic.logger import Logger

logger = Logger("tester").get_logger()
logger = Logger("test-module").get_logger()
1 change: 1 addition & 0 deletions deployability/modules/workflow_engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# 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 .workflow_processor import WorkflowProcessor
1 change: 1 addition & 0 deletions deployability/modules/workflow_engine/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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 os
import sys
import argparse
Expand Down
Loading

0 comments on commit 643a24c

Please sign in to comment.