blob: e647118dbb85a6d4b3cdc51523905cf632f9fcc7 [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
BjornMagnussonXA048aaa12020-06-04 07:48:37 +020026import traceback
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020027
28# disable warning about unverified https requests
29from requests.packages import urllib3
30
31urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
32
BjornMagnussonXAad047782020-06-08 15:54:11 +020033#arg responsecode baseurl num_rics uuid startid count pids pid_id
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020034
35try:
BjornMagnussonXAad047782020-06-08 15:54:11 +020036 if len(sys.argv) != 9:
37 print("1Expected 8 args, got "+str(len(sys.argv)-1)+ ". Args: responsecode baseurl num_rics uuid startid count pids pid_id")
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020038 sys.exit()
39
40 responsecode=int(sys.argv[1])
41 baseurl=sys.argv[2]
42 num_rics=int(sys.argv[3])
BjornMagnussonXAad047782020-06-08 15:54:11 +020043 uuid=sys.argv[4]
44 start=int(sys.argv[5])
45 count=int(sys.argv[6])
46 pids=int(sys.argv[7])
47 pid_id=int(sys.argv[8])
48
49 if uuid == "NOUUID":
50 uuid=""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020051
52 stop=count*num_rics+start
53 for i in range(start,stop):
54 if (i%pids == (pid_id-1)):
BjornMagnussonXAad047782020-06-08 15:54:11 +020055 url=str(baseurl+"?id="+uuid+str(i))
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020056 try:
57 resp=requests.delete(url, verify=False, timeout=90)
58 except Exception as e1:
BjornMagnussonXAad047782020-06-08 15:54:11 +020059 print("1Delete failed for id:"+uuid+str(i)+ ", "+str(e1) + " "+traceback.format_exc())
BjornMagnussonXA048aaa12020-06-04 07:48:37 +020060 sys.exit()
61 if (resp.status_code == None):
BjornMagnussonXAad047782020-06-08 15:54:11 +020062 print("1Delete failed for id:"+uuid+str(i)+ ", expected response code: "+responsecode+", got: None")
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020063 sys.exit()
64 if (resp.status_code != responsecode):
BjornMagnussonXAad047782020-06-08 15:54:11 +020065 print("1Delete failed for id:"+uuid+str(i)+ ", expected response code: "+responsecode+", got: "+str(resp.status_code))
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020066 sys.exit()
67
68 print("0")
69 sys.exit()
70
71except Exception as e:
72 print("1"+str(e))
73sys.exit()