blob: df856820941d38063f3c4bead1b7823a3975fd9b [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):
24
25 @classmethod
26 def setUpClass(cls):
27 super(RoutersTest, cls).setUpClass()
28
29 def _delete_router(self, router_id):
30 resp, _ = self.client.delete_router(router_id)
31 self.assertEqual(204, resp.status)
32 # Asserting that the router is not found in the list
33 # after deletion
34 resp, list_body = self.client.list_routers()
35 self.assertEqual('200', resp['status'])
36 routers_list = list()
37 for router in list_body['routers']:
38 routers_list.append(router['id'])
39 self.assertNotIn(router_id, routers_list)
40
41 def _remove_router_interface_with_subnet_id(self, router_id, subnet_id):
42 resp, _ = self.client.remove_router_interface_with_subnet_id(
43 router_id, subnet_id)
44 self.assertEqual('200', resp['status'])
45
46 def _remove_router_interface_with_port_id(self, router_id, port_id):
47 resp, _ = self.client.remove_router_interface_with_port_id(
48 router_id, port_id)
49 self.assertEqual('200', resp['status'])
50
51 @attr(type='gate')
52 def test_create_show_list_update_delete_router(self):
53 # Create a router
54 name = rand_name('router-')
55 resp, create_body = self.client.create_router(
56 name, external_gateway_info={
57 "network_id": self.network_cfg.public_network_id},
58 admin_state_up=False)
59 self.assertEqual('201', resp['status'])
60 self.addCleanup(self._delete_router, create_body['router']['id'])
61 self.assertEqual(create_body['router']['name'], name)
62 self.assertEqual(
63 create_body['router']['external_gateway_info']['network_id'],
64 self.network_cfg.public_network_id)
65 self.assertEqual(create_body['router']['admin_state_up'], False)
66 # Show details of the created router
67 resp, show_body = self.client.show_router(
68 create_body['router']['id'])
69 self.assertEqual('200', resp['status'])
70 self.assertEqual(show_body['router']['name'], name)
71 self.assertEqual(
72 show_body['router']['external_gateway_info']['network_id'],
73 self.network_cfg.public_network_id)
74 self.assertEqual(show_body['router']['admin_state_up'], False)
75 # List routers and verify if created router is there in response
76 resp, list_body = self.client.list_routers()
77 self.assertEqual('200', resp['status'])
78 routers_list = list()
79 for router in list_body['routers']:
80 routers_list.append(router['id'])
81 self.assertIn(create_body['router']['id'], routers_list)
82 # Update the name of router and verify if it is updated
83 updated_name = 'updated ' + name
84 resp, update_body = self.client.update_router(
85 create_body['router']['id'], name=updated_name)
86 self.assertEqual('200', resp['status'])
87 self.assertEqual(update_body['router']['name'], updated_name)
88 resp, show_body = self.client.show_router(
89 create_body['router']['id'])
90 self.assertEqual(show_body['router']['name'], updated_name)
91
92 @attr(type='gate')
93 def test_add_remove_router_interface_with_subnet_id(self):
94 network = self.create_network()
95 subnet = self.create_subnet(network)
96 name = rand_name('router-')
97 resp, create_body = self.client.create_router(name)
98 self.addCleanup(self.client.delete_router, create_body['router']['id'])
99 # Add router interafce with subnet id
100 resp, interface = self.client.add_router_interface_with_subnet_id(
101 create_body['router']['id'], subnet['id'])
102 self.assertEqual('200', resp['status'])
103 self.addCleanup(self._remove_router_interface_with_subnet_id,
104 create_body['router']['id'], subnet['id'])
105 self.assertTrue('subnet_id' in interface.keys())
106 self.assertTrue('port_id' in interface.keys())
107 # Verify router id is equal to device id in port details
108 resp, show_port_body = self.client.show_port(
109 interface['port_id'])
110 self.assertEqual(show_port_body['port']['device_id'],
111 create_body['router']['id'])
112
113 @attr(type='gate')
114 def test_add_remove_router_interface_with_port_id(self):
115 network = self.create_network()
116 self.create_subnet(network)
117 name = rand_name('router-')
118 resp, create_body = self.client.create_router(name)
119 self.addCleanup(self.client.delete_router, create_body['router']['id'])
120 resp, port_body = self.client.create_port(network['id'])
121 # add router interface to port created above
122 resp, interface = self.client.add_router_interface_with_port_id(
123 create_body['router']['id'], port_body['port']['id'])
124 self.assertEqual('200', resp['status'])
125 self.addCleanup(self._remove_router_interface_with_port_id,
126 create_body['router']['id'], port_body['port']['id'])
127 self.assertTrue('subnet_id' in interface.keys())
128 self.assertTrue('port_id' in interface.keys())
129 # Verify router id is equal to device id in port details
130 resp, show_port_body = self.client.show_port(
131 interface['port_id'])
132 self.assertEqual(show_port_body['port']['device_id'],
133 create_body['router']['id'])