Skip to content

Commit

Permalink
space correction
Browse files Browse the repository at this point in the history
  • Loading branch information
santipadilla committed Apr 3, 2024
1 parent 9b5774a commit e4802a8
Showing 1 changed file with 61 additions and 61 deletions.
122 changes: 61 additions & 61 deletions deps/wazuh_testing/wazuh_testing/tools/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def get_file_content(self, host: str, file_path: str):

return result['stdout']


def apply_config(self, config_yml_path: str, dest_path: str = WAZUH_CONF, clear_files: list = None,
restart_services: list = None):
"""Apply the configuration described in the config_yml_path to the environment.
Expand Down Expand Up @@ -483,7 +484,6 @@ def install_package(self, host, url, system='ubuntu', use_npm=False):
# To install a package via npm:
host_manager.install_package('my_host', 'package_name', 'system_name', use_npm=True)
"""

if use_npm:
# Define the npm install command
cmd = f"npm install -g {url}"
Expand Down Expand Up @@ -514,7 +514,7 @@ def install_package(self, host, url, system='ubuntu', use_npm=False):
result = True
elif system == 'centos':
result = self.get_host(host).ansible("yum", f"name={url} state=present "
'sslverify=false disable_gpg_check=True', check=False)
'sslverify=false disable_gpg_check=True', check=False)
elif system == 'macos':
package_name = url.split('/')[-1]
result = self.get_host(host).ansible("command", f"curl -LO {url}", check=False)
Expand All @@ -525,39 +525,39 @@ def install_package(self, host, url, system='ubuntu', use_npm=False):

return result

def install_npm_package(self, host, url, system='ubuntu'):
"""
Installs a package on the specified host using npm.
def install_npm_package(self, host, url, system='ubuntu'):
"""
Installs a package on the specified host using npm.
Args:
host (str): The target host on which to install the package.
url (str): The URL or name of the package to be installed.
system (str, optional): The operating system type. Defaults to 'ubuntu'.
Supported values: 'windows', 'ubuntu', 'centos', 'macos'.
Args:
host (str): The target host on which to install the package.
url (str): The URL or name of the package to be installed.
system (str, optional): The operating system type. Defaults to 'ubuntu'.
Supported values: 'windows', 'ubuntu', 'centos', 'macos'.
Returns:
Dict: Testinfra Ansible Response of the operation
Returns:
Dict: Testinfra Ansible Response of the operation
Example:
host_manager.install_package('my_host', 'package_name', 'system_name')
"""
Example:
host_manager.install_package('my_host', 'package_name', 'system_name')
"""

# Define the npm install command
cmd = f"npm install -g {url}"
# Define the npm install command
cmd = f"npm install -g {url}"

if system == 'macos':
cmd = f"PATH=/usr/local/bin:$PATH {cmd}"
shell_type = "shell"
elif system == 'windows':
shell_type = "win_shell"
else:
shell_type = "shell"
if system == 'macos':
cmd = f"PATH=/usr/local/bin:$PATH {cmd}"
shell_type = "shell"
elif system == 'windows':
shell_type = "win_shell"
else:
shell_type = "shell"

# Execute the command and log the result
result = self.get_host(host).ansible(shell_type, cmd, check=False)
logging.info(f"npm package installed result {result}")
# Execute the command and log the result
result = self.get_host(host).ansible(shell_type, cmd, check=False)
logging.info(f"npm package installed result {result}")

return result
return result

def get_master_ip(self):
"""
Expand Down Expand Up @@ -666,48 +666,48 @@ def remove_package(self, host, system, package_uninstall_name=None, use_npm=Fals

return remove_operation_result

def remove_npm_package(self, host, system, package_uninstall_name=None, custom_uninstall_playbook=None):
"""
Removes a package from the specified host using npm.
Args:
host (str): The target host from which to remove the package.
package_name (str): The name of the package to be removed.
system (str): The operating system type.
Supported values: 'windows', 'ubuntu', 'centos', 'macos'.
def remove_npm_package(self, host, system, package_uninstall_name=None, custom_uninstall_playbook=None):
"""
Removes a package from the specified host using npm.
Returns:
Dict: Testinfra Ansible Response of the operation
Args:
host (str): The target host from which to remove the package.
package_name (str): The name of the package to be removed.
system (str): The operating system type.
Supported values: 'windows', 'ubuntu', 'centos', 'macos'.
Example:
host_manager.remove_npm_package('my_host', 'system_name', 'package_name')
"""
logging.info(f"Removing package {package_uninstall_name} from host {host}")
logging.info(f"System: {system}")
Returns:
Dict: Testinfra Ansible Response of the operation
remove_operation_result = False
Example:
host_manager.remove_npm_package('my_host', 'system_name', 'package_name')
"""
logging.info(f"Removing package {package_uninstall_name} from host {host}")
logging.info(f"System: {system}")

os_name = self.get_host_variables(host)['os_name']
remove_operation_result = False

if custom_uninstall_playbook:
remove_operation_result = self.run_playbook(host, custom_uninstall_playbook)
else:
# Define the npm uninstall command
cmd = f"npm uninstall -g {package_uninstall_name}"
os_name = self.get_host_variables(host)['os_name']

if system == 'macos':
cmd = f"PATH=/usr/local/bin:$PATH {cmd}"
shell_type = "shell"
elif system == 'windows':
shell_type = "win_shell"
if custom_uninstall_playbook:
remove_operation_result = self.run_playbook(host, custom_uninstall_playbook)
else:
shell_type = "shell"
# Define the npm uninstall command
cmd = f"npm uninstall -g {package_uninstall_name}"

# Execute the command and log the result
remove_operation_result = self.get_host(host).ansible(shell_type, cmd, check=False)
logging.info(f"npm package removed result {remove_operation_result}")
if system == 'macos':
cmd = f"PATH=/usr/local/bin:$PATH {cmd}"
shell_type = "shell"
elif system == 'windows':
shell_type = "win_shell"
else:
shell_type = "shell"

return remove_operation_result
# Execute the command and log the result
remove_operation_result = self.get_host(host).ansible(shell_type, cmd, check=False)
logging.info(f"npm package removed result {remove_operation_result}")

return remove_operation_result

def run_playbook(self, host, playbook_name, params=None):
"""
Expand Down

0 comments on commit e4802a8

Please sign in to comment.