blob: 073fde149f48a2d46ebb14b351daaa7158de27e6 [file] [log] [blame]
Joe Gordonc97f5c72013-02-14 01:15:57 +00001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 OpenStack Foundation
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18import logging
19import shlex
20import subprocess
21
22import testtools
23
24import cli
25
26from tempest import config
27from tempest.openstack.common import cfg
28
29
30CONF = cfg.CONF
31
32
33LOG = logging.getLogger(__name__)
34
35
36class SimpleReadOnlyNovaCLientTest(testtools.TestCase):
37
38 """
39 This is a first pass at a simple read only python-novaclient test. This
40 only exercises client commands that are read only.
41
42 This should test commands:
43 * as a regular user
44 * as a admin user
45 * with and without optional parameters
46 * initially just check return codes, and later test command outputs
47
48 """
49
50 @classmethod
51 def setUpClass(cls):
52 if not CONF.cli.enabled:
53 msg = "cli testing disabled"
54 raise cls.skipException(msg)
55 cls.identity = config.TempestConfig().identity
56 super(SimpleReadOnlyNovaCLientTest, cls).setUpClass()
57
Joe Gordon34dc84d2013-02-21 02:19:23 +000058 #NOTE(jogo): This should eventually be moved into a base class
Joe Gordonc97f5c72013-02-14 01:15:57 +000059 def nova(self, action, flags='', params='', admin=True, fail_ok=False):
60 """Executes nova command for the given action."""
61 #TODO(jogo) make admin=False work
62 creds = ('--os-username %s --os-tenant-name %s --os-password %s '
63 '--os-auth-url %s ' % (self.identity.admin_username,
64 self.identity.admin_tenant_name, self.identity.admin_password,
65 self.identity.uri))
66 flags = creds + ' ' + flags
67 cmd = ' '.join([CONF.cli.cli_dir + 'nova', flags, action, params])
68 LOG.info("running: '%s'" % cmd)
69 cmd = shlex.split(cmd)
Joe Gordon34dc84d2013-02-21 02:19:23 +000070 try:
71 result = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
72 except subprocess.CalledProcessError, e:
73 LOG.error("command output:\n%s" % e.output)
74 raise
Joe Gordonc97f5c72013-02-14 01:15:57 +000075 return result
76
Joe Gordonc97f5c72013-02-14 01:15:57 +000077 def test_admin_fake_action(self):
78 self.assertRaises(subprocess.CalledProcessError,
79 self.nova,
80 'this-does-nova-exist')
81
Joe Gordon34dc84d2013-02-21 02:19:23 +000082 #NOTE(jogo): Commands in order listed in 'nova help'
83
84 # Positional arguments:
85
86 def test_admin_absolute_limites(self):
87 self.nova('absolute-limits')
88
Joe Gordonc97f5c72013-02-14 01:15:57 +000089 def test_admin_aggregate_list(self):
90 self.nova('aggregate-list')
91
Joe Gordon34dc84d2013-02-21 02:19:23 +000092 def test_admin_availability_zone_list(self):
93 self.nova('availability-zone-list')
94
Joe Gordonc97f5c72013-02-14 01:15:57 +000095 def test_admin_cloudpipe_list(self):
96 self.nova('cloudpipe-list')
97
Joe Gordon34dc84d2013-02-21 02:19:23 +000098 def test_admin_credentials(self):
99 self.nova('credentials')
Joe Gordonc97f5c72013-02-14 01:15:57 +0000100
101 def test_admin_dns_domains(self):
102 self.nova('dns-domains')
103
Joe Gordon34dc84d2013-02-21 02:19:23 +0000104 @testtools.skip("needs parameters")
105 def test_admin_dns_list(self):
106 self.nova('dns-list')
107
108 def test_admin_endpoints(self):
109 self.nova('endpoints')
110
111 def test_admin_flavor_acces_list(self):
112 self.assertRaises(subprocess.CalledProcessError,
113 self.nova,
114 'flavor-access-list')
115 # Failed to get access list for public flavor type
116 self.assertRaises(subprocess.CalledProcessError,
117 self.nova,
118 'flavor-access-list',
119 params='--flavor m1.tiny')
120
Joe Gordonc97f5c72013-02-14 01:15:57 +0000121 def test_admin_flavor_list(self):
122 self.nova('flavor-list')
123
Joe Gordon34dc84d2013-02-21 02:19:23 +0000124 def test_admin_floating_ip_bulk_list(self):
125 self.nova('floating-ip-bulk-list')
126
127 def test_admin_floating_ip_list(self):
128 self.nova('floating-ip-list')
129
130 def test_admin_floating_ip_pool_list(self):
131 self.nova('floating-ip-pool-list')
132
133 def test_admin_host_list(self):
134 self.nova('host-list')
135
136 def test_admin_hypervisor_list(self):
137 self.nova('hypervisor-list')
138
139 def test_admin_image_list(self):
140 self.nova('image-list')
141
142 @testtools.skip("needs parameters")
143 def test_admin_interface_list(self):
144 self.nova('interface-list')
145
146 def test_admin_keypair_list(self):
147 self.nova('keypair-list')
148
149 def test_admin_list(self):
150 self.nova('list')
151 self.nova('list', params='--all-tenants 1')
152 self.nova('list', params='--all-tenants 0')
153 self.assertRaises(subprocess.CalledProcessError,
154 self.nova,
155 'list',
156 params='--all-tenants bad')
157
158 def test_admin_network_list(self):
159 self.nova('network-list')
160
161 def test_admin_rate_limits(self):
162 self.nova('rate-limits')
163
164 def test_admin_secgroup_list(self):
165 self.nova('secgroup-list')
166
167 @testtools.skip("needs parameters")
168 def test_admin_secgroup_list_rules(self):
169 self.nova('secgroup-list-rules')
170
171 def test_admin_servce_list(self):
172 self.nova('service-list')
173
174 def test_admin_usage(self):
175 self.nova('usage')
176
177 def test_admin_usage_list(self):
178 self.nova('usage-list')
179
180 def test_admin_volume_list(self):
181 self.nova('volume-list')
182
183 def test_admin_volume_snapshot_list(self):
184 self.nova('volume-snapshot-list')
185
186 def test_admin_volume_type_list(self):
187 self.nova('volume-type-list')
188
189 def test_admin_help(self):
190 self.nova('help')
191
192 def test_admin_list_extensions(self):
193 self.nova('list-extensions')
194
195 def test_admin_net_list(self):
196 self.nova('net-list')
197
198 # Optional arguments:
199
200 def test_admin_version(self):
201 self.nova('', flags='--version')
202
203 def test_admin_debug_list(self):
204 self.nova('list', flags='--debug')
205
206 def test_admin_timeout(self):
207 self.nova('list', flags='--timeout 2')
208
209 def test_admin_timing(self):
210 self.nova('list', flags='--timing')