
* change BASE_RELEASE and TARGET_RELEASE in grenaderc * remove work-arounds from devstack.localrc.target * remove upgrade steps from the upgrade-* scripts * change references to release names in variables to BASE_ and TARGET_ * remove Javelin check from check-sanity, will return in verify-javelin in https://review.openstack.org/#/c/26257/ Fixes bug 1175340 Change-Id: If1523c73ebefeaf3d3e3efdfbc053f47365d123a
153 lines
4.8 KiB
Bash
Executable File
153 lines
4.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# ``setup-javelin``
|
|
|
|
# Keep track of the grenade directory
|
|
GRENADE_DIR=$(cd $(dirname "$0") && pwd)
|
|
|
|
# Import common functions
|
|
source $GRENADE_DIR/functions
|
|
|
|
# Determine what system we are running on. This provides ``os_VENDOR``,
|
|
# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
|
|
# and ``DISTRO``
|
|
GetDistro
|
|
|
|
# Source params
|
|
source $GRENADE_DIR/grenaderc
|
|
|
|
# For debugging
|
|
set -o xtrace
|
|
|
|
|
|
# Create Javelin Project
|
|
# ======================
|
|
|
|
# Get DevStack Configuration
|
|
source $BASE_DEVSTACK_DIR/openrc admin admin
|
|
|
|
# Our configuration
|
|
source $GRENADE_DIR/javelin.conf
|
|
|
|
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
|
|
|
|
|
|
# Add To Keystone
|
|
# ---------------
|
|
|
|
function get_id () {
|
|
echo `"$@" | awk '/ id / { print $4 }'`
|
|
}
|
|
|
|
# Create javelin project and user
|
|
JAVELIN_TENANT=$(keystone tenant-list | awk "/ $JPROJECT / { print \$2 }")
|
|
[[ -z "$JAVELIN_TENANT" ]] && \
|
|
JAVELIN_TENANT=$(get_id keystone tenant-create --name=$JPROJECT)
|
|
|
|
JAVELIN_USER=$(keystone user-list | awk "/ $JUSER / { print \$2 }")
|
|
[[ -z "$JAVELIN_USER" ]] && \
|
|
JAVELIN_USER=$(get_id keystone user-create --name=$JUSER \
|
|
--pass="$JPASSWORD" \
|
|
--email=bob@javelin.org)
|
|
|
|
MEMBER_ROLE=$(keystone role-list | awk "/ Member / { print \$2 }")
|
|
keystone user-role-add --tenant_id $JAVELIN_TENANT \
|
|
--user_id $JAVELIN_USER \
|
|
--role_id $MEMBER_ROLE
|
|
|
|
|
|
# Switch Identities
|
|
# -----------------
|
|
|
|
source $BASE_DEVSTACK_DIR/openrc $JPROJECT $JUSER
|
|
export OS_PASSWORD=$JPASSWORD
|
|
|
|
|
|
# Add Custom Image
|
|
# ----------------
|
|
|
|
# It's really cirros with our own name
|
|
# Assumes DevStack.$BASE has already set this up
|
|
CIRROS_IMAGE=${DEFAULT_IMAGE_NAME:-cirros-0.3.1-x86_64-uec}
|
|
CIRROS_DIR=$BASE_DEVSTACK_DIR/files/images/$CIRROS_IMAGE
|
|
KERNEL=$CIRROS_DIR/${CIRROS_IMAGE/uec/}vmlinuz
|
|
RAMDISK=$CIRROS_DIR/${CIRROS_IMAGE/uec/}initrd
|
|
ROOTDISK=$CIRROS_DIR/${CIRROS_IMAGE/uec/}blank.img
|
|
JAVELIN_IMAGE=${CIRROS_IMAGE/cirros/javelin}
|
|
|
|
# Old glance client cuts off name field, use nova image-list for now
|
|
IMAGE=$(nova image-list | awk "/ $JAVELIN_IMAGE.img / { print \$2 }")
|
|
if [[ -z "$IMAGE" ]]; then
|
|
RVAL=$(glance add --silent-upload name=$JAVELIN_IMAGE-kernel is_public=True container_format=aki disk_format=aki <"$KERNEL")
|
|
KERNEL_ID=$(echo $RVAL | cut -d":" -f2 | tr -d " ")
|
|
RVAL=$(glance add --silent-upload name=$JAVELIN_IMAGE-ramdisk is_public=True container_format=ari disk_format=ari <"$RAMDISK")
|
|
RAMDISK_ID=$(echo $RVAL | cut -d":" -f2 | tr -d " ")
|
|
glance add name=$JAVELIN_IMAGE.img is_public=True container_format=ami disk_format=ami ${KERNEL_ID:+kernel_id=$KERNEL_ID} ${RAMDISK_ID:+ramdisk_id=$RAMDISK_ID} < "${ROOTDISK}"
|
|
|
|
IMAGE=$(nova image-list | awk "/ $JAVELIN_IMAGE.img / { print \$2 }")
|
|
die_if_not_set $LINENO IMAGE "Failure getting image"
|
|
fi
|
|
|
|
|
|
# Add Custom Security Group
|
|
# -------------------------
|
|
|
|
# Create our secgroup
|
|
if ! nova secgroup-list | grep -q $JAVELIN_SECGROUP; then
|
|
nova secgroup-create $JAVELIN_SECGROUP "$JPROJECT access rules"
|
|
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova secgroup-list | grep -q $JAVELIN_SECGROUP; do sleep 1; done"; then
|
|
die $LINENO "$JAVELIN_SECGROUP security group not created"
|
|
fi
|
|
fi
|
|
|
|
# Add some rules
|
|
if ! nova secgroup-list-rules $JAVELIN_SECGROUP | grep tcp | grep -q 22; then
|
|
nova secgroup-add-rule $JAVELIN_SECGROUP icmp -1 -1 0.0.0.0/0
|
|
nova secgroup-add-rule $JAVELIN_SECGROUP tcp 22 22 0.0.0.0/0
|
|
fi
|
|
|
|
|
|
# Identify A Flavor
|
|
# -----------------
|
|
|
|
FLAVOR=`nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | get_field 1`
|
|
if [[ -z "$FLAVOR" ]]; then
|
|
# Grab the first flavor in the list to launch if default doesn't exist
|
|
FLAVOR=`nova flavor-list | head -n 4 | tail -n 1 | get_field 1`
|
|
fi
|
|
|
|
|
|
# Create a Volume
|
|
# ---------------
|
|
|
|
if ! nova volume-list | grep -q $JAVELIN_VOLUME; then
|
|
nova volume-create --display_name=$JAVELIN_VOLUME 1
|
|
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $JAVELIN_VOLUME | grep -q available; do sleep 1; done"; then
|
|
die $LINENO "$JAVELIN_VOLUME volume not created"
|
|
fi
|
|
fi
|
|
|
|
# Create An Instance
|
|
# ------------------
|
|
|
|
# Boot an instance
|
|
BOOT_TXT=$(nova boot --flavor "$FLAVOR" --image "$IMAGE" $JSERVER | awk "/adminPass/ { print \$2 \"=\" \$4 };/ id / { print \$2 \"=\" \$4 }"; exit ${PIPESTATUS[0]})
|
|
ret=$?
|
|
if [[ ! $ret = 0 ]]; then
|
|
die $LINENO "Failed to boot $JSERVER"
|
|
fi
|
|
eval $BOOT_TXT
|
|
|
|
# Check that the status is active within ACTIVE_TIMEOUT seconds
|
|
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $id | grep status | grep -q ACTIVE; do sleep 1; done"; then
|
|
die $LINENO "server didn't become active!"
|
|
fi
|
|
|
|
# Put some stuff in Swift
|
|
# -----------------------
|
|
|
|
swift upload javelin /etc/hosts
|
|
if ! swift list javelin | grep -q hosts; then
|
|
die $LINENO "Swift upload failed"
|
|
fi
|