Skip to content

Commit

Permalink
Merge pull request #5474 from wazuh/enhancement/5391-dtt1-adaptation-…
Browse files Browse the repository at this point in the history
…to4.8.0

DTT1 - 4.8.0 adaptation
  • Loading branch information
rauldpm authored Jun 11, 2024
2 parents 70dbcde + b41369c commit 1fba0b8
Show file tree
Hide file tree
Showing 13 changed files with 869 additions and 16 deletions.
2 changes: 1 addition & 1 deletion deployability/modules/testing/tests/helpers/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def install_agent(inventory_path, agent_name, wazuh_version, wazuh_revision, liv
commands.extend(system_commands)
elif os_type == 'windows' :
commands.extend([
f"Invoke-WebRequest -Uri https://packages.wazuh.com/{release}/windows/wazuh-agent-{wazuh_version}-1.msi "
f"Invoke-WebRequest -Uri https://{s3_url}.wazuh.com/{release}/windows/wazuh-agent-{wazuh_version}-1.msi "
"-OutFile $env:TEMP\wazuh-agent.msi"
])
commands.extend([
Expand Down
26 changes: 16 additions & 10 deletions deployability/modules/testing/tests/helpers/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def get_public_ip_from_aws_dns(dns_name) -> str:
Args:
dns_name (str): host's dns public dns name
Returns:
str: public ip
"""
Expand Down Expand Up @@ -292,7 +292,7 @@ def get_client_keys(inventory_path) -> list[dict]:
client_key = ConnectionManager.execute_commands(inventory_path, f'Get-Content "{WINDOWS_CLIENT_KEYS}"').get('output')
elif os_type == 'macos':
client_key = ConnectionManager.execute_commands(inventory_path, f'cat {MACOS_CLIENT_KEYS}').get('output')

if client_key != None:
lines = client_key.split('\n')[:-1]
for line in lines:
Expand Down Expand Up @@ -372,7 +372,7 @@ def _extract_hosts(paths, is_aws):
return [Utils.extract_ansible_host(path) for path in paths]

@staticmethod
def certs_create(wazuh_version, master_path, dashboard_path, indexer_paths=[], worker_paths=[]) -> None:
def certs_create(wazuh_version, master_path, dashboard_path, indexer_paths=[], worker_paths=[], live="") -> None:
"""
Creates wazuh certificates
Expand All @@ -399,16 +399,22 @@ def certs_create(wazuh_version, master_path, dashboard_path, indexer_paths=[], w

##Basic commands to setup the config file, add the ip for the master & dashboard
os_name = HostInformation.get_os_name_from_inventory(master_path)

if live == "False":
s3_url = 'packages-dev.wazuh.com'
else:
s3_url = 'packages.wazuh.com'

if os_name == 'debian':
commands = [
f'wget https://packages.wazuh.com/{wazuh_version}/wazuh-install.sh',
f'wget https://packages.wazuh.com/{wazuh_version}/config.yml',
f'wget https://{s3_url}/{wazuh_version}/wazuh-install.sh',
f'wget https://{s3_url}/{wazuh_version}/config.yml',
f"sed -i '/^\s*#/d' {current_directory}/config.yml"
]
else:
commands = [
f'curl -sO https://packages.wazuh.com/{wazuh_version}/wazuh-install.sh',
f'curl -sO https://packages.wazuh.com/{wazuh_version}/config.yml',
f'curl -sO https://{s3_url}/{wazuh_version}/wazuh-install.sh',
f'curl -sO https://{s3_url}/{wazuh_version}/config.yml',
f"sed -i '/^\s*#/d' {current_directory}/config.yml"
]

Expand Down Expand Up @@ -866,11 +872,11 @@ def is_component_active(inventory_path, host_role) -> bool:
return result.get('success')

elif os_type == 'macos':
result = ConnectionManager.execute_commands(inventory_path, f'launchctl list | grep com.{host_role.replace("-", ".")}').get('output')
if result == None:
result = ConnectionManager.execute_commands(inventory_path, f'ps aux | grep {host_role} | grep -v grep')
if result.get('output') == None:
return False
else:
return f'com.{host_role.replace("-", ".")}' in result
return result.get('success')


class Waits:
Expand Down
18 changes: 17 additions & 1 deletion deployability/modules/testing/tests/helpers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import requests
import time

from .constants import CLUSTER_CONTROL, AGENT_CONTROL, WAZUH_CONF, WAZUH_ROOT
from .constants import CLUSTER_CONTROL, AGENT_CONTROL, WAZUH_CONF, WAZUH_ROOT, WAZUH_LOG
from .executor import WazuhAPI, ConnectionManager
from .generic import HostInformation, CheckFiles
from modules.testing.utils import logger
Expand Down Expand Up @@ -438,3 +438,19 @@ def get_manager_logs(wazuh_api: WazuhAPI) -> list:
except Exception as e:
logger.error(f"Unexpected error: {e}")
return f"Unexpected error: {e}"

@staticmethod
def get_indexer_status(inventory_path) -> None:
"""
Returns if Wazuh indexer is connected to Wazuh manager
Args:
inventory_path: host's inventory path
Returns:
str: Agents status
"""

indexerConnection = ConnectionManager.execute_commands(inventory_path, f'cat {WAZUH_LOG} | grep "IndexerConnector initialized successfully" | tail -n1').get('output')

return indexerConnection is not None and indexerConnection.strip()
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def test_installation(wazuh_params):
logger.info(f'Manager is already installed in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])}')
else:
HostConfiguration.disable_firewall(manager_params)
HostConfiguration.certs_create(wazuh_params['wazuh_version'], wazuh_params['master'], wazuh_params['dashboard'], wazuh_params['indexers'], wazuh_params['workers'])
WazuhManager.install_manager(wazuh_params['master'], 'wazuh-1', wazuh_params['wazuh_version'])
HostConfiguration.certs_create(wazuh_params['wazuh_version'], wazuh_params['master'], wazuh_params['dashboard'], wazuh_params['indexers'], wazuh_params['workers'], wazuh_params['live'])
WazuhManager.install_manager(wazuh_params['master'], 'wazuh-1', wazuh_params['wazuh_version'], wazuh_params['live'])
assert HostInformation.dir_exists(wazuh_params['master'], WAZUH_ROOT), logger.error(f'The {WAZUH_ROOT} is not present in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])}')

# Agent installation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_installation(wazuh_params):
HostConfiguration.disable_firewall(manager_params)

# Certs create and scp from master to worker
HostConfiguration.certs_create(wazuh_params['wazuh_version'], wazuh_params['master'], wazuh_params['dashboard'], wazuh_params['indexers'], wazuh_params['workers'])
HostConfiguration.certs_create(wazuh_params['wazuh_version'], wazuh_params['master'], wazuh_params['dashboard'], wazuh_params['indexers'], wazuh_params['workers'], wazuh_params['live'])

# Install central components and perform checkfile testing
for _, manager_params in wazuh_params['managers'].items():
Expand Down Expand Up @@ -164,3 +164,8 @@ def test_indexer_port(wazuh_params):

def test_filebeat_status(wazuh_params):
assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f"The Filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active")


def test_indexer_conexion(wazuh_params):
for indexer_params in wazuh_params['indexers']:
assert WazuhManager.get_indexer_status(indexer_params), logger.error(f'IndexerConnector initialization failed {HostInformation.get_os_name_and_version_from_inventory(indexer_params)}')
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_installation(wazuh_params):
HostConfiguration.disable_firewall(manager_params)

# Certs create and scp from master to worker
HostConfiguration.certs_create(wazuh_params['wazuh_version'], wazuh_params['master'], wazuh_params['dashboard'], wazuh_params['indexers'], wazuh_params['workers'])
HostConfiguration.certs_create(wazuh_params['wazuh_version'], wazuh_params['master'], wazuh_params['dashboard'], wazuh_params['indexers'], wazuh_params['workers'], wazuh_params['live'])

for workers in wazuh_params['workers']:
HostConfiguration.scp_to(wazuh_params['master'], workers, 'wazuh-install-files.tar')
Expand Down
Loading

0 comments on commit 1fba0b8

Please sign in to comment.