support MCP installer
[doctor.git] / doctor_tests / installer / apex.py
1 ##############################################################################
2 # Copyright (c) 2017 ZTE 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 from doctor_tests.common.utils import SSHClient
10 from doctor_tests.installer.base import BaseInstaller
11
12
13 class ApexInstaller(BaseInstaller):
14     node_user_name = 'heat-admin'
15     cm_set_script = 'set_ceilometer.py'
16     cm_restore_script = 'restore_ceilometer.py'
17
18     def __init__(self, conf, log):
19         super(ApexInstaller, self).__init__(conf, log)
20         self.client = SSHClient(self.conf.installer.ip,
21                                 self.conf.installer.username,
22                                 look_for_keys=True)
23         self.key_file = None
24         self.controllers = list()
25         self.controller_clients = list()
26
27     def setup(self):
28         self.log.info('Setup Apex installer start......')
29
30         self.key_file = self.get_ssh_key_from_installer()
31         self.controllers = self.get_controller_ips()
32         self.create_flavor()
33         self.set_apply_patches()
34         self.setup_stunnel()
35
36     def cleanup(self):
37         self.restore_apply_patches()
38         for server in self.servers:
39             server.terminate()
40
41     def get_ssh_key_from_installer(self):
42         key_path = '/home/stack/.ssh/id_rsa'
43         return self._get_ssh_key(self.client, key_path)
44
45     def get_controller_ips(self):
46         self.log.info('Get controller ips from Apex installer......')
47
48         command = "source stackrc; " \
49                   "nova list | grep ' overcloud-controller-[0-9] ' " \
50                   "| sed -e 's/^.*ctlplane=//' |awk '{print $1}'"
51         controllers = self._run_cmd_remote(self.client, command)
52         self.log.info('Get controller_ips:%s from Apex installer'
53                       % controllers)
54         return controllers
55
56     def get_host_ip_from_hostname(self, hostname):
57         self.log.info('Get host ip by hostname=%s from Apex installer......'
58                       % hostname)
59
60         hostname_in_undercloud = hostname.split('.')[0]
61         command = "source stackrc; nova show %s | awk '/ ctlplane network /{print $5}'" % (hostname_in_undercloud)   # noqa
62         host_ips = self._run_cmd_remote(self.client, command)
63         return host_ips[0]
64
65     def set_apply_patches(self):
66         self.log.info('Set apply patches start......')
67
68         restart_cm_cmd = 'sudo systemctl restart ' \
69                          'openstack-ceilometer-notification.service'
70
71         for node_ip in self.controllers:
72             client = SSHClient(node_ip, self.node_user_name,
73                                key_filename=self.key_file)
74             self.controller_clients.append(client)
75             self._run_apply_patches(client,
76                                     restart_cm_cmd,
77                                     self.cm_set_script)
78
79     def restore_apply_patches(self):
80         self.log.info('restore apply patches start......')
81
82         restart_cm_cmd = 'sudo systemctl restart ' \
83                          'openstack-ceilometer-notification.service'
84
85         for client in self.controller_clients:
86             self._run_apply_patches(client,
87                                     restart_cm_cmd,
88                                     self.cm_restore_script)