blob: 80376abd79cb69c66bfde61e5aa1cc61f263effb [file] [log] [blame]
saurabh55c29c72013-07-26 21:15:08 +05301# 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 re
19import subprocess
20
21from oslo.config import cfg
saurabh55c29c72013-07-26 21:15:08 +053022
23import tempest.cli
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040024from tempest.openstack.common import log as logging
Matthew Treinishe22c97a2013-10-16 20:55:52 +000025from tempest import test
saurabh55c29c72013-07-26 21:15:08 +053026
27CONF = cfg.CONF
28
29LOG = logging.getLogger(__name__)
30
31
32class SimpleReadOnlyNeutronClientTest(tempest.cli.ClientTestBase):
33 """Basic, read-only tests for Neutron CLI client.
34
35 Checks return values and output of read-only commands.
36 These tests do not presume any content, nor do they create
37 their own. They only verify the structure of output if present.
38 """
Matthew Treinishe8940592013-07-30 13:36:09 -040039
40 @classmethod
41 def setUpClass(cls):
42 if (not CONF.service_available.neutron):
43 msg = "Skiping all Neutron cli tests because it is not available"
44 raise cls.skipException(msg)
45 super(SimpleReadOnlyNeutronClientTest, cls).setUpClass()
saurabh55c29c72013-07-26 21:15:08 +053046
Sean Dagueb6924642013-12-12 10:39:23 -050047 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +053048 def test_neutron_fake_action(self):
49 self.assertRaises(subprocess.CalledProcessError,
50 self.neutron,
51 'this-does-not-exist')
52
Sean Dagueb6924642013-12-12 10:39:23 -050053 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +053054 def test_neutron_net_list(self):
55 self.neutron('net-list')
56
Sean Dagueb6924642013-12-12 10:39:23 -050057 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +053058 def test_neutron_ext_list(self):
59 ext = self.parser.listing(self.neutron('ext-list'))
60 self.assertTableStruct(ext, ['alias', 'name'])
61
Sean Dagueb6924642013-12-12 10:39:23 -050062 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +053063 def test_neutron_dhcp_agent_list_hosting_net(self):
Matt Riedemannd4dc5142013-07-31 03:47:54 -070064 self.neutron('dhcp-agent-list-hosting-net',
65 params=CONF.compute.fixed_network_name)
saurabh55c29c72013-07-26 21:15:08 +053066
Sean Dagueb6924642013-12-12 10:39:23 -050067 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +053068 def test_neutron_agent_list(self):
69 agents = self.parser.listing(self.neutron('agent-list'))
70 field_names = ['id', 'agent_type', 'host', 'alive', 'admin_state_up']
71 self.assertTableStruct(agents, field_names)
72
Sean Dagueb6924642013-12-12 10:39:23 -050073 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +053074 def test_neutron_floatingip_list(self):
75 self.neutron('floatingip-list')
76
Matthew Treinishe22c97a2013-10-16 20:55:52 +000077 @test.skip_because(bug="1240694")
Sean Dagueb6924642013-12-12 10:39:23 -050078 @test.attr(type='smoke')
Cyril Roelandt10a02d72013-10-08 12:31:01 +000079 def test_neutron_meter_label_list(self):
80 self.neutron('meter-label-list')
81
Matthew Treinishe22c97a2013-10-16 20:55:52 +000082 @test.skip_because(bug="1240694")
Sean Dagueb6924642013-12-12 10:39:23 -050083 @test.attr(type='smoke')
Cyril Roelandt10a02d72013-10-08 12:31:01 +000084 def test_neutron_meter_label_rule_list(self):
85 self.neutron('meter-label-rule-list')
86
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +000087 def _test_neutron_lbaas_command(self, command):
88 try:
89 self.neutron(command)
90 except tempest.cli.CommandFailed as e:
91 if '404 Not Found' not in e.stderr:
92 self.fail('%s: Unexpected failure.' % command)
93
Sean Dagueb6924642013-12-12 10:39:23 -050094 @test.attr(type='smoke')
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +000095 def test_neutron_lb_healthmonitor_list(self):
96 self._test_neutron_lbaas_command('lb-healthmonitor-list')
97
Sean Dagueb6924642013-12-12 10:39:23 -050098 @test.attr(type='smoke')
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +000099 def test_neutron_lb_member_list(self):
100 self._test_neutron_lbaas_command('lb-member-list')
101
Sean Dagueb6924642013-12-12 10:39:23 -0500102 @test.attr(type='smoke')
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +0000103 def test_neutron_lb_pool_list(self):
104 self._test_neutron_lbaas_command('lb-pool-list')
105
Sean Dagueb6924642013-12-12 10:39:23 -0500106 @test.attr(type='smoke')
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +0000107 def test_neutron_lb_vip_list(self):
108 self._test_neutron_lbaas_command('lb-vip-list')
109
Sean Dagueb6924642013-12-12 10:39:23 -0500110 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530111 def test_neutron_net_external_list(self):
112 self.neutron('net-external-list')
113
Sean Dagueb6924642013-12-12 10:39:23 -0500114 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530115 def test_neutron_port_list(self):
116 self.neutron('port-list')
117
Sean Dagueb6924642013-12-12 10:39:23 -0500118 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530119 def test_neutron_quota_list(self):
120 self.neutron('quota-list')
121
Sean Dagueb6924642013-12-12 10:39:23 -0500122 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530123 def test_neutron_router_list(self):
124 self.neutron('router-list')
125
Sean Dagueb6924642013-12-12 10:39:23 -0500126 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530127 def test_neutron_security_group_list(self):
128 security_grp = self.parser.listing(self.neutron('security-group-list'))
129 self.assertTableStruct(security_grp, ['id', 'name', 'description'])
130
Sean Dagueb6924642013-12-12 10:39:23 -0500131 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530132 def test_neutron_security_group_rule_list(self):
133 self.neutron('security-group-rule-list')
134
Sean Dagueb6924642013-12-12 10:39:23 -0500135 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530136 def test_neutron_subnet_list(self):
137 self.neutron('subnet-list')
138
Sean Dagueb6924642013-12-12 10:39:23 -0500139 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530140 def test_neutron_help(self):
141 help_text = self.neutron('help')
142 lines = help_text.split('\n')
Pavel Sedlák4c18fa12013-08-22 21:29:45 +0200143 self.assertFirstLineStartsWith(lines, 'usage: neutron')
saurabh55c29c72013-07-26 21:15:08 +0530144
145 commands = []
146 cmds_start = lines.index('Commands for API v2.0:')
147 command_pattern = re.compile('^ {2}([a-z0-9\-\_]+)')
148 for line in lines[cmds_start:]:
149 match = command_pattern.match(line)
150 if match:
151 commands.append(match.group(1))
152 commands = set(commands)
153 wanted_commands = set(('net-create', 'subnet-list', 'port-delete',
154 'router-show', 'agent-update', 'help'))
155 self.assertFalse(wanted_commands - commands)
156
157 # Optional arguments:
158
Sean Dagueb6924642013-12-12 10:39:23 -0500159 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530160 def test_neutron_version(self):
161 self.neutron('', flags='--version')
162
Sean Dagueb6924642013-12-12 10:39:23 -0500163 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530164 def test_neutron_debug_net_list(self):
165 self.neutron('net-list', flags='--debug')
166
Sean Dagueb6924642013-12-12 10:39:23 -0500167 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530168 def test_neutron_quiet_net_list(self):
169 self.neutron('net-list', flags='--quiet')