Skip to content

Commit

Permalink
Merge pull request #5691 from wazuh/merge-4.9.0-into-4.9.1
Browse files Browse the repository at this point in the history
Merge 4.9.0 into 4.9.1
  • Loading branch information
Rebits authored Aug 21, 2024
2 parents ce489f2 + 9330080 commit 090b0e8
Show file tree
Hide file tree
Showing 24 changed files with 553 additions and 37 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ All notable changes to this project will be documented in this file.

### Changed

- Increase Feed update timeout in waiters.py ([#5668](https://github.com/wazuh/wazuh-qa/pull/5668)) \- (Framework)
- Set `/active-response` as xfail ([#5660](https://github.com/wazuh/wazuh-qa/pull/5660)) \- (Tests)
- Modify the directory name for machines deployed in AWS ([#5635](https://github.com/wazuh/wazuh-qa/pull/5635)) \- (Framework)
- Add task information in the allocation logs when create or delete an instance ([#5623](https://github.com/wazuh/wazuh-qa/pull/5623)) \- (Framework)
- Changed _run_tests in testing.py ([#5621](https://github.com/wazuh/wazuh-qa/pull/5621)) \- (Framework)
- Deleted custom field from PUT /active-response performance test. ([#5612](https://github.com/wazuh/wazuh-qa/pull/5612)) \- (Tests)
- Update CentOS 7 Vagrant box ([#5546](https://github.com/wazuh/wazuh-qa/pull/5546)) \- (Framework)
- Update CentOS 7 AMIs ([#5545](https://github.com/wazuh/wazuh-qa/pull/5545)) \- (Framework)
- Update OpenSUSE 15 AMI ([#5536](https://github.com/wazuh/wazuh-qa/pull/5536)) \- (Framework)
Expand All @@ -28,6 +34,12 @@ All notable changes to this project will be documented in this file.

### Fixed

- Fixed unnecesary reference to debian file in dashboard provisioning task ([#5643](https://github.com/wazuh/wazuh-qa/pull/5643)) \- (Framework)
- Changed 'Ensure that the manager version is' expected warning to an agnostic version of regex ([#5630](https://github.com/wazuh/wazuh-qa/pull/5630)) \- (Tests)
- Adding fixed and dynamic waits to port status checks ([#5627](https://github.com/wazuh/wazuh-qa/pull/5627)) (Framework)
- Fixed custom storage for AMIs ([#5625](https://github.com/wazuh/wazuh-qa/pull/5625)) \- (Framework)
- Vulnerability regex changed to match with 4.9.0 solved vulnerability alerts ([#5624](https://github.com/wazuh/wazuh-qa/pull/5624)) \- (Tests)
- Fix cluster reliability test internal error ([#5620](https://github.com/wazuh/wazuh-qa/pull/5620)) \- (Tests)
- Fix CentOS 9 AMI in Allocator module ([#5523](https://github.com/wazuh/wazuh-qa/pull/5523)) \- (Framework)
- Fix stability in cluster reliability tests ([#5477](https://github.com/wazuh/wazuh-qa/pull/5477)) \- (Tests)
- Fix agent_simulator response for active-response configuration commands ([#4895](https://github.com/wazuh/wazuh-qa/pull/4895)) \- (Framework + Tests)
Expand All @@ -37,6 +49,8 @@ All notable changes to this project will be documented in this file.

- Remove configobj library from requirements.txt ([#4803](https://github.com/wazuh/wazuh-qa/pull/4803)) \- (Framework)

## [4.8.2] - 20/08/2024

## [4.8.1] - 18/07/2024

### Added
Expand Down
13 changes: 10 additions & 3 deletions deployability/modules/allocation/allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from .aws.provider import AWSProvider, AWSConfig
from .generic import Instance, Provider, models
from .generic.utils import logger
from .generic.utils import logger, logger_with_instance_name
from .vagrant.provider import VagrantProvider, VagrantConfig


Expand Down Expand Up @@ -58,6 +58,9 @@ def __create(cls, payload: models.CreationPayload):
config = cls.___get_custom_config(payload)
instance = provider.create_instance(
payload.working_dir, instance_params, config, payload.ssh_key)

global logger
logger = logger_with_instance_name(instance)
logger.info(f"Instance {instance.identifier} created.")
# Start the instance.
instance.start()
Expand All @@ -74,10 +77,10 @@ def __create(cls, payload: models.CreationPayload):
logger.warning(f"Rolling back instance creation.")
track_payload = {'track_output': track_file}
cls.__delete(track_payload)
logger.info(f"Instance {instance.identifier} deleted.")
else:
logger.warning(f'The VM will not be automatically removed. Please remove it executing Allocation module with --action delete.')
logger.info(f"Instance {instance.identifier} created successfully.")
else:
logger.info(f"Instance {instance.identifier} created successfully.")

@classmethod
def __delete(cls, payload: models.InstancePayload) -> None:
Expand All @@ -94,6 +97,9 @@ def __delete(cls, payload: models.InstancePayload) -> None:
track = models.TrackOutput(**yaml.safe_load(f))
provider = PROVIDERS[track.provider]()
provider.destroy_instance(models.InstancePayload(**dict(track)))

global logger
logger = logger_with_instance_name(track)
logger.info(f"Instance {track.identifier} deleted.")

@staticmethod
Expand Down Expand Up @@ -176,6 +182,7 @@ def __generate_track_file(instance: Instance, provider_name: str) -> None:
inventory = models.InventoryOutput(**yaml.safe_load(f))
port = inventory.ansible_port
track = models.TrackOutput(identifier=instance.identifier,
name=instance.name,
provider=provider_name,
instance_dir=str(instance.path),
key_path=str(instance.credentials.key_path),
Expand Down
16 changes: 11 additions & 5 deletions deployability/modules/allocation/aws/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import subprocess

from modules.allocation.generic import Provider
from modules.allocation.generic.models import CreationPayload, InstancePayload, InstancePayload
from modules.allocation.generic.models import CreationPayload, InstancePayload
from modules.allocation.generic.utils import logger
from .credentials import AWSCredentials
from .instance import AWSInstance
Expand Down Expand Up @@ -118,7 +118,10 @@ def _create_instance(cls, base_dir: Path, params: CreationPayload, config: AWSCo
# Generate the instance.
instance_id = cls.__create_ec2_instance(config)
# Rename the temp directory to its real name.
instance_dir = Path(base_dir, instance_id)
while True:
instance_dir = Path(base_dir, f"{name}-{str(random.randint(0000, 9999))}")
if not instance_dir.exists():
break
logger.debug(f"Renaming temp {temp_dir} directory to {instance_dir}")
os.rename(temp_dir, instance_dir)
if platform != "windows":
Expand All @@ -129,6 +132,7 @@ def _create_instance(cls, base_dir: Path, params: CreationPayload, config: AWSCo

instance_params = {}
instance_params['instance_dir'] = instance_dir
instance_params['name'] = config.name
instance_params['identifier'] = instance_id
instance_params['platform'] = platform
instance_params['host_identifier'] = host_identifier
Expand Down Expand Up @@ -198,12 +202,15 @@ def __create_ec2_instance(config: AWSConfig) -> str:
# Describe the AMI to get the root device name
ami = client.describe_images(ImageIds=[config.ami])
root_device_name = ami['Images'][0]['RootDeviceName']
ami_storage = ami['Images'][0]['BlockDeviceMappings'][0]['Ebs']['VolumeSize']

if ami_storage > config.storage:
config.storage = ami_storage

if config.platform == 'windows':
with open(windosUserData_file, 'r') as file:
userData = file.read()
userData = userData.replace('ChangeMe', config.key_name)
config.storage = 60
else:
with open(userData_file, 'r') as file:
userData = file.read()
Expand Down Expand Up @@ -278,12 +285,11 @@ def __parse_config(cls, params: CreationPayload, credentials: AWSCredentials, is
# Parse the configuration.
if platform == 'macos':
os_specs['zone'] = os_specs['zone'] + 'c'
config['storage'] = 0
if arch == 'arm64':
config['type'] = 'mac2.metal'
config['storage'] = 100
if arch == 'amd64':
config['type'] = 'mac1.metal'
config['storage'] = 100
else:
for spec in size_specs:
if fnmatch.fnmatch(arch, spec):
Expand Down
2 changes: 1 addition & 1 deletion deployability/modules/allocation/generic/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from abc import ABC, abstractmethod
from pathlib import Path
from .utils import logger

from .credentials import Credentials
from .models import ConnectionInfo, InstancePayload
Expand Down Expand Up @@ -43,6 +42,7 @@ def __init__(self, instance_parameters: InstancePayload, credentials: Credential

self.path: Path = path
self.identifier: str = str(instance_parameters.identifier)
self.name: str = instance_parameters.name
self.credentials: Credentials = credentials
self.host_identifier: str = instance_parameters.host_identifier
self.host_instance_dir: Path = instance_parameters.host_instance_dir
Expand Down
2 changes: 2 additions & 0 deletions deployability/modules/allocation/generic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class InventoryOutput(BaseModel):

class TrackOutput(BaseModel):
identifier: str
name: str
provider: str
instance_dir: str
key_path: str
Expand Down Expand Up @@ -116,6 +117,7 @@ class TrackPayload(BaseModel):

class InstancePayload(BaseModel):
identifier: str
name: str | None = None
instance_dir: str | Path
key_path: Path | None = None
host_identifier: str | None = None
Expand Down
21 changes: 21 additions & 0 deletions deployability/modules/allocation/generic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@
# Created by Wazuh, Inc. <[email protected]>.
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import logging
from modules.allocation.generic.instance import Instance
from modules.allocation.generic.models import TrackOutput
from modules.generic.logger import Logger

# Default logger
logger = Logger("allocator").get_logger()


def logger_with_instance_name(instance_info: Instance | TrackOutput) -> logging.Logger:
"""
Returns a logger with the instance name if it is different from the identifier,
otherwise returns the default logger without the name.
Args:
instance (Instance): The instance object.
Returns:
logging.Logger: The logger object.
"""

if instance_info.name != instance_info.identifier:
return Logger(f"allocator [{instance_info.name}]").get_logger()
return logger
1 change: 1 addition & 0 deletions deployability/modules/allocation/vagrant/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def _create_instance(cls, base_dir: Path, params: CreationPayload, config: Vagra
instance_params = {}
instance_params['instance_dir'] = instance_dir
instance_params['identifier'] = instance_id
instance_params['name'] = config.name
instance_params['platform'] = platform
instance_params['host_identifier'] = host_identifier
instance_params['host_instance_dir'] = host_instance_dir
Expand Down
Loading

0 comments on commit 090b0e8

Please sign in to comment.