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

Fix in remote_operations_handler.py functions #5155

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ All notable changes to this project will be documented in this file.

### Fixed

- Fix remote_operations_handler functions to Vulnerability Detector E2E tests ([#5155](https://github.com/wazuh/wazuh-qa/pull/5155)) \- (Framework)
- Fix test_shutdown_message system test ([#5087](https://github.com/wazuh/wazuh-qa/pull/5087)) \- (Tests)
- Include timeout to test_authd system tests ([#5083](https://github.com/wazuh/wazuh-qa/pull/5083)) \- (Tests)
- Fix Vulnerability Detection mismatch in scans ([#5053](https://github.com/wazuh/wazuh-qa/pull/5053)) \- (Tests)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,37 +164,43 @@ def install_package(host: str, operation_data: Dict[str, Dict], host_manager: Ho
package_id = None

if host_os_name in install_package_data:
if host_os_arch in install_package_data[host_os_name]:
package_id = install_package_data[host_os_name][host_os_arch]
else:
raise ValueError(f"Package for {host_os_name} and {host_os_arch} not found")
try:
if host_os_arch in install_package_data[host_os_name]:
package_id = install_package_data[host_os_name][host_os_arch]

package_data = load_packages_metadata()[package_id]
package_url = package_data['urls'][host_os_name][host_os_arch]

package_data = load_packages_metadata()[package_id]
package_url = package_data['urls'][host_os_name][host_os_arch]
logging.info(f"Installing package on {host}")
logging.info(f"Package URL: {package_url}")

logging.info(f"Installing package on {host}")
logging.info(f"Package URL: {package_url}")
current_datetime = datetime.utcnow().isoformat()

current_datetime = datetime.utcnow().isoformat()
host_manager.install_package(host, package_url, system)

host_manager.install_package(host, package_url, system)
logging.info(f"Package {package_url} installed on {host}")

logging.info(f"Package {package_url} installed on {host}")
logging.info(f"Package installed on {host}")

logging.info(f"Package installed on {host}")
results['checks']['all_successfull'] = True

results['checks']['all_successfull'] = True
wait_is_required = 'check' in operation_data and (operation_data['check']['alerts'] or
operation_data['check']['state_index'] or
operation_data['check']['no_alerts'] or
operation_data['check']['no_indices'])

wait_is_required = 'check' in operation_data and (operation_data['check']['alerts'] or
operation_data['check']['state_index'] or
operation_data['check']['no_alerts'] or
operation_data['check']['no_indices'])
if wait_is_required:
wait_syscollector_and_vuln_scan(host_manager, host, operation_data, current_datetime)

if wait_is_required:
wait_syscollector_and_vuln_scan(host_manager, host, operation_data, current_datetime)
check_vulnerability_alerts(results, operation_data['check'], current_datetime, host_manager, host,
package_data, operation='install')

else:
logging.error(f"Error: Package for {host_os_name} and {host_os_arch} not found")

except Exception as e:
logging.critical(f"Error searching package: {e}")

check_vulnerability_alerts(results, operation_data['check'], current_datetime, host_manager, host,
package_data, operation='install')
else:
logging.info(f"No operation to perform on {host}")

Expand Down Expand Up @@ -239,33 +245,38 @@ def remove_package(host: str, operation_data: Dict[str, Dict], host_manager: Hos
package_id = None

if host_os_name in package_data:
if host_os_arch in package_data[host_os_name]:
package_id = package_data[host_os_name][host_os_arch]
else:
raise ValueError(f"Package for {host_os_name} and {host_os_arch} not found")

package_data = load_packages_metadata()[package_id]

current_datetime = datetime.utcnow().isoformat()

logging.info(f"Removing package on {host}")
if 'uninstall_name' in package_data:
uninstall_name = package_data['uninstall_name']
host_manager.remove_package(host, system, package_uninstall_name=uninstall_name)
elif 'uninstall_custom_playbook' in package_data:
host_manager.remove_package(host, system,
custom_uninstall_playbook=package_data['uninstall_custom_playbook'])

wait_is_required = 'check' in operation_data and (operation_data['check']['alerts'] or
operation_data['check']['state_index'] or
operation_data['check']['no_alerts'] or
operation_data['check']['no_indices'])

if wait_is_required:
wait_syscollector_and_vuln_scan(host_manager, host, operation_data, current_datetime)

check_vulnerability_alerts(results, operation_data['check'], current_datetime, host_manager, host,
package_data, operation='remove')
try:
if host_os_arch in package_data[host_os_name]:
package_id = package_data[host_os_name][host_os_arch]

package_data = load_packages_metadata()[package_id]

current_datetime = datetime.utcnow().isoformat()

logging.info(f"Removing package on {host}")
if 'uninstall_name' in package_data:
uninstall_name = package_data['uninstall_name']
host_manager.remove_package(host, system, package_uninstall_name=uninstall_name)
elif 'uninstall_custom_playbook' in package_data:
host_manager.remove_package(host, system,
custom_uninstall_playbook=package_data['uninstall_custom_playbook'])

wait_is_required = 'check' in operation_data and (operation_data['check']['alerts'] or
operation_data['check']['state_index'] or
operation_data['check']['no_alerts'] or
operation_data['check']['no_indices'])

if wait_is_required:
wait_syscollector_and_vuln_scan(host_manager, host, operation_data, current_datetime)

check_vulnerability_alerts(results, operation_data['check'], current_datetime, host_manager, host,
package_data, operation='remove')

else:
logging.error(f"Error: Package for {host_os_name} and {host_os_arch} not found")

except Exception as e:
logging.critical(f"Error searching package: {e}")

else:
logging.info(f"No operation to perform on {host}")
Expand Down Expand Up @@ -316,41 +327,50 @@ def update_package(host: str, operation_data: Dict[str, Dict], host_manager: Hos
package_id_to = None

if host_os_name in install_package_data_from:
if host_os_arch in install_package_data_from[host_os_name]:
package_id_from = install_package_data_from[host_os_name][host_os_arch]
else:
raise ValueError(f"Package for {host_os_name} and {host_os_arch} not found")
try:
if host_os_arch in install_package_data_from[host_os_name]:
package_id_from = install_package_data_from[host_os_name][host_os_arch]
else:
logging.error(f"Error: Package for {host_os_name} and {host_os_arch} not found")
except Exception as e:
logging.critical(f"Error searching package: {e}")

if host_os_name in install_package_data_to:
if host_os_arch in install_package_data_to[host_os_name]:
package_id_to = install_package_data_to[host_os_name][host_os_arch]
else:
raise ValueError(f"Package for {host_os_name} and {host_os_arch} not found")
try:
if host_os_arch in install_package_data_to[host_os_name]:
package_id_to = install_package_data_to[host_os_name][host_os_arch]

package_data_from = load_packages_metadata()[package_id_from]
package_data_to = load_packages_metadata()[package_id_to]

package_url_to = package_data_to['urls'][host_os_name][host_os_arch]

package_data_from = load_packages_metadata()[package_id_from]
package_data_to = load_packages_metadata()[package_id_to]
logging.info(f"Installing package on {host}")
logging.info(f"Package URL: {package_url_to}")

package_url_to = package_data_to['urls'][host_os_name][host_os_arch]
current_datetime = datetime.utcnow().isoformat()
host_manager.install_package(host, package_url_to, system)

logging.info(f"Installing package on {host}")
logging.info(f"Package URL: {package_url_to}")
logging.info(f"Package {package_url_to} installed on {host}")

current_datetime = datetime.utcnow().isoformat()
host_manager.install_package(host, package_url_to, system)
logging.info(f"Package installed on {host}")

logging.info(f"Package {package_url_to} installed on {host}")
wait_is_required = 'check' in operation_data and (operation_data['check']['alerts'] or
operation_data['check']['state_index'] or
operation_data['check']['no_alerts'] or
operation_data['check']['no_indices'])
if wait_is_required:
wait_syscollector_and_vuln_scan(host_manager, host, operation_data, current_datetime)

logging.info(f"Package installed on {host}")
check_vulnerability_alerts(results, operation_data['check'], current_datetime, host_manager, host,
{'from': package_data_from, 'to': package_data_to}, operation='update')

else:
logging.error(f"Error: Package for {host_os_name} and {host_os_arch} not found")

wait_is_required = 'check' in operation_data and (operation_data['check']['alerts'] or
operation_data['check']['state_index'] or
operation_data['check']['no_alerts'] or
operation_data['check']['no_indices'])
if wait_is_required:
wait_syscollector_and_vuln_scan(host_manager, host, operation_data, current_datetime)
except Exception as e:
logging.critical(f"Error searching package: {e}")

check_vulnerability_alerts(results, operation_data['check'], current_datetime, host_manager, host,
{'from': package_data_from, 'to': package_data_to}, operation='update')
else:
logging.info(f"No operation to perform on {host}")

Expand Down
Loading