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,21 @@
"installation_files_path": {
"type": "string"
},
"version":{
"type": "string"
},
"system":{
"type": "string"
jmv74211 marked this conversation as resolved.
Show resolved Hide resolved
},
"revision":{
"type": "string"
},
"repository":{
"type": "string"
},
"architecture":{
"type": "string"
},
jmv74211 marked this conversation as resolved.
Show resolved Hide resolved
"wazuh_install_path": {
"type": "string",
"default": "/var/ossec"
Expand All @@ -204,7 +219,13 @@
"else": {
"oneOf": [
{"required": ["local_package_path"]},
{"required": ["s3_package_url"]}
{"required": ["s3_package_url"]},
{"required": [
"version",
"system",
"revision",
"repository",
"architecture"]}
jmv74211 marked this conversation as resolved.
Show resolved Hide resolved
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ def __process_config_data(self, host_provision_info):
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']

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']
jmv74211 marked this conversation as resolved.
Show resolved Hide resolved

system = None if 'system' not in deploy_info \
jmv74211 marked this conversation as resolved.
Show resolved Hide resolved
else deploy_info['system']
architecture = None if 'architecture' not in deploy_info \
jmv74211 marked this conversation as resolved.
Show resolved Hide resolved
else deploy_info['architecture']

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,16 +136,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:

if s3_package_url is None and local_package_path is None:
installation_files_parameters['version'] = version
installation_files_parameters['system'] = system
installation_files_parameters['revision'] = revision
installation_files_parameters['repository'] = repository
installation_files_parameters['architecture'] = architecture
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 version is None:
jmv74211 marked this conversation as resolved.
Show resolved Hide resolved
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,
remote_files_path = installation_instance.download_installation_files(self.inventory_file_path,
s3_package_url,
hosts=current_host)

if install_target == 'agent':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from logging import setLoggerClass
jmv74211 marked this conversation as resolved.
Show resolved Hide resolved
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.s3_package import get_s3_package_url


class WazuhS3Package(WazuhPackage):
Expand Down Expand Up @@ -37,36 +38,37 @@ 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,
def __init__(self, wazuh_target, installation_files_path, qa_ctl_configuration, s3_package_url=None, version=None,
system=None, revision=None, repository=None, architecture=None):
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


def get_s3_package_url(self):
pass

def download_installation_files(self, s3_package_url, inventory_file_path, hosts='all'):
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 of the Wazuh installation files.
architecture (string): Architecture of the Wazuh package.

Returns:
str: String with the complete path of the downloaded installation package
"""
WazuhS3Package.LOGGER.debug(f"Downloading Wazuh S3 package from <url> in {hosts} hosts")

if s3_package_url is None:
s3_package_url = get_s3_package_url(self.repository, self.wazuh_target, self.version, self.revision, self.system, self.architecture)
package_name = Path(s3_package_url).name
download_s3_package = AnsibleTask({'name': 'Download S3 package',
'get_url': {'url': s3_package_url,
'dest': self.installation_files_path},
Expand All @@ -76,5 +78,5 @@ 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