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 ##############################################################################
12 from doctor_tests.common.constants import Inspector
13 from doctor_tests.common.utils import SSHClient
14 from doctor_tests.installer.base import BaseInstaller
17 class ApexInstaller(BaseInstaller):
18 node_user_name = 'heat-admin'
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'
26 def __init__(self, conf, log):
27 super(ApexInstaller, self).__init__(conf, log)
28 self.client = SSHClient(self.conf.installer.ip,
29 self.conf.installer.username,
30 key_filename=self.conf.installer.key_file,
33 self.controllers = list()
34 self.computes = list()
35 self.controller_clients = list()
36 self.compute_clients = list()
39 self.log.info('Setup Apex installer start......')
40 self.key_file = self.get_ssh_key_from_installer()
41 self._get_and_set_ips()
43 self.set_apply_patches()
47 self.restore_apply_patches()
48 for server in self.servers:
51 def get_ssh_key_from_installer(self):
52 key_path = '/home/stack/.ssh/id_rsa'
53 return self._get_ssh_key(self.client, key_path)
55 def _get_and_set_ips(self):
56 self.log.info('Get controller and compute ips from Apex installer'
59 command = "source stackrc; nova list | grep ' overcloud-'"
60 raw_ips_list = self._run_cmd_remote(self.client, command)
61 for line in raw_ips_list:
62 ip = line.split('ctlplane=', 1)[1].split(" ", 1)[0]
63 if 'overcloud-controller-' in line:
64 self.controllers.append(ip)
65 elif 'overcloud-novacompute-' in line:
66 self.computes.append(ip)
67 self.log.info('controller_ips:%s' % self.controllers)
68 self.log.info('compute_ips:%s' % self.computes)
70 def get_host_ip_from_hostname(self, hostname):
71 self.log.info('Get host ip by hostname=%s from Apex installer......'
74 hostname_in_undercloud = hostname.split('.')[0]
75 command = "source stackrc; nova show %s | awk '/ ctlplane network /{print $5}'" % (hostname_in_undercloud) # noqa
76 host_ips = self._run_cmd_remote(self.client, command)
79 def get_transport_url(self):
80 client = SSHClient(self.controllers[0], self.node_user_name,
81 key_filename=self.key_file)
83 command = 'sudo grep "^transport_url" /etc/nova/nova.conf'
84 ret, url = client.ssh(command)
86 raise Exception('Exec command to get host ip from controller(%s)'
87 'in Apex installer failed, ret=%s, output=%s'
88 % (self.controllers[0], ret, url))
89 # need to use ip instead of hostname
90 ret = (re.sub("@.*:", "@%s:" % self.controllers[0],
91 url[0].split("=", 1)[1]))
92 self.log.debug('get_transport_url %s' % ret)
95 def set_apply_patches(self):
96 self.log.info('Set apply patches start......')
98 restart_cmd = 'sudo systemctl restart' \
99 ' openstack-ceilometer-notification.service'
101 set_scripts = [self.cm_set_script]
103 if self.conf.test_case != 'fault_management':
104 restart_cmd += ' openstack-nova-scheduler.service'
106 if self.conf.inspector.type == Inspector.CONGRESS:
107 restart_cmd += ' openstack-congress-server.service'
108 set_scripts.append(self.cg_set_script)
110 for node_ip in self.controllers:
111 client = SSHClient(node_ip, self.node_user_name,
112 key_filename=self.key_file)
113 self.controller_clients.append(client)
114 self._run_apply_patches(client,
118 if self.conf.test_case != 'fault_management':
119 restart_cmd = 'sudo systemctl restart' \
120 ' openstack-nova-compute.service'
121 for node_ip in self.computes:
122 client = SSHClient(node_ip, self.node_user_name,
123 key_filename=self.key_file)
124 self.compute_clients.append(client)
125 self._run_apply_patches(client,
127 [self.nc_set_compute_script])
129 if self.conf.test_case != 'fault_management':
132 def restore_apply_patches(self):
133 self.log.info('restore apply patches start......')
135 restart_cmd = 'sudo systemctl restart' \
136 ' openstack-ceilometer-notification.service'
138 restore_scripts = [self.cm_restore_script]
140 if self.conf.test_case != 'fault_management':
141 restart_cmd += ' openstack-nova-scheduler.service'
143 if self.conf.inspector.type == Inspector.CONGRESS:
144 restart_cmd += ' openstack-congress-server.service'
145 restore_scripts.append(self.cg_restore_script)
147 for client in self.controller_clients:
148 self._run_apply_patches(client,
152 if self.conf.test_case != 'fault_management':
153 restart_cmd = 'sudo systemctl restart' \
154 ' openstack-nova-compute.service'
155 for client in self.compute_clients:
156 self._run_apply_patches(client,
158 [self.nc_restore_compute_script])