Skip to content

Commit

Permalink
fix: Fix qactl ansible connection issue #1723
Browse files Browse the repository at this point in the history
  • Loading branch information
jmv74211 committed Aug 23, 2021
1 parent 361e70d commit 0a49d21
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from wazuh_testing.qa_ctl.provisioning.wazuh_deployment.WazuhSources import WazuhSources
from wazuh_testing.qa_ctl.provisioning.wazuh_deployment.AgentDeployment import AgentDeployment
from wazuh_testing.qa_ctl.provisioning.wazuh_deployment.ManagerDeployment import ManagerDeployment
from wazuh_testing.qa_ctl.provisioning.ansible.AnsibleRunner import AnsibleRunner
from wazuh_testing.qa_ctl.provisioning.ansible.AnsibleTask import AnsibleTask
from wazuh_testing.qa_ctl.provisioning.qa_framework.QAFramework import QAFramework


Expand Down Expand Up @@ -38,7 +40,7 @@ def __init__(self, provision_info):
def __read_ansible_instance(self, host_info):
"""Read every host info and generate the AnsibleInstance object.
Attributes:
Args:
host_info (dict): Dict with the host info needed coming from config file.
Returns:
Expand All @@ -55,6 +57,19 @@ def __read_ansible_instance(self, host_info):
ansible_python_interpreter=host_info['ansible_python_interpreter'])
return instance

def check_hosts_connection(self, hosts='all'):
"""Check that all hosts are reachable via SSH connection
Args:
hosts (str): Hosts to check.
"""
wait_for_connection = AnsibleTask({'name': 'Waiting for SSH hosts connection are reachable',
'wait_for_connection': {'delay': 5, 'timeout': 60}})

playbook_parameters = {'hosts': hosts, 'tasks_list': [wait_for_connection]}

AnsibleRunner.run_ephemeral_tasks(self.inventory_file_path, playbook_parameters)

def process_inventory_data(self):
"""Process config file info to generate the ansible inventory file."""
for root_key, root_value in self.provision_info.items():
Expand Down
4 changes: 1 addition & 3 deletions deps/wazuh_testing/wazuh_testing/scripts/qa_ctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import yaml

from time import sleep
from wazuh_testing.qa_ctl.deployment.QAInfraestructure import QAInfraestructure
from wazuh_testing.qa_ctl.provisioning.QAProvisioning import QAProvisioning
from wazuh_testing.qa_ctl.run_tests.QARunTests import RunQATests
Expand Down Expand Up @@ -41,11 +40,10 @@ def main():
instance_handler.run()

if PROVISION_KEY in yaml_config:
if DEPLOY_KEY in yaml_config:
sleep(5) # If machines are deployed, wait 5 seconds before connecting
provision_dict = yaml_config[PROVISION_KEY]
qa_provisioning = QAProvisioning(provision_dict)
qa_provisioning.process_inventory_data()
qa_provisioning.check_hosts_connection()
qa_provisioning.process_deployment_data()

if TEST_KEY in yaml_config:
Expand Down

0 comments on commit 0a49d21

Please sign in to comment.