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

Improve the way that environment data is managed #4059

Merged
merged 4 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ All notable changes to this project will be documented in this file.
- Add new module to support migration tool. ([#3837](https://github.com/wazuh/wazuh-qa/pull/3837))

### Changed

- Improve the way that environment data is managed ([#4059](https://github.com/wazuh/wazuh-qa/pull/4059)) \- (Framework)
- Update FIM test_ambiguous_confs IT to new framework ([#4121](https://github.com/wazuh/wazuh-qa/pull/4121)) \- (Tests + Framework)
- Update `test_logcollector` invalid configs log level ([#4094](https://github.com/wazuh/wazuh-qa/pull/4094)) \- (Tests)
- Update `test_office365` to support the new tag `API_TYPE` ([#4065](https://github.com/wazuh/wazuh-qa/pull/4065)) \- (Framework + Tests)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@
SNAPSHOTS_DIR = f"{GENERATED_FILES_DIR}/snapshots"
DOWNLOADS_DIR = f"{GENERATED_FILES_DIR}/downloads"
UNCOMPRESSED_DIR = f"{GENERATED_FILES_DIR}/uncompressed"
MYSQL_CREDENTIALS = {
'user': None,
'password': None,
'host': None,
'port': None,
'database': None
}
MYSQL_CREDENTIALS = None

# Callback messages
CB_PROCESS_STARTED = r'.+\[info\]\[Orchestrator - start\]: Starting process'
Expand Down
24 changes: 11 additions & 13 deletions deps/wazuh_testing/wazuh_testing/tools/migration_tool/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
from jsonschema.exceptions import ValidationError
from mysql.connector import errorcode

from wazuh_testing.tools.migration_tool import MIGRATION_TOOL_PATH, CVE5_SCHEMA_PATH, DELTA_SCHEMA_PATH, \
ERROR_MESSAGES, SNAPSHOTS_DIR, DOWNLOADS_DIR, MIGRATION_TOOL_LOG_PATH, \
MYSQL_CREDENTIALS, UNCOMPRESSED_DIR
damarisg marked this conversation as resolved.
Show resolved Hide resolved
import wazuh_testing.tools.migration_tool as migration_tool
from wazuh_testing.tools.file import delete_all_files_in_folder, read_json_file, truncate_file
from wazuh_testing.tools.logging import Logging

Expand Down Expand Up @@ -42,11 +40,11 @@ def run_tool(cmd):
return out, err

for file_path in config_files:
truncate_file(MIGRATION_TOOL_LOG_PATH)
command = ' '.join([MIGRATION_TOOL_PATH, '-i', file_path, args])
truncate_file(migration_tool.MIGRATION_TOOL_LOG_PATH)
command = ' '.join([migration_tool.MIGRATION_TOOL_PATH, '-i', file_path, args])
output, _ = run_tool(command)
output = output.decode()
error_checker = [True for msg in ERROR_MESSAGES if msg in output]
error_checker = [True for msg in migration_tool.ERROR_MESSAGES if msg in output]
if len(error_checker) > 0:
errors += f"\n{output}"

Expand Down Expand Up @@ -113,7 +111,7 @@ def validate_against_delta_schema(_elements):
_result = True
_errors = []
for cve in _elements:
_result, _error = validate_json_against_schema(cve, DELTA_SCHEMA_PATH)
_result, _error = validate_json_against_schema(cve, migration_tool.DELTA_SCHEMA_PATH)
if _result is False:
_errors.append(_error)

Expand All @@ -131,7 +129,7 @@ def validate_against_cve5_schema(_elements):

for cves in _elements:
data = json.loads(cves['data_blob'])
_result, _error = validate_json_against_schema(data, CVE5_SCHEMA_PATH)
_result, _error = validate_json_against_schema(data, migration_tool.CVE5_SCHEMA_PATH)
if _result is False:
_errors.append(_error)

Expand All @@ -149,10 +147,10 @@ def query_publisher_db(query):

try:
connection = mysql.connector.connect(
host=MYSQL_CREDENTIALS['host'],
user=MYSQL_CREDENTIALS['user'],
password=MYSQL_CREDENTIALS['password'],
database=MYSQL_CREDENTIALS['database']
host=migration_tool.MYSQL_CREDENTIALS['host'],
user=migration_tool.MYSQL_CREDENTIALS['user'],
password=migration_tool.MYSQL_CREDENTIALS['password'],
database=migration_tool.MYSQL_CREDENTIALS['database']
)
except mysql.connector.Error as error:
connection = None
Expand All @@ -175,7 +173,7 @@ def query_publisher_db(query):
def clean_migration_tool_output_files():
'''Remove all files generated by Content Migration Tool.
'''
output_folders = [SNAPSHOTS_DIR, DOWNLOADS_DIR, UNCOMPRESSED_DIR]
output_folders = [migration_tool.SNAPSHOTS_DIR, migration_tool.DOWNLOADS_DIR, migration_tool.UNCOMPRESSED_DIR]

for output_folder in output_folders:
for folder in vendors:
Expand Down