-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement schema_validator unit tests
- Loading branch information
Marcelo Ariel Hamra
committed
Mar 7, 2024
1 parent
11dacea
commit 6b56e0a
Showing
4 changed files
with
234 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
deployability/modules/workflow_engine/tests/data/wf-ok.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
# Copyright (C) 2015, Wazuh Inc. | ||
# Created by Wazuh, Inc. <info@wazuh.com>. | ||
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2 | ||
version: 0.1 | ||
description: This workflow is used to test agents deployment with a single manager. | ||
variables: | ||
agents-os: | ||
- linux-ubuntu-22.04-amd64 | ||
manager-os: linux-ubuntu-22.04-amd64 | ||
infra-provider: vagrant | ||
working-dir: /tmp/dtt1 | ||
|
||
tasks: | ||
# Generic agent test task | ||
- task: "run-agent-tests-{agent}" | ||
description: "Run tests uninstall for the {agent} agent." | ||
do: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/testing/main.py | ||
- inventory: "{working-dir}/agent-{agent}/inventory.yaml" | ||
- dependencies: | ||
- manager: "{working-dir}/manager-{manager-os}/inventory.yaml" | ||
- agent: "{working-dir}/agent-{agent}/inventory.yaml" | ||
- tests: "install,register,stop" | ||
- component: "agent" | ||
- wazuh-version: "4.7.1" | ||
- wazuh-revision: "40709" | ||
depends-on: | ||
- "provision-install-{agent}" | ||
- "provision-manager" | ||
foreach: | ||
- variable: agents-os | ||
as: agent | ||
|
||
# Generic agent test task | ||
- task: "run-agent-tests-uninstall-{agent}" | ||
description: "Run tests uninstall for the {agent} agent." | ||
do: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/testing/main.py | ||
- inventory: "{working-dir}/agent-{agent}/inventory.yaml" | ||
- dependencies: | ||
- manager: "{working-dir}/manager-{manager-os}/inventory.yaml" | ||
- tests: "uninstall" | ||
- component: "agent" | ||
- wazuh-version: "4.7.1" | ||
- wazuh-revision: "40709" | ||
depends-on: | ||
- "run-agent-tests-{agent}" | ||
- "provision-uninstall-{agent}" | ||
foreach: | ||
- variable: agents-os | ||
as: agent | ||
|
||
# Unique manager provision task | ||
- task: "provision-manager" | ||
description: "Provision the manager." | ||
do: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/provision/main.py | ||
- inventory-manager: "{working-dir}/manager-{manager-os}/inventory.yaml" | ||
- install: | ||
- component: wazuh-manager | ||
type: aio | ||
version: "4.7.0" | ||
depends-on: | ||
- "allocate-manager" | ||
|
||
# Unique manager allocate task | ||
- task: "allocate-manager" | ||
description: "Allocate resources for the manager." | ||
do: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/allocation/main.py | ||
- action: create | ||
- provider: "{infra-provider}" | ||
- size: large | ||
- composite-name: "{manager-os}" | ||
- inventory-output: "{working-dir}/manager-{manager-os}/inventory.yaml" | ||
- track-output: "{working-dir}/manager-{manager-os}/track.yaml" | ||
cleanup: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/allocation/main.py | ||
- action: delete | ||
- track-output: "{working-dir}/manager-{manager-os}/track.yaml" | ||
|
||
# Generic agent provision task | ||
- task: "provision-install-{agent}" | ||
description: "Provision resources for the {agent} agent." | ||
do: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/provision/main.py | ||
- inventory-agent: "{working-dir}/agent-{agent}/inventory.yaml" | ||
- inventory-manager: "{working-dir}/manager-{manager-os}/inventory.yaml" | ||
- install: | ||
- component: wazuh-agent | ||
type: aio | ||
version: "4.8.0" | ||
live: False | ||
depends-on: | ||
- "allocate-{agent}" | ||
- "provision-manager" | ||
foreach: | ||
- variable: agents-os | ||
as: agent | ||
|
||
# Generic agent provision task | ||
- task: "provision-uninstall-{agent}" | ||
description: "Provision resources for the {agent} agent." | ||
do: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/provision/main.py | ||
- inventory-agent: "{working-dir}/agent-{agent}/inventory.yaml" | ||
- inventory-manager: "{working-dir}/manager-{manager-os}/inventory.yaml" | ||
- uninstall: | ||
- component: wazuh-agent | ||
type: package | ||
depends-on: | ||
- "provision-install-{agent}" | ||
foreach: | ||
- variable: agents-os | ||
as: agent | ||
|
||
# Generic agent allocate task | ||
- task: "allocate-{agent}" | ||
description: "Allocate resources for the {agent} agent." | ||
do: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/allocation/main.py | ||
- action: create | ||
- provider: "{infra-provider}" | ||
- size: small | ||
- composite-name: "{agent}" | ||
- inventory-output: "{working-dir}/agent-{agent}/inventory.yaml" | ||
- track-output: "{working-dir}/agent-{agent}/track.yaml" | ||
cleanup: | ||
this: process | ||
with: | ||
path: python3 | ||
args: | ||
- modules/allocation/main.py | ||
- action: delete | ||
- track-output: "{working-dir}/agent-{agent}/track.yaml" | ||
foreach: | ||
- variable: agents-os | ||
as: agent |
39 changes: 39 additions & 0 deletions
39
deployability/modules/workflow_engine/tests/test_schema_validator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (C) 2015-2021, Wazuh Inc. | ||
# Created by Wazuh, Inc. <info@wazuh.com>. | ||
# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 | ||
"""SchemaValidator unit tests.""" | ||
from unittest.mock import patch, MagicMock, call, mock_open | ||
import json | ||
from ruamel.yaml import YAML | ||
from pathlib import Path | ||
import pytest | ||
|
||
from workflow_engine.schema_validator import SchemaValidator | ||
|
||
@pytest.mark.parametrize('logger_mock', | ||
[{'logger_to_patch':'workflow_engine.schema_validator.logger'}], | ||
indirect=True) | ||
def test_schema_validator_constructor(logger_mock: MagicMock): | ||
"""Test SchemaValidator constructor normal flow.""" | ||
schema_path = Path(__file__).parent.parent / 'schemas' / 'schema_v1.json' | ||
with open(schema_path, 'r') as schema_file: | ||
schema_data = json.load(schema_file) | ||
|
||
wf_file_path = Path(__file__).parent / 'data' / 'wf-ok.yml' | ||
with open(wf_file_path, 'r') as file: | ||
yaml = YAML(typ='safe', pure=True) | ||
yaml_data = yaml.load(file) | ||
|
||
validator = SchemaValidator(schema_path, wf_file_path) | ||
assert validator.schema_data == schema_data | ||
assert validator.yaml_data == yaml_data | ||
calls = [call(f"Loading schema file: {schema_path}"), | ||
call(f"Loading yaml file: {wf_file_path}")] | ||
logger_mock.debug.assert_has_calls(calls) | ||
|
||
|
||
def test_preprocess_data(): | ||
pass | ||
|
||
def test_validate_schema(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters