1 ##############################################################################
2 # Copyright (c) 2017 ZTE Corporation and others.
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 ##############################################################################
11 from doctor_tests.common.constants import Inspector
12 from doctor_tests.common.utils import SSHClient
13 from doctor_tests.installer.base import BaseInstaller
16 class ApexInstaller(BaseInstaller):
17 node_user_name = 'heat-admin'
18 installer_username = 'stack'
19 cm_set_script = 'set_config.py'
20 nc_set_compute_script = 'set_compute_config.py'
21 cg_set_script = 'set_congress.py'
22 cm_restore_script = 'restore_config.py'
23 nc_restore_compute_script = 'restore_compute_config.py'
24 cg_restore_script = 'restore_congress.py'
25 ac_restart_script = 'restart_aodh.py'
26 ac_restore_script = 'restore_aodh.py'
29 def __init__(self, conf, log):
30 super(ApexInstaller, self).__init__(conf, log)
31 self.client = SSHClient(self.conf.installer.ip,
32 self.installer_username,
33 key_filename=self.conf.installer.key_file,
36 self.controllers = list()
37 self.computes = list()
40 self.log.info('Setup Apex installer start......')
41 self.key_file = self.get_ssh_key_from_installer()
42 self._get_overcloud_conf()
44 self.set_apply_patches()
48 self.restore_apply_patches()
49 for server in self.servers:
52 def get_ssh_key_from_installer(self):
53 key_path = '/home/stack/.ssh/id_rsa'
54 return self._get_ssh_key(self.client, key_path)
56 def _get_overcloud_conf(self):
57 self.log.info('Get overcloud config details from Apex installer'
60 command = "source stackrc; nova list | grep ' overcloud-'"
61 raw_ips_list = self._run_cmd_remote(self.client, command)
62 for line in raw_ips_list:
63 ip = line.split('ctlplane=', 1)[1].split(" ", 1)[0]
64 if 'overcloud-controller-' in line:
65 self.controllers.append(ip)
66 elif 'overcloud-novacompute-' in line:
67 self.computes.append(ip)
68 command = "grep docker /home/stack/deploy_command"
69 self.use_containers = self._check_cmd_remote(self.client, command)
70 self.log.info('controller_ips:%s' % self.controllers)
71 self.log.info('compute_ips:%s' % self.computes)
72 self.log.info('use_containers:%s' % self.use_containers)
74 def get_host_ip_from_hostname(self, hostname):
75 self.log.info('Get host ip by hostname=%s from Apex installer......'
78 hostname_in_undercloud = hostname.split('.')[0]
79 command = "source stackrc; nova show %s | awk '/ ctlplane network /{print $5}'" % (hostname_in_undercloud) # noqa
80 host_ips = self._run_cmd_remote(self.client, command)
83 def _set_docker_restart_cmd(self, service):
84 # There can be multiple instances running so need to restart all
85 cmd = "for container in `sudo docker ps | grep "
87 cmd += " | awk '{print $1}'`; do sudo docker restart $container; \
91 def set_apply_patches(self):
92 self.log.info('Set apply patches start......')
94 set_scripts = [self.cm_set_script]
96 if self.use_containers:
97 restart_cmd = (self._set_docker_restart_cmd(
98 "ceilometer-notification"))
99 set_scripts.append(self.ac_restart_script)
101 restart_cmd = 'sudo systemctl restart' \
102 ' openstack-ceilometer-notification.service'
104 if self.conf.test_case != 'fault_management':
105 if self.use_containers:
106 restart_cmd += self._set_docker_restart_cmd("nova-scheduler")
108 restart_cmd += ' openstack-nova-scheduler.service'
109 set_scripts.append(self.nc_set_compute_script)
111 if self.conf.inspector.type == Inspector.CONGRESS:
112 if self.use_containers:
113 restart_cmd += self._set_docker_restart_cmd("congress-server")
115 restart_cmd += ' openstack-congress-server.service'
116 set_scripts.append(self.cg_set_script)
118 for node_ip in self.controllers:
119 client = SSHClient(node_ip, self.node_user_name,
120 key_filename=self.key_file)
121 self._run_apply_patches(client,
127 self.log.info('Set apply patches start......')
129 if self.conf.test_case != 'fault_management':
130 if self.use_containers:
131 restart_cmd = self._set_docker_restart_cmd("nova")
133 restart_cmd = 'sudo systemctl restart' \
134 ' openstack-nova-compute.service'
135 for node_ip in self.computes:
136 client = SSHClient(node_ip, self.node_user_name,
137 key_filename=self.key_file)
138 self._run_apply_patches(client,
140 [self.nc_set_compute_script],
144 def restore_apply_patches(self):
145 self.log.info('restore apply patches start......')
147 restore_scripts = [self.cm_restore_script]
149 if self.use_containers:
150 restart_cmd = (self._set_docker_restart_cmd(
151 "ceilometer-notification"))
152 restore_scripts.append(self.ac_restore_script)
154 restart_cmd = 'sudo systemctl restart' \
155 ' openstack-ceilometer-notification.service'
157 if self.conf.test_case != 'fault_management':
158 if self.use_containers:
159 restart_cmd += self._set_docker_restart_cmd("nova-scheduler")
161 restart_cmd += ' openstack-nova-scheduler.service'
162 restore_scripts.append(self.nc_restore_compute_script)
164 if self.conf.inspector.type == Inspector.CONGRESS:
165 if self.use_containers:
166 restart_cmd += self._set_docker_restart_cmd("congress-server")
168 restart_cmd += ' openstack-congress-server.service'
169 restore_scripts.append(self.cg_restore_script)
171 for node_ip in self.controllers:
172 client = SSHClient(node_ip, self.node_user_name,
173 key_filename=self.key_file)
174 self._run_apply_patches(client,
179 if self.conf.test_case != 'fault_management':
180 if self.use_containers:
181 restart_cmd = self._set_docker_restart_cmd("nova-compute")
183 restart_cmd = 'sudo systemctl restart' \
184 ' openstack-nova-compute.service'
185 for node_ip in self.computes:
186 self._run_apply_patches(
188 [self.nc_restore_compute_script],