blob: 83cf9850a6783e2ad1643758361e08af2d2ce8f6 [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
24from tempest.common import log as logging
25
26CONF = cfg.CONF
27
28LOG = logging.getLogger(__name__)
29
30
31class SimpleReadOnlyNeutronClientTest(tempest.cli.ClientTestBase):
32 """Basic, read-only tests for Neutron CLI client.
33
34 Checks return values and output of read-only commands.
35 These tests do not presume any content, nor do they create
36 their own. They only verify the structure of output if present.
37 """
Matthew Treinishe8940592013-07-30 13:36:09 -040038
39 @classmethod
40 def setUpClass(cls):
41 if (not CONF.service_available.neutron):
42 msg = "Skiping all Neutron cli tests because it is not available"
43 raise cls.skipException(msg)
44 super(SimpleReadOnlyNeutronClientTest, cls).setUpClass()
saurabh55c29c72013-07-26 21:15:08 +053045
46 def test_neutron_fake_action(self):
47 self.assertRaises(subprocess.CalledProcessError,
48 self.neutron,
49 'this-does-not-exist')
50
51 def test_neutron_net_list(self):
52 self.neutron('net-list')
53
54 def test_neutron_ext_list(self):
55 ext = self.parser.listing(self.neutron('ext-list'))
56 self.assertTableStruct(ext, ['alias', 'name'])
57
58 def test_neutron_dhcp_agent_list_hosting_net(self):
59 self.neutron('dhcp-agent-list-hosting-net', params="private")
60
61 def test_neutron_agent_list(self):
62 agents = self.parser.listing(self.neutron('agent-list'))
63 field_names = ['id', 'agent_type', 'host', 'alive', 'admin_state_up']
64 self.assertTableStruct(agents, field_names)
65
66 def test_neutron_floatingip_list(self):
67 self.neutron('floatingip-list')
68
69 def test_neutron_net_external_list(self):
70 self.neutron('net-external-list')
71
72 def test_neutron_port_list(self):
73 self.neutron('port-list')
74
75 def test_neutron_quota_list(self):
76 self.neutron('quota-list')
77
78 def test_neutron_router_list(self):
79 self.neutron('router-list')
80
81 def test_neutron_security_group_list(self):
82 security_grp = self.parser.listing(self.neutron('security-group-list'))
83 self.assertTableStruct(security_grp, ['id', 'name', 'description'])
84
85 def test_neutron_security_group_rule_list(self):
86 self.neutron('security-group-rule-list')
87
88 def test_neutron_subnet_list(self):
89 self.neutron('subnet-list')
90
91 def test_neutron_help(self):
92 help_text = self.neutron('help')
93 lines = help_text.split('\n')
94 self.assertTrue(lines[0].startswith('usage: neutron'))
95
96 commands = []
97 cmds_start = lines.index('Commands for API v2.0:')
98 command_pattern = re.compile('^ {2}([a-z0-9\-\_]+)')
99 for line in lines[cmds_start:]:
100 match = command_pattern.match(line)
101 if match:
102 commands.append(match.group(1))
103 commands = set(commands)
104 wanted_commands = set(('net-create', 'subnet-list', 'port-delete',
105 'router-show', 'agent-update', 'help'))
106 self.assertFalse(wanted_commands - commands)
107
108 # Optional arguments:
109
110 def test_neutron_version(self):
111 self.neutron('', flags='--version')
112
113 def test_neutron_debug_net_list(self):
114 self.neutron('net-list', flags='--debug')
115
116 def test_neutron_quiet_net_list(self):
117 self.neutron('net-list', flags='--quiet')