Skip to content

Commit

Permalink
refac: Changed test name #1850
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando committed Dec 22, 2021
1 parent b1623e0 commit da72729
Showing 1 changed file with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,36 @@
from wazuh_testing.tools import WAZUH_PATH
from wazuh_testing.tools.services import control_service, check_daemon_status



# Marks
pytestmark = [pytest.mark.linux, pytest.mark.tier(level=0), pytest.mark.server]

# variables

ANALYSISD_SOCKET = os.path.join(WAZUH_PATH, 'queue', 'sockets', 'queue')
analysisd_path = os.path.join(WAZUH_PATH,'bin', 'wazuh-analysisd')
command_exec = f'{analysisd_path} -t'

# Fixture

This comment has been minimized.

Copy link
@mauromalara

mauromalara Dec 22, 2021

Contributor

@fernandolojano This is not a fixture, because is not used like one.

def configure_analysisd_queue_socket():

This comment has been minimized.

Copy link
@mauromalara

mauromalara Dec 22, 2021

Contributor

@fernandolojano I recommend you change the name of the function to run_analysisd_test_config()

# restart analysisd daemon
control_service('restart', daemon='wazuh-analysisd')
check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd')

def test_queue_socket_status():

# Updating Analysisd

This comment has been minimized.

Copy link
@mauromalara

mauromalara Dec 22, 2021

Contributor

@fernandolojano You're not updating but running the test configuration mode

run = subprocess.Popen(['/bin/bash', '-c', command_exec])
run.communicate()

def test_queue_socket_properties():
# Check if analysisd daemon is running
check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd')
if check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') is not True:

This comment has been minimized.

Copy link
@mauromalara

mauromalara Dec 22, 2021

Contributor

@fernandolojano finally, this is not necessary (my bad), because the check_daemon_status() function throws an error if the daemon does not reach the running condition.

control_service('start', daemon='wazuh-analysisd')

current_inode_file = os.stat(ANALYSISD_SOCKET).st_ino
current_status_time = os.path.getmtime(ANALYSISD_SOCKET)

# Stop analysisd daemon
control_service('stop', daemon='wazuh-analysisd')
check_daemon_status(running_condition=False, target_daemon='wazuh-analysisd')

control_service('start', daemon='wazuh-analysisd')
configure_analysisd_queue_socket()

This comment has been minimized.

Copy link
@mauromalara

mauromalara Dec 22, 2021

Contributor

@fernandolojano You can create 2 fixtures:

  1. One to get the socket file properties (lines 31 and 32). It can be used after and before running the analysisd test config.
  2. And the other one to run the analysisd test config (as I mentioned before)

assert current_inode_file == os.stat(ANALYSISD_SOCKET).st_ino, \

This comment has been minimized.

Copy link
@mauromalara

mauromalara Dec 22, 2021

Contributor

@fernandolojano If you do this, then your test will only compare the value before and after running the test configuration.

f"The Inode value for the socket {ANALYSISD_SOCKET} has changed"

# Updating Analysisd
run = subprocess.Popen(['/bin/bash', '-c', command_exec])
run.communicate()

try:
assert current_inode_file == os.stat(ANALYSISD_SOCKET).st_ino
except AssertionError:
raise AssertionError(f'The Inode value for the socket {ANALYSISD_SOCKET} has changed')

try:
assert current_status_time == os.path.getmtime(ANALYSISD_SOCKET)
except AssertionError:
raise AssertionError(f'The Filetime value for the socket {ANALYSISD_SOCKET} has changed')
assert current_status_time == os.path.getmtime(ANALYSISD_SOCKET), \
f"The Filetime value for the socket {ANALYSISD_SOCKET} has changed"

This comment has been minimized.

Copy link
@mauromalara

mauromalara Dec 22, 2021

Contributor

@fernandolojano Add a newline at the end of the file

0 comments on commit da72729

Please sign in to comment.