blob: be15e924db672d507a73f35f6835911c9ce47fe3 [file] [log] [blame]
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001# ============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
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
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=================================================
16#
17
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>"
21
22import os
23import json
24import sys
25import requests
26
27# disable warning about unverified https requests
28from requests.packages import urllib3
29
30urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
31
32#arg responsecode baseurl num_rics startid count pids pid_id
33
34try:
35 if len(sys.argv) != 8:
36 print("1Expected 7 args, got "+str(len(sys.argv)-1)+ ". Args: responsecode baseurl num_rics startid count pids pid_id")
37 sys.exit()
38
39 responsecode=int(sys.argv[1])
40 baseurl=sys.argv[2]
41 num_rics=int(sys.argv[3])
42 start=int(sys.argv[4])
43 count=int(sys.argv[5])
44 pids=int(sys.argv[6])
45 pid_id=int(sys.argv[7])
46
47 stop=count*num_rics+start
48 for i in range(start,stop):
49 if (i%pids == (pid_id-1)):
50 url=str(baseurl+"?id="+str(i))
51 try:
52 resp=requests.delete(url, verify=False, timeout=90)
53 except Exception as e1:
54 print("1Delete failed for id:"+str(i)+ ", "+str(e1))
55 sys.exit()
56 if (resp.status_code != responsecode):
57 print("1Delete failed for id:"+str(i)+ ", expected response code: "+responsecode+", got: "+str(resp.status_code))
58 sys.exit()
59
60 print("0")
61 sys.exit()
62
63except Exception as e:
64 print("1"+str(e))
65sys.exit()