1 # ============LICENSE_START===============================================
2 # Copyright (C) 2020 Nordix Foundation. All rights reserved.
3 # ========================================================================
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 # ============LICENSE_END=================================================
18 # This script delete policies spread over a number rics
19 # Intended for parallel processing
20 # Returns a string with result, either "0" for ok, or "1<fault description>"
28 # disable warning about unverified https requests
29 from requests.packages import urllib3
31 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
33 #arg responsecode baseurl num_rics uuid startid count pids pid_id proxy
36 if len(sys.argv) != 10:
37 print("1Expected 9 args, got "+str(len(sys.argv)-1)+ ". Args: responsecode baseurl num_rics uuid startid count pids pid_id proxy")
40 responsecode=int(sys.argv[1])
41 baseurl=str(sys.argv[2])
42 num_rics=int(sys.argv[3])
44 start=int(sys.argv[5])
45 count=int(sys.argv[6])
47 pid_id=int(sys.argv[8])
48 httpproxy=str(sys.argv[9])
51 if httpproxy != "NOPROXY":
62 stop=count*num_rics+start
63 for i in range(start,stop):
64 if (i%pids == (pid_id-1)):
68 if ("/v2/policies/" in baseurl):
69 url=str(baseurl+uuid+str(i))
71 url=str(baseurl+"?id="+uuid+str(i))
74 resp=requests.delete(url, verify=False, timeout=90)
76 resp=requests.delete(url, verify=False, timeout=90, proxies=proxydict)
78 except Exception as e1:
82 connect_retry_count += 1
84 print("1Delete failed for id:"+uuid+str(i)+ ", "+str(e1) + " "+traceback.format_exc())
87 if (cconnect_ok == True):
88 if (resp.status_code == None):
89 print("1Delete failed for id:"+uuid+str(i)+ ", expected response code: "+str(responsecode)+", got: None")
91 if (resp.status_code != responsecode):
92 if (resp.status_code >= 500) and (http_retry_count < 600 ) and (retry_cnt > 1):
97 print("1Delete failed for id:"+uuid+str(i)+ ", expected response code: "+str(responsecode)+", got: "+str(resp.status_code)+str(resp.raw))
102 print("0 http retries:"+str(http_retry_count) + ", connect retries: "+str(connect_retry_count))
105 except Exception as e:
107 traceback.print_exc()