Skip to content

Commit

Permalink
Spawn virtual machines using nodepool images on ci.centos.org
Browse files Browse the repository at this point in the history
We are going to be uploading nodepool images to the rdo-centos tenant
in RDO cloud. Since nodepool isn't going to be the one spawning the
virtual machines, we need to update our create-vm script so it knows
which image to use.

Change-Id: I85e3eed1436f7de3bae2d01a0b4adf23f1a0973c
Depends-On: I1236e01fe54309d5b59f28be21abe9da1c8695fa
  • Loading branch information
David Moreau Simard authored and Gerrit Code Review committed May 11, 2018
1 parent 516411b commit cbc0ea2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
10 changes: 7 additions & 3 deletions jenkins/jobs/scripts/create-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LOGSERVER="logs.rdoproject.org ansible_user=uploader"
CLOUD=${CLOUD:-rdo-cloud}
NETWORK=${NETWORK:-private}
NAME="${JOB_NAME_SIMPLIFIED}-${BUILD_NUMBER}"
IMAGE=${IMAGE:-template-centos7-weirdo-cr}
IMAGE=${IMAGE:-template-rdo-centos-7}
TIMEOUT=${TIMEOUT:-120}
FLAVOR=${FLAVOR:-rdo.m1.nodepool}
VM_INFO="${WORKSPACE}/vminfo.json"
Expand All @@ -29,6 +29,10 @@ pushd $WORKSPACE
source provision_venv/bin/activate
pip install ansible==2.3.1.0 ara shade
# Is there a better way ?
git clone https://github.com/rdo-infra/ci-config
nodepool_image=$(python ci-config/jenkins/jobs/scripts/get-nodepool-image.py "${CLOUD}" --pattern "${IMAGE}")
ara_location=$(python -c "import os,ara; print(os.path.dirname(ara.__file__))")
export ANSIBLE_HOST_KEY_CHECKING=False
export ANSIBLE_CALLBACK_PLUGINS="${ara_location}/plugins/callbacks"
Expand Down Expand Up @@ -100,7 +104,7 @@ cat <<EOF >create-vm.yml
state: "present"
cloud: "${CLOUD}"
name: "${NAME}"
image: "${IMAGE}"
image: "${nodepool_image}"
flavor: "${FLAVOR}"
network: "${NETWORK}"
reuse_ips: "no"
Expand All @@ -124,7 +128,7 @@ cat <<EOF >create-vm.yml
state: "present"
cloud: "${CLOUD}"
name: "${NAME}"
image: "${IMAGE}"
image: "${nodepool_image}"
flavor: "${FLAVOR}"
network: "${NETWORK}"
reuse_ips: "no"
Expand Down
61 changes: 61 additions & 0 deletions jenkins/jobs/scripts/get-nodepool-image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python
# Copyright Red Hat, Inc. All Rights Reserved.
#
# 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.
#

# Returns the latest nodepool image matching a pattern from a cloud

import argparse
import shade
import sys


def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('cloud', help='name of the cloud in clouds.yaml')
parser.add_argument('--pattern', help='image name pattern to look for',
default='template-rdo-centos-7')
args = parser.parse_args()
return args


def main():
args = get_args()
cloud = shade.openstack_cloud(cloud=args.cloud)

# List all images
images = cloud.list_images()

# From those images, only pick the ones that have been uploaded by nodepool
# and match our pattern
nodepool_images = [
image
for image in images
if 'nodepool_build_id' in image['properties'] and
args.pattern in image['name']
]

if nodepool_images:
# If there are any matches, alphabetically sort them by name
# This allows us to easily get the latest image since nodepool suffixes
# a unix timestamp at the end after the pattern.
nodepool_images = sorted(nodepool_images, key=lambda k: k['name'])
print(nodepool_images[-1]['name'])
sys.exit(0)
else:
sys.exit(1)


if __name__ == "__main__":
main()

0 comments on commit cbc0ea2

Please sign in to comment.