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 ###############################################################################
15 from ssh_client import SSHClient
16 from dha_adapters.libvirt_adapter import LibvirtAdapter
21 delete = common.delete
23 TRANSPLANT_FUEL_SETTINGS = 'transplant_fuel_settings.py'
24 BOOTSTRAP_ADMIN = '/usr/local/sbin/bootstrap_admin_node'
25 FUEL_CLIENT_CONFIG = '/etc/fuel/client/config.yaml'
26 PLUGINS_DIR = '~/plugins'
29 class InstallFuelMaster(object):
31 def __init__(self, dea_file, dha_file, fuel_ip, fuel_username,
32 fuel_password, fuel_node_id, iso_file, work_dir,
34 self.dea_file = dea_file
35 self.dha = LibvirtAdapter(dha_file)
36 self.fuel_ip = fuel_ip
37 self.fuel_username = fuel_username
38 self.fuel_password = fuel_password
39 self.fuel_node_id = fuel_node_id
40 self.iso_file = iso_file
41 self.iso_dir = os.path.dirname(self.iso_file)
42 self.work_dir = work_dir
43 self.fuel_plugins_dir = fuel_plugins_dir
44 self.file_dir = os.path.dirname(os.path.realpath(__file__))
45 self.ssh = SSHClient(self.fuel_ip, self.fuel_username,
49 log('Start Fuel Installation')
51 self.dha.node_power_off(self.fuel_node_id)
54 self.dha.node_zero_mbr(self.fuel_node_id)
56 self.dha.node_set_boot_order(self.fuel_node_id, ['disk', 'iso'])
59 self.proceed_with_installation()
60 except Exception as e:
61 self.post_install_cleanup()
64 def proceed_with_installation(self):
66 self.dha.node_eject_iso(self.fuel_node_id)
68 log('Insert ISO %s' % self.iso_file)
69 self.dha.node_insert_iso(self.fuel_node_id, self.iso_file)
71 self.dha.node_power_on(self.fuel_node_id)
73 log('Waiting for Fuel master to accept SSH')
74 self.wait_for_node_up()
76 log('Wait until Fuel menu is up')
77 fuel_menu_pid = self.wait_until_fuel_menu_up()
79 log('Inject our own astute.yaml settings')
80 self.inject_own_astute_yaml()
82 log('Let the Fuel deployment continue')
83 log('Found FUEL menu as PID %s, now killing it' % fuel_menu_pid)
84 self.ssh_exec_cmd('kill %s' % fuel_menu_pid, False)
86 log('Wait until installation complete')
87 self.wait_until_installation_completed()
89 log('Waiting for one minute for Fuel to stabilize')
92 self.delete_deprecated_fuel_client_config_from_fuel_6_1()
94 self.upload_plugin_files()
96 self.install_plugins()
98 self.post_install_cleanup()
100 log('Fuel Master installed successfully !')
102 def upload_plugin_files(self):
104 s.exec_cmd('mkdir %s' % PLUGINS_DIR)
105 if self.fuel_plugins_dir:
106 for f in glob.glob('%s/*.rpm' % self.fuel_plugins_dir):
107 s.scp_put(f, PLUGINS_DIR)
109 def install_plugins(self):
110 log('Installing Fuel Plugins')
112 r = s.exec_cmd('find %s -type f -name \'*.rpm\'' % PLUGINS_DIR)
113 for f in r.splitlines():
114 log('Found plugin %s, installing ...' % f)
115 r, e = s.exec_cmd('fuel plugins --install %s' % f, False)
116 if e and 'does not update installed package' not in r:
117 raise Exception('Installation of Fuel Plugin %s '
118 'failed: %s' % (f, e))
120 def wait_for_node_up(self):
124 for i in range(WAIT_LOOP):
129 except Exception as e:
130 log('Trying to SSH into Fuel VM %s ... sleeping %s seconds'
131 % (self.fuel_ip, SLEEP_TIME))
132 time.sleep(SLEEP_TIME)
137 raise Exception('Could not SSH into Fuel VM %s' % self.fuel_ip)
139 def wait_until_fuel_menu_up(self):
146 for i in range(WAIT_LOOP):
147 ret = self.ssh.exec_cmd(CMD)
148 fuel_menu_pid = self.get_fuel_menu_pid(ret, SEARCH)
149 if not fuel_menu_pid:
150 time.sleep(SLEEP_TIME)
153 if not fuel_menu_pid:
154 raise Exception('Could not find the Fuel Menu Process ID')
157 def get_fuel_menu_pid(self, printout, search):
158 for line in printout.splitlines():
159 if line.endswith(search):
160 return clean(line)[1]
162 def ssh_exec_cmd(self, cmd, check=True):
164 ret = self.ssh.exec_cmd(cmd, check=check)
167 def inject_own_astute_yaml(self):
169 s.exec_cmd('rm -rf %s' % self.work_dir, False)
170 s.exec_cmd('mkdir %s' % self.work_dir)
171 s.scp_put(self.dea_file, self.work_dir)
172 s.scp_put('%s/common.py' % self.file_dir, self.work_dir)
173 s.scp_put('%s/dea.py' % self.file_dir, self.work_dir)
174 s.scp_put('%s/transplant_fuel_settings.py'
175 % self.file_dir, self.work_dir)
176 log('Modifying Fuel astute')
177 s.run('python %s/%s %s/%s'
178 % (self.work_dir, TRANSPLANT_FUEL_SETTINGS,
179 self.work_dir, os.path.basename(self.dea_file)))
181 def wait_until_installation_completed(self):
184 CMD = 'ps -ef | grep %s | grep -v grep' % BOOTSTRAP_ADMIN
186 install_completed = False
188 for i in range(WAIT_LOOP):
189 ret = self.ssh.exec_cmd(CMD)
191 install_completed = True
194 time.sleep(SLEEP_TIME)
196 if not install_completed:
197 raise Exception('Fuel installation did not complete')
199 def post_install_cleanup(self):
200 log('Eject ISO file %s' % self.iso_file)
201 self.dha.node_eject_iso(self.fuel_node_id)
202 log('Remove ISO directory %s' % self.iso_dir)
205 def delete_deprecated_fuel_client_config_from_fuel_6_1(self):
207 response, error = s.exec_cmd('fuel -v', False)
209 'DEPRECATION WARNING' in error and
211 FUEL_CLIENT_CONFIG in error):
212 log('Delete deprecated fuel client config %s' % FUEL_CLIENT_CONFIG)
214 s.exec_cmd('rm %s' % FUEL_CLIENT_CONFIG, False)