diff --git a/.github/scripts/agent_robot_test.ps1 b/.github/scripts/agent_robot_test.ps1 index ab7c736c27..15ea89f219 100644 --- a/.github/scripts/agent_robot_test.ps1 +++ b/.github/scripts/agent_robot_test.ps1 @@ -53,7 +53,7 @@ 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 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" @@ -67,8 +67,8 @@ 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 ${my_host_name}:4320 -Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name reversed_grpc_streaming -Value 1 +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 @@ -77,16 +77,16 @@ Start-Process -FilePath build_windows\agent\Release\centagent.exe -RedirectStand 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 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 ${my_host_name}:4321 +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 +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('\','/') if (Test-Path -Path 'reports\windows-cma-failed' -PathType Container) { exit 1 diff --git a/.github/scripts/wsl-collect-test-robot.sh b/.github/scripts/wsl-collect-test-robot.sh index 219d8f76ca..6c70d4f680 100755 --- a/.github/scripts/wsl-collect-test-robot.sh +++ b/.github/scripts/wsl-collect-test-robot.sh @@ -7,6 +7,12 @@ export RUN_ENV=WSL export HOST_NAME=$2 export USED_ADDRESS=$3 export PWSH_PATH=$4 +export WINDOWS_PROJECT_PATH=$5 + + +#ino order to connect to windows we neeed to use windowsw ip +echo "127.0.0.1 localhost" > /etc/hosts +echo "${USED_ADDRESS} ${HOST_NAME}" >> /etc/hosts echo "##### /etc/hosts: ######" cat /etc/hosts diff --git a/tests/broker-engine/cma.robot b/tests/broker-engine/cma.robot index ff73843817..9f91db5224 100644 --- a/tests/broker-engine/cma.robot +++ b/tests/broker-engine/cma.robot @@ -339,17 +339,23 @@ BEOTEL_CENTREON_AGENT_CHECK_HOST_CRYPTED # Let's wait for the otel server start ${content} Create List encrypted server listening on 0.0.0.0:4318 - ${result} Ctn Find In Log With Timeout ${engineLog0} ${start} ${content} 60 + ${result} Ctn Find In Log With Timeout ${engineLog0} ${start} ${content} 10 Should Be True ${result} "encrypted server listening on 0.0.0.0:4318" should be available. Sleep 1 - ${result} Ctn Check Host Check Status With Timeout host_1 30 ${start_int} 0 OK - 127.0.0.1 + ${result} Ctn Check Host Check Status With Timeout host_1 60 ${start_int} 0 OK - 127.0.0.1 Should Be True ${result} hosts table not updated *** Keywords *** Ctn Create Cert And Init [Documentation] create key and certificates used by agent and engine on linux side ${host_name} Ctn Get Hostname - Ctn Create Key And Certificate ${host_name} /tmp/server_grpc.key /tmp/server_grpc.crt + ${run_env} Ctn Run Env + IF "${run_env}" == "WSL" + Copy File ../server_grpc.key /tmp/server_grpc.key + Copy File ../server_grpc.crt /tmp/server_grpc.crt + ELSE + Ctn Create Key And Certificate ${host_name} /tmp/server_grpc.key /tmp/server_grpc.crt + END Ctn Clean Before Suite \ No newline at end of file diff --git a/tests/resources/Agent.py b/tests/resources/Agent.py index f91fe00282..a4e0bbc5bf 100644 --- a/tests/resources/Agent.py +++ b/tests/resources/Agent.py @@ -138,7 +138,7 @@ def ctn_echo_command(to_echo:str): returned an echo command usable by testing agent OS """ if environ.get("RUN_ENV","") == "WSL": - return environ.get("PWSH_PATH") + " C:/Users/Public/echo.ps1 " + to_echo + return '"'+ environ.get('PWSH_PATH') + '"' + " C:/Users/Public/echo.ps1 " + to_echo else: return "/bin/echo " + to_echo @@ -149,7 +149,7 @@ def ctn_check_pl_command(arg:str): returned an check.pl command usable by testing agent OS """ if environ.get("RUN_ENV","") == "WSL": - return environ.get("PWSH_PATH") +" C:/Users/Public/check.ps1 " + arg + return '"'+ environ.get('PWSH_PATH') + '"' +" C:/Users/Public/check.ps1 " + arg + " " + environ.get("WINDOWS_PROJECT_PATH") else: return "/tmp/var/lib/centreon-engine/check.pl " + arg diff --git a/tests/resources/Common.py b/tests/resources/Common.py index d5a35b68be..84ed82fd00 100644 --- a/tests/resources/Common.py +++ b/tests/resources/Common.py @@ -560,7 +560,7 @@ def ctn_clear_commands_status(): def ctn_set_command_status(cmd, status): if os.environ.get("RUN_ENV","") == "WSL": - state_path = "C:/Users/Public/states" + state_path = "states" else: state_path = "/tmp/states" diff --git a/tests/resources/engine-scripts/check.ps1 b/tests/resources/engine-scripts/check.ps1 new file mode 100644 index 0000000000..bb0625feb3 --- /dev/null +++ b/tests/resources/engine-scripts/check.ps1 @@ -0,0 +1,55 @@ +# +# 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 : contact@centreon.com +# + +$id=$args[1] +$project_path = $args[2] + +$status = -1 +if (Test-Path -Path C:\Users\Public\states) { + $state_file = $project_path + "\tests\states" + $status = select-string -path $state_file -pattern "${id}=>(\d+)" | %{$_.Matches[0].Groups[1].Value } +} + +$szd = Get-Date -UFormat "%s" +$dd = [double]$szd +$d = [int]($dd / 1000000) + +$d = [int]($d + 3 * $id) -band 0x1ff; + +$d = $d / ($id + 1); +$w = 300 / ($id + 1); +$c = 400 / ($id + 1); +if ($status -eq 0) { + $d = $w / 2; +} elseif ($status -eq 1) { + $d = ($w + $c) / 2; +} elseif ($status -eq 2) { + $d = 2 * $c; +} else { + if ($d -gt $c) { + $status = 2; + } elseif ($d -gt $w) { + $status = 1; + } else { + $status = 0; + } +} + +"Test check $id | metric={0:n2};{1:n2};{2:n2}" -f $d, $w, $c + +exit $status;