Support Apex with services in containers
[doctor.git] / doctor_tests / installer / common / restart_aodh.py
1 ##############################################################################
2 # Copyright (c) 2018 Nokia Corporation and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 import socket
10 import subprocess
11
12
13 def restart_aodh_event_alarm():
14     # Restart aodh-evaluator docker with localhost as controller host ip
15     # This makes our alarm sending look the same as without container
16
17     orig_docker_id = subprocess.check_output("docker ps | grep aodh-evaluator "
18                                              "| awk '{print $1}'", shell=True)
19     get_docker_startup = (
20         'docker inspect --format=\'{{range .Config.Env}} -e "{{.}}" {{end}} '
21         '{{range .Mounts}} -v {{.Source}}:{{.Destination}}{{if .Mode}}:'
22         '{{.Mode}}{{end}}{{end}} -ti {{.Config.Image}}\''
23     )
24     docker_start = subprocess.check_output("%s %s" % (get_docker_startup,
25                                            orig_docker_id), shell=True)
26     with open("orig_docker_id", 'w') as oid:
27         oid.write(orig_docker_id)
28     oid.close()
29     subprocess.check_output("docker stop %s" % orig_docker_id, shell=True)
30     ip = socket.gethostbyname(socket.gethostname())
31
32     ae_start = '-d --add-host="localhost:%s" %s' % (ip, docker_start)
33     subprocess.check_output("docker run %s" % ae_start, shell=True)
34     new_docker_id = subprocess.check_output("docker ps | grep aodh-evaluator "
35                                             " | awk '{print $1}'", shell=True)
36     if orig_docker_id == new_docker_id:
37         raise Exception("Docker ids matching!")
38     with open("new_docker_id", 'w') as nid:
39         nid.write(new_docker_id)
40     nid.close()
41
42 restart_aodh_event_alarm()