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>"
29 # disable warning about unverified https requests
30 from requests.packages import urllib3
32 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
34 #arg responsecode baseurl num_rics uuid startid count pids pid_id proxy
37 if len(sys.argv) != 10:
38 print("1Expected 9 args, got "+str(len(sys.argv)-1)+ ". Args: responsecode baseurl num_rics uuid startid count pids pid_id proxy")
41 responsecode=int(sys.argv[1])
42 baseurl=str(sys.argv[2])
43 num_rics=int(sys.argv[3])
45 start=int(sys.argv[5])
46 count=int(sys.argv[6])
48 pid_id=int(sys.argv[8])
49 httpproxy=str(sys.argv[9])
52 if httpproxy != "NOPROXY":
63 stop=count*num_rics+start
64 for i in range(start,stop):
65 if (i%pids == (pid_id-1)):
69 if ("/v2/policies/" in baseurl):
70 url=str(baseurl+uuid+str(i))
72 url=str(baseurl+"?id="+uuid+str(i))
75 resp=requests.get(url, verify=False, timeout=90)
77 resp=requests.get(url, verify=False, timeout=90, proxies=proxydict)
79 except Exception as e1:
83 connect_retry_count += 1
85 print("1Get failed for id:"+uuid+str(i)+ ", "+str(e1) + " "+traceback.format_exc())
88 if (cconnect_ok == True):
89 if (resp.status_code == None):
90 print("1Get failed for id:"+uuid+str(i)+ ", expected response code: "+str(responsecode)+", got: None")
92 if (resp.status_code != responsecode):
93 if (resp.status_code >= 500) and (http_retry_count < 600 ) and (retry_cnt > 1):
98 print("1Get failed for id:"+uuid+str(i)+ ", expected response code: "+str(responsecode)+", got: "+str(resp.status_code)+str(resp.raw))
103 print("0 http retries:"+str(http_retry_count) + ", connect retries: "+str(connect_retry_count))
106 except Exception as e:
108 traceback.print_exc()