[sdc] docker file fix for cassandra
[sdc.git] / openecomp-be / lib / openecomp-sdc-translator-lib / openecomp-sdc-translator-core / src / test / resources / mock / services / heattotosca / securityrulestoportconnection / securityRulesToPortGetResource / inputfiles / wait_for_resources.py
1 import argparse
2 import json
3 import netifaces
4 import os
5 import sys
6 import time
7
8 TIME_INTERVAL = 10
9
10
11 def parse_json_file(json_path):
12     with open(json_path, 'r') as json_file:
13         data = json.load(json_file)
14     return data
15
16
17 def check_network_interfaces():
18     for interface in netifaces.interfaces():
19         if(sys.platform != 'win32' or netifaces.ifaddresses(interface)[-1000][0]['addr'] != '00:00:00:00:00:00:00:e0'):
20             while 2 not in netifaces.ifaddresses(interface).keys() and 23 not in netifaces.ifaddresses(interface).keys():
21                 print "Still waiting for interface:", interface
22                 time.sleep(TIME_INTERVAL)
23
24
25 def check_connectivity():
26     if sys.platform.startswith('linux'):
27         ping_str = "ping -c 1 "
28     elif sys.platform == 'cygwin' or sys.platform == 'win32':
29         ping_str = "ping -n 1 "
30
31     while os.system(ping_str + component_ip) != 0:
32         print "No connectivity to", component_ip, "waiting", TIME_INTERVAL, "seconds"
33         time.sleep(TIME_INTERVAL)
34
35
36 def check_cinder_mounts():
37     if sys.platform.startswith('linux'):
38         meta_data = parse_json_file('/meta.js')
39     elif sys.platform == 'cygwin' or sys.platform == 'win32':
40         meta_data = parse_json_file('c:\\meta.js')
41
42     cinder_count = 0
43
44     for info in meta_data:
45         if info.startswith('mount'):
46             cinder_count += 1
47
48     if sys.platform.startswith('linux'):
49         cinder_attached = os.popen('ls /dev/disk/by-id/virtio* | wc -l').read()
50     elif sys.platform == 'cygwin' or sys.platform == 'win32':
51         cinder_attached = os.popen("wmic diskdrive get DeviceID | find /i \"PHYSICALDRIVE\" | find /V \"0\" /C").read()
52
53     while (int(cinder_attached) < cinder_count) and (cinder_count != 0):
54         print "Missing a cinder mount, waiting", TIME_INTERVAL, "seconds"
55         time.sleep(TIME_INTERVAL)
56
57         if sys.platform.startswith('linux'):
58             cinder_attached = os.popen('ls /dev/disk/by-id/virtio* | wc -l').read()
59
60         elif sys.platform == 'cygwin' or sys.platform == 'win32':
61             cinder_attached = os.popen(
62                 "wmic diskdrive get DeviceID | find /i \"PHYSICALDRIVE\" | find /V \"0\" /C").read()
63
64         if int(cinder_attached) == cinder_count:
65             print "All cinder are attached and ready to be formatted and mounted"
66
67
68 def main():
69     check_network_interfaces()
70     check_cinder_mounts()
71
72     if component_ip is not None:
73         check_connectivity()
74
75     print "All resources are ready"
76
77
78 if __name__ == "__main__":
79     parser = argparse.ArgumentParser(description='This script is waiting for network and volume resources to come up')
80     parser.add_argument('-m', '--component_ip', metavar='component_ip', type=str, help='The component ip', required=False)
81     args = parser.parse_args()
82     component_ip = args.component_ip
83     globals().update(args.__dict__)
84     main()