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 a new method for obtaining S3 packages #1828

Merged
merged 10 commits into from
Sep 3, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@
"installation_files_path": {
"type": "string"
},
"system":{
"type":"string"
},
"version":{
"type": "string"
},
"revision":{
"type": "string"
},
"repository":{
"type": "string"
},
"wazuh_install_path": {
"type": "string",
"default": "/var/ossec"
Expand All @@ -204,7 +216,12 @@
"else": {
"oneOf": [
{"required": ["local_package_path"]},
{"required": ["s3_package_url"]}
{"required": ["s3_package_url"]},
{"required": [
"system",
"version",
"revision",
"repository"]}
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from wazuh_testing.qa_ctl import QACTL_LOGGER
from wazuh_testing.tools.logging import Logging


class QAProvisioning():
"""Class to control different options and instances to provisioning with Wazuh and QA Framework.

Expand All @@ -31,6 +32,7 @@ class QAProvisioning():
wazuh_installation_paths (dict): Dict indicating the Wazuh installation paths for every host.
qa_ctl_configuration (QACTLConfiguration): QACTL configuration.
"""

LOGGER = Logging.get_logger(QACTL_LOGGER)

def __init__(self, provision_info, qa_ctl_configuration):
Expand Down Expand Up @@ -104,7 +106,15 @@ def __process_config_data(self, host_provision_info):
else deploy_info['wazuh_install_path']
wazuh_branch = 'master' if 'wazuh_branch' not in deploy_info else deploy_info['wazuh_branch']
s3_package_url = None if 's3_package_url' not in deploy_info \
else deploy_info['s3_package_url']
else deploy_info['s3_package_url']
system = None if 'version' not in deploy_info \
else deploy_info['system']
version = None if 'version' not in deploy_info \
else deploy_info['version']
repository = None if 'repository' not in deploy_info \
else deploy_info['repository']
revision = None if 'revision' not in deploy_info \
else deploy_info['revision']
local_package_path = None if 'local_package_path' not in deploy_info \
else deploy_info['local_package_path']
manager_ip = None if 'manager_ip' not in deploy_info else deploy_info['manager_ip']
Expand All @@ -122,17 +132,27 @@ def __process_config_data(self, host_provision_info):
installation_files_parameters['wazuh_branch'] = wazuh_branch
installation_instance = WazuhSources(**installation_files_parameters)
if install_type == 'package':
if s3_package_url is None:
installation_files_parameters['local_package_path'] = local_package_path
installation_instance = WazuhLocalPackage(**installation_files_parameters)
remote_files_path = installation_instance.download_installation_files(self.inventory_file_path,
hosts=current_host)
else:
installation_files_parameters['s3_package_url'] = s3_package_url
installation_instance = WazuhS3Package(**installation_files_parameters)
remote_files_path = installation_instance.download_installation_files(s3_package_url,
self.inventory_file_path,
hosts=current_host)

if s3_package_url is None and local_package_path is None:
installation_files_parameters['system'] = system
installation_files_parameters['version'] = version
installation_files_parameters['revision'] = revision
installation_files_parameters['repository'] = repository
installation_instance = WazuhS3Package(**installation_files_parameters)
remote_files_path = installation_instance.download_installation_files(self.inventory_file_path,
hosts=current_host)
elif s3_package_url is None and local_package_path is not None:
installation_files_parameters['local_package_path'] = local_package_path
installation_instance = WazuhLocalPackage(**installation_files_parameters)
remote_files_path = installation_instance.download_installation_files(self.inventory_file_path,
hosts=current_host)

else:
installation_files_parameters['s3_package_url'] = s3_package_url
installation_instance = WazuhS3Package(**installation_files_parameters)
remote_files_path = installation_instance.download_installation_files(self.inventory_file_path,
s3_package_url,
hosts=current_host)

if install_target == 'agent':
deployment_instance = AgentDeployment(remote_files_path,
Expand Down Expand Up @@ -187,7 +207,7 @@ def run(self):
"""Provision all hosts in a parallel way"""
self.__check_hosts_connection()
provision_threads = [ThreadExecutor(self.__process_config_data, parameters={'host_provision_info': host_value})
for _, host_value in self.provision_info['hosts'].items()]
for _, host_value in self.provision_info['hosts'].items()]
QAProvisioning.LOGGER.info(f"Provisioning {len(provision_threads)} instances")

for runner_thread in provision_threads:
Expand All @@ -201,4 +221,4 @@ def run(self):
def destroy(self):
"""Destroy all the temporary files created by an instance of this object"""
if os.path.exists(self.inventory_file_path):
os.remove(self.inventory_file_path)
os.remove(self.inventory_file_path)
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os

from pathlib import Path

from wazuh_testing.qa_ctl.provisioning.wazuh_deployment.wazuh_package import WazuhPackage
from wazuh_testing.qa_ctl.provisioning.ansible.ansible_task import AnsibleTask
from wazuh_testing.qa_ctl import QACTL_LOGGER
from wazuh_testing.tools.logging import Logging
from wazuh_testing.tools.exceptions import QAValueError
from wazuh_testing.tools.s3_package import get_s3_package_url


class WazuhS3Package(WazuhPackage):
Expand Down Expand Up @@ -37,34 +38,63 @@ class WazuhS3Package(WazuhPackage):

LOGGER = Logging.get_logger(QACTL_LOGGER)

def __init__(self, wazuh_target, s3_package_url, installation_files_path, qa_ctl_configuration, version=None,
system=None, revision=None, repository=None, architecture=None):
def __init__(self, wazuh_target, installation_files_path, qa_ctl_configuration,
s3_package_url=None, system=None, version=None, revision=None, repository=None):
self.system = system
self.revision = revision
self.repository = repository
self.architecture = architecture
self.s3_package_url = s3_package_url
self.package_name = Path(self.s3_package_url).name
super().__init__(wazuh_target=wazuh_target, installation_files_path=installation_files_path, version=version,
system=system, qa_ctl_configuration=qa_ctl_configuration)

def get_package_name(self):
pass
super().__init__(wazuh_target=wazuh_target, installation_files_path=installation_files_path,
system=system, version=version, qa_ctl_configuration=qa_ctl_configuration)

def __get_architecture(self, system):
"""Get the needed architecture for the wazuh package

def get_s3_package_url(self):
pass
Args:
system (string): String with the system value given

def download_installation_files(self, s3_package_url, inventory_file_path, hosts='all'):
Returns:
str: String with the default architecture for the system
"""
default_architectures = {
'deb': 'amd64',
'rpm': 'x86_64',
'rpm5': 'x86_64',
'windows': 'i386',
'macos': 'amd64',
'solaris10': 'i386',
'solaris11': 'i386',
'wpk-linux': 'x86_64',
'wpk-windows': 'i386',
}
return default_architectures[system]

def download_installation_files(self, inventory_file_path, s3_package_url=None, hosts='all'):
"""Download the installation files of Wazuh in the given inventory file path

Args:
s3_package_url (string): URL of the S3 Wazuh package.
inventory_file_path (string): path where the instalation files are going to be stored.
hosts (string): Parameter set to `all` by default.

repository (string): Repository of the wazuh package.
wazuh_target (string): Type of the Wazuh instance desired (agent or manager).
version (string): The version of Wazuh.
revision (string): Revision of the wazuh package.
system (string): System for the wazuh package.

Returns:
str: String with the complete path of the downloaded installation package
"""
"""
if s3_package_url is None and self.version is not None and self.repository is not None and \
self.system is not None and self.revision is not None:
architecture = self.__get_architecture(self.system)
s3_package_url = get_s3_package_url(self.repository, self.wazuh_target, self.version,
self.revision, self.system, architecture)
else:
raise QAValueError(f"Could not get Wazuh Package S3 URL from {hosts} host. s3_package_url or "
'(version, repository, sistem, revision) has None value')

package_name = Path(s3_package_url).name
WazuhS3Package.LOGGER.debug(f"Downloading Wazuh S3 package from <url> in {hosts} hosts")

download_s3_package = AnsibleTask({'name': 'Download S3 package',
Expand All @@ -76,5 +106,4 @@ def download_installation_files(self, s3_package_url, inventory_file_path, hosts

super().download_installation_files(inventory_file_path, [download_s3_package], hosts)

return os.path.join(self.installation_files_path, self.package_name)

return os.path.join(self.installation_files_path, package_name)
Loading