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.utils import SSHClient
13 from doctor_tests.installer.base import BaseInstaller
16 class ApexInstaller(BaseInstaller):
17 node_user_name = 'heat-admin'
18 cm_set_script = 'set_config.py'
19 cm_set_compute_script = 'set_compute_config.py'
20 cm_restore_script = 'restore_config.py'
21 cm_restore_compute_script = 'restore_compute_config.py'
23 def __init__(self, conf, log):
24 super(ApexInstaller, self).__init__(conf, log)
25 self.client = SSHClient(self.conf.installer.ip,
26 self.conf.installer.username,
27 key_filename=self.conf.installer.key_file,
30 self.controllers = list()
31 self.computes = list()
32 self.controller_clients = list()
33 self.compute_clients = list()
36 self.log.info('Setup Apex installer start......')
37 self.key_file = self.get_ssh_key_from_installer()
38 self._get_and_set_ips()
40 self.set_apply_patches()
44 self.restore_apply_patches()
45 for server in self.servers:
48 def get_ssh_key_from_installer(self):
49 key_path = '/home/stack/.ssh/id_rsa'
50 return self._get_ssh_key(self.client, key_path)
52 def _get_and_set_ips(self):
53 self.log.info('Get controller and compute ips from Apex installer'
56 command = "source stackrc; nova list | grep ' overcloud-'"
57 raw_ips_list = self._run_cmd_remote(self.client, command)
58 for line in raw_ips_list:
59 ip = line.split('ctlplane=', 1)[1].split(" ", 1)[0]
60 if 'overcloud-controller-' in line:
61 self.controllers.append(ip)
62 elif 'overcloud-novacompute-' in line:
63 self.computes.append(ip)
64 self.log.info('controller_ips:%s' % self.controllers)
65 self.log.info('compute_ips:%s' % self.computes)
67 def get_host_ip_from_hostname(self, hostname):
68 self.log.info('Get host ip by hostname=%s from Apex installer......'
71 hostname_in_undercloud = hostname.split('.')[0]
72 command = "source stackrc; nova show %s | awk '/ ctlplane network /{print $5}'" % (hostname_in_undercloud) # noqa
73 host_ips = self._run_cmd_remote(self.client, command)
76 def get_transport_url(self):
77 client = SSHClient(self.controllers[0], self.node_user_name,
78 key_filename=self.key_file)
80 command = 'sudo grep "^transport_url" /etc/nova/nova.conf'
81 ret, url = client.ssh(command)
83 raise Exception('Exec command to get host ip from controller(%s)'
84 'in Apex installer failed, ret=%s, output=%s'
85 % (self.controllers[0], ret, url))
86 # need to use ip instead of hostname
87 ret = (re.sub("@.*:", "@%s:" % self.controllers[0],
88 url[0].split("=", 1)[1]))
89 self.log.debug('get_transport_url %s' % ret)
92 def set_apply_patches(self):
93 self.log.info('Set apply patches start......')
95 restart_cm_cmd = 'sudo systemctl restart ' \
96 'openstack-ceilometer-notification.service'
98 if self.conf.test_case != 'fault_management':
99 restart_cm_cmd += ' openstack-nova-scheduler.service'
101 for node_ip in self.controllers:
102 client = SSHClient(node_ip, self.node_user_name,
103 key_filename=self.key_file)
104 self.controller_clients.append(client)
105 self._run_apply_patches(client,
109 if self.conf.test_case != 'fault_management':
110 restart_cm_cmd = 'sudo systemctl restart ' \
111 'openstack-nova-compute.service'
112 for node_ip in self.computes:
113 client = SSHClient(node_ip, self.node_user_name,
114 key_filename=self.key_file)
115 self.compute_clients.append(client)
116 self._run_apply_patches(client,
118 self.cm_set_compute_script)
120 if self.conf.test_case != 'fault_management':
123 def restore_apply_patches(self):
124 self.log.info('restore apply patches start......')
126 restart_cm_cmd = 'sudo systemctl restart ' \
127 'openstack-ceilometer-notification.service'
129 if self.conf.test_case != 'fault_management':
130 restart_cm_cmd += ' openstack-nova-scheduler.service'
132 for client in self.controller_clients:
133 self._run_apply_patches(client,
135 self.cm_restore_script)
137 if self.conf.test_case != 'fault_management':
138 restart_cm_cmd = 'sudo systemctl restart ' \
139 'openstack-nova-compute.service'
140 for client in self.compute_clients:
141 self._run_apply_patches(client,
143 self.cm_restore_compute_script)