Browse Source

Basic tests for airship-seaworthy deployment

Change-Id: I1a4cd173371dbfebf454d6385aa67882437dda0c
changes/10/604210/13
Kaspars Skels 3 years ago
parent
commit
1094488b0a
  1. 118
      tools/files/heat-basic-vm-deployment.yaml
  2. 75
      tools/files/heat-public-net-deployment.yaml
  3. 20
      tools/files/heat-vm-volume-attach.yaml
  4. 9
      tools/openstack
  5. 128
      tools/tests.sh

118
tools/files/heat-basic-vm-deployment.yaml

@ -0,0 +1,118 @@
heat_template_version: '2016-10-14'
parameters:
public_net:
type: string
default: public
image:
type: string
default: Cirros 0.3.5 64-bit
ssh_key:
type: string
default: heat-vm-key
cidr:
type: string
default: 10.11.11.0/24
dns_nameserver:
type: comma_delimited_list
description: address of a dns nameserver reachable in your environment
default: 8.8.8.8
resources:
flavor:
type: OS::Nova::Flavor
properties:
disk: 1
ram: 64
vcpus: 1
server:
type: OS::Nova::Server
properties:
image:
get_param: image
flavor:
get_resource: flavor
key_name:
get_param: ssh_key
networks:
- port:
get_resource: server_port
user_data_format: RAW
router:
type: OS::Neutron::Router
properties:
external_gateway_info:
network:
get_param: public_net
router_interface:
type: OS::Neutron::RouterInterface
properties:
router_id:
get_resource: router
subnet_id:
get_resource: private_subnet
private_net:
type: OS::Neutron::Net
private_subnet:
type: OS::Neutron::Subnet
properties:
network:
get_resource: private_net
cidr:
get_param: cidr
dns_nameservers:
get_param: dns_nameserver
port_security_group:
type: OS::Neutron::SecurityGroup
properties:
name: default_port_security_group
description: 'Default security group assigned to port.'
rules:
- remote_ip_prefix: 0.0.0.0/0
protocol: tcp
port_range_min: 22
port_range_max: 22
- remote_ip_prefix: 0.0.0.0/0
protocol: icmp
server_port:
type: OS::Neutron::Port
properties:
network:
get_resource: private_net
fixed_ips:
- subnet:
get_resource: private_subnet
security_groups:
- get_resource: port_security_group
server_floating_ip:
type: OS::Neutron::FloatingIP
properties:
floating_network:
get_param: public_net
port_id:
get_resource: server_port
outputs:
floating_ip:
value:
get_attr:
- server_floating_ip
- floating_ip_address
instance_uuid:
value:
get_attr:
- server
- show
- id

75
tools/files/heat-public-net-deployment.yaml

@ -0,0 +1,75 @@
heat_template_version: 2016-10-14
parameters:
network_name:
type: string
default: public
physical_network_name:
type: string
default: public
physical_network_interface:
type: string
default: bond0
physical_network_vlan:
type: string
default: 27
subnet_name:
type: string
default: public
subnet_cidr:
type: string
default: 172.24.4.0/24
subnet_gateway:
type: string
default: 172.24.4.1
subnet_pool_start:
type: string
default: 172.24.4.11
subnet_pool_end:
type: string
default: 172.24.4.99
resources:
public_net:
type: OS::Neutron::ProviderNet
properties:
admin_state_up: true
name:
get_param: network_name
network_type: vlan
physical_network:
get_param: physical_network_interface
port_security_enabled: true
router_external: true
segmentation_id:
get_param: physical_network_vlan
shared: true
private_subnet:
type: OS::Neutron::Subnet
properties:
name:
get_param: subnet_name
network:
get_resource: public_net
cidr:
get_param: subnet_cidr
gateway_ip:
get_param: subnet_gateway
enable_dhcp: false
allocation_pools:
- start:
get_param: subnet_pool_start
end:
get_param: subnet_pool_end
dns_nameservers:
- 10.96.0.10

20
tools/files/heat-vm-volume-attach.yaml

@ -0,0 +1,20 @@
heat_template_version: 2016-10-14
parameters:
instance_uuid:
type: string
resources:
cinder_volume:
type: OS::Cinder::Volume
properties:
name: vol1
size: 1
cinder_volume_attach:
type: OS::Cinder::VolumeAttachment
properties:
instance_uuid:
get_param: instance_uuid
volume_id:
get_resource: cinder_volume

9
tools/openstack

@ -9,6 +9,9 @@ set -e
OS_CLOUD_CFG=${HOME}/.openstack/clouds.yaml
: ${TERM_OPTS:=-it}
if [ ! -f $OS_CLOUD_CFG ]; then
echo " => Creating OpenStack client config"
mkdir -p ~/.openstack
@ -23,13 +26,13 @@ clouds:
project_name: 'admin'
project_domain_name: 'default'
user_domain_name: 'default'
auth_url: 'http://keystone-api.openstack.svc.cluster.local:80/v3'
auth_url: 'http://identity.airship-seaworthy.atlantafoundry.com/v3'
EOF
fi
exec sudo docker run --rm -it --net host \
exec sudo docker run --rm ${TERM_OPTS} --net host \
-v $(pwd):/target \
-v ${OS_CLOUD_CFG}:/etc/openstack/clouds.yaml:ro \
-e OS_CLOUD=openstack_helm \
docker.io/openstackhelm/heat:ocata openstack $*
docker.io/openstackhelm/heat:ocata openstack "$@"

128
tools/tests.sh

@ -0,0 +1,128 @@
#!/bin/bash
# Copyright 2017 The Openstack-Helm Authors.
#
# 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.
set -xe
export OS_CLOUD=openstack_helm
: ${OSH_EXT_NET_NAME:="public"}
: ${OSH_EXT_SUBNET_NAME:="public-subnet"}
: ${OSH_EXT_SUBNET:="10.23.27.0/24"}
: ${OSH_EXT_GATEWAY:="10.23.27.1"}
: ${OSH_EXT_SUBNET_POOL_START:="10.23.27.11"}
: ${OSH_EXT_SUBNET_POOL_END:="10.23.27.99"}
tools/openstack stack create --wait \
--parameter network_name=${OSH_EXT_NET_NAME} \
--parameter physical_network_name=public \
--parameter subnet_name=${OSH_EXT_SUBNET_NAME} \
--parameter subnet_cidr=${OSH_EXT_SUBNET} \
--parameter subnet_gateway=${OSH_EXT_GATEWAY} \
--parameter subnet_pool_start=${OSH_EXT_SUBNET_POOL_START} \
--parameter subnet_pool_end=${OSH_EXT_SUBNET_POOL_END} \
-t /target/tools/files/heat-public-net-deployment.yaml \
heat-public-net-deployment
: ${OSH_EXT_NET_NAME:="public"}
: ${OSH_VM_KEY_STACK:="heat-vm-key"}
: ${OSH_PRIVATE_SUBNET:="10.0.0.0/24"}
# NOTE(portdirect): We do this fancy, and seemingly pointless, footwork to get
# the full image name for the cirros Image without having to be explicit.
IMAGE_NAME=$(tools/openstack image show -f value -c name \
$(tools/openstack image list -f csv | awk -F ',' '{ print $2 "," $1 }' | \
grep "^\"Cirros" | head -1 | awk -F ',' '{ print $2 }' | tr -d '"'))
rm -rf ${OSH_VM_KEY_STACK}*
ssh-keygen -t rsa -N '' -f $OSH_VM_KEY_STACK
chmod 600 $OSH_VM_KEY_STACK
# Setup SSH Keypair in Nova
tools/openstack keypair create --public-key \
/target/"${OSH_VM_KEY_STACK}.pub" \
${OSH_VM_KEY_STACK}
: ${OSH_EXT_DNS:="8.8.8.8"}
tools/openstack stack create --wait \
--parameter public_net=${OSH_EXT_NET_NAME} \
--parameter image="${IMAGE_NAME}" \
--parameter ssh_key=${OSH_VM_KEY_STACK} \
--parameter cidr=${OSH_PRIVATE_SUBNET} \
--parameter dns_nameserver=${OSH_EXT_DNS} \
-t /target/tools/files/heat-basic-vm-deployment.yaml \
heat-basic-vm-deployment
FLOATING_IP=$(tools/openstack stack output show \
heat-basic-vm-deployment \
floating_ip \
-f value -c output_value)
function wait_for_ssh_port {
# Default wait timeout is 300 seconds
set +x
end=$(date +%s)
if ! [ -z $2 ]; then
end=$((end + $2))
else
end=$((end + 300))
fi
while true; do
# Use Nmap as its the same on Ubuntu and RHEL family distros
nmap -Pn -p22 $1 | awk '$1 ~ /22/ {print $2}' | grep -q 'open' && \
break || true
sleep 1
now=$(date +%s)
[ $now -gt $end ] && echo "Could not connect to $1 port 22 in time" && exit -1
done
set -x
}
wait_for_ssh_port $FLOATING_IP
# SSH into the VM and check it can reach the outside world
ssh-keygen -R "$FLOATING_IP"
ssh-keyscan "$FLOATING_IP" >> ~/.ssh/known_hosts
ssh -i ${OSH_VM_KEY_STACK} cirros@${FLOATING_IP} ping -q -c 1 -W 2 ${OSH_EXT_GATEWAY}
# Check the VM can reach the metadata server
ssh -i ${OSH_VM_KEY_STACK} cirros@${FLOATING_IP} curl --verbose --connect-timeout 5 169.254.169.254
# Check the VM can reach the keystone server
ssh -i ${OSH_VM_KEY_STACK} cirros@${FLOATING_IP} curl --verbose --connect-timeout 5 identity.airship-seaworthy.atlantafoundry.com
# Check to see if cinder has been deployed, if it has then perform a volume attach.
if tools/openstack service list -f value -c Type | grep -q "^volume"; then
INSTANCE_ID=$(tools/openstack stack output show \
heat-basic-vm-deployment \
instance_uuid \
-f value -c output_value)
# Get the devices that are present on the instance
DEVS_PRE_ATTACH=$(mktemp)
ssh -i ${OSH_VM_KEY_STACK} cirros@${FLOATING_IP} lsblk > ${DEVS_PRE_ATTACH}
# Create and attach a block device to the instance
tools/openstack stack create --wait \
--parameter instance_uuid=${INSTANCE_ID} \
-t /target/tools/files/heat-vm-volume-attach.yaml \
heat-vm-volume-attach
# Get the devices that are present on the instance
DEVS_POST_ATTACH=$(mktemp)
ssh -i ${OSH_VM_KEY_STACK} cirros@${FLOATING_IP} lsblk > ${DEVS_POST_ATTACH}
# Check that we have the expected number of extra devices on the instance post attach
if ! [ "$(comm -13 ${DEVS_PRE_ATTACH} ${DEVS_POST_ATTACH} | wc -l)" -eq "1" ]; then
echo "Volume not successfully attached"
exit 1
fi
fi
Loading…
Cancel
Save