1 # ============LICENSE_START===============================================
2 # Copyright (C) 2020-2023 Nordix Foundation. All rights reserved.
3 # Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.
4 # ========================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ============LICENSE_END=================================================
19 # This script gets policies spread over a number rics
20 # Intended for parallel processing
21 # Returns a string with result, either "0" for ok, or "1<fault description>"
26 from time import sleep
28 # disable warning about unverified https requests
29 from requests.packages import urllib3
31 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
33 #arg responseCode baseurl policyIdsFilePath proxy
36 if len(sys.argv) != 8:
37 print("1Expected 7 args, got "+str(len(sys.argv)-1)+ ". Args: responseCode baseurl policyIdsFilePath startId pids pidID proxy")
40 responseCode=int(sys.argv[1])
41 baseurl=str(sys.argv[2])
42 policyIdsFilePath=str(sys.argv[3])
43 startId=int(sys.argv[4])
45 pidId=int(sys.argv[6])
46 httpproxy=str(sys.argv[7])
49 if httpproxy != "NOPROXY":
58 with open(str(policyIdsFilePath)) as file:
60 if startId%pids == (pidId - 1):
64 url=str(baseurl+policyId.strip())
67 resp=requests.get(url, verify=False, timeout=90)
69 resp=requests.get(url, verify=False, timeout=90, proxies=proxydict)
71 except Exception as e1:
75 connect_retry_count += 1
77 print("1Get failed for id:"+policyId.strip()+ ", "+str(e1) + " "+traceback.format_exc())
80 if (connect_ok == True):
81 if (resp.status_code == None):
82 print("1Get failed for id:"+policyId.strip()+ ", expected response code: "+str(responseCode)+", got: None")
84 if (resp.status_code != responseCode):
85 if (resp.status_code >= 500) and (http_retry_count < 600 ) and (retry_cnt > 1):
90 print("1Get failed for id:"+policyId.strip()+ ", expected response code: "+str(responseCode)+", got: "+str(resp.status_code)+str(resp.raw))
95 print("0 http retries:"+str(http_retry_count) + ", connect retries: "+str(connect_retry_count))
98 except Exception as e:
100 traceback.print_exc()