1 ###############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # szilard.cserey@ericsson.com
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 ###############################################################################
14 from ssh_client import SSHClient
15 from dha_adapters.libvirt_adapter import LibvirtAdapter
20 delete = common.delete
22 TRANSPLANT_FUEL_SETTINGS = 'transplant_fuel_settings.py'
23 BOOTSTRAP_ADMIN = '/usr/local/sbin/bootstrap_admin_node'
24 FUEL_CLIENT_CONFIG = '/etc/fuel/client/config.yaml'
27 class InstallFuelMaster(object):
29 def __init__(self, dea_file, dha_file, fuel_ip, fuel_username,
30 fuel_password, fuel_node_id, iso_file, work_dir):
31 self.dea_file = dea_file
32 self.dha = LibvirtAdapter(dha_file)
33 self.fuel_ip = fuel_ip
34 self.fuel_username = fuel_username
35 self.fuel_password = fuel_password
36 self.fuel_node_id = fuel_node_id
37 self.iso_file = iso_file
38 self.iso_dir = os.path.dirname(self.iso_file)
39 self.work_dir = work_dir
40 self.file_dir = os.path.dirname(os.path.realpath(__file__))
41 self.ssh = SSHClient(self.fuel_ip, self.fuel_username,
45 log('Start Fuel Installation')
47 self.dha.node_power_off(self.fuel_node_id)
50 self.dha.node_zero_mbr(self.fuel_node_id)
52 self.dha.node_set_boot_order(self.fuel_node_id, ['disk', 'iso'])
54 self.proceed_with_installation()
56 def proceed_with_installation(self):
58 self.dha.node_eject_iso(self.fuel_node_id)
60 log('Insert ISO %s' % self.iso_file)
61 self.dha.node_insert_iso(self.fuel_node_id, self.iso_file)
63 self.dha.node_power_on(self.fuel_node_id)
65 log('Waiting for Fuel master to accept SSH')
66 self.wait_for_node_up()
68 log('Wait until Fuel menu is up')
69 fuel_menu_pid = self.wait_until_fuel_menu_up()
71 log('Inject our own astute.yaml settings')
72 self.inject_own_astute_yaml()
74 log('Let the Fuel deployment continue')
75 log('Found FUEL menu as PID %s, now killing it' % fuel_menu_pid)
76 self.ssh_exec_cmd('kill %s' % fuel_menu_pid, False)
78 log('Wait until installation complete')
79 self.wait_until_installation_completed()
81 log('Waiting for one minute for Fuel to stabilize')
84 self.delete_deprecated_fuel_client_config_from_fuel_6_1()
86 self.post_install_cleanup()
88 log('Fuel Master installed successfully !')
90 def wait_for_node_up(self):
94 for i in range(WAIT_LOOP):
99 except Exception as e:
100 log('Trying to SSH into Fuel VM %s ... sleeping %s seconds'
101 % (self.fuel_ip, SLEEP_TIME))
102 time.sleep(SLEEP_TIME)
107 err('Could not SSH into Fuel VM %s' % self.fuel_ip)
109 def wait_until_fuel_menu_up(self):
116 for i in range(WAIT_LOOP):
117 ret = self.ssh.exec_cmd(CMD)
118 fuel_menu_pid = self.get_fuel_menu_pid(ret, SEARCH)
119 if not fuel_menu_pid:
120 time.sleep(SLEEP_TIME)
123 if not fuel_menu_pid:
124 err('Could not find the Fuel Menu Process ID')
127 def get_fuel_menu_pid(self, printout, search):
128 for line in printout.splitlines():
129 if line.endswith(search):
130 return clean(line)[1]
132 def ssh_exec_cmd(self, cmd, check=True):
134 ret = self.ssh.exec_cmd(cmd, check=check)
137 def inject_own_astute_yaml(self):
139 s.exec_cmd('rm -rf %s' % self.work_dir, False)
140 s.exec_cmd('mkdir %s' % self.work_dir)
141 s.scp_put(self.dea_file, self.work_dir)
142 s.scp_put('%s/common.py' % self.file_dir, self.work_dir)
143 s.scp_put('%s/dea.py' % self.file_dir, self.work_dir)
144 s.scp_put('%s/transplant_fuel_settings.py'
145 % self.file_dir, self.work_dir)
146 log('Modifying Fuel astute')
147 s.run('python %s/%s %s/%s'
148 % (self.work_dir, TRANSPLANT_FUEL_SETTINGS,
149 self.work_dir, os.path.basename(self.dea_file)))
151 def wait_until_installation_completed(self):
154 CMD = 'ps -ef | grep %s | grep -v grep' % BOOTSTRAP_ADMIN
156 install_completed = False
158 for i in range(WAIT_LOOP):
159 ret = self.ssh.exec_cmd(CMD)
161 install_completed = True
164 time.sleep(SLEEP_TIME)
166 if not install_completed:
167 self.post_install_cleanup()
168 err('Fuel installation did not complete')
170 def post_install_cleanup(self):
171 log('Eject ISO file %s' % self.iso_file)
172 self.dha.node_eject_iso(self.fuel_node_id)
173 log('Remove ISO directory %s' % self.iso_dir)
176 def delete_deprecated_fuel_client_config_from_fuel_6_1(self):
178 response, error = s.exec_cmd('fuel -v', False)
180 'DEPRECATION WARNING' in error and
182 FUEL_CLIENT_CONFIG in error):
183 log('Delete deprecated fuel client config %s' % FUEL_CLIENT_CONFIG)
185 s.exec_cmd('rm %s' % FUEL_CLIENT_CONFIG, False)