From 52fc5ba30b821243a8bed48b914d36ae725aced8 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Wed, 10 Oct 2012 10:38:55 -0700 Subject: [PATCH] Fix image update script. gate-dev script: * Use "jenkins" username image-update script: * Fix quoting around puppet class * Correctly determine devstack branches * Work around bogus mysql package in devstack * Update IMAGE_URL parsing logic * Delete image server when done * Add dry-run option to test local operations without launching a server Change-Id: Ifaabff3544b0d9f0f93c866ae1f8f964decfc1f8 --- devstack-vm-gate-dev.sh | 6 ++-- devstack-vm-update-image.py | 61 ++++++++++++++++++++++--------------- devstack-vm-update-image.sh | 2 +- utils.py | 2 +- 4 files changed, 43 insertions(+), 28 deletions(-) diff --git a/devstack-vm-gate-dev.sh b/devstack-vm-gate-dev.sh index 3901dc2e..c35c6f1e 100755 --- a/devstack-vm-gate-dev.sh +++ b/devstack-vm-gate-dev.sh @@ -8,6 +8,7 @@ cat >$WORKSPACE/test-env.sh < false, ssh_key => '%s' }" % JENKINS_SSH_KEY + PUPPET_CLASS = ("class {'openstack_project::slave_template': " + "install_users => false, ssh_key => '%s', }" % + JENKINS_SSH_KEY) else: - PUPPET_CLASS="class {'openstack_project::slave_template': }" + PUPPET_CLASS = "class {'openstack_project::slave_template': }" PROJECTS = ['openstack/nova', 'openstack/glance', @@ -74,10 +76,11 @@ def run_local(cmd, status=False, cwd='.', env={}): def git_branches(): branches = [] - for branch in run_local(['git', 'branch'], cwd=DEVSTACK).split("\n"): - if branch.startswith('*'): - branch = branch.split()[1] - branches.append(branch.strip()) + for branch in run_local(['git', 'branch', '-a'], cwd=DEVSTACK).split("\n"): + branch = branch.strip() + if not branch.startswith('remotes/origin'): + continue + branches.append(branch) return branches @@ -86,7 +89,7 @@ def tokenize(fn, tokens, distribution, comment=None): if 'dist:' in line and ('dist:%s' % distribution not in line): continue if 'qpid' in line: - continue # XXX + continue # TODO: explain why this is here if comment and comment in line: line = line[:line.rfind(comment)] line = line.strip() @@ -125,10 +128,14 @@ def local_prep(distribution): line = line[:line.rfind('#')] if line.endswith(';;'): line = line[:-2] - value = line.split('=', 1)[1].strip() - if value[0] == value[-1] == '"': - value = value[1:-1] - images += [x.strip() for x in value.split(',')] + line = line.split('=', 1)[1].strip() + if line.startswith('${IMAGE_URLS:-'): + line = line[len('${IMAGE_URLS:-'):] + if line.endswith('}'): + line = line[:-1] + if line[0] == line[-1] == '"': + line = line[1:-1] + images += [x.strip() for x in line.split(',')] branch_data['images'] = images branches.append(branch_data) return branches @@ -182,7 +189,7 @@ def bootstrap_server(provider, server, admin_pass, key): client.ssh("run puppet", "sudo puppet apply --modulepath=/root/openstack-ci-puppet/modules:" "/etc/puppet/modules " - "-e '%s'" % PUPPET_CLASS) + '-e "%s"' % PUPPET_CLASS) def configure_server(server, branches): @@ -282,8 +289,7 @@ def build_image(provider, client, base_image, image, # We made the snapshot, try deleting the server, but it's okay # if we fail. The reap script will find it and try again. try: - pass # XXX - # utils.delete_server(server) + utils.delete_server(server) except: print "Exception encountered deleting server:" traceback.print_exc() @@ -308,6 +314,11 @@ def build_image(provider, client, base_image, image, def main(): + if '-n' in sys.argv: + dry = True + else: + dry = False + db = vmdatabase.VMDatabase() provider = db.getProvider(PROVIDER_NAME) print "Working with provider %s" % provider.name @@ -322,16 +333,18 @@ def main(): print "Found flavor", flavor branches = local_prep(base_image.name) + pprint.pprint(branches) remote_base_image = client.images.find(name=base_image.external_id) - timestamp = int(time.time()) - remote_snap_image_name = ('%sdevstack-%s-%s.template.openstack.org' % - (DEVSTACK_GATE_PREFIX, - base_image.name, str(timestamp))) - remote_snap_image = build_image(provider, client, base_image, - remote_base_image, flavor, - remote_snap_image_name, - branches, timestamp) + if not dry: + timestamp = int(time.time()) + remote_snap_image_name = ('%sdevstack-%s-%s.template.openstack.org' % + (DEVSTACK_GATE_PREFIX, + base_image.name, str(timestamp))) + remote_snap_image = build_image(provider, client, base_image, + remote_base_image, flavor, + remote_snap_image_name, + branches, timestamp) if __name__ == '__main__': diff --git a/devstack-vm-update-image.sh b/devstack-vm-update-image.sh index 39a76557..734392d7 100755 --- a/devstack-vm-update-image.sh +++ b/devstack-vm-update-image.sh @@ -29,5 +29,5 @@ git remote update git remote prune origin cd $WORKSPACE -$GATE_SCRIPT_DIR/devstack-vm-update-image.py $1 +$GATE_SCRIPT_DIR/devstack-vm-update-image.py $1 $2 diff --git a/utils.py b/utils.py index 42456054..01d32447 100644 --- a/utils.py +++ b/utils.py @@ -177,6 +177,6 @@ def delete_server(server): except: print "Unable to delete keypair" traceback.print_exc() - + print "Deleting server", server.id server.delete()