volume['Display Name'].startswith('target'))
return filter(select, all)
- def cloud_init_wait(self):
+ def cloud_init_wait(self, instance):
"""
Wait for cloud-init to complete on the name_or_ip OpenStack instance.
"""
- ip = self.instance.get_floating_ip_or_ip()
+ ip = instance.get_floating_ip_or_ip()
log.debug('cloud_init_wait ' + ip)
client_args = {
'user_at_host': '@'.join((self.username, ip)),
if self.key_filename:
log.debug("using key " + self.key_filename)
client_args['key_filename'] = self.key_filename
- with safe_while(sleep=30, tries=100,
+ with safe_while(sleep=30, tries=30,
action="cloud_init_wait " + ip) as proceed:
success = False
# CentOS 6.6 logs in /var/log/clout-init-output.log
# CentOS 7.0 logs in /var/log/clout-init.log
- all_done = ("tail /var/log/cloud-init*.log ; " +
- " test -f /tmp/init.out && tail /tmp/init.out ; " +
- " grep '" + self.up_string + "' " +
- "/var/log/cloud-init*.log")
+ tail = ("tail --follow=name --retry"
+ " /var/log/cloud-init*.log /tmp/init.out")
while proceed():
try:
client = connection.connect(**client_args)
continue
log.exception('cloud_init_wait ' + ip)
raise
- log.debug('cloud_init_wait ' + all_done)
+ log.debug('cloud_init_wait ' + tail)
try:
- stdin, stdout, stderr = client.exec_command(all_done)
- stdout.channel.settimeout(5)
- out = stdout.read()
- log.debug('cloud_init_wait stdout ' + all_done + ' ' + out)
+ # get the I/O channel to iterate line by line
+ transport = client.get_transport()
+ channel = transport.open_session()
+ channel.get_pty()
+ channel.settimeout(240)
+ output = channel.makefile('r', 1)
+ channel.exec_command(tail)
+ for line in iter(output.readline, b''):
+ log.info(line.strip())
+ if self.up_string in line:
+ success = True
+ break
except socket.timeout as e:
client.close()
- log.debug('cloud_init_wait socket.timeout ' + all_done)
+ log.debug('cloud_init_wait socket.timeout ' + tail)
continue
except socket.error as e:
client.close()
- log.debug('cloud_init_wait socket.error ' + str(e) + ' ' + all_done)
+ log.debug('cloud_init_wait socket.error ' + str(e) + ' ' + tail)
continue
- log.debug('cloud_init_wait stderr ' + all_done +
- ' ' + stderr.read())
- if stdout.channel.recv_exit_status() == 0:
- success = True
client.close()
if success:
break
else:
identity = ''
if self.args.upload:
- upload = 'upload to : ' + self.args.archive_upload
+ upload = 'upload to : ' + self.args.archive_upload
else:
upload = ''
log.info("""
"""
Remove the floating ip from instance_id and delete it.
"""
- ip = TeuthologyOpenStack.get_floating_ip(instance_id)
+ ip = OpenStackInstance(instance_id).get_floating_ip()
if not ip:
return
misc.sh("openstack ip floating remove " + ip + " " + instance_id)
os.unlink(user_data)
self.instance = OpenStackInstance(self.args.name)
self.associate_floating_ip(self.instance['id'])
- return self.cloud_init_wait()
+ return self.cloud_init_wait(self.instance)
def teardown(self):
"""
instances = filter(
lambda instance: self.property in instance['Properties'],
self.list_instances())
- instances = [OpenStackInstance(i['ID'], i) for i in instances]
+ instances = [OpenStackInstance(i['ID']) for i in instances]
fqdns = []
try:
network = config['openstack'].get('network', '')
for instance in instances:
- name = self.ip2name(self.basename, instance.get_ip(network))
+ ip = instance.get_ip(network)
+ name = self.ip2name(self.basename, ip)
misc.sh("openstack server set " +
"--name " + name + " " +
instance['ID'])
if not misc.ssh_keyscan_wait(fqdn):
raise ValueError('ssh_keyscan_wait failed for ' + fqdn)
time.sleep(15)
- if not self.cloud_init_wait(fqdn):
- raise ValueError('clound_init_wait failed for ' + fqdn)
+ if not self.cloud_init_wait(instance):
+ raise ValueError('cloud_init_wait failed for ' + fqdn)
self.attach_volumes(name, resources_hint['volumes'])
fqdns.append(fqdn)
except Exception as e: