diff --git a/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/docker_wrapper.py b/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/docker_wrapper.py index 8191062122..437a335175 100644 --- a/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/docker_wrapper.py +++ b/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/docker_wrapper.py @@ -74,14 +74,15 @@ def get_container(self): return self.docker_client.containers.get(self.name) def run(self): - DockerWrapper.LOGGER.debug(f"Running {self.name} cointainer...") + DockerWrapper.LOGGER.debug(f"Starting {self.name} cointainer") container = self.docker_client.containers.run(image=self.image, name=self.name, ports=self.ports, remove=self.remove, detach=self.detach, stdout=self.stdout, stderr=self.stderr) + DockerWrapper.LOGGER.debug(f"The container {self.name} is running") if self.ip and self.network_name: try: self.docker_client.networks.get(self.network_name).connect(container, ipv4_address=self.ip) - except docker.errors.APIError: #requests.exceptions.HTTPError: + except docker.errors.APIError: exception_message = f"Invalid address {self.ip} It does not belong to any of this network's " \ 'subnets. Please check if you have already set this docker network ' \ '(run `docker network ls`) and then remove it if it is created with ' \ @@ -95,8 +96,9 @@ def restart(self): docker.errors.APIError: If the server returns an error. """ try: - DockerWrapper.LOGGER.debug(f"Restarting {self.name} cointainer...") + DockerWrapper.LOGGER.debug(f"Restarting {self.name} cointainer") self.get_container().restart() + DockerWrapper.LOGGER.debug(f"The {self.name} cointainer has been restarted sucessfully") except docker.errors.NotFound: pass @@ -107,8 +109,9 @@ def halt(self): docker.errors.APIError: If the server returns an error. """ try: - DockerWrapper.LOGGER.debug(f"Stopping {self.name} cointainer...") + DockerWrapper.LOGGER.debug(f"Stopping {self.name} cointainer") self.get_container().stop() + DockerWrapper.LOGGER.debug(f"The {self.name} cointainer has been stopped sucessfully") except docker.errors.NotFound: pass @@ -127,14 +130,16 @@ def destroy(self, remove_image=False): pass try: - DockerWrapper.LOGGER.debug(f"Removing {self.name} cointainer...") + DockerWrapper.LOGGER.debug(f"Removing {self.name} cointainer") self.get_container().remove() + DockerWrapper.LOGGER.debug(f"The {self.name} cointainer has been removed sucessfully") except docker.errors.NotFound: pass if remove_image: - DockerWrapper.LOGGER.debug(f"Removing {self.image.id} docker image...") + DockerWrapper.LOGGER.debug(f"Removing {self.image.id} docker image") self.docker_client.images.remove(image=self.image.id, force=True) + DockerWrapper.LOGGER.debug(f"The {self.image.id} image has been removed sucessfully") def get_instance_info(self): """Get the parameters information. diff --git a/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/qa_infraestructure.py b/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/qa_infraestructure.py index f803933863..4c89a3f3fc 100644 --- a/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/qa_infraestructure.py +++ b/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/qa_infraestructure.py @@ -41,7 +41,7 @@ def __init__(self, instance_list, qa_ctl_configuration): self.docker_network = None self.network_address = None - QAInfraestructure.LOGGER.debug('Processing deployment configuration...') + QAInfraestructure.LOGGER.debug('Processing deployment configuration') for host in instance_list: for provider in instance_list[host]['provider']: data = instance_list[host]['provider'][provider] @@ -49,15 +49,16 @@ def __init__(self, instance_list, qa_ctl_configuration): continue if provider == 'vagrant': - QAInfraestructure.LOGGER.debug(f"Setting {data['vm_name']} vagrant instance for deployment...") + QAInfraestructure.LOGGER.debug(f"Setting {data['vm_name']} vagrant instance for deployment") quiet_out = True if not self.qa_ctl_configuration.vagrant_output else False vagrant_instance = VagrantWrapper(data['vagrantfile_path'], data['vagrant_box'], data['label'], data['vm_name'], data['vm_cpu'], data['vm_memory'], data['vm_system'], data['vm_ip'], quiet_out) self.instances.append(vagrant_instance) + QAInfraestructure.LOGGER.debug(f"{data['vm_name']} vagrant instance has been set successfully") elif provider == 'docker': - QAInfraestructure.LOGGER.debug(f"Setting {data['name']} docker instance for deployment...") + QAInfraestructure.LOGGER.debug(f"Setting {data['name']} docker instance for deployment") if not self.docker_client: self.docker_client = docker.from_env() @@ -85,7 +86,7 @@ def __init__(self, instance_list, qa_ctl_configuration): self.docker_network = self.docker_client.networks.get(self.DOCKER_NETWORK_NAME) except docker.errors.NotFound: QAInfraestructure.LOGGER.debug(f"Docker network {self.network_address} not found." - 'Creating it...') + 'Creating it') ipam_pool = docker.types.IPAMPool(subnet=str(self.network_address), gateway=str(self.network_address[-2])) @@ -93,11 +94,15 @@ def __init__(self, instance_list, qa_ctl_configuration): self.docker_network = self.docker_client.networks.create(self.DOCKER_NETWORK_NAME, driver='bridge', ipam=ipam_config) - + QAInfraestructure.LOGGER.debug(f"Docker network {self.network_address} has been " + 'created successfully') docker_instance = DockerWrapper(self.docker_client, data['dockerfile_path'], data['name'], _remove, _ports, _detach, _stdout, _stderr, ip=_ip, network_name=self.DOCKER_NETWORK_NAME) self.instances.append(docker_instance) + QAInfraestructure.LOGGER.debug(f"{data['vm_name']} docker container has been set successfully") + + QAInfraestructure.LOGGER.debug('Deployment configuration processing has been finished successfully') def __threads_runner(self, threads): """Auxiliary function to start and wait for threads @@ -113,28 +118,32 @@ def __threads_runner(self, threads): def run(self): """Execute the run method on every configured instance.""" - QAInfraestructure.LOGGER.info(f"Running {len(self.instances)} instances deployment...") + 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') def halt(self): """Execute the 'halt' method on every configured instance.""" - QAInfraestructure.LOGGER.info(f"Stopping {len(self.instances)} instances...") + QAInfraestructure.LOGGER.info(f"Stopping {len(self.instances)} instances") self.__threads_runner([ThreadExecutor(instance.halt) for instance in self.instances]) + QAInfraestructure.LOGGER.info('The instances have been stopped sucessfully') def restart(self): """Execute the 'restart' method on every configured instance.""" - QAInfraestructure.LOGGER.info(f"Restarting {len(self.instances)} instances...") + QAInfraestructure.LOGGER.info(f"Restarting {len(self.instances)} instances") self.__threads_runner([ThreadExecutor(instance.restart) for instance in self.instances]) def destroy(self): """Execute the 'destroy' method on every configured instance.""" - QAInfraestructure.LOGGER.info(f"Destroying {len(self.instances)} instances...") + QAInfraestructure.LOGGER.info(f"Destroying {len(self.instances)} instances") self.__threads_runner([ThreadExecutor(instance.destroy) for instance in self.instances]) + QAInfraestructure.LOGGER.info(f"The instances have been destroyed sucessfully") if self.docker_network: - QAInfraestructure.LOGGER.debug('Removing docker network...') + QAInfraestructure.LOGGER.info('Removing docker network') try: self.docker_network.remove() + QAInfraestructure.LOGGER.info('Docker network has been removed sucessfully') except docker.errors.NotFound: QAInfraestructure.LOGGER.error('Could not remove docker network') pass @@ -146,9 +155,10 @@ def status(self): (dict): Contains the status for each configured instance. """ status = {} - QAInfraestructure.LOGGER.debug('Getting instances status...') + QAInfraestructure.LOGGER.debug('Getting instances status') for instance in self.instances: status[instance.get_name()] = instance.status() + QAInfraestructure.LOGGER.debug('Instances status info was obtained sucessfully') return status @@ -159,8 +169,9 @@ def get_instances_info(self): (dict): Dictionary with the information for each configured instance. """ info = {} - QAInfraestructure.LOGGER.debug('Getting instances info...') + QAInfraestructure.LOGGER.debug('Getting instances info') for instance in self.instances: info[instance.get_name()] = instance.get_instance_info() + QAInfraestructure.LOGGER.debug('Instances info was obtained sucessfully') return info diff --git a/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/vagrant_wrapper.py b/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/vagrant_wrapper.py index f731576a6a..50de3a9395 100644 --- a/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/vagrant_wrapper.py +++ b/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/vagrant_wrapper.py @@ -48,23 +48,27 @@ def __init__(self, vagrant_root_folder, vm_box, vm_label, vm_name, vm_cpus, vm_m def run(self): """Write the vagrantfile and starts the VM specified in the vagrantfile.""" - VagrantWrapper.LOGGER.debug(f"Running {self.vm_name} vagrant up...") + VagrantWrapper.LOGGER.debug(f"Running {self.vm_name} vagrant up") self.vagrant.up() + VagrantWrapper.LOGGER.debug(f"Instance {self.vm_name} has been created sucessfully") def halt(self): """Stop the VM specified in the vagrantfile.""" - VagrantWrapper.LOGGER.debug(f"Running {self.vm_name} vagrant halt...") + VagrantWrapper.LOGGER.debug(f"Running {self.vm_name} vagrant halt") self.vagrant.halt() + VagrantWrapper.LOGGER.debug(f"Instance {self.vm_name} has been off sucessfully") def restart(self): """Restart the VM specified in the vagrantfile.""" - VagrantWrapper.LOGGER.debug(f"Running {self.vm_name} vagrant restrt...") + VagrantWrapper.LOGGER.debug(f"Running {self.vm_name} vagrant restart") self.vagrant.restart() + VagrantWrapper.LOGGER.debug(f"Instance {self.vm_name} has been restarted sucessfully") def destroy(self): """Destroy the VM specified in the vagrantfile and remove the vagrantfile.""" - VagrantWrapper.LOGGER.debug(f"Running {self.vm_name} vagrant destroy...") + VagrantWrapper.LOGGER.debug(f"Running {self.vm_name} vagrant destroy") self.vagrant.destroy() + VagrantWrapper.LOGGER.debug(f"{self.vm_name} instance has been destroyed sucessfully") self.vagrantfile.remove_vagrantfile() rmtree(self.box_folder) diff --git a/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/vagrantfile.py b/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/vagrantfile.py index f41fbf4379..c08ff5c493 100644 --- a/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/vagrantfile.py +++ b/deps/wazuh_testing/wazuh_testing/qa_ctl/deployment/vagrantfile.py @@ -64,7 +64,7 @@ def __get_box_url(self): try: return box_mapping[self.box_image] except KeyError: - Vagrantfile.LOGGER.warning('Using a non default box...') + Vagrantfile.LOGGER.warning('Using a non default box') return None def __str__(self): diff --git a/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/ansible/ansible_playbook.py b/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/ansible/ansible_playbook.py index 349cfbf007..705921c374 100644 --- a/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/ansible/ansible_playbook.py +++ b/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/ansible/ansible_playbook.py @@ -73,5 +73,5 @@ def write_playbook_to_file(self): def delete_playbook_file(self): if os.path.exists(self.playbook_file_path): - AnsiblePlaybook.LOGGER.debug(f"Removing {self.playbook_file_path} playbook") os.remove(self.playbook_file_path) + AnsiblePlaybook.LOGGER.debug(f"{self.playbook_file_path} playbook file was deleted") diff --git a/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/qa_framework/qa_framework.py b/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/qa_framework/qa_framework.py index e407bb22e7..fe4f269456 100644 --- a/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/qa_framework/qa_framework.py +++ b/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/qa_framework/qa_framework.py @@ -41,10 +41,12 @@ def install_dependencies(self, inventory_file_path, hosts='all'): 'args': {'chdir': self.workdir}}) ansible_tasks = [dependencies_task] playbook_parameters = {'hosts': hosts, 'tasks_list': ansible_tasks} - QAFramework.LOGGER.debug(f"Installing python dependencies in {hosts} hosts.") + QAFramework.LOGGER.debug(f"Installing python dependencies in {hosts} hosts") AnsibleRunner.run_ephemeral_tasks(inventory_file_path, playbook_parameters, output=self.qa_ctl_configuration.ansible_output) + QAFramework.LOGGER.debug(f"Python dependencies have been installed successfully in {hosts} hosts") + def install_framework(self, inventory_file_path, hosts='all'): """Install the wazuh_testing framework to allow the execution of the tests. @@ -61,6 +63,7 @@ def install_framework(self, inventory_file_path, hosts='all'): AnsibleRunner.run_ephemeral_tasks(inventory_file_path, playbook_parameters, output=self.qa_ctl_configuration.ansible_output) + QAFramework.LOGGER.debug(f"wazuh-qa framework has been installed successfully in {hosts} hosts.") def download_qa_repository(self, inventory_file_path, hosts='all'): """Download the qa-framework in the specified attribute workdir. @@ -80,3 +83,5 @@ def download_qa_repository(self, inventory_file_path, hosts='all'): AnsibleRunner.run_ephemeral_tasks(inventory_file_path, playbook_parameters, output=self.qa_ctl_configuration.ansible_output) + QAFramework.LOGGER.debug(f"{self.qa_branch} branch of QA repository has been downloaded successfully in " + f"{hosts} hosts") diff --git a/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/qa_provisioning.py b/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/qa_provisioning.py index d4437d1e71..35b1f72e00 100644 --- a/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/qa_provisioning.py +++ b/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/qa_provisioning.py @@ -66,7 +66,7 @@ def __read_ansible_instance(self, host_info): def __process_inventory_data(self): """Process config file info to generate the ansible inventory file.""" - QAProvisioning.LOGGER.debug('Processing inventory data from provisioning hosts info...') + QAProvisioning.LOGGER.debug('Processing inventory data from provisioning hosts info') for root_key, root_value in self.provision_info.items(): if root_key == "hosts": @@ -82,7 +82,7 @@ def __process_inventory_data(self): inventory_instance = AnsibleInventory(ansible_instances=self.instances_list, ansible_groups=self.group_dict) self.inventory_file_path = inventory_instance.inventory_file_path - + QAProvisioning.LOGGER.debug('The inventory data from provisioning hosts info has been processed successfully') def __process_config_data(self, host_provision_info): """Process config file info to generate all the tasks needed for deploy Wazuh @@ -90,7 +90,6 @@ def __process_config_data(self, host_provision_info): Args: host_provision_info (dict): Dicionary with host provisioning info """ - QAProvisioning.LOGGER.debug('Processing provisioning data from hosts..') current_host = host_provision_info['host_info']['host'] if 'wazuh_deployment' in host_provision_info: @@ -119,28 +118,29 @@ def __process_config_data(self, host_provision_info): installation_files_parameters['qa_ctl_configuration'] = self.qa_ctl_configuration - if install_type == "sources": + if install_type == 'sources': installation_files_parameters['wazuh_branch'] = wazuh_branch installation_instance = WazuhSources(**installation_files_parameters) - if install_type == "package": + 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) + 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) + remote_files_path = installation_instance.download_installation_files(s3_package_url, + self.inventory_file_path, + hosts=current_host) - if install_target == "agent": + if install_target == 'agent': deployment_instance = AgentDeployment(remote_files_path, inventory_file_path=self.inventory_file_path, install_mode=install_type, hosts=current_host, server_ip=manager_ip, qa_ctl_configuration=self.qa_ctl_configuration) - if install_target == "manager": + if install_target == 'manager': deployment_instance = ManagerDeployment(remote_files_path, inventory_file_path=self.inventory_file_path, install_mode=install_type, hosts=current_host, @@ -149,7 +149,10 @@ def __process_config_data(self, host_provision_info): if health_check: # Wait for Wazuh initialization before health_check - sleep(60) + health_check_sleep_time = 60 + QAProvisioning.LOGGER.info(f"Waiting {health_check_sleep_time} seconds before performing the " + f"healthcheck in {current_host} host") + sleep(health_check_sleep_time) deployment_instance.health_check() self.wazuh_installation_paths[deployment_instance.hosts] = deployment_instance.install_dir_path @@ -170,7 +173,7 @@ def __check_hosts_connection(self, hosts='all'): Args: hosts (str): Hosts to check. """ - QAProvisioning.LOGGER.info('Checking hosts SSH connection...') + QAProvisioning.LOGGER.info('Checking hosts SSH connection') wait_for_connection = AnsibleTask({'name': 'Waiting for SSH hosts connection are reachable', 'wait_for_connection': {'delay': 5, 'timeout': 60}}) @@ -178,13 +181,14 @@ def __check_hosts_connection(self, hosts='all'): AnsibleRunner.run_ephemeral_tasks(self.inventory_file_path, playbook_parameters, output=self.qa_ctl_configuration.ansible_output) + QAProvisioning.LOGGER.info('Hosts connection OK. The instances are accessible via ssh') 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()] - QAProvisioning.LOGGER.info(f"Provisioning {len(provision_threads)} instances...") + QAProvisioning.LOGGER.info(f"Provisioning {len(provision_threads)} instances") for runner_thread in provision_threads: runner_thread.start() @@ -192,6 +196,8 @@ def run(self): for runner_thread in provision_threads: runner_thread.join() + QAProvisioning.LOGGER.info(f"The instances have been provisioned sucessfully") + def destroy(self): if os.path.exists(self.inventory_file_path): os.remove(self.inventory_file_path) \ No newline at end of file diff --git a/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_deployment.py b/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_deployment.py index 1ba3bfc4a6..39b135c077 100644 --- a/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_deployment.py +++ b/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_deployment.py @@ -55,7 +55,7 @@ def install(self, install_type): Returns: AnsibleOutput: Result of the ansible playbook run. """ - WazuhDeployment.LOGGER.debug(f"Installing wazuh {install_type} via {self.install_mode} in {self.hosts} hosts..") + WazuhDeployment.LOGGER.debug(f"Installing wazuh {install_type} via {self.install_mode} in {self.hosts} hosts") tasks_list = [] parent_path = Path(__file__).parent if self.install_mode == 'sources': @@ -113,8 +113,11 @@ def install(self, install_type): playbook_parameters = {'tasks_list': tasks_list, 'hosts': self.hosts, 'gather_facts': True, 'become': True} - return AnsibleRunner.run_ephemeral_tasks(self.inventory_file_path, playbook_parameters, - output=self.qa_ctl_configuration.ansible_output) + tasks_result = AnsibleRunner.run_ephemeral_tasks(self.inventory_file_path, playbook_parameters, + output=self.qa_ctl_configuration.ansible_output) + WazuhDeployment.LOGGER.debug(f"Wazuh installation has been successfully done in {self.hosts} hosts") + + return tasks_result def __control_service(self, command, install_type): """Private method to control the Wazuh service in different systems. @@ -149,8 +152,11 @@ def __control_service(self, command, install_type): playbook_parameters = {'tasks_list': tasks_list, 'hosts': self.hosts, 'gather_facts': True, 'become': True} - return AnsibleRunner.run_ephemeral_tasks(self.inventory_file_path, playbook_parameters, - output=self.qa_ctl_configuration.ansible_output) + tasks_result = AnsibleRunner.run_ephemeral_tasks(self.inventory_file_path, playbook_parameters, + output=self.qa_ctl_configuration.ansible_output) + WazuhDeployment.LOGGER.debug(f"Wazuh service was {command}ed in {self.hosts} hosts") + + return tasks_result @abstractmethod def start_service(self, install_type): @@ -186,7 +192,7 @@ def health_check(self): Returns: AnsibleOutput: Result of the ansible playbook run. """ - WazuhDeployment.LOGGER.debug(f"Doing wazuh deployment healthcheck in {self.hosts} hosts") + WazuhDeployment.LOGGER.debug(f"Starting wazuh deployment healthcheck in {self.hosts} hosts") tasks_list = [] tasks_list.append(AnsibleTask({'name': 'Read ossec.log searching errors', 'lineinfile': {'path': f'{self.install_dir_path}/logs/ossec.log', @@ -206,8 +212,11 @@ def health_check(self): playbook_parameters = {'tasks_list': tasks_list, 'hosts': self.hosts, 'gather_facts': True, 'become': True} - return AnsibleRunner.run_ephemeral_tasks(self.inventory_file_path, playbook_parameters, + tasks_result = AnsibleRunner.run_ephemeral_tasks(self.inventory_file_path, playbook_parameters, output=self.qa_ctl_configuration.ansible_output) + WazuhDeployment.LOGGER.debug(f"Wazuh deployment healthcheck OK in {self.hosts} hosts") + + return tasks_result def wazuh_is_already_installed(self): """Check if Wazuh is installed in the system diff --git a/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_local_package.py b/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_local_package.py index 01ad22a5c8..f86c27176c 100644 --- a/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_local_package.py +++ b/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_local_package.py @@ -19,12 +19,15 @@ def __init__(self, wazuh_target, installation_files_path, local_package_path, qa system=system, qa_ctl_configuration=qa_ctl_configuration) def download_installation_files(self, inventory_file_path, hosts='all'): + WazuhLocalPackage.LOGGER.debug(f"Copying local package {self.local_package_path} to " + f"{self.installation_files_path} in {hosts} hosts") + copy_ansible_task = AnsibleTask({'name': f"Copy {self.local_package_path} package to \ {self.installation_files_path}", 'copy': {'src': self.local_package_path, 'dest': self.installation_files_path}}) - WazuhLocalPackage.LOGGER.debug(f"Copying local package {self.local_package_path} to " - f"{self.installation_files_path} in {hosts} hosts") + WazuhLocalPackage.LOGGER.debug(f"{self.local_package_path} has been successfully copied in {hosts} hosts") + super().download_installation_files(inventory_file_path, [copy_ansible_task], hosts) return os.path.join(self.installation_files_path, self.package_name) diff --git a/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_s3_package.py b/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_s3_package.py index b588b2dff9..41ee111483 100644 --- a/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_s3_package.py +++ b/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_s3_package.py @@ -29,12 +29,15 @@ def get_s3_package_url(self): pass def download_installation_files(self, s3_package_url, inventory_file_path, hosts='all'): + WazuhS3Package.LOGGER.debug(f"Downloading Wazuh S3 package from in {hosts} hosts") + download_s3_package = AnsibleTask({'name': 'Download S3 package', 'get_url': {'url': s3_package_url, 'dest': self.installation_files_path}, 'register': 'download_state', 'retries': 6, 'delay': 10, 'until': 'download_state is success'}) - WazuhS3Package.LOGGER.debug(f"Downloading Wazuh S3 package from in {hosts} hosts") + WazuhS3Package.LOGGER.debug(f"Wazuh S3 package was successfully downloaded in {hosts} hosts") + super().download_installation_files(inventory_file_path, [download_s3_package], hosts) return os.path.join(self.installation_files_path, self.package_name) diff --git a/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_sources.py b/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_sources.py index 531cdc8b0c..b63a24bc7f 100644 --- a/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_sources.py +++ b/deps/wazuh_testing/wazuh_testing/qa_ctl/provisioning/wazuh_deployment/wazuh_sources.py @@ -14,11 +14,14 @@ def __init__(self, wazuh_target, installation_files_path, qa_ctl_configuration, installation_files_path=f"{installation_files_path}/wazuh-{self.wazuh_branch}") def download_installation_files(self, inventory_file_path, hosts='all'): + WazuhSources.LOGGER.debug(f"Downloading Wazuh sources from {self.wazuh_branch} branch in {hosts} hosts") + download_wazuh_sources_task = AnsibleTask({'name': f"Download Wazuh branch in {self.installation_files_path}", 'shell': f"cd {self.installation_files_path} && " + 'curl -Ls https://github.com/wazuh/wazuh/archive/' + f"{self.wazuh_branch}.tar.gz | tar zx && mv wazuh-*/* ."}) - WazuhSources.LOGGER.debug(f"Downloading Wazuh sources from {self.wazuh_branch} branch in {hosts} hosts") + WazuhSources.LOGGER.debug(f"Wazuh sources from {self.wazuh_branch} branch were successfully downloaded in " + f"{hosts} hosts") super().download_installation_files(inventory_file_path, [download_wazuh_sources_task], hosts) return self.installation_files_path diff --git a/deps/wazuh_testing/wazuh_testing/qa_ctl/run_tests/pytest.py b/deps/wazuh_testing/wazuh_testing/qa_ctl/run_tests/pytest.py index 9b41226849..e6f2097a7b 100644 --- a/deps/wazuh_testing/wazuh_testing/qa_ctl/run_tests/pytest.py +++ b/deps/wazuh_testing/wazuh_testing/qa_ctl/run_tests/pytest.py @@ -178,13 +178,20 @@ def run(self, ansible_inventory_path): playbook_parameters = {'become': True, 'tasks_list': ansible_tasks, 'playbook_file_path': playbook_file_path, "hosts": self.hosts} - Pytest.LOGGER.debug(f"Running {pytest_command} on {self.hosts} hosts...") - Pytest.LOGGER.info(f"Running {self.tests_path} test on {self.hosts} hosts...") + Pytest.LOGGER.info(f"Running {self.tests_path} test on {self.hosts} hosts") + Pytest.LOGGER.debug(f"Running {pytest_command} on {self.hosts} hosts") AnsibleRunner.run_ephemeral_tasks(ansible_inventory_path, playbook_parameters, raise_on_error=False, output=self.qa_ctl_configuration.ansible_output) - Pytest.LOGGER.debug(f"Saving {self.tests_path} test resulsts of {self.hosts} hosts in {self.tests_result_path}") - self.result = TestResult(html_report_file_path=os.path.join(self.tests_result_path, html_report_file_name), - plain_report_file_path=os.path.join(self.tests_result_path, plain_report_file_name)) + plain_report_file_path=os.path.join(self.tests_result_path, plain_report_file_name), + test_name=self.tests_path) + + Pytest.LOGGER.debug(f"{self.tests_path} tests of {self.hosts} hosts were saved in {self.tests_result_path}") + + # Print test result in stdout + if self.qa_ctl_configuration.logging_enable: + Pytest.LOGGER.info(self.result) + else: + print(self.result) diff --git a/deps/wazuh_testing/wazuh_testing/qa_ctl/run_tests/qa_test_runner.py b/deps/wazuh_testing/wazuh_testing/qa_ctl/run_tests/qa_test_runner.py index ed727a1014..5223e18013 100644 --- a/deps/wazuh_testing/wazuh_testing/qa_ctl/run_tests/qa_test_runner.py +++ b/deps/wazuh_testing/wazuh_testing/qa_ctl/run_tests/qa_test_runner.py @@ -57,7 +57,7 @@ def __process_inventory_data(self, instances_info): Args: instances_info (dict): Dictionary with hosts configuration. """ - QATestRunner.LOGGER.debug('Processing inventory data from testing hosts info...') + QATestRunner.LOGGER.debug('Processing inventory data from testing hosts info') instances_list = [] for _, host_value in instances_info.items(): @@ -69,6 +69,7 @@ def __process_inventory_data(self, instances_info): inventory_instance = AnsibleInventory(ansible_instances=instances_list) self.inventory_file_path = inventory_instance.inventory_file_path + QATestRunner.LOGGER.debug('Inventory data from testing hosts info was processed successfully') def __process_test_data(self, instances_info): @@ -77,7 +78,7 @@ def __process_test_data(self, instances_info): Args: instances_info (dict): Dictionary with hosts configuration. """ - QATestRunner.LOGGER.debug('Processing testing data from hosts..') + QATestRunner.LOGGER.debug('Processing testing data from hosts') for _, host_value in instances_info.items(): test_launcher = TestLauncher([], self.inventory_file_path, self.qa_ctl_configuration) @@ -86,7 +87,7 @@ def __process_test_data(self, instances_info): if module_key == 'test': test_launcher.add(self.__build_test(module_value, hosts)) self.test_launchers.append(test_launcher) - + QATestRunner.LOGGER.debug('Testing data from hosts info was processed successfully') def __build_test(self, test_params, host=['all']): """Private method in charge of reading all the required fields to build one test of type Pytest @@ -132,17 +133,17 @@ def run(self): """Run testing threads. One thread per TestLauncher object""" runner_threads = [ThreadExecutor(test_launcher.run) for test_launcher in self.test_launchers] - QATestRunner.LOGGER.info(f"Launching {len(runner_threads)} tests...") + QATestRunner.LOGGER.info(f"Launching {len(runner_threads)} tests") for runner_thread in runner_threads: runner_thread.start() - QATestRunner.LOGGER.info(f'Waiting until tests finish...') + QATestRunner.LOGGER.info('Waiting for tests to finish') for runner_thread in runner_threads: runner_thread.join() - QATestRunner.LOGGER.info(f'Tests have been finished...') + QATestRunner.LOGGER.info('The test run is finished') def destroy(self): if os.path.exists(self.inventory_file_path): diff --git a/deps/wazuh_testing/wazuh_testing/qa_ctl/run_tests/test_result.py b/deps/wazuh_testing/wazuh_testing/qa_ctl/run_tests/test_result.py index 5fd559548f..6abb623be1 100644 --- a/deps/wazuh_testing/wazuh_testing/qa_ctl/run_tests/test_result.py +++ b/deps/wazuh_testing/wazuh_testing/qa_ctl/run_tests/test_result.py @@ -12,11 +12,22 @@ class TestResult: custom_report_file_path (str, None): Local file path pointing to the custom report """ - def __init__(self, html_report_file_path=None, plain_report_file_path=None, - custom_report_file_path=None): + def __init__(self, html_report_file_path=None, plain_report_file_path=None, custom_report_file_path=None, + test_name=None): self.html_report_file_path = html_report_file_path self.plain_report_file_path = plain_report_file_path self.custom_report_file_path = custom_report_file_path + self.test_name = test_name + + def __str__(self): + result = '\n' * 2 + + with open(self.plain_report_file_path) as plain_report_file: + result += plain_report_file.read() + + result += '\n' * 2 + + return result def generate_custom_report(self): pass diff --git a/deps/wazuh_testing/wazuh_testing/tools/logging.py b/deps/wazuh_testing/wazuh_testing/tools/logging.py index f49dd97234..5aae14b26f 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/logging.py +++ b/deps/wazuh_testing/wazuh_testing/tools/logging.py @@ -45,7 +45,10 @@ def __initialize_parameters(self): def __default_config(self): """Set default handler configuration""" - formatter = logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(module)s - %(message)s') + if self.level == logging.DEBUG: + formatter = logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(module)s - %(message)s') + else: + formatter = logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(message)s') self.logger.setLevel(self.level) if self.stdout: