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

Improve asistant test completion status #188

Merged
merged 21 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
47 changes: 47 additions & 0 deletions .github/workflows/Test_installation_assistant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 \
Expand 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 \
Expand All @@ -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
Expand All @@ -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
116 changes: 116 additions & 0 deletions .github/workflows/Test_installation_assistant_distributed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -224,68 +227,126 @@ 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 \
-l indexers \
-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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/ansible-playbooks/aio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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'


1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion install_functions/installMain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/install/test_installation_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down