Skip to content

Commit

Permalink
MON 137835 cma windows robot tests (#1555)
Browse files Browse the repository at this point in the history
* add wsl robot test
  • Loading branch information
jean-christophe81 authored and bouda1 committed Sep 25, 2024
1 parent 7abd865 commit 28b0b6a
Show file tree
Hide file tree
Showing 24 changed files with 986 additions and 474 deletions.
111 changes: 111 additions & 0 deletions .github/scripts/agent_robot_test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#
# Copyright 2024 Centreon
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# For more information : [email protected]
#

# This script test windows CMA
# We first start four instances of centreon agent (reverse or not, encryption or not)
# Then, we install collect in a wsl and start robot test on it.
# Used ports are:
# - 4317 no reversed, no encryption
# - 4318 no reversed, encryption
# - 4320 reversed, no encryption
# - 4321 reversed, encryption
# All files are shared between wsl and windows, we translate it with $wsl_path
# By this share, we use certificates (server.*) on both world
# In order to communicate bteween two worlds, we use hostname and IP of the host
# That's why we rewrite /etc/hosts on wsl side
# agent logs are saved in reports and wsl fail tests are saved in it also in case of failure


Write-Host "Work in" $pwd.ToString()

$current_dir = (pwd).Path
$wsl_path = "/mnt/" + $current_dir.SubString(0,1).ToLower() + "/" + $current_dir.SubString(3).replace('\','/')

mkdir reports

reg import agent/conf/centagent.reg

Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name log_type -Value file
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name host -Value host_1
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name log_level -Value trace


#in wsl1, no VM, so IP address are identical in host and wsl
#windows can connect to linux on localhost but linux must use host ip
$my_host_name = $env:COMPUTERNAME
$my_ip = (Get-NetIpAddress -AddressFamily IPv4 | Where-Object IPAddress -ne "127.0.0.1" | SELECT IPAddress -First 1).IPAddress
$pwsh_path = (get-command pwsh.exe).Path

# generate certificate used by wsl and windows
openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout server_grpc.key -out server_grpc.crt -subj "/CN=${my_host_name}"

Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name endpoint -Value ${my_host_name}:4317
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name reversed_grpc_streaming -Value 0
$agent_log_path = $current_dir + "\reports\centagent.log"
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name log_file -Value $agent_log_path

#Start agent
Start-Process -FilePath build_windows\agent\Release\centagent.exe -RedirectStandardOutput reports\centagent_stdout.log -RedirectStandardError reports\centagent_stderr.log

Write-Host ($agent_process | Format-Table | Out-String)

Start-Sleep -Seconds 1

#encrypted version
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name ca_certificate -Value ${current_dir}/server_grpc.crt
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name endpoint -Value ${my_host_name}:4318
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name encryption -Value 1
$agent_log_path = $current_dir + "\reports\encrypted_centagent.log"
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name log_file -Value $agent_log_path

Start-Process -FilePath build_windows\agent\Release\centagent.exe -RedirectStandardOutput reports\encrypted_centagent_stdout.log -RedirectStandardError reports\encrypted_centagent_stderr.log


Start-Sleep -Seconds 1

#Start reverse agent
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name ca_certificate -Value ""
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name encryption -Value 0
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name endpoint -Value 0.0.0.0:4320
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name reverse_connection -Value 1
$agent_log_path = $current_dir + "\reports\reverse_centagent.log"
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name log_file -Value $agent_log_path

Start-Process -FilePath build_windows\agent\Release\centagent.exe -RedirectStandardOutput reports\reversed_centagent_stdout.log -RedirectStandardError reports\reversed_centagent_stderr.log

Start-Sleep -Seconds 1

#reversed and encrypted
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name private_key -Value ${current_dir}/server_grpc.key
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name public_cert -Value ${current_dir}/server_grpc.crt
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name encryption -Value 1
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name endpoint -Value 0.0.0.0:4321
$agent_log_path = $current_dir + "\reports\encrypted_reverse_centagent.log"
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name log_file -Value $agent_log_path

Start-Process -FilePath build_windows\agent\Release\centagent.exe -RedirectStandardOutput reports\encrypted_reversed_centagent_stdout.log -RedirectStandardError reports\encrypted_reversed_centagent_stderr.log

wsl cd $wsl_path `&`& .github/scripts/wsl-collect-test-robot.sh broker-engine/cma.robot $my_host_name $my_ip $pwsh_path ${current_dir}.replace('\','/')

#something wrong in robot test => exit 1 => failure
if (Test-Path -Path 'reports\windows-cma-failed' -PathType Container) {
exit 1
}



42 changes: 1 addition & 41 deletions .github/scripts/collect-prepare-test-robot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,7 @@ ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -P "" <<<y
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -P "" <<<y
mkdir -p /run/sshd

if [ $database_type == 'mysql' ]; then
echo "########################### Start MySQL ######################################"
#workaround of forbidden execution of mysqld
cp /usr/libexec/mysqld /usr/libexec/mysqldtoto
/usr/libexec/mysqldtoto --user=root --initialize-insecure
/usr/libexec/mysqldtoto --user=root &

while [ ! -S /var/lib/mysql/mysql.sock ] && [ ! -S /var/run/mysqld/mysqld.sock ]; do
sleep 10
done

sleep 5
echo "########################### Init centreon database ############################"

mysql -e "CREATE USER IF NOT EXISTS 'centreon'@'localhost' IDENTIFIED BY 'centreon'"
mysql -e "CREATE USER IF NOT EXISTS 'root_centreon'@'localhost' IDENTIFIED BY 'centreon'"
else
echo "########################### Start MariaDB ######################################"
if [ "$distrib" = "ALMALINUX" ]; then
mysql_install_db --user=root --basedir=/usr --datadir=/var/lib/mysql
mariadbd --socket=/var/lib/mysql/mysql.sock --user=root > /dev/null 2>&1 &
else
mkdir -p /run/mysqld
chown mysql:mysql /run/mysqld
mariadbd --socket=/run/mysqld/mysqld.sock --user=root > /dev/null 2>&1 &
fi
sleep 5

echo "########################### Init centreon database ############################"

mysql -e "CREATE USER IF NOT EXISTS 'centreon'@'localhost' IDENTIFIED BY 'centreon'"
mysql -e "CREATE USER IF NOT EXISTS 'root_centreon'@'localhost' IDENTIFIED BY 'centreon'"
fi

mysql -e "GRANT SELECT,UPDATE,DELETE,INSERT,CREATE,DROP,INDEX,ALTER,LOCK TABLES,CREATE TEMPORARY TABLES, EVENT,CREATE VIEW ON *.* TO 'centreon'@'localhost'"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root_centreon'@'localhost'"

cat resources/centreon.sql | sed "s/DBNameConf/centreon/g" > /tmp/centreon.sql

mysql -u root_centreon -pcentreon < resources/centreon_storage.sql
mysql -u root_centreon -pcentreon < /tmp/centreon.sql
.github/scripts/collect-setup-database.sh $database_type

if [ $database_type == 'mysql' ]; then
killall -w mysqldtoto
Expand Down
53 changes: 53 additions & 0 deletions .github/scripts/collect-setup-database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
set -e
set -x


database_type=$1

. /etc/os-release
distrib=${ID}
distrib=$(echo $distrib | tr '[:lower:]' '[:upper:]')


if [ $database_type == 'mysql' ]; then
echo "########################### Start MySQL ######################################"
#workaround of forbidden execution of mysqld
cp /usr/libexec/mysqld /usr/libexec/mysqldtoto
/usr/libexec/mysqldtoto --user=root --initialize-insecure
/usr/libexec/mysqldtoto --user=root &

while [ ! -S /var/lib/mysql/mysql.sock ] && [ ! -S /var/run/mysqld/mysqld.sock ]; do
sleep 10
done

else
echo "########################### Start MariaDB ######################################"
if [ "$distrib" = "ALMALINUX" ]; then
mysql_install_db --user=root --basedir=/usr --datadir=/var/lib/mysql
mariadbd --socket=/var/lib/mysql/mysql.sock --user=root > /dev/null 2>&1 &
else
mkdir -p /run/mysqld
chown mysql:mysql /run/mysqld
mariadbd --socket=/run/mysqld/mysqld.sock --user=root > /dev/null 2>&1 &
fi
fi

sleep 5
echo "########################### Init centreon database ############################"

mysql -e "CREATE USER IF NOT EXISTS 'centreon'@'localhost' IDENTIFIED BY 'centreon'"
mysql -e "CREATE USER IF NOT EXISTS 'root_centreon'@'localhost' IDENTIFIED BY 'centreon'"


mysql -e "GRANT SELECT,UPDATE,DELETE,INSERT,CREATE,DROP,INDEX,ALTER,LOCK TABLES,CREATE TEMPORARY TABLES, EVENT,CREATE VIEW ON *.* TO 'centreon'@'localhost'"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root_centreon'@'localhost'"

cat resources/centreon.sql | sed "s/DBNameConf/centreon/g" > /tmp/centreon.sql

echo "create storage database"
mysql -u root_centreon -pcentreon < resources/centreon_storage.sql

echo "create conf database"
mysql -u root_centreon -pcentreon < /tmp/centreon.sql

2 changes: 1 addition & 1 deletion .github/scripts/windows-agent-compile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $file_name = "windows-agent-vcpkg-dependencies-cache-" + $vcpkg_hash.Hash
$file_name_extension = "${file_name}.7z"

#try to get compiled dependenciesfrom s3
Write-Host "try to download compiled dependencies from s3: $file_name_extension $file_name_extension"
Write-Host "try to download compiled dependencies from s3: $file_name_extension"
aws --quiet s3 cp s3://centreon-collect-robot-report/$file_name_extension $file_name_extension
if ( $? -ne $true ) {
#no => generate
Expand Down
35 changes: 35 additions & 0 deletions .github/scripts/wsl-collect-test-robot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -x

test_file=$1

export RUN_ENV=WSL
export HOST_NAME=$2
export USED_ADDRESS=$3
export PWSH_PATH=$4
export WINDOWS_PROJECT_PATH=$5


#in order to connect to windows we neeed to use windows ip
echo "127.0.0.1 localhost" > /etc/hosts
echo "${USED_ADDRESS} ${HOST_NAME}" >> /etc/hosts

echo "##### /etc/hosts: ######"
cat /etc/hosts

echo "##### Starting tests #####"
cd tests
./init-proto.sh

echo "####################### Run Centreon Collect Robot Tests #######################"

robot $test_file

echo "####################### End of Centreon Collect Robot Tests #######################"

if [ -d failed ] ; then
echo "failure save logs in ${PWD}/../reports"
cp -rp failed ../reports/windows-cma-failed
cp log.html ../reports/windows-cma-log.html
cp output.xml ../reports/windows-cma-output.xml
fi
45 changes: 45 additions & 0 deletions .github/workflows/centreon-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,46 @@ jobs:
package:
needs: [get-version]
if: ${{ ! contains(fromJson('["stable"]'), needs.get-version.outputs.stability) }}
strategy:
fail-fast: false
matrix:
include:
- image: centreon-collect-alma8
distrib: el8
package_extension: rpm
runner: collect
arch: amd64
- image: centreon-collect-alma9
distrib: el9
package_extension: rpm
runner: collect
arch: amd64
- image: centreon-collect-debian-bullseye
distrib: bullseye
package_extension: deb
runner: collect
arch: amd64
- image: centreon-collect-debian-bookworm
distrib: bookworm
package_extension: deb
runner: collect
arch: amd64
- image: centreon-collect-ubuntu-jammy
distrib: jammy
package_extension: deb
runner: collect
arch: amd64
- image: centreon-collect-debian-bullseye-arm64
distrib: bullseye
package_extension: deb
runner: collect-arm64
arch: arm64
- image: centreon-collect-debian-bookworm-arm64
distrib: bookworm
package_extension: deb
runner: collect-arm64
arch: arm64

uses: ./.github/workflows/package-collect.yml
with:
major_version: ${{ needs.get-version.outputs.major_version }}
Expand All @@ -251,6 +291,11 @@ jobs:
stability: ${{ needs.get-version.outputs.stability }}
legacy_engine: ${{ github.event.inputs.legacy_engine == 'true' }}
packages_in_artifact: ${{ github.event.inputs.packages_in_artifact == 'true' }}
image: ${{ matrix.image }}
distrib: ${{ matrix.distrib }}
package_extension: ${{ matrix.package_extension }}
runner: ${{ matrix.runner }}
arch: ${{ matrix.arch }}
secrets: inherit

robot-test:
Expand Down
Loading

0 comments on commit 28b0b6a

Please sign in to comment.