1 ##############################################################################
2 # Copyright (c) 2019 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 ##############################################################################
9 from os.path import isfile
12 from doctor_tests.common.constants import is_fenix
13 from doctor_tests.common.utils import get_doctor_test_root_dir
14 from doctor_tests.common.utils import SSHClient
15 from doctor_tests.installer.base import BaseInstaller
18 class McpInstaller(BaseInstaller):
19 node_user_name = 'ubuntu'
21 cm_set_script = 'set_config.py'
22 nc_set_compute_script = 'set_compute_config.py'
23 fe_set_script = 'set_fenix.sh'
24 cm_restore_script = 'restore_config.py'
25 nc_restore_compute_script = 'restore_compute_config.py'
26 ac_restart_script = 'restart_aodh.py'
27 ac_restore_script = 'restore_aodh.py'
30 def __init__(self, conf, log):
31 super(McpInstaller, self).__init__(conf, log)
32 self.key_file = self.get_ssh_key_from_installer()
33 self.client = SSHClient(self.conf.installer.ip,
35 key_filename=self.key_file,
37 self.controllers = list()
38 self.controller_clients = list()
39 self.computes = list()
42 self.log.info('Setup MCP installer start......')
45 if is_fenix(self.conf):
46 self.set_apply_patches()
50 if is_fenix(self.conf):
51 self.restore_apply_patches()
52 for server in self.servers:
55 def get_ssh_key_from_installer(self):
56 self.log.info('Get SSH keys from MCP......')
58 # Default in path /var/lib/opnfv/mcp.rsa
59 ssh_key = '/root/.ssh/id_rsa'
60 mcp_key = '/var/lib/opnfv/mcp.rsa'
61 return mcp_key if isfile(mcp_key) else ssh_key
63 def _copy_overcloudrc_to_controllers(self):
64 for ip in self.controllers:
65 cmd = "scp overcloudrc %s@%s:" % (self.node_user_name, ip)
66 self._run_cmd_remote(self.client, cmd)
68 def get_node_ips(self):
69 self.log.info('Get node ips from Mcp installer......')
71 command = 'sudo salt "*" --out yaml pillar.get _param:single_address'
72 node_details = self._run_cmd_remote(self.client, command)
74 self.controllers = [line.split()[1] for line in node_details
75 if line.startswith("ctl")]
76 self.computes = [line.split()[1] for line in node_details
77 if line.startswith("cmp")]
79 self.log.info('controller_ips:%s' % self.controllers)
80 self.log.info('compute_ips:%s' % self.computes)
82 def get_host_ip_from_hostname(self, hostname):
83 command = "sudo salt --out yaml '%s*' " \
84 "pillar.get _param:single_address |" \
85 "awk '{print $2}'" % hostname
86 host_ips = self._run_cmd_remote(self.client, command)
89 def set_apply_patches(self):
90 self.log.info('Set apply patches start......')
93 set_scripts = [self.cm_set_script]
95 restart_cmd = 'sudo systemctl restart' \
96 ' ceilometer-agent-notification.service'
98 if self.conf.test_case != 'fault_management':
99 if is_fenix(self.conf):
100 set_scripts.append(self.fe_set_script)
101 testdir = get_doctor_test_root_dir()
102 fenix_files = ["Dockerfile", "run"]
103 restart_cmd += ' nova-scheduler.service'
104 set_scripts.append(self.nc_set_compute_script)
106 for node_ip in self.controllers:
107 client = SSHClient(node_ip, self.node_user_name,
108 key_filename=self.key_file)
109 if fenix_files is not None:
110 for fenix_file in fenix_files:
111 src_file = '{0}/{1}/{2}'.format(testdir,
114 client.scp(src_file, fenix_file)
115 self._run_apply_patches(client,
121 self.log.info('Set apply patches start......')
123 if self.conf.test_case != 'fault_management':
124 restart_cmd = 'sudo systemctl restart nova-compute.service'
125 for node_ip in self.computes:
126 client = SSHClient(node_ip, self.node_user_name,
127 key_filename=self.key_file)
128 self._run_apply_patches(client,
130 [self.nc_set_compute_script],
134 def restore_apply_patches(self):
135 self.log.info('restore apply patches start......')
137 restore_scripts = [self.cm_restore_script]
139 restore_scripts.append(self.ac_restore_script)
140 restart_cmd = 'sudo systemctl restart' \
141 ' ceilometer-agent-notification.service'
143 if self.conf.test_case != 'fault_management':
144 restart_cmd += ' nova-scheduler.service'
145 restore_scripts.append(self.nc_restore_compute_script)
147 for node_ip in self.controllers:
148 client = SSHClient(node_ip, self.node_user_name,
149 key_filename=self.key_file)
150 self._run_apply_patches(client,
155 if self.conf.test_case != 'fault_management':
156 restart_cmd = 'sudo systemctl restart nova-compute.service'
157 for node_ip in self.computes:
158 client = SSHClient(node_ip, self.node_user_name,
159 key_filename=self.key_file)
160 self._run_apply_patches(
162 [self.nc_restore_compute_script],