Skip to content

Commit

Permalink
Implement tests for the VCH Creation API
Browse files Browse the repository at this point in the history
Implement a suite of positive and negative tests for API-based VCH
creation. These tests are not intended to be exhaustive; we can use
unit tests for that.
  • Loading branch information
zjs committed Oct 27, 2017
1 parent 5da6cee commit c98e4aa
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 3 deletions.
11 changes: 11 additions & 0 deletions tests/resources/Group23-VIC-Machine-Service-Util.robot
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ Get Path Under Target
Set Test Variable ${STATUS}


Post Path Under Target
[Arguments] ${path} ${data} @{query}
${fullQuery}= Catenate SEPARATOR=& thumbprint=%{TEST_THUMBPRINT} @{query}
${auth}= Evaluate base64.b64encode("%{TEST_USERNAME}:%{TEST_PASSWORD}") modules=base64
${RC} ${OUTPUT}= Run And Return Rc And Output curl -s -w "\n\%{http_code}\n" -X POST "http://127.0.0.1:${HTTP_PORT}/container/target/%{TEST_URL}/${PATH}?${fullQuery}" -H "Accept: application/json" -H "Authorization: Basic ${auth}" -H "Content-Type: application/json" --data ${data}
${OUTPUT} ${STATUS}= Split String From Right ${OUTPUT} \n 1
Set Test Variable ${RC}
Set Test Variable ${OUTPUT}
Set Test Variable ${STATUS}


Verify Return Code
Should Be Equal As Integers ${RC} 0

Expand Down
6 changes: 3 additions & 3 deletions tests/resources/VCH-Util.robot
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Set Test Environment Variables
${status} ${message}= Run Keyword And Ignore Error Environment Variable Should Be Set BRIDGE_NETWORK
Run Keyword If '${status}' == 'FAIL' Set Environment Variable BRIDGE_NETWORK network
${status} ${message}= Run Keyword And Ignore Error Environment Variable Should Be Set PUBLIC_NETWORK
Run Keyword If '${status}' == 'FAIL' Set Environment Variable PUBLIC_NETWORK 'VM Network'
Run Keyword If '${status}' == 'FAIL' Set Environment Variable PUBLIC_NETWORK VM Network
${status} ${message}= Run Keyword And Ignore Error Environment Variable Should Be Set TEST_DATACENTER
Run Keyword If '${status}' == 'FAIL' Set Environment Variable TEST_DATACENTER ${SPACE}
${status} ${message}= Run Keyword And Ignore Error Environment Variable Should Be Set DRONE_MACHINE
Expand Down Expand Up @@ -190,11 +190,11 @@ Install VIC Appliance To Test Server
Run VIC Machine Command
[Tags] secret
[Arguments] ${vic-machine} ${appliance-iso} ${bootstrap-iso} ${certs} ${vol} ${debug} ${additional-args}
${output}= Run Keyword If ${certs} Run ${vic-machine} create --debug ${debug} --name=%{VCH-NAME} --target=%{TEST_URL}%{TEST_DATACENTER} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --image-store=%{TEST_DATASTORE} --appliance-iso=${appliance-iso} --bootstrap-iso=${bootstrap-iso} --password=%{TEST_PASSWORD} --force=true --bridge-network=%{BRIDGE_NETWORK} --public-network=%{PUBLIC_NETWORK} --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} --insecure-registry harbor.ci.drone.local --volume-store=%{TEST_DATASTORE}/%{VCH-NAME}-VOL:${vol} ${vicmachinetls} ${additional-args}
${output}= Run Keyword If ${certs} Run ${vic-machine} create --debug ${debug} --name=%{VCH-NAME} --target=%{TEST_URL}%{TEST_DATACENTER} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --image-store=%{TEST_DATASTORE} --appliance-iso=${appliance-iso} --bootstrap-iso=${bootstrap-iso} --password=%{TEST_PASSWORD} --force=true --bridge-network=%{BRIDGE_NETWORK} --public-network="%{PUBLIC_NETWORK}" --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} --insecure-registry harbor.ci.drone.local --volume-store=%{TEST_DATASTORE}/%{VCH-NAME}-VOL:${vol} ${vicmachinetls} ${additional-args}
Run Keyword If ${certs} Should Contain ${output} Installer completed successfully
Return From Keyword If ${certs} ${output}

${output}= Run Keyword Unless ${certs} Run ${vic-machine} create --debug ${debug} --name=%{VCH-NAME} --target=%{TEST_URL}%{TEST_DATACENTER} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --image-store=%{TEST_DATASTORE} --appliance-iso=${appliance-iso} --bootstrap-iso=${bootstrap-iso} --password=%{TEST_PASSWORD} --force=true --bridge-network=%{BRIDGE_NETWORK} --public-network=%{PUBLIC_NETWORK} --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} --insecure-registry harbor.ci.drone.local --volume-store=%{TEST_DATASTORE}/%{VCH-NAME}-VOL:${vol} --no-tlsverify ${additional-args}
${output}= Run Keyword Unless ${certs} Run ${vic-machine} create --debug ${debug} --name=%{VCH-NAME} --target=%{TEST_URL}%{TEST_DATACENTER} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --image-store=%{TEST_DATASTORE} --appliance-iso=${appliance-iso} --bootstrap-iso=${bootstrap-iso} --password=%{TEST_PASSWORD} --force=true --bridge-network=%{BRIDGE_NETWORK} --public-network="%{PUBLIC_NETWORK}" --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} --insecure-registry harbor.ci.drone.local --volume-store=%{TEST_DATASTORE}/%{VCH-NAME}-VOL:${vol} --no-tlsverify ${additional-args}
Run Keyword Unless ${certs} Should Contain ${output} Installer completed successfully
[Return] ${output}

Expand Down
24 changes: 24 additions & 0 deletions tests/test-cases/Group23-VIC-Machine-Service/23-03-VCH-Create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Test 23-03 - VCH Create
=======

# Purpose:
To verify vic-machine-server can create a VCH with a specified configuration

# References:
1. [The design document](../../../doc/design/vic-machine/service.md)

# Environment:
This test requires a vSphere system where VCHs can be deployed

# Test Steps:
1. Create a VCH with as minimal a configuration as possible
2. Inspect that VCH using the CLI
3. Create a VCH with a more complex configuration
4. Inspect that VCH using the CLI

# Expected Outcome:
* The results of 2 should contain the same information as was supplied when the VCH was created in 1.
* The results of 4 should contain the same information as was supplied when the VCH was created in 3.

# Possible Problems:
None known
265 changes: 265 additions & 0 deletions tests/test-cases/Group23-VIC-Machine-Service/23-03-VCH-Create.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
# Copyright 2017 VMware, 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

*** Settings ***
Documentation Test 23-03 - VCH Create
Resource ../../resources/Util.robot
Resource ../../resources/Group23-VIC-Machine-Service-Util.robot
Suite Setup Setup
Suite Teardown Teardown
Default Tags


*** Keywords ***
Setup
Start VIC Machine Server
Set Test Environment Variables


Teardown
Terminate All Processes kill=True


Create VCH
[Arguments] ${data}
Post Path Under Target vch ${data}


Create VCH Within Datacenter
[Arguments] ${data}
${dcID}= Get Datacenter ID
Post Path Under Target datacenter/${dcID}/vch ${data}


Inspect VCH ${name}
${RC} ${OUTPUT}= Run And Return Rc And Output bin/vic-machine-linux inspect config --target=%{TEST_URL} --thumbprint=%{TEST_THUMBPRINT} --user %{TEST_USERNAME} --password=%{TEST_PASSWORD} --name=${name} --format raw
Should Be Equal As Integers ${RC} 0
Set Test Variable ${OUTPUT}


Arguments Should Contain
[Arguments] ${expected}
Should Contain ${OUTPUT} ${expected}


Get VCH
[Arguments] ${name}

Get Path Under Target vch
${id}= Run echo '${OUTPUT}' | jq -r '.vchs[] | select(.name=="${name}").id'

Get Path Under Target vch/${id}


Property Should Be Equal
[Arguments] ${jq} ${expected}

${actual}= Run echo '${OUTPUT}' | jq -r '${jq}'
Should Be Equal ${actual} ${expected}


Property Should Not Be Equal
[Arguments] ${jq} ${expected}

${actual}= Run echo '${OUTPUT}' | jq -r '${jq}'
Should Not Be Equal ${actual} ${expected}


Property Should Contain
[Arguments] ${jq} ${expected}

${actual}= Run echo '${OUTPUT}' | jq -r '${jq}'
Should Contain ${actual} ${expected}


*** Test Cases ***
Create minimal VCH
Create VCH '{"name":"%{VCH-NAME}-api-test-minimal","compute":{"resource":{"name":"%{TEST_RESOURCE}"}},"storage":{"image_stores":["ds://%{TEST_DATASTORE}"]},"network":{"bridge":{"ip_range":"172.16.0.0/12","port_group":{"name":"%{BRIDGE_NETWORK}"}},"public":{"port_group":{"name":"%{PUBLIC_NETWORK}"}}},"auth":{"server":{"generate":{"cname":"vch.example.com","organization":["VMware, Inc."],"size":{"value":2048,"units":"bits"}}},"client":{"no_tls_verify": true}}}'

Verify Return Code
Verify Status 201


Inspect VCH %{VCH-NAME}-api-test-minimal

Arguments Should Contain --image-store=ds://%{TEST_DATASTORE}
Arguments Should Contain --bridge-network=%{BRIDGE_NETWORK}


Get VCH %{VCH-NAME}-api-test-minimal

Property Should Be Equal .name %{VCH-NAME}-api-test-minimal

Property Should Not Be Equal .compute.resource.id null

Property Should Contain .storage.image_stores[0] %{TEST_DATASTORE}
Property Should Be Equal .storage.base_image_size.value 8000000
Property Should Be Equal .storage.base_image_size.units KB

Property Should Contain .auth.server.certificate.pem -----BEGIN CERTIFICATE-----
Property Should Be Equal .auth.server.private_key.pem null

Property Should Contain .network.bridge.ip_range 172.16.0.0/12

Property Should Contain .runtime.power_state poweredOn
Property Should Contain .runtime.upgrade_status Up to date

[Teardown] Run Secret VIC Machine Delete Command %{VCH-NAME}-api-test-minimal


Create minimal VCH within datacenter
Create VCH Within Datacenter '{"name":"%{VCH-NAME}-api-test-dc","compute":{"resource":{"name":"%{TEST_RESOURCE}"}},"storage":{"image_stores":["ds://%{TEST_DATASTORE}"]},"network":{"bridge":{"ip_range":"172.16.0.0/12","port_group":{"name":"%{BRIDGE_NETWORK}"}},"public":{"port_group":{"name":"%{PUBLIC_NETWORK}"}}},"auth":{"server":{"generate":{"cname":"vch.example.com","organization":["VMware, Inc."],"size":{"value":2048,"units":"bits"}}},"client":{"no_tls_verify": true}}}'

Verify Return Code
Verify Status 201


Inspect VCH %{VCH-NAME}-api-test-dc

Arguments Should Contain --image-store=ds://%{TEST_DATASTORE}
Arguments Should Contain --bridge-network=%{BRIDGE_NETWORK}


Get VCH %{VCH-NAME}-api-test-dc

Property Should Be Equal .name %{VCH-NAME}-api-test-dc

Property Should Not Be Equal .compute.resource.id null

Property Should Contain .storage.image_stores[0] %{TEST_DATASTORE}
Property Should Be Equal .storage.base_image_size.value 8000000
Property Should Be Equal .storage.base_image_size.units KB

Property Should Contain .auth.server.certificate.pem -----BEGIN CERTIFICATE-----
Property Should Be Equal .auth.server.private_key.pem null

Property Should Contain .network.bridge.ip_range 172.16.0.0/12

Property Should Contain .runtime.power_state poweredOn
Property Should Contain .runtime.upgrade_status Up to date

[Teardown] Run Secret VIC Machine Delete Command %{VCH-NAME}-api-test-dc


Create complex VCH
Create VCH '{"name":"%{VCH-NAME}-api-test-complex","debug":3,"compute":{"cpu":{"limit":{"units":"MHz","value":2345},"reservation":{"units":"GHz","value":2},"shares":{"level":"high"}},"memory":{"limit":{"units":"MiB","value":1200},"reservation":{"units":"MiB","value":501},"shares":{"number":81910}},"resource":{"name":"%{TEST_RESOURCE}"}},"endpoint":{"cpu":{"sockets":2},"memory":{"units":"MiB","value":3072}},"storage":{"image_stores":["ds://%{TEST_DATASTORE}"],"volume_stores":[{"datastore":"ds://%{TEST_DATASTORE}/test-volumes/foo","label":"foo"}],"base_image_size":{"units":"B","value":16000000}},"network":{"bridge":{"ip_range":"172.16.0.0/12","port_group":{"name":"%{BRIDGE_NETWORK}"}},"public":{"port_group":{"name":"%{PUBLIC_NETWORK}"}}},"registry":{"image_fetch_proxy":{"http":"http://example.com","https":"https://example.com"},"insecure":["https://insecure.example.com"],"whitelist":["10.0.0.0/8"]},"auth":{"server":{"generate":{"cname":"vch.example.com","organization":["VMware, Inc."],"size":{"value":2048,"units":"bits"}}},"client":{"no_tls_verify": true}},"syslog_addr":"tcp://syslog.example.com:4444"}'

Verify Return Code
Verify Status 201


Inspect VCH %{VCH-NAME}-api-test-complex

Arguments Should Contain --debug=3

Arguments Should Contain --cpu=2345
Arguments Should Contain --cpu-reservation=2000
Arguments Should Contain --cpu-shares=high
Arguments Should Contain --memory=1200
Arguments Should Contain --memory-reservation=501
Arguments Should Contain --memory-shares=81910

Arguments Should Contain --endpoint-cpu=2
Arguments Should Contain --endpoint-memory=3072

Arguments Should Contain --image-store=ds://%{TEST_DATASTORE}
Arguments Should Contain --volume-store=ds://%{TEST_DATASTORE}/test-volumes/foo:foo
Arguments Should Contain --base-image-size=16MB

Arguments Should Contain --bridge-network=%{BRIDGE_NETWORK}

Arguments Should Contain --insecure-registry=https://insecure.example.com
Arguments Should Contain --whitelist-registry=10.0.0.0/8
Arguments Should Contain --whitelist-registry=https://insecure.example.com


Get VCH %{VCH-NAME}-api-test-complex

Property Should Be Equal .name %{VCH-NAME}-api-test-complex
Property Should Be Equal .debug 3
Property Should Be Equal .syslog_addr tcp://syslog.example.com:4444

Property Should Not Be Equal .compute.resource.id null
Property Should Be Equal .compute.cpu.limit.value 2345
Property Should Be Equal .compute.cpu.limit.units MHz
Property Should Be Equal .compute.cpu.reservation.value 2000
Property Should Be Equal .compute.cpu.reservation.units MHz
Property Should Be Equal .compute.cpu.shares.level high
Property Should Be Equal .compute.memory.limit.value 1200
Property Should Be Equal .compute.memory.limit.units MiB
Property Should Be Equal .compute.memory.reservation.value 501
Property Should Be Equal .compute.memory.reservation.units MiB
Property Should Be Equal .compute.memory.shares.number 81910

Property Should Be Equal .endpoint.cpu.sockets 2
Property Should Be Equal .endpoint.memory.value 3072
Property Should Be Equal .endpoint.memory.units MiB

Property Should Contain .storage.image_stores[0] %{TEST_DATASTORE}
Property Should Contain .storage.volume_stores[0].datastore %{TEST_DATASTORE}/test-volumes/foo
Property Should Contain .storage.volume_stores[0].label foo
Property Should Be Equal .storage.base_image_size.value 16000
Property Should Be Equal .storage.base_image_size.units KB

Property Should Be Equal .registry.image_fetch_proxy.http http://example.com
Property Should Be Equal .registry.image_fetch_proxy.https https://example.com
Property Should Contain .registry.insecure | join(" ") https://insecure.example.com
Property Should Contain .registry.whitelist | join(" ") https://insecure.example.com
Property Should Contain .registry.whitelist | join(" ") 10.0.0.0/8

Property Should Contain .auth.server.certificate.pem -----BEGIN CERTIFICATE-----
Property Should Be Equal .auth.server.private_key.pem null

Property Should Be Equal .network.bridge.ip_range 172.16.0.0/12

Property Should Be Equal .runtime.power_state poweredOn
Property Should Be Equal .runtime.upgrade_status Up to date

[Teardown] Run Secret VIC Machine Delete Command %{VCH-NAME}-api-test-complex


Fail to create VCH with invalid operations credentials
Create VCH '{"name":"%{VCH-NAME}-api-bad-ops","compute":{"resource":{"name":"%{TEST_RESOURCE}"}},"endpoint":{"operations_credentials":{"user":"invalid","password":"invalid"}},"storage":{"image_stores":["ds://%{TEST_DATASTORE}"]},"network":{"bridge":{"ip_range":"172.16.0.0/12","port_group":{"name":"%{BRIDGE_NETWORK}"}},"public":{"port_group":{"name":"%{PUBLIC_NETWORK}"}}},"auth":{"server":{"generate":{"cname":"vch.example.com","organization":["VMware, Inc."],"size":{"value":2048,"units":"bits"}}},"client":{"no_tls_verify": true}}}'

Verify Return Code
Verify Status 400

Should Contain ${output} operations credentials


Fail to create VCH with invalid datastore
Create VCH '{"name":"%{VCH-NAME}-api-bad-storage","compute":{"resource":{"name":"%{TEST_RESOURCE}"}},"storage":{"image_stores":["ds://%{TEST_DATASTORE}-invalid"]},"network":{"bridge":{"ip_range":"172.16.0.0/12","port_group":{"name":"%{BRIDGE_NETWORK}"}},"public":{"port_group":{"name":"%{PUBLIC_NETWORK}"}}},"auth":{"server":{"generate":{"cname":"vch.example.com","organization":["VMware, Inc."],"size":{"value":2048,"units":"bits"}}},"client":{"no_tls_verify": true}}}'

Verify Return Code
Verify Status 400

Should Contain ${output} datastore


Fail to create VCH with invalid compute
Create VCH '{"name":"%{VCH-NAME}-api-bad-compute","compute":{"resource":{"name":"%{TEST_RESOURCE}-invalid"}},"storage":{"image_stores":["ds://%{TEST_DATASTORE}"]},"network":{"bridge":{"ip_range":"172.16.0.0/12","port_group":{"name":"%{BRIDGE_NETWORK}"}},"public":{"port_group":{"name":"%{PUBLIC_NETWORK}"}}},"auth":{"server":{"generate":{"cname":"vch.example.com","organization":["VMware, Inc."],"size":{"value":2048,"units":"bits"}}},"client":{"no_tls_verify": true}}}'

Verify Return Code
Verify Status 400

Should Contain ${output} compute resource


Fail to create VCH without network
Create VCH '{"name":"%{VCH-NAME}-api-bad-network","compute":{"resource":{"name":"%{TEST_RESOURCE}"}},"storage":{"image_stores":["ds://%{TEST_DATASTORE}"]},"auth":{"server":{"generate":{"cname":"vch.example.com","organization":["VMware, Inc."],"size":{"value":2048,"units":"bits"}}},"client":{"no_tls_verify": true}}}'

Verify Return Code
Verify Status 400

Should Contain ${output} network

0 comments on commit c98e4aa

Please sign in to comment.