blob: c1d58b5570987f5f016c87754ccb8595f6128baa [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')
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090060 @test.requires_ext(extension='dhcp_agent_scheduler', service='network')
saurabh55c29c72013-07-26 21:15:08 +053061 def test_neutron_dhcp_agent_list_hosting_net(self):
Matt Riedemannd4dc5142013-07-31 03:47:54 -070062 self.neutron('dhcp-agent-list-hosting-net',
63 params=CONF.compute.fixed_network_name)
saurabh55c29c72013-07-26 21:15:08 +053064
Sean Dagueb6924642013-12-12 10:39:23 -050065 @test.attr(type='smoke')
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090066 @test.requires_ext(extension='agent', service='network')
saurabh55c29c72013-07-26 21:15:08 +053067 def test_neutron_agent_list(self):
68 agents = self.parser.listing(self.neutron('agent-list'))
69 field_names = ['id', 'agent_type', 'host', 'alive', 'admin_state_up']
70 self.assertTableStruct(agents, field_names)
71
Sean Dagueb6924642013-12-12 10:39:23 -050072 @test.attr(type='smoke')
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090073 @test.requires_ext(extension='router', service='network')
saurabh55c29c72013-07-26 21:15:08 +053074 def test_neutron_floatingip_list(self):
75 self.neutron('floatingip-list')
76
Sean Dagueb6924642013-12-12 10:39:23 -050077 @test.attr(type='smoke')
mouad benchchaouiea2440d2013-12-22 00:38:06 +010078 @test.requires_ext(extension='metering', service='network')
Cyril Roelandt10a02d72013-10-08 12:31:01 +000079 def test_neutron_meter_label_list(self):
80 self.neutron('meter-label-list')
81
Sean Dagueb6924642013-12-12 10:39:23 -050082 @test.attr(type='smoke')
mouad benchchaouiea2440d2013-12-22 00:38:06 +010083 @test.requires_ext(extension='metering', service='network')
Cyril Roelandt10a02d72013-10-08 12:31:01 +000084 def test_neutron_meter_label_rule_list(self):
85 self.neutron('meter-label-rule-list')
86
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090087 @test.requires_ext(extension='lbaas_agent_scheduler', service='network')
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +000088 def _test_neutron_lbaas_command(self, command):
89 try:
90 self.neutron(command)
vponomaryovaa86a802014-01-06 09:29:58 +020091 except cli.CommandFailed as e:
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +000092 if '404 Not Found' not in e.stderr:
93 self.fail('%s: Unexpected failure.' % command)
94
Sean Dagueb6924642013-12-12 10:39:23 -050095 @test.attr(type='smoke')
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +000096 def test_neutron_lb_healthmonitor_list(self):
97 self._test_neutron_lbaas_command('lb-healthmonitor-list')
98
Sean Dagueb6924642013-12-12 10:39:23 -050099 @test.attr(type='smoke')
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +0000100 def test_neutron_lb_member_list(self):
101 self._test_neutron_lbaas_command('lb-member-list')
102
Sean Dagueb6924642013-12-12 10:39:23 -0500103 @test.attr(type='smoke')
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +0000104 def test_neutron_lb_pool_list(self):
105 self._test_neutron_lbaas_command('lb-pool-list')
106
Sean Dagueb6924642013-12-12 10:39:23 -0500107 @test.attr(type='smoke')
Cyril Roelandtb18d5fb2013-10-09 20:23:39 +0000108 def test_neutron_lb_vip_list(self):
109 self._test_neutron_lbaas_command('lb-vip-list')
110
Sean Dagueb6924642013-12-12 10:39:23 -0500111 @test.attr(type='smoke')
Yoshihiro Kaneko05670262014-01-18 19:22:44 +0900112 @test.requires_ext(extension='external-net', service='network')
saurabh55c29c72013-07-26 21:15:08 +0530113 def test_neutron_net_external_list(self):
114 self.neutron('net-external-list')
115
Sean Dagueb6924642013-12-12 10:39:23 -0500116 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530117 def test_neutron_port_list(self):
118 self.neutron('port-list')
119
Sean Dagueb6924642013-12-12 10:39:23 -0500120 @test.attr(type='smoke')
Yoshihiro Kaneko05670262014-01-18 19:22:44 +0900121 @test.requires_ext(extension='quotas', service='network')
saurabh55c29c72013-07-26 21:15:08 +0530122 def test_neutron_quota_list(self):
123 self.neutron('quota-list')
124
Sean Dagueb6924642013-12-12 10:39:23 -0500125 @test.attr(type='smoke')
Yoshihiro Kaneko05670262014-01-18 19:22:44 +0900126 @test.requires_ext(extension='router', service='network')
saurabh55c29c72013-07-26 21:15:08 +0530127 def test_neutron_router_list(self):
128 self.neutron('router-list')
129
Sean Dagueb6924642013-12-12 10:39:23 -0500130 @test.attr(type='smoke')
Yoshihiro Kaneko05670262014-01-18 19:22:44 +0900131 @test.requires_ext(extension='security-group', service='network')
saurabh55c29c72013-07-26 21:15:08 +0530132 def test_neutron_security_group_list(self):
133 security_grp = self.parser.listing(self.neutron('security-group-list'))
134 self.assertTableStruct(security_grp, ['id', 'name', 'description'])
135
Sean Dagueb6924642013-12-12 10:39:23 -0500136 @test.attr(type='smoke')
Yoshihiro Kaneko05670262014-01-18 19:22:44 +0900137 @test.requires_ext(extension='security-group', service='network')
saurabh55c29c72013-07-26 21:15:08 +0530138 def test_neutron_security_group_rule_list(self):
139 self.neutron('security-group-rule-list')
140
Sean Dagueb6924642013-12-12 10:39:23 -0500141 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530142 def test_neutron_subnet_list(self):
143 self.neutron('subnet-list')
144
Sean Dagueb6924642013-12-12 10:39:23 -0500145 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530146 def test_neutron_help(self):
147 help_text = self.neutron('help')
148 lines = help_text.split('\n')
Pavel Sedlák4c18fa12013-08-22 21:29:45 +0200149 self.assertFirstLineStartsWith(lines, 'usage: neutron')
saurabh55c29c72013-07-26 21:15:08 +0530150
151 commands = []
152 cmds_start = lines.index('Commands for API v2.0:')
153 command_pattern = re.compile('^ {2}([a-z0-9\-\_]+)')
154 for line in lines[cmds_start:]:
155 match = command_pattern.match(line)
156 if match:
157 commands.append(match.group(1))
158 commands = set(commands)
159 wanted_commands = set(('net-create', 'subnet-list', 'port-delete',
160 'router-show', 'agent-update', 'help'))
161 self.assertFalse(wanted_commands - commands)
162
vponomaryovaa86a802014-01-06 09:29:58 +0200163 # Optional arguments:
saurabh55c29c72013-07-26 21:15:08 +0530164
Sean Dagueb6924642013-12-12 10:39:23 -0500165 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530166 def test_neutron_version(self):
167 self.neutron('', flags='--version')
168
Sean Dagueb6924642013-12-12 10:39:23 -0500169 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530170 def test_neutron_debug_net_list(self):
171 self.neutron('net-list', flags='--debug')
172
Sean Dagueb6924642013-12-12 10:39:23 -0500173 @test.attr(type='smoke')
saurabh55c29c72013-07-26 21:15:08 +0530174 def test_neutron_quiet_net_list(self):
175 self.neutron('net-list', flags='--quiet')