1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2011 Cisco Systems, Inc. All rights reserved.
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
17
# @author: Shubhangi Satras, Cisco Systems, Inc.
18
# @author: Peter Strunk, Cisco Systems, Inc.
19
# @author: Atul Gaikad, Cisco Systems, Inc.
20
# @author: Tyler Smith, Cisco Systems, Inc.
25
from quantum.common import exceptions as exc
26
from quantum.openstack.common import importutils
27
from quantum.plugins.cisco.common import cisco_constants as const
28
from quantum.plugins.cisco.common import cisco_credentials as creds
29
from quantum.plugins.cisco.db import api as db
30
from quantum.plugins.cisco.db import l2network_db as cdb
31
from quantum.plugins.cisco import l2network_plugin_configuration as conf
32
from quantum.plugins.cisco.models import l2network_multi_blade
35
logging.basicConfig(level=logging.WARN)
36
LOG = logging.getLogger(__name__)
39
# Set some data to use in tests
40
tenant_id = "network_admin"
41
net_name = "TestNetwork1"
42
new_net_name = "NewTestNetwork1"
45
port_state = const.PORT_UP
46
interface_id = "vif-01"
51
return "q-%svlan" % id[0:10]
54
class TestMultiBlade(unittest.TestCase):
56
Tests for the multi-blade model for the L2Network plugin
63
# Initialize cdb and credentials
64
db.configure_db({'sql_connection': 'sqlite:///:memory:'})
66
creds.Store.initialize()
68
# Create a place a store net and port ids for the druation of the test
72
# Create the multiblade object
73
self._l2network_multiblade = (
74
l2network_multi_blade.L2NetworkMultiBlade())
76
"quantum.plugins.cisco.ucs.cisco_ucs_plugin.UCSVICPlugin")
78
# Get UCS inventory to make sure all UCSs are affected by tests
79
for key in conf.PLUGINS[const.PLUGINS].keys():
80
if key in conf.PLUGINS[const.INVENTORY].keys():
81
plugin_obj = conf.PLUGINS[const.INVENTORY][key]
82
self._inventory[key] = importutils.import_object(plugin_obj)
84
self.ucs_count = self._inventory['ucs_plugin']._inventory.__len__()
87
"""Tear down our tests"""
89
port = db.port_get(self.net_id, self.port_id)
90
self._l2network_multiblade.delete_port([tenant_id, self.net_id,
92
except exc.NetworkNotFound:
93
# We won't always have a port to remove
95
except exc.PortNotFound:
96
# We won't always have a port to remove
100
net = db.network_get(self.net_id)
101
self._l2network_multiblade.delete_network([tenant_id, self.net_id])
102
except exc.NetworkNotFound:
103
# We won't always have a network to remove
107
def test_create_network(self):
108
"""Support for the Quantum core API call"""
109
LOG.debug("test_create_network - START")
111
# Create the network in the test DB, then with the model
112
self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
113
networks = self._l2network_multiblade.create_network([
117
vlan_name(self.net_id),
120
cdb.add_vlan_binding(vlan_id, vlan_name(self.net_id), self.net_id)
122
for network in networks:
123
self.assertEqual(network[const.NET_ID], self.net_id)
124
self.assertEqual(network[const.NET_NAME], net_name)
126
LOG.debug("test_create_network - END")
128
def test_delete_network(self):
129
"""Support for the Quantum core API call"""
130
LOG.debug("test_delete_network - START")
132
# Create the network in the test DB, then with the model
133
self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
134
self._l2network_multiblade.create_network([tenant_id,
137
vlan_name(self.net_id),
139
cdb.add_vlan_binding(vlan_id, vlan_name(self.net_id), self.net_id)
141
networks = self._l2network_multiblade.delete_network([tenant_id,
143
cdb.remove_vlan_binding(self.net_id)
144
db.network_destroy(self.net_id)
145
for network in networks:
146
self.assertEqual(network[const.NET_ID], self.net_id)
147
self.assertEqual(network[const.NET_NAME], net_name)
149
LOG.debug("test_delete_network - END")
151
def test_delete_networkDNE(self):
152
"""Support for the Quantum core API call"""
153
LOG.debug("test_delete_networkDNE - START")
155
self.assertRaises(exc.NetworkNotFound,
156
self._l2network_multiblade.delete_network,
159
LOG.debug("test_delete_networkDNE - END")
161
def test_update_network(self):
162
"""Support for the Quantum core API call"""
163
LOG.debug("test_update_network - START")
165
self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
167
self._l2network_multiblade.create_network([tenant_id,
170
vlan_name(self.net_id),
172
cdb.add_vlan_binding(vlan_id, vlan_name(self.net_id), self.net_id)
174
net_details = db.network_update(self.net_id, tenant_id,
176
networks = self._l2network_multiblade.update_network([
179
{'name': new_net_name},
182
for network in networks:
183
self.assertEqual(network[const.NET_ID], self.net_id)
184
self.assertEqual(network[const.NET_NAME], new_net_name)
185
LOG.debug("test_update_network - END")
187
def test_update_networkDNE(self):
188
"""Support for the Quantum core API call"""
189
LOG.debug("test_update_networkDNE - START")
190
self.assertRaises(exc.NetworkNotFound,
191
self._l2network_multiblade.update_network,
192
[tenant_id, net_id, {'name': new_net_name}])
193
LOG.debug("test_update_networkDNE - END")
195
def test_get_all_networks(self):
196
"""Not implemented for this model"""
199
def test_get_network_details(self):
200
"""Not implemented for this model"""
203
def test_create_port(self):
204
"""Support for the Quantum core API call"""
205
LOG.debug("test_create_port - START")
206
self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
207
self._l2network_multiblade.create_network([tenant_id,
210
vlan_name(self.net_id),
212
cdb.add_vlan_binding(vlan_id, vlan_name(self.net_id), self.net_id)
214
self.port_id = db.port_create(self.net_id, port_state)[const.UUID]
215
port = self._l2network_multiblade.create_port([tenant_id,
220
self.assertEqual(self.port_id, port[0][const.PORTID])
221
LOG.debug("test_create_port - END")
223
def test_delete_port(self):
224
"""Support for the Quantum core API call"""
225
LOG.debug("test_delete_port - START")
226
self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
227
self._l2network_multiblade.create_network([tenant_id,
230
vlan_name(self.net_id),
232
cdb.add_vlan_binding(vlan_id, vlan_name(self.net_id), self.net_id)
234
self.port_id = db.port_create(self.net_id, port_state)[const.UUID]
235
self._l2network_multiblade.create_port([tenant_id,
237
port_state, self.port_id])
239
port = self._l2network_multiblade.delete_port([tenant_id,
243
self.assertEqual(self.port_id, port[0][const.PORTID])
245
# Recreating port so tear down doesn't cause an error
246
self.port_id = db.port_create(self.net_id, port_state)[const.UUID]
247
self._l2network_multiblade.create_port([tenant_id,
249
port_state, self.port_id])
251
LOG.debug("test_delete_port - END")
253
def test_get_all_ports(self):
254
"""Not implemented for this model"""
257
def test_update_port(self):
258
"""Not implemented for this model"""
261
def test_update_portDNE(self):
262
"""Not implemented for this model"""
265
def test_update_port_networkDNE(self):
266
"""Not implemented for this model"""
269
def test_port_details(self):
270
"""Not implemented for this model"""
273
def test_plug_interface(self):
274
"""Support for the Quantum core API call"""
275
LOG.debug("test_plug_interface - START")
276
self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
277
self._l2network_multiblade.create_network([tenant_id,
280
vlan_name(self.net_id),
282
cdb.add_vlan_binding(vlan_id, vlan_name(self.net_id), self.net_id)
284
self.port_id = db.port_create(self.net_id, port_state)[const.UUID]
285
self._l2network_multiblade.create_port([tenant_id,
287
port_state, self.port_id])
289
interface = self._l2network_multiblade.plug_interface(
290
[tenant_id, self.net_id, self.port_id, interface_id])
291
port = db.port_set_attachment(self.net_id, self.port_id, interface_id)
293
self.assertEqual(self.port_id, interface[0][const.PORTID])
294
self.assertEqual(port[const.INTERFACEID], interface_id)
295
LOG.debug("test_plug_interface - END")
297
def test_plug_interface_networkDNE(self):
298
"""Support for the Quantum core API call"""
299
LOG.debug("test_plug_interface_networkDNE - START")
300
self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
301
self._l2network_multiblade.create_network([tenant_id,
304
vlan_name(self.net_id),
306
cdb.add_vlan_binding(vlan_id, vlan_name(self.net_id), self.net_id)
308
self.port_id = db.port_create(self.net_id, port_state)[const.UUID]
309
self._l2network_multiblade.create_port([tenant_id,
311
port_state, self.port_id])
313
self.assertRaises(exc.NetworkNotFound,
314
self._l2network_multiblade.plug_interface,
315
[tenant_id, net_id, self.port_id, interface_id])
317
LOG.debug("test_plug_interface_networkDNE - END")
319
def test_plug_interface_portDNE(self):
320
"""Support for the Quantum core API call"""
321
LOG.debug("test_plug_interface_portDNE - START")
322
self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
323
self._l2network_multiblade.create_network([tenant_id,
326
vlan_name(self.net_id),
328
cdb.add_vlan_binding(vlan_id, vlan_name(self.net_id), self.net_id)
330
self.assertRaises(exc.PortNotFound,
331
self._l2network_multiblade.plug_interface,
332
[tenant_id, self.net_id, port_id, interface_id])
334
LOG.debug("test_plug_interface_portDNE - START")
336
def test_unplug_interface(self):
337
"""Support for the Quantum core API call"""
338
LOG.debug("test_unplug_interface - START")
339
self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
340
self._l2network_multiblade.create_network([tenant_id,
343
vlan_name(self.net_id),
345
cdb.add_vlan_binding(vlan_id, vlan_name(self.net_id), self.net_id)
347
self.port_id = db.port_create(self.net_id, port_state)[const.UUID]
348
self._l2network_multiblade.create_port([tenant_id,
350
port_state, self.port_id])
352
self._l2network_multiblade.plug_interface([tenant_id, self.net_id,
353
self.port_id, interface_id])
354
db.port_set_attachment(self.net_id, self.port_id, interface_id)
355
interface = self._l2network_multiblade.unplug_interface([tenant_id,
359
self.assertEqual(self.port_id, interface[0][const.PORTID])
360
LOG.debug("test_unplug_interface - END")