Monty Taylor e14471dcc6 Update for ansible and puppet apply
Shade supports all of the TODO items in here now, so use it. Also,
we have ansible playbooks that do the work of running puppet - and since
we're on puppet apply now, we can use them.

Change-Id: I6f57e9a31bf835ef2e22db1f5531d92e99806cf4
2016-03-09 14:23:54 -06:00

103 lines
3.1 KiB
Python

#!/usr/bin/env python
# Update the base image that is used for devstack VMs.
# Copyright (C) 2011-2012 OpenStack LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
import time
import traceback
import socket
import paramiko
from sshclient import SSHClient
def iterate_timeout(max_seconds, purpose):
start = time.time()
count = 0
while (time.time() < start + max_seconds):
count += 1
yield count
time.sleep(2)
raise Exception("Timeout waiting for %s" % purpose)
def wait_for_resource(wait_resource):
last_progress = None
last_status = None
# It can take a _very_ long time for Rackspace 1.0 to save an image
for count in iterate_timeout(21600, "waiting for %s" % wait_resource):
try:
resource = wait_resource.manager.get(wait_resource.id)
except:
print "Unable to list resources, will retry"
traceback.print_exc()
time.sleep(5)
continue
# In Rackspace v1.0, there is no progress attribute while queued
if hasattr(resource, 'progress'):
if (last_progress != resource.progress
or last_status != resource.status):
print resource.status, resource.progress
last_progress = resource.progress
elif last_status != resource.status:
print resource.status
last_status = resource.status
if resource.status == 'ACTIVE':
return resource
def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
# HPcloud may return errno 111 for about 30 seconds after adding the IP
for count in iterate_timeout(timeout, "ssh access"):
try:
client = SSHClient(ip, username, **connect_kwargs)
break
except socket.error as e:
print "While testing ssh access:", e
time.sleep(5)
except paramiko.ssh_exception.AuthenticationException:
return None
ret, out = client.ssh("echo access okay")
if "access okay" in out:
return client
return None
def interpret_puppet_exitcodes(rc, output):
if rc == 0:
# success
return
elif rc == 1:
# rc==1 could be because it's disabled
# rc==1 could also mean there was a compilation failure
disabled = "administratively disabled" in output
if disabled:
msg = "puppet is disabled"
else:
msg = "puppet did not run"
raise Exception(msg)
elif rc == 2:
# success with changes
return
elif rc == 124:
# timeout
raise Exception("Puppet timed out")