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

Add Windows native support for qa-ctl tool #1961

Merged
merged 44 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ee2bd03
add: Add vagrant deployer for Windows #1900
jmv74211 Sep 17, 2021
fcd84c2
add: Add ansible module to launch common ansible tasks #1900
jmv74211 Sep 20, 2021
b110b8a
add: Add support for WinRM in AnsibleInventory class #1900
jmv74211 Sep 20, 2021
863ace2
add: Add vagrant deployer script to setup data files #1900
jmv74211 Sep 20, 2021
2f12b18
add: Add windows deployment provisioning to QA infraestructure class …
jmv74211 Sep 20, 2021
6307a47
add: Create and use AnsibleException to manage ansible exceptions #1900
jmv74211 Sep 21, 2021
21903df
add: Add new common ansible tasks to ansible module #1900
jmv74211 Sep 21, 2021
0bac911
add: Add `vagrant_deployer` integration in `qa-ctl` #1900
jmv74211 Sep 21, 2021
f813123
refac: Improve QA exceptions according to the logging level #1900
jmv74211 Sep 21, 2021
86081c4
refac: Unify `qa-ctl` logging #1916
jmv74211 Sep 22, 2021
a6c6ef7
add: Show only traceback exceptions when `qa-ctl` is in debug mode #1916
jmv74211 Sep 22, 2021
bd607b2
add: Add the possibility to log ansible runner exceptions #1916
jmv74211 Sep 23, 2021
9bd3e45
add: Add custom AnsibleException management #1916
jmv74211 Sep 23, 2021
b2dfb8a
fix: Fix error parameters in `qa-ctl` script #1916
jmv74211 Sep 23, 2021
55267e0
Merge pull request #1924 from wazuh/1916-qa-ctl-loggers
jmv74211 Sep 23, 2021
a198cd3
refac: Update python dependencies for Windows compatibility #1900
jmv74211 Sep 27, 2021
f81e99c
refac: Update qa-ctl instances deployment for Windows hosts #1900
jmv74211 Sep 27, 2021
8a9f4a1
fix: Replace backslash in paths used as arguments
mdengra Sep 27, 2021
c1bcdb9
Merge branch '1900-qa-ctl-windows' of https://github.com/wazuh/wazuh-…
jmv74211 Sep 27, 2021
4543780
refac: Change group name in qa-ctl Vagrantfile template #1900
jmv74211 Sep 27, 2021
bc610a3
fix: Replace backslash in regex used as ignore and include paths
mdengra Sep 27, 2021
63f671d
Merge branch '1900-qa-ctl-windows' of github.com:wazuh/wazuh-qa into …
mdengra Sep 27, 2021
7587555
fix: Fix QA provisioning health check
jmv74211 Sep 28, 2021
ade8d23
refac: Delete wazuh_deployment and qa_framework schema contraints #1900
jmv74211 Sep 28, 2021
2f77124
add: Add `qa-ctl` Dockerfile to launch provisioning and testing modul…
jmv74211 Sep 28, 2021
11a085e
fix: Fix qa repository download path in qa-ctl #1900
jmv74211 Sep 29, 2021
16af414
add: Add new function for running local commands without output #1900
jmv74211 Sep 29, 2021
7a33280
add: Add no-validation-logging parameter to qa-ctl #1900
jmv74211 Sep 29, 2021
4357d88
add: Integrate docker container provision and testing tasks in Window…
jmv74211 Sep 29, 2021
6fc5692
refac: Move qa-ctl Dockerfile #1900
jmv74211 Sep 29, 2021
f5c9a1b
refac: Improve docker integration in Windows qa-ctl #1900
jmv74211 Sep 29, 2021
19ec5f2
refac: Rename ubuntu focal vagrant box URL
jmv74211 Sep 29, 2021
1cbb1bf
refac: Rename assets directory from qa-ctl results
jmv74211 Sep 30, 2021
3e46588
add: Add new util function to move all files from one directory to an…
jmv74211 Sep 30, 2021
da19098
add: Add test results collection for Windows qa-ctl #1900
jmv74211 Sep 30, 2021
580b996
refac: Improve the download process of wazuh-qa repository for qa-ctl…
jmv74211 Sep 30, 2021
8ddcfbb
style: Improve some log messages in qa-ctl #1900
jmv74211 Sep 30, 2021
263e9c7
refac: Update qa-ctl deployment range IPs #1900
jmv74211 Sep 30, 2021
602902a
add: Add env var to know if qa-ctl is running in a docker container #…
jmv74211 Oct 1, 2021
8970a61
refac: Improve how to run Linux commands with subprocess module #1900
jmv74211 Oct 1, 2021
554c631
add: Clean configuration info after finishing the qa-ctl run #1900
jmv74211 Oct 1, 2021
afd93c6
refac: Update Windows requirements dependencies for qa-ctl #1900
jmv74211 Oct 1, 2021
b7784e4
fix: Fix qa-ctl docker image name #1900
jmv74211 Oct 1, 2021
65650fb
add: Add new log message to the qa-ctl provision stage #1900
jmv74211 Oct 1, 2021
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
3 changes: 2 additions & 1 deletion deps/wazuh_testing/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
'tools/macos_log/log_generator.m',
'qa_docs/config.yaml',
'qa_ctl/deployment/dockerfiles/*',
'qa_ctl/deployment/dockerfiles/qa_ctl/*',
'qa_ctl/deployment/vagrantfile_template.txt',
'qa_ctl/provisioning/wazuh_deployment/templates/preloaded_vars.conf.j2',
'data/qactl_conf_validator_schema.json'
'data/qactl_conf_validator_schema.json',
]

scripts_list = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@
"^host[0-9]*$": {
"type": "object",
"required": [
"host_info",
"wazuh_deployment",
"qa_framework"
"host_info"
],
"properties": {
"host_info": {
Expand Down Expand Up @@ -219,8 +217,8 @@
{"required": ["s3_package_url"]},
{"required": [
"system",
"version",
"revision",
"version",
"revision",
"repository"]}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

from tempfile import gettempdir
from sys import exit
from packaging.version import parse

from wazuh_testing.tools import file
Expand All @@ -12,7 +11,7 @@
from wazuh_testing.tools.s3_package import get_s3_package_url
from wazuh_testing.qa_ctl.provisioning.wazuh_deployment.wazuh_s3_package import WazuhS3Package
from wazuh_testing.tools.github_repository import get_last_wazuh_version
from wazuh_testing.qa_ctl.provisioning.local_actions import run_local_command
from wazuh_testing.qa_ctl.provisioning.local_actions import run_local_command_with_output


class QACTLConfigGenerator:
Expand All @@ -38,6 +37,9 @@ class QACTLConfigGenerator:
generated.
"""

LOGGER = Logging.get_logger(QACTL_LOGGER)
LINUX_TMP = '/tmp'

BOX_MAPPING = {
'Ubuntu Focal': 'qactl/ubuntu_20_04',
'CentOS 8': 'qactl/centos_8'
Expand All @@ -51,7 +53,7 @@ class QACTLConfigGenerator:
'connection_port': 22,
'ansible_python_interpreter': '/usr/bin/python3',
'system': 'deb',
'installation_files_path': '/tmp'
'installation_files_path': LINUX_TMP
},
'qactl/centos_8': {
'connection_method': 'ssh',
Expand All @@ -60,12 +62,10 @@ class QACTLConfigGenerator:
'connection_port': 22,
'ansible_python_interpreter': '/usr/bin/python3',
'system': 'rpm',
'installation_files_path': '/tmp'
'installation_files_path': LINUX_TMP
}
}

LOGGER = Logging.get_logger(QACTL_LOGGER)

def __init__(self, tests, wazuh_version, qa_files_path=f"{gettempdir()}/wazuh-qa"):
self.tests = tests
self.wazuh_version = get_last_wazuh_version() if wazuh_version is None else wazuh_version
Expand Down Expand Up @@ -94,15 +94,15 @@ def __get_test_info(self, test_name):
"""
qa_docs_command = f"qa-docs -T {test_name} -o {gettempdir()} -I {self.qa_files_path}/tests"

run_local_command(qa_docs_command)
run_local_command_with_output(qa_docs_command)

# Read test data file
try:
info = file.read_json_file(f"{gettempdir()}/{test_name}.json")
except FileNotFoundError:
raise QAValueError(f"Could not find {gettempdir()}/{test_name}.json file. Perhaps qa-docs has not "
f"generated it correctly. Try manually with command: {qa_docs_command}",
QACTLConfigGenerator.LOGGER.error)
QACTLConfigGenerator.LOGGER.error, QACTL_LOGGER)

# Add test name extra info
info['test_name'] = test_name
Expand Down Expand Up @@ -153,7 +153,7 @@ def _check_validate(check, test_info, allowed_values):
if len(list(set(test_info[check]) & set(allowed_values))) == 0:
error_message = f"{test_info['test_name']} cannot be launched. Reason: Currently we do not "\
f"support {test_info[check]}. Allowed values: {allowed_values}"
raise QAValueError(error_message, QACTLConfigGenerator.LOGGER.error)
raise QAValueError(error_message, QACTLConfigGenerator.LOGGER.error, QACTL_LOGGER)

return True

Expand All @@ -170,7 +170,7 @@ def _check_validate(check, test_info, allowed_values):
if parse(str(test_info['wazuh_min_version'])) > parse(str(self.wazuh_version)):
error_message = f"The minimal version of wazuh to launch the {test_info['test_name']} is " \
f"{test_info['wazuh_min_version']} and you are using {self.wazuh_version}"
raise QAValueError(error_message, QACTLConfigGenerator.LOGGER.error)
raise QAValueError(error_message, QACTLConfigGenerator.LOGGER.error, QACTL_LOGGER)

return True

Expand All @@ -196,13 +196,13 @@ def ip_is_already_used(ip, qactl_host_used_ips):
open(self.qactl_used_ips_file, 'a').close()

# Get a free IP in HOST_NETWORK range
for _ip in range(1, 256):
for _ip in range(2, 256):
host_ip = HOST_NETWORK.replace('x', str(_ip))
if not ip_is_already_used(host_ip, self.qactl_used_ips_file):
break
if _ip == 255:
raise QAValueError(f"Could not find an IP available in {HOST_NETWORK}",
QACTLConfigGenerator.LOGGER.error)
QACTLConfigGenerator.LOGGER.error, QACTL_LOGGER)

# Write new used IP in used IPs file
with open(self.qactl_used_ips_file, 'a') as used_ips_file:
Expand Down Expand Up @@ -345,7 +345,7 @@ def __process_provision_data(self):
wazuh_qa_branch = self.__get_qa_branch()
self.config['provision']['hosts'][instance]['qa_framework'] = {
'wazuh_qa_branch': wazuh_qa_branch,
'qa_workdir': gettempdir()
'qa_workdir': self.LINUX_TMP
}

def __process_test_data(self, tests_info):
Expand All @@ -365,8 +365,8 @@ def __process_test_data(self, tests_info):
self.config['tests'][instance]['test'] = {
'type': 'pytest',
'path': {
'test_files_path': f"{gettempdir()}/wazuh-qa/{test['path']}",
'run_tests_dir_path': f"{gettempdir()}/wazuh-qa/test/integration",
'test_files_path': f"{self.LINUX_TMP}/wazuh-qa/{test['path']}",
'run_tests_dir_path': f"{self.LINUX_TMP}/wazuh-qa/test/integration",
'test_results_path': f"{gettempdir()}/{test['test_name']}_{get_current_timestamp()}/"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class QACTLConfiguration:

Args:
configuration_data (dict) : Dict with all the info needed for this module coming from config file.
debug_level (int): Debug level. It is indicated in the qa-ctl script parameters.

Attributes:
configuration_data (dict) : Dict with all the info needed for this module coming from config file.
Expand All @@ -18,20 +19,28 @@ class QACTLConfiguration:
logging_file (string): This field defines a path for a file where the outputs will be logged as well
"""

def __init__(self, configuration_data):
def __init__(self, configuration_data, debug_level=0):
self.configuration_data = configuration_data
self.vagrant_output = False
self.ansible_output = False
self.logging_enable = True
self.logging_level = 'INFO'
self.logging_file = None
self.debug_level = debug_level

self.__read_configuration_data()

# Check debug level parameter set in qa-ctl script parameters. It has a higher priority than indicated in
# the configuration file.
if debug_level == 1:
self.logging_level = 'DEBUG'
if debug_level > 1:
self.vagrant_output = True
self.ansible_output = True

def __read_configuration_data(self):
"""Read the given configuration data of the object and sets the values of the
parameters of the class.
"""
"""Read the given configuration data of the object and sets the values of the parameters of the class."""

if 'config' in self.configuration_data:
if 'vagrant_output' in self.configuration_data['config']:
self.vagrant_output = self.configuration_data['config']['vagrant_output']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def run(self):
'subnets. Please check if you have already set this docker network ' \
'(run `docker network ls`) and then remove it if it is created with ' \
'docker network rm `<network_id>`'
raise QAValueError(exception_message, DockerWrapper.LOGGER.error)
raise QAValueError(exception_message, DockerWrapper.LOGGER.error, QACTL_LOGGER)

def restart(self):
"""Restart the container.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
From ubuntu:focal

ENV DEBIAN_FRONTEND=noninteractive
ENV RUNNING_ON_DOCKER_CONTAINER=true

RUN apt-get -q update && \
apt-get install -y \
git \
python \
python3 \
sshpass \
python3-pip \
python3-setuptools

ADD https://raw.githubusercontent.com/wazuh/wazuh-qa/1900-qa-ctl-windows/requirements.txt /tmp/requirements.txt
RUN python3 -m pip install --upgrade pip && python3 -m pip install -r /tmp/requirements.txt --ignore-installed

RUN mkdir /qa_ctl

COPY ./entrypoint.sh /usr/bin/entrypoint.sh
RUN chmod 755 /usr/bin/entrypoint.sh

ENTRYPOINT ["/usr/bin/entrypoint.sh"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

BRANCH="$1"
CONFIG_FILE_PATH="$2"
EXTRA_ARGS="${@:3}"

# Clone custom wazuh-qa repository branch
git clone https://github.com/wazuh/wazuh-qa --depth=1 -b ${BRANCH} &> /dev/null

# Install python dependencies not installed from
python3 -m pip install -r wazuh-qa/requirements.txt &> /dev/null

# Install Wazuh QA framework
cd wazuh-qa/deps/wazuh_testing &> /dev/null
python3 setup.py install &> /dev/null

# Run qa-ctl tool
/usr/local/bin/qa-ctl -c /qa_ctl/${CONFIG_FILE_PATH} ${EXTRA_ARGS}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class QAInfraestructure:
"""Class to handle multiples instances objects.

Args:
instance_list (dict): Dictionary with the information of the instances. Must follow the format of the yaml
deployment_data (dict): Dictionary with the information of the instances. Must follow the format of the yaml
template.
qa_ctl_configuration (QACTLConfiguration): QACTL configuration.

Expand All @@ -34,17 +34,18 @@ class QAInfraestructure:
DOCKER_NETWORK_NAME = 'wazuh_net'
LOGGER = Logging.get_logger(QACTL_LOGGER)

def __init__(self, instance_list, qa_ctl_configuration):
def __init__(self, deployment_data, qa_ctl_configuration):
self.deployment_data = deployment_data
self.qa_ctl_configuration = qa_ctl_configuration
self.instances = []
self.docker_client = None
self.docker_network = None
self.network_address = None

QAInfraestructure.LOGGER.debug('Processing deployment configuration')
for host in instance_list:
for provider in instance_list[host]['provider']:
data = instance_list[host]['provider'][provider]
for host in deployment_data:
for provider in deployment_data[host]['provider']:
data = deployment_data[host]['provider'][provider]
if not data['enabled']:
continue

Expand Down Expand Up @@ -79,7 +80,7 @@ def __init__(self, instance_list, qa_ctl_configuration):
if network != self.network_address:
exception_message = 'Two different networks where found for docker containers when only ' \
f"one network is allowed: {network} != {self.network_address}"
raise QAValueError(exception_message, QAInfraestructure.LOGGER.error)
raise QAValueError(exception_message, QAInfraestructure.LOGGER.error, QACTL_LOGGER)

if not self.docker_network:
# Try to get the DOCKER_NETWORK_NAME network, if it fails, try to create it.
Expand Down Expand Up @@ -118,7 +119,7 @@ def __threads_runner(self, threads):
runner_thread.join()

def run(self):
"""Execute the run method on every configured instance."""
"""Run the instances deployment when the local host is UNIX."""
QAInfraestructure.LOGGER.info(f"Starting {len(self.instances)} instances deployment")
self.__threads_runner([ThreadExecutor(instance.run) for instance in self.instances])
QAInfraestructure.LOGGER.info('The instances deployment has finished sucessfully')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from wazuh_testing.qa_ctl.deployment.instance import Instance
from wazuh_testing.qa_ctl import QACTL_LOGGER
from wazuh_testing.tools.logging import Logging
from wazuh_testing.qa_ctl.provisioning.local_actions import run_local_command
from wazuh_testing.qa_ctl.provisioning.local_actions import run_local_command_with_output


class VagrantWrapper(Instance):
Expand Down Expand Up @@ -54,7 +54,7 @@ def run(self):
"""Write the vagrantfile and starts the VM specified in the vagrantfile."""
VagrantWrapper.LOGGER.debug(f"Running {self.vm_name} vagrant up")

if len(run_local_command(f"vagrant box list | grep {self.vm_box}")) == 0:
if len(run_local_command_with_output(f"vagrant box list | grep {self.vm_box}")) == 0:
VagrantWrapper.LOGGER.info(f"{self.vm_box} vagrant box not found in local repository. Downloading and "
'running')
self.vagrant.up()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __get_box_url(self):
it will return a 'None' value.
"""
box_mapping = {
'qactl/ubuntu_20_04': 'https://s3.amazonaws.com/ci.wazuh.com/qa/boxes/QACTL_ubuntu20_04.box',
'qactl/ubuntu_20_04': 'https://s3.amazonaws.com/ci.wazuh.com/qa/boxes/QACTL_ubuntu_20_04.box',
'qactl/centos_8': 'https://s3.amazonaws.com/ci.wazuh.com/qa/boxes/QACTL_centos_8.box'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Vagrant.configure("2") do |config|
vb.cpus = "#{vm_parameters['cpus']}"
vb.name = "#{vm_name}"
vb.customize ["setextradata", :id, "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled", 1]
vb.customize ["modifyvm", "#{vm_name}", "--groups", "#{vm_parameters['system']}"]
vb.customize ["modifyvm", "#{vm_name}", "--groups", "/qac-tl"]
end
end
end
Expand Down
Loading