Skip to content

Commit

Permalink
Implement tests for the VCH Creation API
Browse files Browse the repository at this point in the history
  • Loading branch information
zjs committed Oct 25, 2017
1 parent 4cc1a61 commit be08f85
Show file tree
Hide file tree
Showing 4 changed files with 181 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
143 changes: 143 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,143 @@
# 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}


Count VCHs
Get Path Under Target vch
${count}= Run echo '${OUTPUT}' | jq -r '.vchs | length'
${count}= Convert To Integer ${count}
[Return] ${count}


*** Test Cases ***
Create minimal VCH
${before}= Count VCHs
${expected}= Evaluate ${before}+1
Log To Console Found ${before} VCHs, expecting ${expected} after the following creation.

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

${after}= Count VCHs
Should Be Equal As Integers ${expected} ${after}

${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=%{VCH-NAME}-api-test-minimal --format raw
Should Be Equal As Integers ${rc} 0

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

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


Create complex VCH
${before}= Count VCHs
${expected}= Evaluate ${before}+1
Log To Console Found ${before} VCHs, expecting ${expected} after the following creation.

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}}}'

Verify Return Code
Verify Status 201

${after}= Count VCHs
Should Be Equal As Integers ${expected} ${after}

${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=%{VCH-NAME}-api-test-complex --format raw
Should Be Equal As Integers ${rc} 0

Should Contain ${output} --debug=3

Should Contain ${output} --cpu=2345
Should Contain ${output} --cpu-reservation=2000
Should Contain ${output} --cpu-shares=high
Should Contain ${output} --memory=1200
Should Contain ${output} --memory-reservation=501
Should Contain ${output} --memory-shares=81910

Should Contain ${output} --endpoint-cpu=2
Should Contain ${output} --endpoint-memory=3072

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

Should Contain ${output} --bridge-network=%{BRIDGE_NETWORK}

Should Contain ${output} --insecure-registry=https://insecure.example.com
Should Contain ${output} --whitelist-registry=10.0.0.0/8
Should Contain ${output} --whitelist-registry=https://insecure.example.com

[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-datastore","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 be08f85

Please sign in to comment.