-
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.
tests(Gorgone): test action module to retrieve result of command (#1619)
* tests(Gorgone): test action module to retrieve result of command * doc(Gorgone): Fix documentation of action module * ci(Gorgone): remove os specific db name as database are not shared across jobs * test(Gorgone): fix pull test to start poller first, so there is no failed ping from the host (hopefully) Co-authored-by: cg-tw <[email protected]> Refs:MON-139728
- Loading branch information
Showing
6 changed files
with
233 additions
and
45 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
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
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 |
---|---|---|
@@ -1,13 +1,69 @@ | ||
# | ||
# 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] | ||
# | ||
|
||
from robot.api import logger | ||
import re | ||
import time | ||
from dateutil import parser | ||
from datetime import datetime, timedelta | ||
from robot.libraries.BuiltIn import BuiltIn | ||
import requests | ||
|
||
|
||
def ctn_get_api_log_with_timeout(token: str, node_path='', host='http://127.0.0.1:8085', timeout=15): | ||
"""! Query gorgone log API until the response contains a log with code 2 (success) or 1 (failure) | ||
@param token: token to search in the API | ||
@param node_path: part of the API URL defining if we use the local gorgone or another one, ex node/2/ | ||
@param timeout: timeout in seconds | ||
@param host: gorgone API URL with the port | ||
@return True(when output of the command is found)/False(on failure or timeout), | ||
and a json object containing the incriminated log for failure or success. | ||
""" | ||
limit_date = time.time() + timeout | ||
api_json = [] | ||
while time.time() < limit_date: | ||
time.sleep(1) | ||
uri = host + "/api/" + node_path + "log/" + token | ||
response = requests.get(uri) | ||
(status, output) = parse_json_response(response) | ||
if status == '': | ||
continue | ||
return status, output | ||
|
||
return False, api_json["data"] | ||
|
||
|
||
def parse_json_response(response): | ||
api_json = response.json() | ||
# http code should either be 200 for success or 404 for no log found if we are too early. | ||
# as the time of writing, status code is always 200 because webapp autodiscovery module always expect a 200. | ||
if response.status_code != 200 and response.status_code != 404: | ||
return False, api_json | ||
|
||
TIMEOUT = 30 | ||
if 'error' in api_json and api_json['error'] == "no_log": | ||
return '', '' | ||
for log_detail in api_json["data"]: | ||
if log_detail["code"] == 2: | ||
return False, log_detail | ||
if log_detail["code"] == 100: | ||
return True, log_detail | ||
|
||
|
||
# these function search log in the gorgone log file | ||
def ctn_find_in_log_with_timeout(log: str, content, timeout=20, date=-1, regex=False): | ||
"""! search a pattern in log from date param | ||
@param log: path of the log file | ||
|
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.
8260721
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Robot Results
Failed Tests
Hostgroups