blob: ebf0dc4f9db427644e29a62dcf181367941b4cb4 [file] [log] [blame]
saurabh55c29c72013-07-26 21:15:08 +05301# Copyright 2013 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# 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, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import re
17import subprocess
18
vponomaryovaa86a802014-01-06 09:29:58 +020019from tempest import cli
20from tempest import config
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040021from tempest.openstack.common import log as logging
Matthew Treinishe22c97a2013-10-16 20:55:52 +000022from tempest import test
saurabh55c29c72013-07-26 21:15:08 +053023
vponomaryovaa86a802014-01-06 09:29:58 +020024CONF = config.CONF
saurabh55c29c72013-07-26 21:15:08 +053025
26LOG = logging.getLogger(__name__)
27
28
vponomaryovaa86a802014-01-06 09:29:58 +020029class SimpleReadOnlyNeutronClientTest(cli.ClientTestBase):
saurabh55c29c72013-07-26 21:15:08 +053030 """Basic, read-only tests for Neutron CLI client.
31
32 Checks return values and output of read-only commands.
33 These tests do not presume any content, nor do they create
34 their own. They only verify the structure of output if present.
35 """
Matthew Treinishe8940592013-07-30 13:36:09 -040036
37 @classmethod
38 def setUpClass(cls):
39 if (not CONF.service_available.neutron):
Steven Hardy028d2e52014-01-06 10:03:11 +000040 msg = "Skipping all Neutron cli tests because it is not available"
Matthew Treinishe8940592013-07-30 13:36:09 -040041 raise cls.skipException(msg)
42 super(SimpleReadOnlyNeutronClientTest, cls).setUpClass()
saurabh55c29c72013-07-26 21:15:08 +053043
Sean Dagueb6924642013-12-12 10:39:23 -050044 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +053045 def test_neutron_fake_action(self):
46 self.assertRaises(subprocess.CalledProcessError,
47 self.neutron,
48 'this-does-not-exist')
49
Sean Dagueb6924642013-12-12 10:39:23 -050050 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +053051 def test_neutron_net_list(self):
52 self.neutron('net-list')
53
Sean Dagueb6924642013-12-12 10:39:23 -050054 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +053055 def test_neutron_ext_list(self):
56 ext = self.parser.listing(self.neutron('ext-list'))
57 self.assertTableStruct(ext, ['alias', 'name'])
58
Sean Dagueb6924642013-12-12 10:39:23 -050059 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +053060 def test_neutron_dhcp_agent_list_hosting_net(self):
Matt Riedemannd4dc5142013-07-31 03:47:54 -070061 self.neutron('dhcp-agent-list-hosting-net',
62 params=CONF.compute.fixed_network_name)
saurabh55c29c72013-07-26 21:15:08 +053063
Sean Dagueb6924642013-12-12 10:39:23 -050064 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +053065 def test_neutron_agent_list(self):
66 agents = self.parser.listing(self.neutron('agent-list'))
67 field_names = ['id', 'agent_type', 'host', 'alive', 'admin_state_up']
68 self.assertTableStruct(agents, field_names)
69
Sean Dagueb6924642013-12-12 10:39:23 -050070 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +053071 def test_neutron_floatingip_list(self):
72 self.neutron('floatingip-list')
73
Matthew Treinishe22c97a2013-10-16 20:55:52 +000074 @test.skip_because(bug="1240694")
Sean Dagueb6924642013-12-12 10:39:23 -050075 @test.attr(type='smoke')
mouad benchchaouiea2440d2013-12-22 00:38:06 +010076 @test.requires_ext(extension='metering', service='network')
Cyril Roelandt10a02d72013-10-08 12:31:01 +000077 def test_neutron_meter_label_list(self):
78 self.neutron('meter-label-list')
79
Matthew Treinishe22c97a2013-10-16 20:55:52 +000080 @test.skip_because(bug="1240694")
Sean Dagueb6924642013-12-12 10:39:23 -050081 @test.attr(type='smoke')
mouad benchchaouiea2440d2013-12-22 00:38:06 +010082 @test.requires_ext(extension='metering', service='network')
Cyril Roelandt10a02d72013-10-08 12:31:01 +000083 def test_neutron_meter_label_rule_list(self):
84 self.neutron('meter-label-rule-list')
85
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +000086 def _test_neutron_lbaas_command(self, command):
87 try:
88 self.neutron(command)
vponomaryovaa86a802014-01-06 09:29:58 +020089 except cli.CommandFailed as e:
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +000090 if '404 Not Found' not in e.stderr:
91 self.fail('%s: Unexpected failure.' % command)
92
Sean Dagueb6924642013-12-12 10:39:23 -050093 @test.attr(type='smoke')
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +000094 def test_neutron_lb_healthmonitor_list(self):
95 self._test_neutron_lbaas_command('lb-healthmonitor-list')
96
Sean Dagueb6924642013-12-12 10:39:23 -050097 @test.attr(type='smoke')
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +000098 def test_neutron_lb_member_list(self):
99 self._test_neutron_lbaas_command('lb-member-list')
100
Sean Dagueb6924642013-12-12 10:39:23 -0500101 @test.attr(type='smoke')
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +0000102 def test_neutron_lb_pool_list(self):
103 self._test_neutron_lbaas_command('lb-pool-list')
104
Sean Dagueb6924642013-12-12 10:39:23 -0500105 @test.attr(type='smoke')
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +0000106 def test_neutron_lb_vip_list(self):
107 self._test_neutron_lbaas_command('lb-vip-list')
108
Sean Dagueb6924642013-12-12 10:39:23 -0500109 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530110 def test_neutron_net_external_list(self):
111 self.neutron('net-external-list')
112
Sean Dagueb6924642013-12-12 10:39:23 -0500113 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530114 def test_neutron_port_list(self):
115 self.neutron('port-list')
116
Sean Dagueb6924642013-12-12 10:39:23 -0500117 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530118 def test_neutron_quota_list(self):
119 self.neutron('quota-list')
120
Sean Dagueb6924642013-12-12 10:39:23 -0500121 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530122 def test_neutron_router_list(self):
123 self.neutron('router-list')
124
Sean Dagueb6924642013-12-12 10:39:23 -0500125 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530126 def test_neutron_security_group_list(self):
127 security_grp = self.parser.listing(self.neutron('security-group-list'))
128 self.assertTableStruct(security_grp, ['id', 'name', 'description'])
129
Sean Dagueb6924642013-12-12 10:39:23 -0500130 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530131 def test_neutron_security_group_rule_list(self):
132 self.neutron('security-group-rule-list')
133
Sean Dagueb6924642013-12-12 10:39:23 -0500134 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530135 def test_neutron_subnet_list(self):
136 self.neutron('subnet-list')
137
Sean Dagueb6924642013-12-12 10:39:23 -0500138 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530139 def test_neutron_help(self):
140 help_text = self.neutron('help')
141 lines = help_text.split('\n')
Pavel Sedlák4c18fa12013-08-22 21:29:45 +0200142 self.assertFirstLineStartsWith(lines, 'usage: neutron')
saurabh55c29c72013-07-26 21:15:08 +0530143
144 commands = []
145 cmds_start = lines.index('Commands for API v2.0:')
146 command_pattern = re.compile('^ {2}([a-z0-9\-\_]+)')
147 for line in lines[cmds_start:]:
148 match = command_pattern.match(line)
149 if match:
150 commands.append(match.group(1))
151 commands = set(commands)
152 wanted_commands = set(('net-create', 'subnet-list', 'port-delete',
153 'router-show', 'agent-update', 'help'))
154 self.assertFalse(wanted_commands - commands)
155
vponomaryovaa86a802014-01-06 09:29:58 +0200156 # Optional arguments:
saurabh55c29c72013-07-26 21:15:08 +0530157
Sean Dagueb6924642013-12-12 10:39:23 -0500158 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530159 def test_neutron_version(self):
160 self.neutron('', flags='--version')
161
Sean Dagueb6924642013-12-12 10:39:23 -0500162 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530163 def test_neutron_debug_net_list(self):
164 self.neutron('net-list', flags='--debug')
165
Sean Dagueb6924642013-12-12 10:39:23 -0500166 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530167 def test_neutron_quiet_net_list(self):
168 self.neutron('net-list', flags='--quiet')