saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 1 | # 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 | |
| 18 | import re |
| 19 | import subprocess |
| 20 | |
| 21 | from oslo.config import cfg |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 22 | |
| 23 | import tempest.cli |
Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 24 | from tempest.openstack.common import log as logging |
Matthew Treinish | e22c97a | 2013-10-16 20:55:52 +0000 | [diff] [blame] | 25 | from tempest import test |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 26 | |
| 27 | CONF = cfg.CONF |
| 28 | |
| 29 | LOG = logging.getLogger(__name__) |
| 30 | |
| 31 | |
| 32 | class 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 Treinish | e894059 | 2013-07-30 13:36:09 -0400 | [diff] [blame] | 39 | |
| 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() |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 46 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 47 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 48 | def test_neutron_fake_action(self): |
| 49 | self.assertRaises(subprocess.CalledProcessError, |
| 50 | self.neutron, |
| 51 | 'this-does-not-exist') |
| 52 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 53 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 54 | def test_neutron_net_list(self): |
| 55 | self.neutron('net-list') |
| 56 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 57 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 58 | def test_neutron_ext_list(self): |
| 59 | ext = self.parser.listing(self.neutron('ext-list')) |
| 60 | self.assertTableStruct(ext, ['alias', 'name']) |
| 61 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 62 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 63 | def test_neutron_dhcp_agent_list_hosting_net(self): |
Matt Riedemann | d4dc514 | 2013-07-31 03:47:54 -0700 | [diff] [blame] | 64 | self.neutron('dhcp-agent-list-hosting-net', |
| 65 | params=CONF.compute.fixed_network_name) |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 66 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 67 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 68 | 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 Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 73 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 74 | def test_neutron_floatingip_list(self): |
| 75 | self.neutron('floatingip-list') |
| 76 | |
Matthew Treinish | e22c97a | 2013-10-16 20:55:52 +0000 | [diff] [blame] | 77 | @test.skip_because(bug="1240694") |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 78 | @test.attr(type='smoke') |
Cyril Roelandt | 10a02d7 | 2013-10-08 12:31:01 +0000 | [diff] [blame] | 79 | def test_neutron_meter_label_list(self): |
| 80 | self.neutron('meter-label-list') |
| 81 | |
Matthew Treinish | e22c97a | 2013-10-16 20:55:52 +0000 | [diff] [blame] | 82 | @test.skip_because(bug="1240694") |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 83 | @test.attr(type='smoke') |
Cyril Roelandt | 10a02d7 | 2013-10-08 12:31:01 +0000 | [diff] [blame] | 84 | def test_neutron_meter_label_rule_list(self): |
| 85 | self.neutron('meter-label-rule-list') |
| 86 | |
Cyril Roelandt | b18d5fb | 2013-10-09 20:23:39 +0000 | [diff] [blame] | 87 | 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 Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 94 | @test.attr(type='smoke') |
Cyril Roelandt | b18d5fb | 2013-10-09 20:23:39 +0000 | [diff] [blame] | 95 | def test_neutron_lb_healthmonitor_list(self): |
| 96 | self._test_neutron_lbaas_command('lb-healthmonitor-list') |
| 97 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 98 | @test.attr(type='smoke') |
Cyril Roelandt | b18d5fb | 2013-10-09 20:23:39 +0000 | [diff] [blame] | 99 | def test_neutron_lb_member_list(self): |
| 100 | self._test_neutron_lbaas_command('lb-member-list') |
| 101 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 102 | @test.attr(type='smoke') |
Cyril Roelandt | b18d5fb | 2013-10-09 20:23:39 +0000 | [diff] [blame] | 103 | def test_neutron_lb_pool_list(self): |
| 104 | self._test_neutron_lbaas_command('lb-pool-list') |
| 105 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 106 | @test.attr(type='smoke') |
Cyril Roelandt | b18d5fb | 2013-10-09 20:23:39 +0000 | [diff] [blame] | 107 | def test_neutron_lb_vip_list(self): |
| 108 | self._test_neutron_lbaas_command('lb-vip-list') |
| 109 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 110 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 111 | def test_neutron_net_external_list(self): |
| 112 | self.neutron('net-external-list') |
| 113 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 114 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 115 | def test_neutron_port_list(self): |
| 116 | self.neutron('port-list') |
| 117 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 118 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 119 | def test_neutron_quota_list(self): |
| 120 | self.neutron('quota-list') |
| 121 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 122 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 123 | def test_neutron_router_list(self): |
| 124 | self.neutron('router-list') |
| 125 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 126 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 127 | 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 Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 131 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 132 | def test_neutron_security_group_rule_list(self): |
| 133 | self.neutron('security-group-rule-list') |
| 134 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 135 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 136 | def test_neutron_subnet_list(self): |
| 137 | self.neutron('subnet-list') |
| 138 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 139 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 140 | def test_neutron_help(self): |
| 141 | help_text = self.neutron('help') |
| 142 | lines = help_text.split('\n') |
Pavel Sedlák | 4c18fa1 | 2013-08-22 21:29:45 +0200 | [diff] [blame] | 143 | self.assertFirstLineStartsWith(lines, 'usage: neutron') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 144 | |
| 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 Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 159 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 160 | def test_neutron_version(self): |
| 161 | self.neutron('', flags='--version') |
| 162 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 163 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 164 | def test_neutron_debug_net_list(self): |
| 165 | self.neutron('net-list', flags='--debug') |
| 166 | |
Sean Dague | b692464 | 2013-12-12 10:39:23 -0500 | [diff] [blame] | 167 | @test.attr(type='smoke') |
saurabh | 55c29c7 | 2013-07-26 21:15:08 +0530 | [diff] [blame] | 168 | def test_neutron_quiet_net_list(self): |
| 169 | self.neutron('net-list', flags='--quiet') |