|
| 1 | +# VMware vCloud Director vCD CLI |
| 2 | +# Copyright (c) 2018 VMware, Inc. All Rights Reserved. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +import os |
| 16 | + |
| 17 | +from click.testing import CliRunner |
| 18 | +from pyvcloud.system_test_framework.base_test import BaseTestCase |
| 19 | +from pyvcloud.system_test_framework.environment import Environment |
| 20 | + |
| 21 | +from vcd_cli.login import login, logout |
| 22 | +from vcd_cli.vm import vm |
| 23 | + |
| 24 | + |
| 25 | +class VMTest(BaseTestCase): |
| 26 | + """Test vm-related commands |
| 27 | +
|
| 28 | + Tests cases in this module do not have ordering dependencies, |
| 29 | + so setup is accomplished using Python unittest setUp and tearDown |
| 30 | + methods. |
| 31 | +
|
| 32 | + Be aware that this test will delete existing vcd-cli sessions. |
| 33 | + """ |
| 34 | + |
| 35 | + def setUp(self): |
| 36 | + """Load configuration and create a click runner to invoke CLI.""" |
| 37 | + os.environ["LC_ALL"] = "en_US.UTF-8" |
| 38 | + os.environ["LANG"] = "en_US.UTF-8" |
| 39 | + self._config = Environment.get_config() |
| 40 | + self._logger = Environment.get_default_logger() |
| 41 | + self._runner = CliRunner() |
| 42 | + |
| 43 | + def tearDown(self): |
| 44 | + """Logout ignoring any errors to ensure test session is gone.""" |
| 45 | + self._logout() |
| 46 | + |
| 47 | + def _login(self): |
| 48 | + """Logs in using admin credentials""" |
| 49 | + host = self._config['vcd']['host'] |
| 50 | + org = self._config['vcd']['sys_org_name'] |
| 51 | + admin_user = self._config['vcd']['sys_admin_username'] |
| 52 | + admin_pass = self._config['vcd']['sys_admin_pass'] |
| 53 | + login_args = [ |
| 54 | + host, org, admin_user, "-i", "-w", |
| 55 | + "--password={0}".format(admin_pass) |
| 56 | + ] |
| 57 | + result = self._runner.invoke(login, args=login_args) |
| 58 | + self.assertEqual(0, result.exit_code) |
| 59 | + self.assertTrue("logged in" in result.output) |
| 60 | + |
| 61 | + def _logout(self): |
| 62 | + """Logs out current session, ignoring errors""" |
| 63 | + self._runner.invoke(logout) |
| 64 | + |
| 65 | + def test_0010_vm_list(self): |
| 66 | + """user can list vms |
| 67 | + """ |
| 68 | + self._login() |
| 69 | + result = self._runner.invoke(vm, args=['list', 'build-vms']) |
| 70 | + self._logger.debug("VM List: {0}".format(result.output)) |
| 71 | + self.assertEqual(0, result.exit_code) |
| 72 | + |
| 73 | + def test_0020_vm_show_snapshot(self): |
| 74 | + """user can show-snapshot vm |
| 75 | + """ |
| 76 | + self._login() |
| 77 | + result = self._runner.invoke(vm, args=['show-snapshot', 'build-vms', 'build-03-422']) |
| 78 | + self._logger.debug("VM Snapshot List: {0}".format(result.output)) |
| 79 | + self.assertEqual(0, result.exit_code) |
| 80 | + |
| 81 | + def test_0030_vm_create_snapshot(self): |
| 82 | + """user can create-snapshot vm |
| 83 | + """ |
| 84 | + self._login() |
| 85 | + result = self._runner.invoke(vm, args=['create-snapshot', 'build-vms', 'build-03-422', 'vanilla']) |
| 86 | + self._logger.debug("VM Snapshot Create: {0}".format(result.output)) |
| 87 | + self.assertEqual(0, result.exit_code) |
| 88 | + |
| 89 | + def test_0030_vm_revert_snapshot(self): |
| 90 | + """user can revert-snapshot vm |
| 91 | + """ |
| 92 | + self._login() |
| 93 | + result = self._runner.invoke(vm, args=['revert-snapshot', 'build-vms', 'build-03-422']) |
| 94 | + self._logger.debug("VM Snapshot Revert: {0}".format(result.output)) |
| 95 | + self.assertEqual(0, result.exit_code) |
| 96 | + |
| 97 | + def test_0040_vm_remove_snapshot(self): |
| 98 | + """user can remove-snapshot vm |
| 99 | + """ |
| 100 | + self._login() |
| 101 | + result = self._runner.invoke(vm, args=['remove-snapshot', 'build-vms', 'build-03-422']) |
| 102 | + self._logger.debug("VM Snapshot Revert: {0}".format(result.output)) |
| 103 | + self.assertEqual(0, result.exit_code) |
| 104 | + |
| 105 | + def test_0050_vm_power_on(self): |
| 106 | + """user can power-on vm |
| 107 | + """ |
| 108 | + self._login() |
| 109 | + result = self._runner.invoke(vm, args=['power-on', 'build-vms', 'build-03-422']) |
| 110 | + self._logger.debug("VM Power On: {0}".format(result.output)) |
| 111 | + self.assertEqual(0, result.exit_code) |
| 112 | + |
| 113 | + def test_0060_vm_power_off(self): |
| 114 | + """user can power-off vm |
| 115 | + """ |
| 116 | + self._login() |
| 117 | + result = self._runner.invoke(vm, args=['power-off', 'build-vms', 'build-03-422']) |
| 118 | + self._logger.debug("VM Power On: {0}".format(result.output)) |
| 119 | + self.assertEqual(0, result.exit_code) |
| 120 | + |
| 121 | + def test_0070_vm_power_reset(self): |
| 122 | + """user can power-reset vm |
| 123 | + """ |
| 124 | + self._login() |
| 125 | + result = self._runner.invoke(vm, args=['power-reset', 'build-vms', 'build-03-422']) |
| 126 | + self._logger.debug("VM Power On: {0}".format(result.output)) |
| 127 | + self.assertEqual(0, result.exit_code) |
| 128 | + |
| 129 | + def test_0080_vm_reboot(self): |
| 130 | + """user can reboot vm |
| 131 | + """ |
| 132 | + self._login() |
| 133 | + result = self._runner.invoke(vm, args=['reboot', 'build-vms', 'build-03-422']) |
| 134 | + self._logger.debug("VM Reboot: {0}".format(result.output)) |
| 135 | + self.assertEqual(0, result.exit_code) |
| 136 | + |
| 137 | + def test_0090_vm_shutdown(self): |
| 138 | + """user can shutdown vm |
| 139 | + """ |
| 140 | + self._login() |
| 141 | + result = self._runner.invoke(vm, args=['shutdown', 'build-vms', 'build-03-422']) |
| 142 | + self._logger.debug("VM Shutdown: {0}".format(result.output)) |
| 143 | + self.assertEqual(0, result.exit_code) |
0 commit comments