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......')
38 self.key_file = self.get_ssh_key_from_installer()
39 self._get_and_set_ips()
41 self.set_apply_patches()
45 self.restore_apply_patches()
46 for server in self.servers:
49 def get_ssh_key_from_installer(self):
50 key_path = '/home/stack/.ssh/id_rsa'
51 return self._get_ssh_key(self.client, key_path)
53 def _get_and_set_ips(self):
54 self.log.info('Get controller and compute ips from Apex installer'
57 command = "source stackrc; nova list | grep ' overcloud-'"
58 raw_ips_list = self._run_cmd_remote(self.client, command)
59 for line in raw_ips_list:
60 ip = line.split('ctlplane=', 1)[1].split(" ", 1)[0]
61 if 'overcloud-controller-' in line:
62 self.controllers.append(ip)
63 elif 'overcloud-novacompute-' in line:
64 self.computes.append(ip)
65 self.log.info('controller_ips:%s' % self.controllers)
66 self.log.info('compute_ips:%s' % self.computes)
68 def get_host_ip_from_hostname(self, hostname):
69 self.log.info('Get host ip by hostname=%s from Apex installer......'
72 hostname_in_undercloud = hostname.split('.')[0]
73 command = "source stackrc; nova show %s | awk '/ ctlplane network /{print $5}'" % (hostname_in_undercloud) # noqa
74 host_ips = self._run_cmd_remote(self.client, command)
77 def get_transport_url(self):
78 client = SSHClient(self.controllers[0], self.node_user_name,
79 key_filename=self.key_file)
81 command = 'sudo grep "^transport_url" /etc/nova/nova.conf'
82 ret, url = client.ssh(command)
84 raise Exception('Exec command to get host ip from controller(%s)'
85 'in Apex installer failed, ret=%s, output=%s'
86 % (self.controllers[0], ret, url))
87 # need to use ip instead of hostname
88 ret = (re.sub("@.*:", "@%s:" % self.controllers[0],
89 url[0].split("=", 1)[1]))
90 self.log.debug('get_transport_url %s' % ret)
93 def set_apply_patches(self):
94 self.log.info('Set apply patches start......')
96 restart_cm_cmd = 'sudo systemctl restart ' \
97 'openstack-ceilometer-notification.service'
99 if self.conf.test_case != 'fault_management':
100 restart_cm_cmd += ' openstack-nova-scheduler.service'
102 for node_ip in self.controllers:
103 client = SSHClient(node_ip, self.node_user_name,
104 key_filename=self.key_file)
105 self.controller_clients.append(client)
106 self._run_apply_patches(client,
110 if self.conf.test_case != 'fault_management':
111 restart_cm_cmd = 'sudo systemctl restart ' \
112 'openstack-nova-compute.service'
113 for node_ip in self.computes:
114 client = SSHClient(node_ip, self.node_user_name,
115 key_filename=self.key_file)
116 self.compute_clients.append(client)
117 self._run_apply_patches(client,
119 self.cm_set_compute_script)
121 if self.conf.test_case != 'fault_management':
124 def restore_apply_patches(self):
125 self.log.info('restore apply patches start......')
127 restart_cm_cmd = 'sudo systemctl restart ' \
128 'openstack-ceilometer-notification.service'
130 if self.conf.test_case != 'fault_management':
131 restart_cm_cmd += ' openstack-nova-scheduler.service'
133 for client in self.controller_clients:
134 self._run_apply_patches(client,
136 self.cm_restore_script)
138 if self.conf.test_case != 'fault_management':
139 restart_cm_cmd = 'sudo systemctl restart ' \
140 'openstack-nova-compute.service'
141 for client in self.compute_clients:
142 self._run_apply_patches(client,
144 self.cm_restore_compute_script)