blob: 9f8c742aa37ede687e786680f4127b9358fe2fb3 [file] [log] [blame]
nayna-patel197c0122013-07-11 10:18:00 +00001# 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
18from tempest.api.network import base
19from tempest.common.utils.data_utils import rand_name
20from tempest.test import attr
21
22
23class RoutersTest(base.BaseNetworkTest):
raiesmh0867698322013-08-20 13:09:01 +053024 _interface = 'json'
nayna-patel197c0122013-07-11 10:18:00 +000025
26 @classmethod
27 def setUpClass(cls):
28 super(RoutersTest, cls).setUpClass()
29
30 def _delete_router(self, router_id):
31 resp, _ = self.client.delete_router(router_id)
32 self.assertEqual(204, resp.status)
33 # Asserting that the router is not found in the list
34 # after deletion
35 resp, list_body = self.client.list_routers()
36 self.assertEqual('200', resp['status'])
37 routers_list = list()
38 for router in list_body['routers']:
39 routers_list.append(router['id'])
40 self.assertNotIn(router_id, routers_list)
41
42 def _remove_router_interface_with_subnet_id(self, router_id, subnet_id):
43 resp, _ = self.client.remove_router_interface_with_subnet_id(
44 router_id, subnet_id)
45 self.assertEqual('200', resp['status'])
46
47 def _remove_router_interface_with_port_id(self, router_id, port_id):
48 resp, _ = self.client.remove_router_interface_with_port_id(
49 router_id, port_id)
50 self.assertEqual('200', resp['status'])
51
Attila Fazekas71834a22013-08-18 06:56:21 +020052 @attr(type='smoke')
nayna-patel197c0122013-07-11 10:18:00 +000053 def test_create_show_list_update_delete_router(self):
54 # Create a router
55 name = rand_name('router-')
56 resp, create_body = self.client.create_router(
57 name, external_gateway_info={
58 "network_id": self.network_cfg.public_network_id},
59 admin_state_up=False)
60 self.assertEqual('201', resp['status'])
61 self.addCleanup(self._delete_router, create_body['router']['id'])
62 self.assertEqual(create_body['router']['name'], name)
63 self.assertEqual(
64 create_body['router']['external_gateway_info']['network_id'],
65 self.network_cfg.public_network_id)
66 self.assertEqual(create_body['router']['admin_state_up'], False)
67 # Show details of the created router
68 resp, show_body = self.client.show_router(
69 create_body['router']['id'])
70 self.assertEqual('200', resp['status'])
71 self.assertEqual(show_body['router']['name'], name)
72 self.assertEqual(
73 show_body['router']['external_gateway_info']['network_id'],
74 self.network_cfg.public_network_id)
75 self.assertEqual(show_body['router']['admin_state_up'], False)
76 # List routers and verify if created router is there in response
77 resp, list_body = self.client.list_routers()
78 self.assertEqual('200', resp['status'])
79 routers_list = list()
80 for router in list_body['routers']:
81 routers_list.append(router['id'])
82 self.assertIn(create_body['router']['id'], routers_list)
83 # Update the name of router and verify if it is updated
84 updated_name = 'updated ' + name
85 resp, update_body = self.client.update_router(
86 create_body['router']['id'], name=updated_name)
87 self.assertEqual('200', resp['status'])
88 self.assertEqual(update_body['router']['name'], updated_name)
89 resp, show_body = self.client.show_router(
90 create_body['router']['id'])
91 self.assertEqual(show_body['router']['name'], updated_name)
92
Attila Fazekas71834a22013-08-18 06:56:21 +020093 @attr(type='smoke')
nayna-patel197c0122013-07-11 10:18:00 +000094 def test_add_remove_router_interface_with_subnet_id(self):
95 network = self.create_network()
96 subnet = self.create_subnet(network)
97 name = rand_name('router-')
98 resp, create_body = self.client.create_router(name)
99 self.addCleanup(self.client.delete_router, create_body['router']['id'])
100 # Add router interafce with subnet id
101 resp, interface = self.client.add_router_interface_with_subnet_id(
102 create_body['router']['id'], subnet['id'])
103 self.assertEqual('200', resp['status'])
104 self.addCleanup(self._remove_router_interface_with_subnet_id,
105 create_body['router']['id'], subnet['id'])
106 self.assertTrue('subnet_id' in interface.keys())
107 self.assertTrue('port_id' in interface.keys())
108 # Verify router id is equal to device id in port details
109 resp, show_port_body = self.client.show_port(
110 interface['port_id'])
111 self.assertEqual(show_port_body['port']['device_id'],
112 create_body['router']['id'])
113
Attila Fazekas71834a22013-08-18 06:56:21 +0200114 @attr(type='smoke')
nayna-patel197c0122013-07-11 10:18:00 +0000115 def test_add_remove_router_interface_with_port_id(self):
116 network = self.create_network()
117 self.create_subnet(network)
118 name = rand_name('router-')
119 resp, create_body = self.client.create_router(name)
120 self.addCleanup(self.client.delete_router, create_body['router']['id'])
121 resp, port_body = self.client.create_port(network['id'])
122 # add router interface to port created above
123 resp, interface = self.client.add_router_interface_with_port_id(
124 create_body['router']['id'], port_body['port']['id'])
125 self.assertEqual('200', resp['status'])
126 self.addCleanup(self._remove_router_interface_with_port_id,
127 create_body['router']['id'], port_body['port']['id'])
128 self.assertTrue('subnet_id' in interface.keys())
129 self.assertTrue('port_id' in interface.keys())
130 # Verify router id is equal to device id in port details
131 resp, show_port_body = self.client.show_port(
132 interface['port_id'])
133 self.assertEqual(show_port_body['port']['device_id'],
134 create_body['router']['id'])