Add template to create test file
This commit creates a template to manage the nova test file. It was converted to a template to make it more configurable. It deletes the old static file.
This commit is contained in:
@@ -4,9 +4,7 @@
|
||||
#
|
||||
|
||||
# deploy a script that can be used to test nova
|
||||
file { '/tmp/test_nova.sh':
|
||||
source => 'puppet:///modules/openstack/nova_test.sh',
|
||||
}
|
||||
class { 'openstack::test_file': }
|
||||
|
||||
####### shared variables ##################
|
||||
|
||||
|
@@ -1,30 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# assumes that resonable credentials have been stored at
|
||||
# /root/auth
|
||||
source /root/openrc
|
||||
|
||||
# get an image to test with
|
||||
#wget http://uec-images.ubuntu.com/releases/12.04/release/ubuntu-12.04-server-cloudimg-amd64-disk1.img
|
||||
|
||||
# import that image into glance
|
||||
#glance add name="Ubuntu 12.04 cloudimg amd64" is_public=true container_format=ovf disk_format=qcow2 < ubuntu-12.04-server-cloudimg-amd64-disk1.img
|
||||
|
||||
#IMAGE_ID=`glance index | grep 'Ubuntu 12.04 cloudimg amd64' | head -1 | awk -F' ' '{print $1}'`
|
||||
|
||||
wget https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-i386-disk.img
|
||||
|
||||
glance add name='cirros image' is_public=true container_format=bare disk_format=qcow2 < cirros-0.3.0-i386-disk.img
|
||||
|
||||
IMAGE_ID=`glance index | grep 'cirros image' | head -1 | awk -F' ' '{print $1}'`
|
||||
|
||||
# create a pub key
|
||||
ssh-keygen -f /tmp/id_rsa -t rsa -N ''
|
||||
nova keypair-add --pub_key /tmp/id_rsa.pub key1
|
||||
|
||||
nova boot --flavor 1 --image ${IMAGE_ID} --key_name key1 dans_vm
|
||||
|
||||
nova show dans_vm
|
||||
|
||||
# create ec2 credentials
|
||||
keystone ec2-credentials-create
|
28
manifests/test_file.pp
Normal file
28
manifests/test_file.pp
Normal file
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# Class that can be used to create a test script for testing an
|
||||
# installed openstack environment.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# [path] Path of test file to be created. Optional. Defaults to /tmp/test_nova.sh
|
||||
# [rc_file_path] Path of openrc file that sets up all authentication environment
|
||||
# variables. Optional. Defaults to /root/openrc.
|
||||
# [image_type] Type of image to download. Accepts cirros or ubuntu. Optional.
|
||||
# Defaults to cirros.
|
||||
# [sleep_time] Used to tune how long to sleep for. Optional. Defaults to 60.
|
||||
# [floating_ip] Rather to test flating ip address allocation. Optional.
|
||||
# Defaults to true.
|
||||
class openstack::test_file(
|
||||
$path = '/tmp/test_nova.sh',
|
||||
$rc_file_path = '/root/openrc',
|
||||
$image_type = 'cirros',
|
||||
$sleep_time = '15',
|
||||
$floating_ip = true
|
||||
) {
|
||||
|
||||
file { $path:
|
||||
content => template('openstack/test_nova.sh.erb'),
|
||||
}
|
||||
|
||||
}
|
69
templates/test_nova.sh.erb
Normal file
69
templates/test_nova.sh.erb
Normal file
@@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# assumes that openstack credentails are set in this file
|
||||
source <%= rc_file_path %>
|
||||
|
||||
<% if image_type == 'cirros' -%>
|
||||
|
||||
# Grab an image. Cirros is a nice small Linux that's easy to deploy
|
||||
wget https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img
|
||||
|
||||
# Add it to glance so that we can use it in Openstack
|
||||
glance add name='cirros image' is_public=true container_format=bare disk_format=qcow2 < cirros-0.3.0-x86_64-disk.img
|
||||
|
||||
# Caputre the Image ID so taht we can call the right UUID for this image
|
||||
IMAGE_ID=`glance index | grep 'cirros image' | head -1 | awk -F' ' '{print $1}'`
|
||||
|
||||
login_user='cirros'
|
||||
<% else -%>
|
||||
|
||||
# otherwise, use an Ubuntu precise image. This is a larger image, but a little more
|
||||
# feature-full and realistic
|
||||
wget http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64-disk1.img
|
||||
# import that image into glance
|
||||
glance add name="precise-amd64" is_public=true container_format=ovf disk_format=qcow2 < precise-server-cloudimg-amd64-disk1.img
|
||||
# Caputre the Image ID so taht we can call the right UUID for this image
|
||||
IMAGE_ID=`glance index | grep 'precise-amd64' | head -1 | awk -F' ' '{print $1}'`
|
||||
|
||||
login_user='ubuntu'
|
||||
<% end -%>
|
||||
|
||||
# create a pub/priv keypair
|
||||
ssh-keygen -f /tmp/id_rsa -t rsa -N ''
|
||||
|
||||
#add the public key to nova.
|
||||
nova keypair-add --pub_key /tmp/id_rsa.pub key_cirros
|
||||
|
||||
<% if floating_ip -%>
|
||||
# create a security group so that we can allow ssh, http, and ping traffic
|
||||
# when we add a floating IP (assuming you are adding floating IPs)
|
||||
nova secgroup-create nova_test 'Cirros test security group'
|
||||
nova secgroup-add-rule nova_test tcp 22 22 0.0.0.0/0
|
||||
nova secgroup-add-rule nova_test tcp 80 80 0.0.0.0/0
|
||||
nova secgroup-add-rule nova_test icmp -1 -1 0.0.0.0/0
|
||||
|
||||
# request a floating IP address, and extract the address from the results message
|
||||
floating_ip=`nova floating-ip-create | grep None | awk '{print $2}'`
|
||||
<% end -%>
|
||||
|
||||
instance_name='<%= image_type %>_test_vm'
|
||||
# Boot the added image against the "1" flavor which by default maps to a micro instance. <% if floating_ip -%> Include the cirros_test group so our address will work when we add it later <% end %>
|
||||
nova boot --flavor 1 <% if floating_ip -%>--security_groups nova_test<% end %> --image ${IMAGE_ID} --key_name key_cirros $instance_name
|
||||
|
||||
# let the system catch up
|
||||
sleep <%= sleep_time %>
|
||||
|
||||
# Show the state of the system we just requested.
|
||||
nova show $instance_name
|
||||
|
||||
# wait for the server to boot
|
||||
sleep <%= sleep_time %>
|
||||
|
||||
<% if floating_ip -%>
|
||||
# Now add the floating IP we reserved earlier to the machine.
|
||||
nova add-floating-ip $instance_name $floating_ip
|
||||
# Wait and then try to SSH to the node, leveraging the private key
|
||||
# we generated earlier.
|
||||
sleep <%= sleep_time %>
|
||||
ssh $login_user@$floating_ip -i /tmp/id_rsa
|
||||
<% end -%>
|
Reference in New Issue
Block a user