Skip to content

Commit

Permalink
Add bosh acceptance test job (apache#226)
Browse files Browse the repository at this point in the history
* Add bosh acceptance test job
* replace zuul home path with ansible var
* Add resource cleanup and improve for bosh acc test job

Close theopenlab/openlab#4
  • Loading branch information
liusheng authored and kiwik committed Jun 5, 2018
1 parent 08fa131 commit 3dbae74
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 0 deletions.
62 changes: 62 additions & 0 deletions playbooks/bosh-acceptance-test/post.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
- hosts: all
become: yes
roles:
- role: export-cloud-openrc
vars:
cloud_name: 'opentelekomcloud'
tasks:
- name: Clean up resources for bosh acceptance tests
shell:
cmd: |
set -e
set -x
# Cloud provider specific variables
NET_ID="134ca339-24dc-44f5-ae6a-cf0404216ed2"
SUBNET_ID="3d6e9157-655f-42ec-9778-94d455730e5c"
BUILD_ID="{{ zuul.build }}"
cd bosh-1
export BOSH_CLIENT=admin
export BOSH_CLIENT_SECRET=`bosh int ./creds.yml --path /admin_password`
bosh_ip=$(bosh environments --column=URL)
bosh alias-env bosh-1 -e ${bosh_ip} --ca-cert <(bosh int ./creds.yml --path /director_ssl/ca)
bosh -e bosh-1 env
for vm_id in $(bosh -e bosh-1 vms --column="VM CID"); do
bosh -e bosh-1 -d bat --non-interactive delete-vm ${vm_id}
done
for vol_id in $(bosh -e bosh-1 disks --orphaned); do
bosh -e bosh-1 --non-interactive delete-disk ${vol_id}
done
for dep_name in $(bosh -e bosh-1 deployments --column="Name"); do
bosh -e bosh-1 --non-interactive delete-deployment -d ${dep_name}
done
for img_id in $(bosh -e bosh-1 ss --column=CID); do
img_name=$(openstack image show $img_id -f value -c name)
bosh -e bosh-1 --non-interactive delete-stemcell $img_name
done
set +x
bosh delete-env bosh-deployment/bosh.yml \
--state=state.json \
--vars-store=creds.yml \
-o bosh-deployment/openstack/cpi.yml \
-v director_name=bosh-1 \
-v internal_cidr=$(openstack subnet show ${SUBNET_ID} -f value -c cidr) \
-v internal_gw=$(openstack subnet show ${SUBNET_ID} -f value -c gateway_ip) \
-v internal_ip=${bosh_ip} \
-v auth_url=${OS_AUTH_URL} \
-v az=${OS_AVAILABILITY_ZONE} \
-v default_key_name=microbosh-${BUILD_ID} \
-v default_security_groups=[bosh-${BUILD_ID}] \
-v net_id=${NET_ID} \
-v openstack_password=${OS_PASSWORD} \
-v openstack_username=${OS_USERNAME} \
-v openstack_domain=${OS_DOMAIN_NAME} \
-v openstack_project=${OS_TENANT_NAME} \
-v private_key="{{ ansible_user_dir }}/bosh-1/microbosh.pem" \
-v region=${OS_REGION_NAME}
set -x
openstack security group delete bosh-${BUILD_ID} || true
openstack keypair delete microbosh-${BUILD_ID} || true
executable: /bin/bash
environment: '{{ golang_env }}'
137 changes: 137 additions & 0 deletions playbooks/bosh-acceptance-test/run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
- hosts: all
become: yes
roles:
- role: export-cloud-openrc
vars:
cloud_name: 'opentelekomcloud'
tasks:
- name: Install bosh and run bosh acceptance tests
shell:
cmd: |
set -x
set -e
set -o pipefail
# Cloud provider specific variables
NET_ID="134ca339-24dc-44f5-ae6a-cf0404216ed2"
SUBNET_ID="3d6e9157-655f-42ec-9778-94d455730e5c"
SMALL_FLAVOR="s2.medium.1" #1U1G
MEDIUM_FLAVOR="s2.large.1" #2U2G
LARGE_FLAVOR="s2.2xlarge.1" #8U8G
BUILD_ID="{{ zuul.build }}"
pip install python-openstackclient
curl -Lo ./bosh https://s3.amazonaws.com/bosh-cli-artifacts/bosh-cli-3.0.1-linux-amd64
chmod +x ./bosh
cp ./bosh /usr/local/bin/bosh
bosh -v
apt-get install -y build-essential zlibc zlib1g-dev ruby ruby-dev openssl libxslt-dev libxml2-dev libssl-dev libreadline6 libreadline6-dev libyaml-dev libsqlite3-dev sqlite3
mkdir bosh-1 && cd bosh-1
git clone https://github.com/cloudfoundry/bosh-deployment.git
openstack keypair create microbosh-${BUILD_ID} > microbosh.pem
openstack security group create bosh-${BUILD_ID} --description 'BOSH Security Group'
openstack security group rule create --protocol tcp --ingress bosh-${BUILD_ID}
openstack security group rule create --protocol icmp --ingress bosh-${BUILD_ID}
wget --content-disposition https://bosh.io/d/stemcells/bosh-openstack-kvm-ubuntu-trusty-go_agent -O bosh-openstack-kvm-ubuntu-trusty-go_agent.tgz
sed -i 's|https://bosh.io/d/stemcells/.*$|file://{{ ansible_user_dir }}/bosh-1/bosh-openstack-kvm-ubuntu-trusty-go_agent.tgz|' bosh-deployment/openstack/cpi.yml
sed -i "s/m1.small/${SMALL_FLAVOR}/g" `grep m1.small -rl bosh-deployment/openstack`
sed -i "s/m1.xlarge/${LARGE_FLAVOR}/g" `grep m1.xlarge -rl bosh-deployment/openstack`
sed -i '/^.*human_readable_vm_names.*$/ a\ \ \ \ state_timeout: 300000' bosh-deployment/openstack/cpi.yml
# NOTE: We need an available ip for bosh deployment, so following port creation and deletion actions are just
# used to reserve an available ip address for bosh deployment
_port_id=$(openstack port create --network ${NET_ID} bosh-port -f value -c id)
bosh_ip=$(openstack port show ${_port_id} -f value -c fixed_ips | grep -Eo '([0-9]+\.){3}[0-9]+')
openstack port delete ${_port_id}
set +x
bosh create-env bosh-deployment/bosh.yml \
--state=state.json \
--vars-store=creds.yml \
-o bosh-deployment/openstack/cpi.yml \
-v director_name=bosh-1 \
-v internal_cidr=$(openstack subnet show ${SUBNET_ID} -f value -c cidr) \
-v internal_gw=$(openstack subnet show ${SUBNET_ID} -f value -c gateway_ip) \
-v internal_ip=${bosh_ip} \
-v auth_url=${OS_AUTH_URL} \
-v az=${OS_AVAILABILITY_ZONE} \
-v default_key_name=microbosh-${BUILD_ID} \
-v default_security_groups=[bosh-${BUILD_ID}] \
-v net_id=${NET_ID} \
-v openstack_password=${OS_PASSWORD} \
-v openstack_username=${OS_USERNAME} \
-v openstack_domain=${OS_DOMAIN_NAME} \
-v openstack_project=${OS_TENANT_NAME} \
-v private_key="{{ ansible_user_dir }}/bosh-1/microbosh.pem" \
-v region=${OS_REGION_NAME}
set -x
bosh alias-env bosh-1 -e ${bosh_ip} --ca-cert <(bosh int ./creds.yml --path /director_ssl/ca)
export BOSH_CLIENT=admin
export BOSH_CLIENT_SECRET=`bosh int ./creds.yml --path /admin_password`
bosh -e bosh-1 env
# path to the stemcell you want to use for testing
export BAT_STEMCELL="{{ ansible_user_dir }}/bosh-1/bosh-openstack-kvm-ubuntu-trusty-go_agent.tgz"
# path to the bat yaml file which is used to generate the deployment manifest (see below `bat.yml`)
export BAT_DEPLOYMENT_SPEC="{{ ansible_user_dir }}/bosh-1/bat.yml"
# BOSH CLI executable path
export BAT_BOSH_CLI=bosh
# DNS host or IP where BOSH-controlled PowerDNS server is running, which is required for the DNS tests. For example, if BAT is being run against a MicroBOSH then this value will be the same as BAT_DIRECTOR
export BAT_DNS_HOST=8.8.8.8
# the name of infrastructure that is used by bosh deployment. Examples: aws, vsphere, openstack, warden, oci.
export BAT_INFRASTRUCTURE=openstack
# the type of networking being used: `dynamic` or `manual`.
export BAT_NETWORKING=dynamic
# the path to ssh key, used by OS specs to ssh into BOSH VMs
export BAT_PRIVATE_KEY="{{ ansible_user_dir }}/bosh-1/microbosh.pem"
# Run tests with --fail-fast and skip cleanup in case of failure (optional)
export BAT_DEBUG_MODE=true
export BOSH_OS_BATS=true
export BOSH_ENVIRONMENT=bosh-1
# export BOSH_CLIENT=<director username>
# export BOSH_CLIENT_SECRET=<director password>
# export BOSH_CA_CERT=<director ca cert content or path>
cat << EOF >> bat.yml
---
cpi: openstack
properties:
stemcell:
name: bosh-openstack-kvm-ubuntu-trusty-go_agent
version: latest
pool_size: 1
instances: 1
instance_type: ${SMALL_FLAVOR}
availability_zone: ${OS_AVAILABILITY_ZONE}
flavor_with_no_ephemeral_disk: ${MEDIUM_FLAVOR}
vip: 0.0.0.43 # Virtual (public/floating) IP assigned to the bat-release job vm, for ssh testing
networks:
- name: default
type: dynamic
cloud_properties:
net_id: ${NET_ID} # Network ID
security_groups: [bosh-${BUILD_ID}] # security groups assigned to deployed VMs
key_name: microbosh-${BUILD_ID} # (optional) SSH keypair name
EOF
pushd '{{ ansible_user_dir }}/{{ zuul.project.src_dir }}'
gem install bundler
bundle install
cp '{{ ansible_user_dir }}/bosh' /usr/local/bin/bosh
bundle exec rspec spec --tag ~raw_ephemeral_storage
popd
executable: /bin/bash
chdir: '{{ ansible_user_dir }}'
environment: '{{ golang_env }}'
11 changes: 11 additions & 0 deletions zuul.d/jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,14 @@
run: playbooks/cf-openstack-validator-acceptance-test/run.yaml
vars:
os_branch: 'stable/newton'

- job:
name: bosh-acceptance-test
parent: golang-test
description: |
Run acceptance tests of bosh-acceptance-tests
run: playbooks/bosh-acceptance-test/run.yaml
post-run: playbooks/bosh-acceptance-test/post.yaml
nodeset: ubuntu-xenial-otc
secrets:
- opentelekomcloud_credentials
6 changes: 6 additions & 0 deletions zuul.d/nodesets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@
nodes:
- name: ubuntu-bionic-vxh-arm64
label: ubuntu-bionic-vxh-arm64

- nodeset:
name: ubuntu-xenial-otc
nodes:
- name: ubuntu-xenial-otc
label: ubuntu-xenial-otc

0 comments on commit 3dbae74

Please sign in to comment.