-
Notifications
You must be signed in to change notification settings - Fork 1
/
DestroyServerGroup.py
58 lines (48 loc) · 1.78 KB
/
DestroyServerGroup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
import adal
import requests
import os
import json
from time import sleep, ctime
import sys
import TestUtilities
subscription_id = os.environ['AZURE_SUBSCRIPTION_ID']
clouddriver_host = 'http://localhost:7002'
azure_creds = os.getenv('AZURE_CREDENTIALS', 'azure-cred1')
appName = 'pytest'
server_group_endpoint = 'https://management.azure.com/subscriptions/' + subscription_id + '/resourceGroups/' + appName + '-westus/providers/Microsoft.Network/networkSecurityGroups/' + appName + '-st1-d1?api-version=2016-03-30'
sg_destroy = '[ { "destroyServerGroup": { "cloudProvider" : "azure", "appName" : "' + appName + '", "serverGroupName" : "' + appName + '-st1-d1-v000", "regions": ["westus"], "credentials": "' + azure_creds + '" }} ]'
#
# DESTROY
#
# destroy a Server Group through clouddriver
url = clouddriver_host + '/ops'
print ctime(), ' - Destroy server group'
sys.stdout.flush()
r = requests.post(url, data = sg_destroy, headers={'Content-Type': 'application/json'})
print ctime(), ' - result: ', (r.text)
sys.stdout.flush()
#validate delete
print ctime(), ' - Validate Delete'
sys.stdout.flush()
authHeaders = TestUtilities.GetAzureAccessHeaders()
r = requests.get(server_group_endpoint, headers=authHeaders)
timeout = 10 * 60
loopCounter = 0
while (r.text.find('error') == -1 and loopCounter <= timeout):
sleep(5)
loopCounter += 5
r = requests.get(server_group_endpoint, headers=authHeaders)
if (loopCounter > timeout):
print ctime(), ' - Check operation timed out'
if (r.json()['error']['code'] == 'ResourceNotFound' or r.json()['error']['code'] == 'NotFound'):
print ctime(), ' - Server Group Destroyed'
print ctime(), ' - Test Passed'
else:
print ctime(), ' - Destroy Failed: ', r.text
print ctime(), ' - Test Failed'
#end delete validation
#
# DESTROY
#
sys.stdout.flush()