diff --git a/.github/workflows/Test_installation_assistant.yml b/.github/workflows/Test_installation_assistant.yml index 81e5178..85b9512 100644 --- a/.github/workflows/Test_installation_assistant.yml +++ b/.github/workflows/Test_installation_assistant.yml @@ -155,7 +155,10 @@ jobs: echo "$ansible_host ansible_port=$ansible_port ansible_user=$ansible_user ansible_ssh_private_key_file=$ansible_ssh_private_key_file ansible_ssh_common_args='$ansible_ssh_common_args'" >> $ALLOCATOR_PATH/inventory - name: Execute provision playbook + id: provision_instance + if: success() && steps.allocator_instance.outcome == 'success' run: | + set +e INSTALL_DEPS=true INSTALL_PYTHON=true INSTALL_PIP_DEPS=true @@ -170,9 +173,17 @@ jobs: -e "install_python=$INSTALL_PYTHON" \ -e "install_pip_deps=$INSTALL_PIP_DEPS" \ "${{ inputs.VERBOSITY }}" + EXIT_CODE=$? + echo "provision_instance=$EXIT_CODE" >> $GITHUB_OUTPUT + if [ $EXIT_CODE != 0 ]; then + exit 1 + fi - name: Execute AIO installation playbook + id: install_aio + if: success() && steps.provision_instance.outcome == 'success' run: | + set +e ansible-playbook .github/workflows/ansible-playbooks/aio.yml \ -i $ALLOCATOR_PATH/inventory \ -l all \ @@ -181,9 +192,17 @@ jobs: -e "test_name=$TEST_NAME" \ -e "pkg_repository=$PKG_REPOSITORY" \ "${{ inputs.VERBOSITY }}" + EXIT_CODE=$? + echo "install_aio=$EXIT_CODE" >> $GITHUB_OUTPUT + if [ $EXIT_CODE != 0 ]; then + exit 1 + fi - name: Execute Python test playbook + id: execute_test + if: success() && steps.install_aio.outcome == 'success' run: | + set +e TEST_NAME="test_installation_assistant" ansible-playbook .github/workflows/ansible-playbooks/aio_tests.yml \ -i $ALLOCATOR_PATH/inventory \ @@ -192,6 +211,9 @@ jobs: -e "logs_path=$LOGS_PATH" \ -e "test_name=$TEST_NAME" \ "${{ inputs.VERBOSITY }}" + EXIT_CODE=$? + echo "execute_test=$EXIT_CODE" >> $GITHUB_OUTPUT + - name: Compress Allocator VM directory id: compress_allocator_files @@ -210,3 +232,28 @@ jobs: if: always() && steps.allocator_instance.outcome == 'success' && inputs.DESTROY == true run: python3 wazuh-automation/deployability/modules/allocation/main.py --action delete --track-output $ALLOCATOR_PATH/track.yml + - name: Set final workflow status + if: always() + shell: bash + run: | + PROVISION_INSTANCE="${{ steps.provision_instance.outputs.provision_instance }}" + INSTALL_AIO="${{ steps.install_aio.outputs.install_aio }}" + EXECUTE_TEST="${{ steps.execute_test.outputs.execute_test }}" + + if [ "$PROVISION_INSTANCE" != "0" ] ; then + echo "::error :: Failed provisioning instances" + exit 1 + fi + + if [ "$INSTALL_AIO" != "0" ] ; then + echo "::error :: Failed installing wiht AIO" + exit 1 + fi + + if [ "$EXECUTE_TEST" != "0" ]; then + echo "::warning ::Test completed successfully but some errors detected" + exit 0 + fi + + echo "All test completed successfully" + exit 0 diff --git a/.github/workflows/Test_installation_assistant_distributed.yml b/.github/workflows/Test_installation_assistant_distributed.yml index 9dd4e2b..cfd389e 100644 --- a/.github/workflows/Test_installation_assistant_distributed.yml +++ b/.github/workflows/Test_installation_assistant_distributed.yml @@ -209,7 +209,10 @@ jobs: cat $inventory_common >> $inventory_file - name: Execute provision playbook + id: provision_instance + if: success() && steps.allocator_instance.outcome == 'success' run: | + set +e INSTALL_DEPS=true INSTALL_PYTHON=true INSTALL_PIP_DEPS=true @@ -224,34 +227,66 @@ jobs: -e "install_python=$INSTALL_PYTHON" \ -e "install_pip_deps=$INSTALL_PIP_DEPS" \ "${{ inputs.VERBOSITY }}" + EXIT_CODE=$? + echo "provision_instance=$EXIT_CODE" >> $GITHUB_OUTPUT + if [ $EXIT_CODE != 0 ]; then + exit 1 + fi - name: Execute certificates generation playbook + id: generate_certificates + if: success() && steps.provision_instance.outcome == 'success' run: | + set +e ANSIBLE_STDOUT_CALLBACK=$ANSIBLE_CALLBACK ansible-playbook .github/workflows/ansible-playbooks/distributed_generate_certificates.yml \ -i $ALLOCATOR_PATH/inventory \ -e "resources_path=$RESOURCES_PATH" \ "${{ inputs.VERBOSITY }}" + EXIT_CODE=$? + echo "generate_certificates=$EXIT_CODE" >> $GITHUB_OUTPUT + if [ $EXIT_CODE != 0 ]; then + exit 1 + fi - name: Copy certificates to nodes + id: copy_certificates + if: success() && steps.generate_certificates.outcome == 'success' run: | + set +e ANSIBLE_STDOUT_CALLBACK=$ANSIBLE_CALLBACK ansible-playbook .github/workflows/ansible-playbooks/distributed_copy_certificates.yml \ -i $ALLOCATOR_PATH/inventory \ -l indexers \ -e "tmp_path=$TMP_PATH" \ -e "resources_path=$RESOURCES_PATH" \ "${{ inputs.VERBOSITY }}" + EXIT_CODE=$? + echo "copy_certificates=$EXIT_CODE" >> $GITHUB_OUTPUT + if [ $EXIT_CODE != 0 ]; then + exit 1 + fi - name: Execute indexer installation playbook + id: install_indexer + if: success() && steps.copy_certificates.outcome == 'success' run: | + set +e ANSIBLE_STDOUT_CALLBACK=$ANSIBLE_CALLBACK ansible-playbook .github/workflows/ansible-playbooks/distributed_install_indexer.yml \ -i $ALLOCATOR_PATH/inventory \ -l indexers \ -e "tmp_path=$TMP_PATH" \ -e "pkg_repository=$PKG_REPOSITORY" \ "${{ inputs.VERBOSITY }}" + EXIT_CODE=$? + echo "install_indexer=$EXIT_CODE" >> $GITHUB_OUTPUT + if [ $EXIT_CODE != 0 ]; then + exit 1 + fi - name: Execute indexer cluster start playbook + id: start_indexer + if: success() && steps.install_indexer.outcome == 'success' run: | + set +e INDEXER_ADMIN_PASSWORD="admin" ANSIBLE_STDOUT_CALLBACK=$ANSIBLE_CALLBACK ansible-playbook .github/workflows/ansible-playbooks/distributed_start_indexer_cluster.yml \ -i $ALLOCATOR_PATH/inventory \ @@ -259,33 +294,59 @@ jobs: -e "tmp_path=$TMP_PATH" \ -e "pkg_repository=$PKG_REPOSITORY" \ "${{ inputs.VERBOSITY }}" + EXIT_CODE=$? + echo "start_indexer=$EXIT_CODE" >> $GITHUB_OUTPUT + if [ $EXIT_CODE != 0 ]; then + exit 1 + fi - name: Execute server installation playbook + id: install_server + if: success() && steps.start_indexer.outcome == 'success' run: | + set +e ANSIBLE_STDOUT_CALLBACK=$ANSIBLE_CALLBACK ansible-playbook .github/workflows/ansible-playbooks/distributed_install_wazuh.yml \ -i $ALLOCATOR_PATH/inventory \ -l managers \ -e "tmp_path=$TMP_PATH" \ -e "pkg_repository=$PKG_REPOSITORY" \ "${{ inputs.VERBOSITY }}" + EXIT_CODE=$? + echo "install_server=$EXIT_CODE" >> $GITHUB_OUTPUT + if [ $EXIT_CODE != 0 ]; then + exit 1 + fi - name: Execute dashboard installation playbook + id: install_dashboard + if: success() && steps.install_server.outcome == 'success' run: | + set +e ANSIBLE_STDOUT_CALLBACK=$ANSIBLE_CALLBACK ansible-playbook .github/workflows/ansible-playbooks/distributed_install_dashboard.yml \ -i $ALLOCATOR_PATH/inventory \ -l dashboards \ -e "tmp_path=$TMP_PATH" \ -e "pkg_repository=$PKG_REPOSITORY" \ "${{ inputs.VERBOSITY }}" + EXIT_CODE=$? + echo "install_dashboard=$EXIT_CODE" >> $GITHUB_OUTPUT + if [ $EXIT_CODE != 0 ]; then + exit 1 + fi - name: Execute Python test playbook + id: execute_test + if: success() && steps.install_dashboard.outcome == 'success' run: | + set +e ANSIBLE_STDOUT_CALLBACK=$ANSIBLE_CALLBACK ansible-playbook .github/workflows/ansible-playbooks/distributed_tests.yml \ -i $ALLOCATOR_PATH/inventory \ -l managers \ -e "tmp_path=$TMP_PATH" \ -e "test_name=$TEST_NAME" \ "${{ inputs.VERBOSITY }}" + EXIT_CODE=$? + echo "execute_test=$EXIT_CODE" >> $GITHUB_OUTPUT - name: Compress Allocator VM directory id: compress_allocator_files @@ -321,3 +382,58 @@ jobs: # Wait for all deletion tasks to complete wait + - name: Set final workflow status + if: always() + shell: bash + run: | + PROVISION_INSTANCE="${{ steps.provision_instance.outputs.provision_instance }}" + GENERATE_CERTIFICATES="${{ steps.generate_certificates.outputs.generate_certificates }}" + COPY_CERTIFICATES="${{ steps.copy_certificates.outputs.copy_certificates }}" + INSTALL_INDEXER="${{ steps.install_indexer.outputs.install_indexer }}" + START_INDEXER="${{ steps.start_indexer.outputs.start_indexer }}" + INSTALL_SERVER="${{ steps.install_server.outputs.install_server }}" + INSTALL_DASHBOARD="${{ steps.install_dashboard.outputs.install_dashboard }}" + EXECUTE_TEST="${{ steps.execute_test.outputs.execute_test }}" + + if [ "$PROVISION_INSTANCE" != "0" ] ; then + echo "::error :: Failed provisioning instances" + exit 1 + fi + + if [ "$GENERATE_CERTIFICATES" != "0" ] ; then + echo "::error :: Failed generating certificates" + exit 1 + fi + + if [ "$COPY_CERTIFICATES" != "0" ] ; then + echo "::error :: Failed copy certificates" + exit 1 + fi + + if [ "$INSTALL_INDEXER" != "0" ] ; then + echo "::error :: Failed installing Wazuh indexer" + exit 1 + fi + + if [ "$START_INDEXER" != "0" ] ; then + echo "::error :: Failed starting Wazuh indexer" + exit 1 + fi + + if [ "$INSTALL_SERVER" != "0" ] ; then + echo "::error :: Failed installing Wazuh server" + exit 1 + fi + + if [ "$INSTALL_DASHBOARD" != "0" ] ; then + echo "::error :: Failed installing Wazuh dashboard" + exit 1 + fi + + if [ "$EXECUTE_TEST" != "0" ]; then + echo "::warning ::Test completed successfully but some errors detected" + exit 0 + fi + + echo "All test completed successfully" + exit 0 diff --git a/.github/workflows/ansible-playbooks/aio.yml b/.github/workflows/ansible-playbooks/aio.yml index 4acd184..a4980bc 100644 --- a/.github/workflows/ansible-playbooks/aio.yml +++ b/.github/workflows/ansible-playbooks/aio.yml @@ -9,7 +9,7 @@ tasks: - name: Test assistant AIO install - command: "bash {{ script_name }} -a -v -d {{ pkg_repository }}" + command: "bash {{ script_name }} -a -v -id -d {{ pkg_repository }}" args: chdir: "{{ script_path }}" register: install_results diff --git a/.github/workflows/ansible-playbooks/distributed_install_dashboard.yml b/.github/workflows/ansible-playbooks/distributed_install_dashboard.yml index fb04278..a974752 100644 --- a/.github/workflows/ansible-playbooks/distributed_install_dashboard.yml +++ b/.github/workflows/ansible-playbooks/distributed_install_dashboard.yml @@ -9,7 +9,7 @@ tasks: - name: Install Wazuh dashboard - command: "bash wazuh-install.sh -wd {{ inventory_hostname }} -v -d {{ pkg_repository }}" + command: "bash wazuh-install.sh -wd {{ inventory_hostname }} -v -d {{ pkg_repository }} -id" args: chdir: "{{ tmp_path }}" register: dashboard diff --git a/.github/workflows/ansible-playbooks/distributed_install_indexer.yml b/.github/workflows/ansible-playbooks/distributed_install_indexer.yml index c5736da..f8258dc 100644 --- a/.github/workflows/ansible-playbooks/distributed_install_indexer.yml +++ b/.github/workflows/ansible-playbooks/distributed_install_indexer.yml @@ -9,6 +9,6 @@ tasks: - name: Install Wazuh indexer - command: "bash {{ tmp_path }}/wazuh-install.sh -wi {{ inventory_hostname }} -v -d {{ pkg_repository }}" + command: "bash {{ tmp_path }}/wazuh-install.sh -wi {{ inventory_hostname }} -v -d {{ pkg_repository }} -id" register: indexer diff --git a/.github/workflows/ansible-playbooks/distributed_install_wazuh.yml b/.github/workflows/ansible-playbooks/distributed_install_wazuh.yml index ac5cfe1..a8af601 100644 --- a/.github/workflows/ansible-playbooks/distributed_install_wazuh.yml +++ b/.github/workflows/ansible-playbooks/distributed_install_wazuh.yml @@ -11,7 +11,7 @@ tasks: - name: Install Wazuh server on master - command: "bash {{ tmp_path }}/wazuh-install.sh -ws {{ inventory_hostname }} -v -d {{ pkg_repository }}" + command: "bash {{ tmp_path }}/wazuh-install.sh -ws {{ inventory_hostname }} -v -d {{ pkg_repository }} -id" register: wazuh when: hostvars[inventory_hostname].manager_type == 'master' @@ -28,8 +28,8 @@ poll: 5 - name: Install Wazuh server (Workers) - command: "bash {{ tmp_path }}/wazuh-install.sh -ws {{ inventory_hostname }} -v -d {{ pkg_repository }}" + command: "bash {{ tmp_path }}/wazuh-install.sh -ws {{ inventory_hostname }} -v -d {{ pkg_repository }} -id" register: wazuh when: hostvars[inventory_hostname].manager_type == 'worker' - - + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 2105e4f..7dd62e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ### Added +- Improve asistant test completion status ([#188](https://github.com/wazuh/wazuh-installation-assistant/pull/188)) - Added available packages check before installation ([#80](https://github.com/wazuh/wazuh-installation-assistant/pull/80)) ### Changed diff --git a/install_functions/installMain.sh b/install_functions/installMain.sh index 7b80503..d76882a 100755 --- a/install_functions/installMain.sh +++ b/install_functions/installMain.sh @@ -262,7 +262,7 @@ function main() { fi if [ -z "${uninstall}" ] && [ -z "${offline_install}" ]; then - installCommon_installCheckDependencies + installCommon_installDependencies elif [ -n "${offline_install}" ]; then offline_checkPrerequisites "wia_offline_dependencies" "${wia_offline_dependencies[@]}" fi diff --git a/tests/install/test_installation_assistant.py b/tests/install/test_installation_assistant.py index 0cdd7df..365eed6 100644 --- a/tests/install/test_installation_assistant.py +++ b/tests/install/test_installation_assistant.py @@ -214,7 +214,7 @@ def test_check_log_errors(): "ERROR: Could not send message through the cluster after '10' attempts" ] - + with open('/var/ossec/logs/ossec.log', 'r') as f: for line in f.readlines(): if 'ERROR' in line: