-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MON 137835 cma windows robot tests (#1555)
* add wsl robot test
- Loading branch information
1 parent
7abd865
commit 28b0b6a
Showing
24 changed files
with
986 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.