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

DTT1 - Iteration 3 - Test module - Multiple dependencies in InputPayload #4880

Closed
4 tasks done
Tracked by #4848
QU3B1M opened this issue Jan 25, 2024 · 4 comments · Fixed by #4884
Closed
4 tasks done
Tracked by #4848

DTT1 - Iteration 3 - Test module - Multiple dependencies in InputPayload #4880

QU3B1M opened this issue Jan 25, 2024 · 4 comments · Fixed by #4884
Assignees

Comments

@QU3B1M
Copy link
Member

QU3B1M commented Jan 25, 2024

Epic #4848

Description

This issue aims to add support for multiple dependencies in the Test InputPayload

Tasks

  • Modify the InputPayload & ExtraVars models
  • Modify Tester class to get the IP of every dependency received and configure the ExtraVars with it
  • Update the workflow's .yaml to send a list of key values (component_name: inventory_path)
  • Update test.yml template to receive the dependencies argument
@QU3B1M
Copy link
Member Author

QU3B1M commented Jan 25, 2024

class ExtraVars(BaseModel):
    """Extra vars for testing module."""
    component: Literal['manager', 'agent']
    dependencies: list[dict] | None = None
    wazuh_version: str
    wazuh_revision: str
    wazuh_branch: str | None = None
    working_dir: str = '/tmp/tests'


class InputPayload(ExtraVars):
    """Input payload for testing module."""
    tests: list[str]
    inventory: Path
    dependency: list[dict] = None # Dict comes component: inventory_path
    cleanup: bool = True

@pro-akim
Copy link
Member

pro-akim commented Jan 26, 2024

Update

Executing the test with some additional prints (for testing purposes)

  • print(extra_vars)
    @classmethod
    def run(cls, payload: InputPayload) -> None:
        payload = InputPayload(**dict(payload))
        inventory = Inventory(**Utils.load_from_yaml(payload.inventory))
        extra_vars = cls._get_extra_vars(payload).model_dump()
        dependencies_dict = {}
        for dependency in extra_vars['dependencies']:
            dependency = ast.literal_eval(dependency)
            dependencies_dict.update(dependency)
        extra_vars['dependencies'] = dependencies_dict
        print(extra_vars)
        ansible = Ansible(ansible_data=inventory.model_dump())
        cls._setup(ansible, extra_vars['working_dir'])
        cls._run_tests(payload.tests, ansible, extra_vars)
        if payload.cleanup:
            cls._cleanup(ansible, extra_vars['working_dir'])

Using the following command:

(deployability) akim@akim-PC:~/Desktop/wazuh-qa/deployability$ python3 launchers/test.py --inventory '/tmp/dtt1-poc/agent-linux-ubuntu-22.04-amd64/inventory.yaml' --dependencies '{"manager": "/tmp/dtt1-poc/manager-linux-ubuntu-22.04-amd64/inventory.yaml"}','{"agent": "/tmp/dtt1-poc/agent-linux-ubuntu-22.04-amd64/inventory.yaml"}' --tests install --wazuh-version 4.7.1 --wazuh-revision 1 --component agent

It is possible to see:

  • Result of print(extra_vars)
{'component': 'agent', 'dependencies': {'manager': '127.0.0.1', 'agent': '127.0.0.1'}, 'wazuh_version': '4.7.1', 'wazuh_revision': '1', 'wazuh_branch': None, 'working_dir': '/tmp/tests'}
Complete result
{'component': 'agent', 'dependencies': {'manager': '127.0.0.1', 'agent': '127.0.0.1'}, 'wazuh_version': '4.7.1', 'wazuh_revision': '1', 'wazuh_branch': None, 'working_dir': '/tmp/tests'}
No config file found; using defaults

PLAY [all] *********************************************************************

TASK [Gathering Facts] *********************************************************
fatal: [127.0.0.1]: UNREACHABLE! => changed=false 
  msg: 'Failed to connect to the host via ssh: ssh: connect to host 127.0.0.1 port 2200: Connection refused'
  unreachable: true

PLAY RECAP *********************************************************************
127.0.0.1                  : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0   
No config file found; using defaults

PLAY [all] *********************************************************************

TASK [Gathering Facts] *********************************************************
fatal: [127.0.0.1]: UNREACHABLE! => changed=false 
  msg: 'Failed to connect to the host via ssh: ssh: connect to host 127.0.0.1 port 2200: Connection refused'
  unreachable: true

PLAY RECAP *********************************************************************
127.0.0.1                  : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0   
No config file found; using defaults

PLAY [all] *********************************************************************

TASK [Gathering Facts] *********************************************************
fatal: [127.0.0.1]: UNREACHABLE! => changed=false 
  msg: 'Failed to connect to the host via ssh: ssh: connect to host 127.0.0.1 port 2200: Connection refused'
  unreachable: true

PLAY RECAP *********************************************************************
127.0.0.1                  : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0   

Executing:

(deployability) akim@akim-PC:~/Desktop/wazuh-qa/deployability$  python3 launchers/workflow_engine.py modules/workflow_engine/examples/dtt1-agents-poc.yaml modules/workflow_engine/schema.json

The result is:

Validation error: {'action': 'create'} is not of type 'string'

Failed validating 'type' in schema[0]:
    {'type': 'string'}

On instance:
    {'action': 'create'}
[2024-01-26 13:53:23] [INFO] Executing tasks in parallel.
[2024-01-26 13:53:23] [INFO] [allocate-manager] Starting task.
task_args ['/home/akim/Desktop/wazuh-qa/deployability/launchers/allocation.py', '--action=create', '--provider=vagrant', '--size=large', '--composite-name=linux-ubuntu-22.04-amd64', '--inventory-output=/tmp/dtt1-poc/manager-linux-ubuntu-22.04-amd64/inventory.yaml', '--track-output=/tmp/dtt1-poc/manager-linux-ubuntu-22.04-amd64/track.yaml']
[2024-01-26 13:56:11] [INFO] [allocate-manager] Finished task in 168.30 seconds.
[2024-01-26 13:56:11] [INFO] [allocate-linux-ubuntu-22.04-amd64] Starting task.
task_args ['/home/akim/Desktop/wazuh-qa/deployability/launchers/allocation.py', '--action=create', '--provider=vagrant', '--size=small', '--composite-name=linux-ubuntu-22.04-amd64', '--inventory-output=/tmp/dtt1-poc/agent-linux-ubuntu-22.04-amd64/inventory.yaml', '--track-output=/tmp/dtt1-poc/agent-linux-ubuntu-22.04-amd64/track.yaml']
[2024-01-26 13:59:00] [INFO] [allocate-linux-ubuntu-22.04-amd64] Finished task in 169.26 seconds.
[2024-01-26 13:59:00] [INFO] [provision-manager] Starting task.
task_args ['/home/akim/Desktop/wazuh-qa/deployability/launchers/provision.py', '--inventory-manager=/tmp/dtt1-poc/manager-linux-ubuntu-22.04-amd64/inventory.yaml', '--install=component:wazuh-manager,install-type:package', '--install=component:curl']
[2024-01-26 14:02:18] [INFO] [provision-manager] Finished task in 197.65 seconds.
[2024-01-26 14:02:18] [INFO] [provision-linux-ubuntu-22.04-amd64] Starting task.
task_args ['/home/akim/Desktop/wazuh-qa/deployability/launchers/provision.py', '--inventory-agent=/tmp/dtt1-poc/agent-linux-ubuntu-22.04-amd64/inventory.yaml', '--inventory-manager=/tmp/dtt1-poc/manager-linux-ubuntu-22.04-amd64/inventory.yaml', '--install=component:wazuh-agent,install-type:package', '--install=component:curl', '--install=component:nano']
[2024-01-26 14:04:06] [INFO] [provision-linux-ubuntu-22.04-amd64] Finished task in 107.78 seconds.
[2024-01-26 14:04:06] [INFO] [run-agent-tests-linux-ubuntu-22.04-amd64] Starting task.
task_args ['/home/akim/Desktop/wazuh-qa/deployability/launchers/test.py', '--inventory=/tmp/dtt1-poc/agent-linux-ubuntu-22.04-amd64/inventory.yaml', "--dependencies={'manager': '/tmp/dtt1-poc/manager-linux-ubuntu-22.04-amd64/inventory.yaml'}", "--dependencies={'agent': '/tmp/dtt1-poc/agent-linux-ubuntu-22.04-amd64/inventory.yaml'}", '--tests=install,register,stop', '--component=agent', '--wazuh-version=4.7.1', '--wazuh-revision=40709']
[2024-01-26 14:04:27] [INFO] [run-agent-tests-linux-ubuntu-22.04-amd64] Finished task in 21.12 seconds.
[2024-01-26 14:04:27] [INFO] Executing cleanup tasks.

Where is possible to see:

task_args ['/home/akim/Desktop/wazuh-qa/deployability/launchers/test.py', '--inventory=/tmp/dtt1-poc/agent-linux-ubuntu-22.04-amd64/inventory.yaml', "--dependencies={'manager': '/tmp/dtt1-poc/manager-linux-ubuntu-22.04-amd64/inventory.yaml'}", "--dependencies={'agent': '/tmp/dtt1-poc/agent-linux-ubuntu-22.04-amd64/inventory.yaml'}", '--tests=install,register,stop', '--component=agent', '--wazuh-version=4.7.1', '--wazuh-revision=40709']

@QU3B1M
Copy link
Member Author

QU3B1M commented Jan 26, 2024

LGTM

1 similar comment
@fcaffieri
Copy link
Member

LGTM

@wazuhci wazuhci moved this to Done in Release 4.9.0 Jan 30, 2024
@fcaffieri fcaffieri added level/task Task issue and removed level/subtask Subtask issue labels Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants