This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VCDA-731] Create initial system tests for vcd-cli (#240)
Implemented system tests for vcd-cli using pyvcloud model and pyvcloud.system_test_framework infra code. Copied and adapted pyvcloud README.md, base_config.yaml, and run_system_tests.sh as well as .ova files required by test framework. Implemented tests for vcd version, login, logout, help, and org commands. Tests run with same vcd_connection file used by pyvcloud to point to vCD installation for test cases.
- Loading branch information
Robert Hodges
committed
Sep 19, 2018
1 parent
e4b39e8
commit 0071023
Showing
10 changed files
with
480 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,6 @@ docs/.bundle | |
docs/_site | ||
docs/vendor | ||
docs/Gemfile.lock | ||
|
||
# Automatically generated system test config | ||
**/auto.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# vcd-cli System Tests | ||
|
||
## Running Tests | ||
|
||
This directory contains system tests that exercise vcd-cli API | ||
functions on any operating system. You can run tests individually | ||
as follows. | ||
|
||
1. Fill in required values in `base_config.yaml`. | ||
2. Execute the test as a Python unit test, e.g.: | ||
``` | ||
python3 -m unittest org_tests.py | ||
``` | ||
|
||
To run system tests in a build, follow the steps below. | ||
|
||
1. Copy `vcd_connection.sample` to `vcd_connection` and fill in | ||
connection data. | ||
2. Export `VCD_CONNECTION`, e.g., `export VDC_CONNECTION=$PWD/vcd_connection` | ||
3. Execute the script as follows: `./run_system_tests.sh` | ||
|
||
This will run a default list of tests. You can specify different tests | ||
by listing the file names on the command line, e.g., | ||
`./run_system_tests.sh my_test.py`. | ||
|
||
## Writing New Tests | ||
|
||
System tests for vcd-cli follow the same conventions as | ||
[pyvcloud](https://github.com/vmware/pyvcloud). Please refer to the pyvcloud | ||
[system_tests/README.md file](https://github.com/vmware/pyvcloud/blob/master/system_tests/README.md) | ||
for more information. | ||
|
||
vcd-cli tests use the Click CliRunner() class, which issues mock calls | ||
against CLI command functions. Have a look at the tests in this directory | ||
as well as [Testing Click Applications](http://click.pocoo.org/5/testing/) | ||
for a full description of how to test Click applications efficiently. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Config parameters for running system tests on pyvcloud | ||
|
||
global: | ||
# If this is turned on, any method decorated with @developer_mode will not be | ||
# executed by unittest. Primarily used to suppress running teardown test | ||
# methods. | ||
developer_mode: False | ||
|
||
connection: | ||
# Supress warnings generated by unittest related to unclosed sockets, | ||
# leaking http connections or missing https certificates | ||
verify: False | ||
disable_ssl_warnings: True | ||
|
||
logging: | ||
default_log_filename: 'vcd-cli-system-test.log' | ||
default_client_log_filename: 'vcd-cli-system-test-client.log' | ||
log_requests: True | ||
log_headers: True | ||
log_bodies: True | ||
|
||
|
||
vcd: | ||
# Fill in the vCloud Dirctor host, sysadmin credentials and other related | ||
# information here. These will be required for the tests to run. | ||
host: '<vcd ip>' | ||
api_version: '30.0' | ||
sys_admin_username: 'administrator' | ||
sys_admin_pass: '<root-password>' | ||
sys_org_name: 'System' | ||
|
||
# The following params defines the org, pvdc, ovdc, etc. that the tests will | ||
# run in / use. It's better to not change them. | ||
|
||
# * = choose first available pdvc | ||
default_pvdc_name: '*' | ||
|
||
default_org_name: 'pyvcloud-system-test-org' | ||
|
||
# org_admin, catalog_author, vapp_author, vapp_user and console_user are | ||
# created by default, their password will be dictated by the following | ||
default_org_user_password : 'vmware' | ||
|
||
default_ovdc_name: 'pyvcloud-system-test-org-vdc' | ||
# * = choose first available storage profile | ||
default_storage_profile_name: '*' | ||
# * = choose first available netpool | ||
default_netpool_name: '*' | ||
default_network_quota: '5' | ||
|
||
default_ovdc_network_name: 'test-isolated-vdc-network' | ||
default_ovdc_network_gateway_ip: '10.1.1.1' | ||
default_ovdc_network_gateway_netmask: '255.255.255.0' | ||
|
||
default_catalog_name: 'test-cat' | ||
default_template_file_name: 'test_vapp_template.ova' | ||
|
||
default_vapp_name: 'test_vapp' | ||
default_vm_name: 'testvm1' | ||
|
||
# vCenter and NSX that must be attached to vCD prior to running tests | ||
vc: | ||
vcenter_host_name: 'vc1' | ||
vcenter_host_ip: '<vc ip>' | ||
vcenter_admin_username: 'administrator@vsphere.local' | ||
vcenter_admin_password: '<vc root password>' | ||
|
||
nsx: | ||
nsx_hostname: 'nsx1' | ||
nsx_host_ip: '<nsx ip>' | ||
nsx_admin_username: 'admin' | ||
nsx_admin_password: '<nsx root password>' | ||
|
||
nsxt: | ||
manager_name: 'nsxTManager1' | ||
manager_host_url: '<nsx-t manager ip>' | ||
admin_user: 'admin' | ||
admin_pwd: '<nsx-t admin password>' | ||
descrip: 'This is a description.' | ||
|
||
pvdc: | ||
pvdc_name: '<pvdc-name>' | ||
resource_pool_names: ['resource-pool-name-1', 'resource-pool-name-2', ...] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
# VMware vCloud Director vCD CLI | ||
# Copyright (c) 2018 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. | ||
|
||
import os | ||
import re | ||
import unittest | ||
from click.testing import CliRunner | ||
|
||
from pyvcloud.system_test_framework.base_test import BaseTestCase | ||
from pyvcloud.system_test_framework.environment import CommonRoles, Environment | ||
from vcd_cli.login import login, logout | ||
from vcd_cli.vcd import vcd, version | ||
|
||
|
||
class LoginAndVcdTest(BaseTestCase): | ||
"""Test login, logout, help, and version operations. | ||
Test cases in this module do not have ordering dependencies, hence all | ||
setup is accomplished using Python unittest setUp and tearDown methods. | ||
Be aware that the login cases will delete existing sessions. | ||
""" | ||
|
||
def setUp(self): | ||
"""Load configuration and create a click runner to invoke CLI.""" | ||
self._config = Environment.get_config() | ||
self._host = self._config['vcd']['host'] | ||
self._org = self._config['vcd']['sys_org_name'] | ||
self._admin_user = self._config['vcd']['sys_admin_username'] | ||
self._admin_pass = self._config['vcd']['sys_admin_pass'] | ||
self._logger = Environment.get_default_logger() | ||
|
||
self._runner = CliRunner() | ||
|
||
def tearDown(self): | ||
"""Logout ignoring any errors to ensure test session is gone.""" | ||
self._logout(check_assertions=False) | ||
|
||
def _logout(self, check_assertions=True): | ||
"""Logs out, checking assertions by default""" | ||
result = self._runner.invoke(logout) | ||
if check_assertions: | ||
self.assertEqual(0, result.exit_code) | ||
self.assertTrue("logged out" in result.output) | ||
|
||
def test_0010_admin_login(self): | ||
"""Login with valid admin credentials succeeds and shows 'logged in' tag | ||
""" | ||
login_args = [ | ||
self._host, self._org, self._admin_user, "-i", | ||
"-w", "--password={0}".format(self._admin_pass) | ||
] | ||
result = self._runner.invoke(login, args=login_args) | ||
self.assertEqual(0, result.exit_code) | ||
self.assertTrue("logged in" in result.output) | ||
self._logout() | ||
|
||
def test_0015_tenant_login(self): | ||
"""Login with valid tenant credentials succeeds and shows 'logged in' tag | ||
""" | ||
org = self._config['vcd']['default_org_name'] | ||
user = Environment.get_username_for_role_in_test_org( | ||
CommonRoles.VAPP_USER) | ||
password = self._config['vcd']['default_org_user_password'] | ||
login_args = [ | ||
self._host, org, user, "-i", | ||
"-w", "--password={0}".format(password) | ||
] | ||
result = self._runner.invoke(login, args=login_args) | ||
self.assertEqual(0, result.exit_code) | ||
self.assertTrue("logged in" in result.output) | ||
self._logout() | ||
|
||
def test_0020_login_with_env_password(self): | ||
"""Login works with password in VCD_PASSWORD environmental variable | ||
""" | ||
login_args = [self._host, self._org, self._admin_user, "-i", "-w"] | ||
try: | ||
os.environ["VCD_PASSWORD"] = self._admin_pass | ||
result = self._runner.invoke(login, args=login_args) | ||
self.assertEqual(0, result.exit_code) | ||
self.assertTrue("logged in" in result.output) | ||
finally: | ||
# Pop value to prevent other cases from using it accidentally. | ||
os.environ.pop("VCD_PASSWORD") | ||
|
||
def test_0025_set_server_version(self): | ||
"""Login can set any API version supported by server | ||
""" | ||
# Use a pyvcloud client to find out the supported versions. | ||
client = Environment.get_sys_admin_client() | ||
server_versions = client.get_supported_versions_list() | ||
client.logout() | ||
|
||
# Use the aforesaid versions and login/logout to each. | ||
for server_version in server_versions: | ||
self._logger.debug( | ||
"Login using server API version {0}".format(server_version)) | ||
login_args = [ | ||
self._host, self._org, self._admin_user, "-i", "--password", | ||
self._admin_pass, "-w", "--version", server_version | ||
] | ||
result = self._runner.invoke(login, args=login_args) | ||
self.assertEqual(0, result.exit_code) | ||
self.assertTrue("logged in" in result.output) | ||
self._logout() | ||
|
||
def test_0030_invalid_login(self): | ||
"""Login with valid tenant credentials succeeds and shows 'logged in' tag | ||
""" | ||
login_args = [ | ||
self._host, self._org, self._admin_user, "-i", | ||
"-w", "--password={0}".format('invalidpassword')] | ||
result = self._runner.invoke(login, args=login_args) | ||
self.assertNotEqual(0, result.exit_code) | ||
self.assertFalse("logged in" in result.output) | ||
|
||
def test_0040_vcd_help(self): | ||
"""help, -h, and --help options provide vcd command help""" | ||
for help in ['help', '-h', '--help']: | ||
res = self._runner.invoke(vcd, args=[help]) | ||
self.assertEqual(0, res.exit_code, msg="Option: " + help) | ||
self.assertTrue( | ||
"VMware vCloud Director Command Line Interface" in res.output, | ||
msg="Option: " + help) | ||
|
||
def test_0050_version(self): | ||
"""vcd version command shows a version string""" | ||
result = self._runner.invoke(version) | ||
self.assertEqual(0, result.exit_code) | ||
self.assertTrue("vcd-cli" in result.output, msg=result.output) | ||
version_pattern = re.compile('[0-9]+\.[0-3]+\.[0-9]+') | ||
self.assertTrue( | ||
version_pattern.search(result.output) is not None, | ||
msg=result.output) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.