Merge lp:~tylesmit/neutron/lp845140 into lp:neutron/diablo

Proposed by Tyler Smith
Status: Merged
Merged at revision: 72
Proposed branch: lp:~tylesmit/neutron/lp845140
Merge into: lp:neutron/diablo
Diff against target: 1588 lines (+938/-437)
5 files modified
quantum/plugins/cisco/common/cisco_constants.py (+1/-1)
quantum/plugins/cisco/models/l2network_multi_blade.py (+40/-24)
quantum/plugins/cisco/tests/unit/test_l2network_multi_blade.py (+365/-0)
quantum/plugins/cisco/tests/unit/test_ucs_inventory.py (+201/-0)
quantum/plugins/cisco/tests/unit/test_ucs_plugin.py (+331/-412)
To merge this branch: bzr merge lp:~tylesmit/neutron/lp845140
Reviewer Review Type Date Requested Status
Sumit Naiksatam Approve
Salvatore Orlando Approve
dan wendlandt Approve
Review via email: mp+74826@code.launchpad.net

Description of the change

Adds tests for the UCS multi-blade model. Also contains some fixes to tests by Shweta.

To post a comment you must log in.
Revision history for this message
dan wendlandt (danwent) wrote :

Hi Tyler, I've done a quick scan of the code and nothing stood out as being problematic. I didn't read the code for correctness though.

Given that this is very late in the cycle and a pretty large patch, it may be challenging to get this in. If you can get another reviewer, I'll count my quick review as an approve and merge it in, since it is entirely contained within the Cisco plugin.

review: Approve
Revision history for this message
Salvatore Orlando (salvatore-orlando) wrote :

Hi Tyler.
As already stated by Dan this mergeprop came a bit too close to the deadline. I have a few comments for you and I hope you can address them before rbp is released.

None of the issues I found appear to break the plugin, but my judgement is merely based on static code analysis. Moreover, I would not consider this review that I've done as 'accurate'; however since the risk is 'contained' to the Cisco plugin, I'm willing to approve it.

29 for device_ip in device_ips:
30 new_device_params = deepcopy(device_params)
Looks like there no need to perfom the deepcopy operation in the loop.

31 new_device_params[const.DEVICE_IP] = device_ip
At a first glance this seems a workaround needed as _invoke_plugin with the specific function used in this case does not accept a list of IPs. Probably the ideal approach would be to update _invoke_plugin to deal with multiple ips. But this is not a problem at all.

226 + """Tear down our tests"""
227 + try:
228 + self._l2network_multiblade.delete_port([tenant_id, self.net_id,
229 + self.port_id])
230 + except exc.PortNotFound:
231 + # We won't always have a port to remove
232 + pass
233 +
234 + try:
235 + self._l2network_multiblade.delete_network([tenant_id, self.net_id])
236 + except exc.NetworkNotFound:
237 + # We won't always have a network to remove
238 + pass

The above is probably not necessary as the last line in tearDown destroys all the contents of the test database.

538 +class TestUCSInventory(unittest.TestCase):

This class has not teardown method for clearing the database.

1544 + def tearDown(self):
1545 + """Clear the test environment"""
1546 + # Remove database contents
1547 + db.clear_db()

Not very useful, but probably still good to have, as this class has methods for tearing down reasources created in each unit test.

review: Approve
Revision history for this message
Tyler Smith (tylesmit) wrote :

Hi Salvatore,

>Looks like there no need to perfom the deepcopy operation in the loop.

This is not code I'm adding, it's merely shown in the diff because of its proximity to code I did alter.

>At a first glance this seems a workaround needed as _invoke_plugin with the specific function used in this case does not accept a list of IPs. Probably the ideal approach would be to update _invoke_plugin to deal with multiple ips. But this is not a problem at all.

Same as above.

>The above is probably not necessary as the last line in tearDown destroys all the contents of the test database.

These calls aren't doing anything to the database. They're cleaning up the created networks and ports on the UCS devices themselves.

>This class has not teardown method for clearing the database.

Good call. I'll add that.

>Not very useful, but probably still good to have, as this class has methods for tearing down reasources created in each unit test.

I don't know much about how sqlite in-memory works. I figured it would force sqlite to free the used memory, otherwise it may stick around. That could be completely wrong though.

Revision history for this message
dan wendlandt (danwent) wrote :

Hi Tyler,

I'm looking to create the diablo-rbp release soon (prior to 6pm Pacific
today). If you're planning on making these changes quickly, let me know and
I'll hold things up. Otherwise, we can put them in after the release,
though I'd prefer to avoid that.

dan

On Fri, Sep 9, 2011 at 3:42 PM, Tyler Smith <email address hidden> wrote:

> Hi Salvatore,
>
> >Looks like there no need to perfom the deepcopy operation in the loop.
>
> This is not code I'm adding, it's merely shown in the diff because of its
> proximity to code I did alter.
>
> >At a first glance this seems a workaround needed as _invoke_plugin with
> the specific function used in this case does not accept a list of IPs.
> Probably the ideal approach would be to update _invoke_plugin to deal with
> multiple ips. But this is not a problem at all.
>
> Same as above.
>
> >The above is probably not necessary as the last line in tearDown destroys
> all the contents of the test database.
>
> These calls aren't doing anything to the database. They're cleaning up the
> created networks and ports on the UCS devices themselves.
>
>
> >This class has not teardown method for clearing the database.
>
> Good call. I'll add that.
>
>
> >Not very useful, but probably still good to have, as this class has
> methods for tearing down reasources created in each unit test.
>
> I don't know much about how sqlite in-memory works. I figured it would
> force sqlite to free the used memory, otherwise it may stick around. That
> could be completely wrong though.
> --
> https://code.launchpad.net/~tylesmit/quantum/lp845140/+merge/74826
> You are reviewing the proposed merge of lp:~tylesmit/quantum/lp845140 into
> lp:quantum.
>

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dan Wendlandt
Nicira Networks, Inc.
www.nicira.com | www.openvswitch.org
Sr. Product Manager
cell: 650-906-2650
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Revision history for this message
Sumit Naiksatam (snaiksat) wrote :

Suggest checking whether the corresponding inventory class is configured for a plugin before doing conf.PLUGINS[const.INVENTORY][key]

219 + self._inventory[key] = utils.import_object(
220 + conf.PLUGINS[const.INVENTORY][key])

Something like:

            if key in conf.PLUGINS[const.INVENTORY].keys():
                self._inventory[key] = utils.import_object(
                    conf.PLUGINS[const.INVENTORY][key])

should work.

Can you please change the following to reflect the test module:

190 + """
191 + Implements the L2NetworkModelBase
192 + This implementation works with UCS and Nexus plugin for the
193 + following topology:
194 + One or more UCSM (each with one or more chasses connected)
195 + All UCSM connected to a single Nexus Switch
196 + """

review: Approve
Revision history for this message
Tyler Smith (tylesmit) wrote :

Thanks for the reviews. I've got all of the issues resolved, and will have them pushed shortly.

Revision history for this message
Tyler Smith (tylesmit) wrote :

Okay, I've pushed fixes for all of the discusses issues. Sorry for taking it to the 11th hour (or 11th:45), and thanks again for the last minute reviews.

It should be ready to merge.

Revision history for this message
Sumit Naiksatam (snaiksat) wrote :

Dan, I believe Tyler has made all the changes, and this branch is ready to be merged.

(He is trying to respond but having issues posting here.)

Thanks,
~Sumit.

Revision history for this message
dan wendlandt (danwent) wrote :

Ok, thanks. I will merge it in and close diablo-rbp.

Dan

On Fri, Sep 9, 2011 at 4:25 PM, Sumit Naiksatam <email address hidden> wrote:

> Dan, I believe Tyler has made all the changes, and this branch is ready to
> be merged.
>
> (He is trying to respond but having issues posting here.)
>
> Thanks,
> ~Sumit.
> --
> https://code.launchpad.net/~tylesmit/quantum/lp845140/+merge/74826
> You are reviewing the proposed merge of lp:~tylesmit/quantum/lp845140 into
> lp:quantum.
>

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dan Wendlandt
Nicira Networks, Inc.
www.nicira.com | www.openvswitch.org
Sr. Product Manager
cell: 650-906-2650
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'quantum/plugins/cisco/common/cisco_constants.py'
2--- quantum/plugins/cisco/common/cisco_constants.py 2011-08-29 09:06:48 +0000
3+++ quantum/plugins/cisco/common/cisco_constants.py 2011-09-09 23:16:27 +0000
4@@ -85,7 +85,7 @@
5
6 LOGGER_COMPONENT_NAME = "cisco_plugin"
7
8-BLADE_INTF_DN = "blade-intf-distinguished-name"
9+BLADE_INTF_DN = "blade_intf_distinguished_name"
10 BLADE_INTF_ORDER = "blade-intf-order"
11 BLADE_INTF_LINK_STATE = "blade-intf-link-state"
12 BLADE_INTF_OPER_STATE = "blade-intf-operational-state"
13
14=== modified file 'quantum/plugins/cisco/models/l2network_multi_blade.py'
15--- quantum/plugins/cisco/models/l2network_multi_blade.py 2011-08-30 23:12:49 +0000
16+++ quantum/plugins/cisco/models/l2network_multi_blade.py 2011-09-09 23:16:27 +0000
17@@ -73,14 +73,18 @@
18 args)
19 device_ips = device_params[const.DEVICE_IP]
20 if not device_ips:
21- self._invoke_plugin(plugin_key, function_name, args,
22- device_params)
23+ # Return in a list
24+ return [self._invoke_plugin(plugin_key, function_name, args,
25+ device_params)]
26 else:
27+ # Return a list of return values from each device
28+ output = []
29 for device_ip in device_ips:
30 new_device_params = deepcopy(device_params)
31 new_device_params[const.DEVICE_IP] = device_ip
32- self._invoke_plugin(plugin_key, function_name, args,
33- new_device_params)
34+ output.append(self._invoke_plugin(plugin_key, function_name,
35+ args, new_device_params))
36+ return output
37
38 def _invoke_inventory(self, plugin_key, function_name, args):
39 """Invoke only the inventory implementation"""
40@@ -103,17 +107,25 @@
41
42 def create_network(self, args):
43 """Support for the Quantum core API call"""
44- self._invoke_plugin_per_device(const.UCS_PLUGIN, self._func_name(),
45- args)
46- self._invoke_plugin_per_device(const.NEXUS_PLUGIN,
47- self._func_name(), args)
48+ output = []
49+ ucs_output = self._invoke_plugin_per_device(const.UCS_PLUGIN,
50+ self._func_name(), args)
51+ nexus_output = self._invoke_plugin_per_device(const.NEXUS_PLUGIN,
52+ self._func_name(), args)
53+ output.extend(ucs_output or [])
54+ output.extend(nexus_output or [])
55+ return output
56
57 def delete_network(self, args):
58 """Support for the Quantum core API call"""
59- self._invoke_plugin_per_device(const.UCS_PLUGIN, self._func_name(),
60- args)
61- self._invoke_plugin_per_device(const.NEXUS_PLUGIN,
62- self._func_name(), args)
63+ output = []
64+ ucs_output = self._invoke_plugin_per_device(const.UCS_PLUGIN,
65+ self._func_name(), args)
66+ nexus_output = self._invoke_plugin_per_device(const.NEXUS_PLUGIN,
67+ self._func_name(), args)
68+ output.extend(ucs_output or [])
69+ output.extend(nexus_output or [])
70+ return output
71
72 def get_network_details(self, args):
73 """Not implemented for this model"""
74@@ -121,10 +133,14 @@
75
76 def rename_network(self, args):
77 """Support for the Quantum core API call"""
78- self._invoke_plugin_per_device(const.UCS_PLUGIN, self._func_name(),
79- args)
80- self._invoke_plugin_per_device(const.NEXUS_PLUGIN,
81- self._func_name(), args)
82+ output = []
83+ ucs_output = self._invoke_plugin_per_device(const.UCS_PLUGIN,
84+ self._func_name(), args)
85+ nexus_output = self._invoke_plugin_per_device(const.NEXUS_PLUGIN,
86+ self._func_name(), args)
87+ output.extend(ucs_output or [])
88+ output.extend(nexus_output or [])
89+ return output
90
91 def get_all_ports(self, args):
92 """Not implemented for this model"""
93@@ -132,13 +148,13 @@
94
95 def create_port(self, args):
96 """Support for the Quantum core API call"""
97- self._invoke_plugin_per_device(const.UCS_PLUGIN, self._func_name(),
98- args)
99+ return self._invoke_plugin_per_device(const.UCS_PLUGIN,
100+ self._func_name(), args)
101
102 def delete_port(self, args):
103 """Support for the Quantum core API call"""
104- self._invoke_plugin_per_device(const.UCS_PLUGIN, self._func_name(),
105- args)
106+ return self._invoke_plugin_per_device(const.UCS_PLUGIN,
107+ self._func_name(), args)
108
109 def update_port(self, args):
110 """Not implemented for this model"""
111@@ -150,13 +166,13 @@
112
113 def plug_interface(self, args):
114 """Support for the Quantum core API call"""
115- self._invoke_plugin_per_device(const.UCS_PLUGIN, self._func_name(),
116- args)
117+ return self._invoke_plugin_per_device(const.UCS_PLUGIN,
118+ self._func_name(), args)
119
120 def unplug_interface(self, args):
121 """Support for the Quantum core API call"""
122- self._invoke_plugin_per_device(const.UCS_PLUGIN, self._func_name(),
123- args)
124+ return self._invoke_plugin_per_device(const.UCS_PLUGIN,
125+ self._func_name(), args)
126
127 def schedule_host(self, args):
128 """Provides the hostname on which a dynamic vnic is reserved"""
129
130=== added file 'quantum/plugins/cisco/tests/unit/test_l2network_multi_blade.py'
131--- quantum/plugins/cisco/tests/unit/test_l2network_multi_blade.py 1970-01-01 00:00:00 +0000
132+++ quantum/plugins/cisco/tests/unit/test_l2network_multi_blade.py 2011-09-09 23:16:27 +0000
133@@ -0,0 +1,365 @@
134+"""
135+# vim: tabstop=4 shiftwidth=4 softtabstop=4
136+#
137+# Copyright 2011 Cisco Systems, Inc. All rights reserved.
138+#
139+# Licensed under the Apache License, Version 2.0 (the "License"); you may
140+# not use this file except in compliance with the License. You may obtain
141+# a copy of the License at
142+#
143+# http://www.apache.org/licenses/LICENSE-2.0
144+#
145+# Unless required by applicable law or agreed to in writing, software
146+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
147+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
148+# License for the specific language governing permissions and limitations
149+# under the License.
150+#
151+# @author: Shubhangi Satras, Cisco Systems, Inc.
152+# @author: Peter Strunk, Cisco Systems, Inc.
153+# @author: Atul Gaikad, Cisco Systems, Inc.
154+# @author: Tyler Smith, Cisco Systems, Inc.
155+#
156+"""
157+
158+import unittest
159+import logging as LOG
160+
161+from quantum.common import exceptions as exc
162+from quantum.common import utils
163+from quantum.plugins.cisco import l2network_plugin_configuration as conf
164+from quantum.plugins.cisco.common import cisco_constants as const
165+from quantum.plugins.cisco.common import cisco_credentials as creds
166+from quantum.plugins.cisco.models import l2network_multi_blade
167+from quantum.plugins.cisco.db import api as db
168+from quantum.plugins.cisco.db import l2network_db as cdb
169+
170+LOG.basicConfig(level=LOG.WARN)
171+LOG.getLogger(__name__)
172+
173+
174+# Set some data to use in tests
175+tenant_id = "network_admin"
176+net_name = "TestNetwork1"
177+new_net_name = "NewTestNetwork1"
178+net_id = "44"
179+port_id = "p0005"
180+port_state = const.PORT_UP
181+interface_id = "vif-01"
182+vlan_id = "102"
183+
184+
185+def vlan_name(id):
186+ return "q-%svlan" % id
187+
188+
189+class TestMultiBlade(unittest.TestCase):
190+ """
191+ Tests for the multi-blade model for the L2Network plugin
192+ """
193+ _plugins = {}
194+ _inventory = {}
195+
196+ def setUp(self):
197+ """Setup our tests"""
198+ # Initialize cdb and credentials
199+ db.configure_db({'sql_connection': 'sqlite:///:memory:'})
200+ cdb.initialize()
201+ creds.Store.initialize()
202+
203+ # Create a place a store net and port ids for the druation of the test
204+ self.net_id = 0
205+ self.port_id = 0
206+
207+ # Create the multiblade object
208+ self._l2network_multiblade = l2network_multi_blade. \
209+ L2NetworkMultiBlade()
210+ self.plugin_key = "quantum.plugins.cisco.ucs.cisco_ucs_plugin" + \
211+ ".UCSVICPlugin"
212+
213+ # Get UCS inventory to make sure all UCSs are affected by tests
214+ for key in conf.PLUGINS[const.PLUGINS].keys():
215+ if key in conf.PLUGINS[const.INVENTORY].keys():
216+ self._inventory[key] = utils.import_object(
217+ conf.PLUGINS[const.INVENTORY][key])
218+
219+ self.ucs_count = self._inventory['ucs_plugin'].\
220+ _inventory.__len__()
221+
222+ def tearDown(self):
223+ """Tear down our tests"""
224+ try:
225+ port = db.port_get(self.net_id, self.port_id)
226+ self._l2network_multiblade.delete_port([tenant_id, self.net_id,
227+ self.port_id])
228+ except exc.NetworkNotFound:
229+ # We won't always have a port to remove
230+ pass
231+ except exc.PortNotFound:
232+ # We won't always have a port to remove
233+ pass
234+
235+ try:
236+ net = db.network_get(self.net_id)
237+ self._l2network_multiblade.delete_network([tenant_id, self.net_id])
238+ except exc.NetworkNotFound:
239+ # We won't always have a network to remove
240+ pass
241+ db.clear_db()
242+
243+ def test_create_network(self):
244+ """Support for the Quantum core API call"""
245+ LOG.debug("test_create_network - START")
246+
247+ # Create the network in the test DB, then with the model
248+ self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
249+ networks = self._l2network_multiblade.create_network([tenant_id,
250+ net_name,
251+ self.net_id,
252+ vlan_name(self.net_id),
253+ vlan_id])
254+
255+ self.assertEqual(networks.__len__(), self.ucs_count)
256+ for network in networks:
257+ self.assertEqual(network[const.NET_ID], self.net_id)
258+ self.assertEqual(network[const.NET_NAME], net_name)
259+
260+ LOG.debug("test_create_network - END")
261+
262+ def test_create_networkDNE(self):
263+ """Support for the Quantum core API call"""
264+ LOG.debug("test_create_networkDNE - START")
265+
266+ self.assertRaises(exc.NetworkNotFound,
267+ self._l2network_multiblade.create_network,
268+ [tenant_id, net_name, net_id,
269+ vlan_name(net_id), vlan_id])
270+
271+ LOG.debug("test_create_networkDNE - END")
272+
273+ def test_delete_network(self):
274+ """Support for the Quantum core API call"""
275+ LOG.debug("test_delete_network - START")
276+
277+ # Create the network in the test DB, then with the model
278+ self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
279+ self._l2network_multiblade.create_network([tenant_id,
280+ net_name,
281+ self.net_id,
282+ vlan_name(self.net_id),
283+ vlan_id])
284+ cdb.add_vlan_binding(vlan_id, vlan_name(self.net_id), self.net_id)
285+
286+ networks = self._l2network_multiblade.delete_network([tenant_id,
287+ self.net_id])
288+
289+ self.assertEqual(networks.__len__(), self.ucs_count)
290+ for network in networks:
291+ self.assertEqual(network[const.NET_ID], self.net_id)
292+ self.assertEqual(network[const.NET_NAME], net_name)
293+
294+ LOG.debug("test_delete_network - END")
295+
296+ def test_delete_networkDNE(self):
297+ """Support for the Quantum core API call"""
298+ LOG.debug("test_delete_networkDNE - START")
299+
300+ self.assertRaises(exc.NetworkNotFound,
301+ self._l2network_multiblade.delete_network,
302+ [tenant_id, net_id])
303+
304+ LOG.debug("test_delete_networkDNE - END")
305+
306+ def test_rename_network(self):
307+ """Support for the Quantum core API call"""
308+ LOG.debug("test_rename_network - START")
309+
310+ self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
311+ self._l2network_multiblade.create_network([tenant_id,
312+ net_name,
313+ self.net_id,
314+ vlan_name(self.net_id),
315+ vlan_id])
316+
317+ db.network_rename(tenant_id, self.net_id, new_net_name)
318+ networks = self._l2network_multiblade.rename_network([tenant_id,
319+ self.net_id,
320+ new_net_name])
321+
322+ self.assertEqual(networks.__len__(), self.ucs_count)
323+ for network in networks:
324+ self.assertEqual(network[const.NET_ID], self.net_id)
325+ self.assertEqual(network[const.NET_NAME], new_net_name)
326+ LOG.debug("test_rename_network - END")
327+
328+ def test_rename_networkDNE(self):
329+ """Support for the Quantum core API call"""
330+ LOG.debug("test_rename_networkDNE - START")
331+ self.assertRaises(exc.NetworkNotFound,
332+ self._l2network_multiblade.rename_network,
333+ [tenant_id, net_id, new_net_name])
334+ LOG.debug("test_rename_networkDNE - END")
335+
336+ def test_get_all_networks(self):
337+ """Not implemented for this model"""
338+ pass
339+
340+ def test_get_network_details(self):
341+ """Not implemented for this model"""
342+ pass
343+
344+ def test_create_port(self):
345+ """Support for the Quantum core API call"""
346+ LOG.debug("test_create_port - START")
347+ self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
348+ self._l2network_multiblade.create_network([tenant_id,
349+ net_name,
350+ self.net_id,
351+ vlan_name(self.net_id),
352+ vlan_id])
353+
354+ self.port_id = db.port_create(self.net_id, port_state)[const.UUID]
355+ port = self._l2network_multiblade.create_port([tenant_id,
356+ self.net_id,
357+ port_state,
358+ self.port_id])
359+
360+ self.assertEqual(self.port_id, port[0][const.PORTID])
361+ LOG.debug("test_create_port - END")
362+
363+ def test_delete_port(self):
364+ """Support for the Quantum core API call"""
365+ LOG.debug("test_delete_port - START")
366+ self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
367+ self._l2network_multiblade.create_network([tenant_id,
368+ net_name,
369+ self.net_id,
370+ vlan_name(self.net_id),
371+ vlan_id])
372+
373+ self.port_id = db.port_create(self.net_id, port_state)[const.UUID]
374+ self._l2network_multiblade.create_port([tenant_id,
375+ self.net_id,
376+ port_state, self.port_id])
377+
378+ port = self._l2network_multiblade.delete_port([tenant_id,
379+ self.net_id,
380+ self.port_id])
381+
382+ self.assertEqual(self.port_id, port[0][const.PORTID])
383+
384+ # Recreating port so tear down doesn't cause an error
385+ self.port_id = db.port_create(self.net_id, port_state)[const.UUID]
386+ self._l2network_multiblade.create_port([tenant_id,
387+ self.net_id,
388+ port_state, self.port_id])
389+
390+ LOG.debug("test_delete_port - END")
391+
392+ def test_get_all_ports(self):
393+ """Not implemented for this model"""
394+ pass
395+
396+ def test_update_port(self):
397+ """Not implemented for this model"""
398+ pass
399+
400+ def test_update_portDNE(self):
401+ """Not implemented for this model"""
402+ pass
403+
404+ def test_update_port_networkDNE(self):
405+ """Not implemented for this model"""
406+ pass
407+
408+ def test_port_details(self):
409+ """Not implemented for this model"""
410+ pass
411+
412+ def test_plug_interface(self):
413+ """Support for the Quantum core API call"""
414+ LOG.debug("test_plug_interface - START")
415+ self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
416+ self._l2network_multiblade.create_network([tenant_id,
417+ net_name,
418+ self.net_id,
419+ vlan_name(self.net_id),
420+ vlan_id])
421+ cdb.add_vlan_binding(vlan_id, vlan_name(self.net_id), self.net_id)
422+
423+ self.port_id = db.port_create(self.net_id, port_state)[const.UUID]
424+ self._l2network_multiblade.create_port([tenant_id,
425+ self.net_id,
426+ port_state, self.port_id])
427+
428+ interface = self._l2network_multiblade.plug_interface([tenant_id,
429+ self.net_id, self.port_id, interface_id])
430+ port = db.port_set_attachment(self.net_id, self.port_id, interface_id)
431+
432+ self.assertEqual(self.port_id, interface[0][const.PORTID])
433+ self.assertEqual(port[const.INTERFACEID], interface_id)
434+ LOG.debug("test_plug_interface - END")
435+
436+ def test_plug_interface_networkDNE(self):
437+ """Support for the Quantum core API call"""
438+ LOG.debug("test_plug_interface_networkDNE - START")
439+ self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
440+ self._l2network_multiblade.create_network([tenant_id,
441+ net_name,
442+ self.net_id,
443+ vlan_name(self.net_id),
444+ vlan_id])
445+ cdb.add_vlan_binding(vlan_id, vlan_name(self.net_id), self.net_id)
446+
447+ self.port_id = db.port_create(self.net_id, port_state)[const.UUID]
448+ self._l2network_multiblade.create_port([tenant_id,
449+ self.net_id,
450+ port_state, self.port_id])
451+
452+ self.assertRaises(exc.NetworkNotFound,
453+ self._l2network_multiblade.plug_interface,
454+ [tenant_id, net_id, self.port_id, interface_id])
455+
456+ LOG.debug("test_plug_interface_networkDNE - END")
457+
458+ def test_plug_interface_portDNE(self):
459+ """Support for the Quantum core API call"""
460+ LOG.debug("test_plug_interface_portDNE - START")
461+ self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
462+ self._l2network_multiblade.create_network([tenant_id,
463+ net_name,
464+ self.net_id,
465+ vlan_name(self.net_id),
466+ vlan_id])
467+ cdb.add_vlan_binding(vlan_id, vlan_name(self.net_id), self.net_id)
468+
469+ self.assertRaises(exc.PortNotFound,
470+ self._l2network_multiblade.plug_interface,
471+ [tenant_id, self.net_id, port_id, interface_id])
472+
473+ LOG.debug("test_plug_interface_portDNE - START")
474+
475+ def test_unplug_interface(self):
476+ """Support for the Quantum core API call"""
477+ LOG.debug("test_unplug_interface - START")
478+ self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
479+ self._l2network_multiblade.create_network([tenant_id,
480+ net_name,
481+ self.net_id,
482+ vlan_name(self.net_id),
483+ vlan_id])
484+ cdb.add_vlan_binding(vlan_id, vlan_name(self.net_id), self.net_id)
485+
486+ self.port_id = db.port_create(self.net_id, port_state)[const.UUID]
487+ self._l2network_multiblade.create_port([tenant_id,
488+ self.net_id,
489+ port_state, self.port_id])
490+
491+ self._l2network_multiblade.plug_interface([tenant_id, self.net_id,
492+ self.port_id, interface_id])
493+ db.port_set_attachment(self.net_id, self.port_id, interface_id)
494+ interface = self._l2network_multiblade.unplug_interface([tenant_id,
495+ self.net_id, self.port_id])
496+
497+ self.assertEqual(self.port_id, interface[0][const.PORTID])
498+ LOG.debug("test_unplug_interface - END")
499
500=== added file 'quantum/plugins/cisco/tests/unit/test_ucs_inventory.py'
501--- quantum/plugins/cisco/tests/unit/test_ucs_inventory.py 1970-01-01 00:00:00 +0000
502+++ quantum/plugins/cisco/tests/unit/test_ucs_inventory.py 2011-09-09 23:16:27 +0000
503@@ -0,0 +1,201 @@
504+"""
505+# vim: tabstop=4 shiftwidth=4 softtabstop=4
506+#
507+# Copyright 2011 Cisco Systems, Inc. All rights reserved.
508+#
509+# Licensed under the Apache License, Version 2.0 (the "License"); you may
510+# not use this file except in compliance with the License. You may obtain
511+# a copy of the License at
512+#
513+# http://www.apache.org/licenses/LICENSE-2.0
514+#
515+# Unless required by applicable law or agreed to in writing, software
516+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
517+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
518+# License for the specific language governing permissions and limitations
519+# under the License.
520+#
521+# @author: Shubhangi Satras, Cisco Systems, Inc.
522+# @author: Tyler Smith, Cisco Systems, Inc.
523+#
524+"""
525+
526+import unittest
527+import logging as LOG
528+
529+from quantum.common import exceptions as exc
530+from quantum.plugins.cisco.l2network_plugin import L2Network
531+from quantum.plugins.cisco.common import cisco_constants as const
532+from quantum.plugins.cisco.common import cisco_credentials as creds
533+from quantum.plugins.cisco.db import api as db
534+from quantum.plugins.cisco.db import l2network_db as cdb
535+from quantum.plugins.cisco.ucs.cisco_ucs_inventory import UCSInventory
536+
537+LOG.basicConfig(level=LOG.WARN)
538+LOG.getLogger(__name__)
539+
540+# Set some data to use in tests
541+tenant = 'shubh'
542+net_name = 'TestNetwork1'
543+port_state = const.PORT_UP
544+interface_id = 'vif-01'
545+
546+
547+class TestUCSInventory(unittest.TestCase):
548+ """
549+ Tests for the UCS Inventory. Each high-level operation should return
550+ some information about which devices to perform the action on.
551+ """
552+
553+ def setUp(self):
554+ """Setup our tests"""
555+ # Initialize cdb and credentials
556+ db.configure_db({'sql_connection': 'sqlite:///:memory:'})
557+ cdb.initialize()
558+ creds.Store.initialize()
559+
560+ # Create the ucs inventory object
561+ self._ucs_inventory = UCSInventory()
562+ self.inventory = self._ucs_inventory._inventory
563+
564+ # Create a plugin instance to create networks/ports
565+ self._l2network = L2Network()
566+
567+ def assertValidUCM(self, ip_address):
568+ """Asserts that the given ip is in the UCS inventory"""
569+ if ip_address in self.inventory.keys():
570+ assert(1)
571+ return
572+ assert(0)
573+
574+ def assertPortNotFound(self, cmd, args):
575+ """Asserts that the given command raises a PortNotFound exception"""
576+ cmd = getattr(self._ucs_inventory, cmd)
577+ self.assertRaises(exc.PortNotFound, cmd, args)
578+
579+ def _test_get_all_ucms(self, cmd):
580+ """Runs tests for commands that expect a list of all UCMS"""
581+ LOG.debug("test_%s - START", cmd)
582+ results = getattr(self._ucs_inventory, cmd)([])
583+ self.assertEqual(results[const.DEVICE_IP], self.inventory.keys())
584+ LOG.debug("test_%s - END", cmd)
585+
586+ def _test_with_port_creation(self, cmd, params=None):
587+ """Tests commands that requires a port to exist"""
588+ LOG.debug("test_%s - START", cmd)
589+ net = self._l2network.create_network(tenant, net_name)
590+ port = self._l2network.create_port(tenant, net[const.NET_ID],
591+ port_state)
592+
593+ args = [tenant, net[const.NET_ID], port[const.PORT_ID]]
594+ if params is not None:
595+ args.extend(params)
596+
597+ ip_address = getattr(self._ucs_inventory, cmd)(args)
598+ ip_address = ip_address[const.DEVICE_IP][0]
599+ self.assertValidUCM(ip_address)
600+
601+ # Clean up created network and port
602+ try:
603+ self._l2network.unplug_interface(tenant,
604+ net[const.NET_ID], port[const.PORT_ID])
605+ except:
606+ pass
607+ self._l2network.delete_port(tenant,
608+ net[const.NET_ID], port[const.PORT_ID])
609+ self._l2network.delete_network(tenant, net[const.NET_ID])
610+ db.clear_db()
611+
612+ LOG.debug("test_%s - END", cmd)
613+
614+ def _test_port_not_found(self, cmd, params=None):
615+ """Tests commands that should raise a PortNotFound exception"""
616+ # Figure out the correct name of this test
617+ name = cmd
618+ if name[-5:] == "_port":
619+ name += "_not_found"
620+ else:
621+ name += "_port_not_found"
622+
623+ LOG.debug("test_%s - START", name)
624+ args = [tenant, 1, 1]
625+ if params is not None:
626+ args.extend(params)
627+
628+ self.assertPortNotFound(cmd, args)
629+ LOG.debug("test_%s - END", name)
630+
631+ def test_create_port(self):
632+ """Test that the UCS Inventory returns the correct devices to use"""
633+ LOG.debug("test_create_port - START")
634+ results = self._ucs_inventory.create_port([])
635+ results = results[const.LEAST_RSVD_BLADE_DICT]
636+
637+ ip_address = results[const.LEAST_RSVD_BLADE_UCSM]
638+ chassis = results[const.LEAST_RSVD_BLADE_CHASSIS]
639+ blade = results[const.LEAST_RSVD_BLADE_ID]
640+
641+ if blade not in self.inventory[ip_address][chassis]:
642+ self.assertEqual(0, 1)
643+ self.assertEqual(1, 1)
644+ LOG.debug("test_create_port - END")
645+
646+ def test_get_all_networks(self):
647+ """Test that the UCS Inventory returns the correct devices to use"""
648+ self._test_get_all_ucms('get_all_networks')
649+
650+ def test_create_network(self):
651+ """Test that the UCS Inventory returns the correct devices to use"""
652+ self._test_get_all_ucms('create_network')
653+
654+ def test_delete_network(self):
655+ """Test that the UCS Inventory returns the correct devices to use"""
656+ self._test_get_all_ucms('delete_network')
657+
658+ def test_get_network_details(self):
659+ """Test that the UCS Inventory returns the correct devices to use"""
660+ self._test_get_all_ucms('get_network_details')
661+
662+ def test_rename_network(self):
663+ """Test that the UCS Inventory returns the correct devices to use"""
664+ self._test_get_all_ucms('rename_network')
665+
666+ def test_get_all_ports(self):
667+ """Test that the UCS Inventory returns the correct devices to use"""
668+ self._test_get_all_ucms('get_all_ports')
669+
670+ def test_delete_port(self):
671+ """Test that the UCS Inventory returns a valid UCM"""
672+ self._test_with_port_creation('delete_port')
673+
674+ def test_get_port_details(self):
675+ """Test that the UCS Inventory returns a valid UCM"""
676+ self._test_with_port_creation('get_port_details')
677+
678+ def test_update_port(self):
679+ """Test that the UCS Inventory returns a valid UCM"""
680+ self._test_with_port_creation('update_port', [port_state])
681+
682+ def test_plug_interface(self):
683+ """Test that the UCS Inventory returns a valid UCM"""
684+ self._test_with_port_creation('plug_interface', [interface_id])
685+
686+ def test_unplug_interface(self):
687+ """Test that the UCS Inventory returns a valid UCM"""
688+ self._test_with_port_creation('unplug_interface')
689+
690+ def test_update_port_not_found(self):
691+ """Test that the UCS Inventory raises a PortNotFound exception"""
692+ self._test_port_not_found('update_port')
693+
694+ def test_get_port_details_port_not_found(self):
695+ """Test that the UCS Inventory raises a PortNotFound exception"""
696+ self._test_port_not_found('get_port_details')
697+
698+ def test_plug_interface_port_not_found(self):
699+ """Test that the UCS Inventory raises a PortNotFound exception"""
700+ self._test_port_not_found('plug_interface', [interface_id])
701+
702+ def test_unplug_interface_port_not_found(self):
703+ """Test that the UCS Inventory raises a PortNotFound exception"""
704+ self._test_port_not_found('unplug_interface')
705
706=== modified file 'quantum/plugins/cisco/tests/unit/test_ucs_plugin.py'
707--- quantum/plugins/cisco/tests/unit/test_ucs_plugin.py 2011-08-24 20:36:32 +0000
708+++ quantum/plugins/cisco/tests/unit/test_ucs_plugin.py 2011-09-09 23:16:27 +0000
709@@ -14,6 +14,7 @@
710 # under the License.
711 #
712 # @author: Shubhangi Satras, Cisco Systems, Inc.
713+# Shweta Padubidri, Cisco Systems, Inc.
714 #
715 import unittest
716 import logging as LOG
717@@ -21,39 +22,54 @@
718 from quantum.plugins.cisco.common import cisco_constants as const
719 from quantum.plugins.cisco.ucs import cisco_ucs_plugin
720 from quantum.plugins.cisco.ucs import cisco_ucs_configuration as conf
721+from quantum.plugins.cisco.common import cisco_credentials as cred
722+
723+from quantum.plugins.cisco.db import api as db
724+from quantum.plugins.cisco.db import l2network_db as cdb
725+from quantum.plugins.cisco.common import cisco_exceptions as c_exc
726+
727+from quantum.plugins.cisco.ucs import cisco_ucs_inventory as ucsinv
728
729 LOG.basicConfig(level=LOG.WARN)
730-LOG.getLogger("cisco_plugin")
731+LOG.getLogger("cisco_ucs_plugin")
732
733
734 class UCSVICTestPlugin(unittest.TestCase):
735
736 def setUp(self):
737- """
738- Set up function.
739- """
740
741 self.tenant_id = "test_tenant_cisco12"
742 self.net_name = "test_network_cisco12"
743 self.net_id = 000011
744- self.vlan_name = "q-" + str(self.net_id) + "vlan"
745- self.vlan_id = 266
746+ self.vlan_name = conf.DEFAULT_VLAN_NAME
747+ self.vlan_id = conf.DEFAULT_VLAN_ID
748 self.port_id = "4"
749+ cdb.initialize()
750+ cred.Store.initialize()
751 self._cisco_ucs_plugin = cisco_ucs_plugin.UCSVICPlugin()
752+ self.device_ip = conf.UCSM_IP_ADDRESS
753+ self._ucs_inventory = ucsinv.UCSInventory()
754+ self.chassis_id = '1'
755+ self.blade_id = '5'
756+ self.blade_intf_distinguished_name = 'sys/chassis-1/blade-5/'\
757+ 'adaptor-1/host-eth-6'
758
759 def test_create_network(self):
760 """
761 Tests creation of new Virtual Network.
762 """
763 LOG.debug("UCSVICTestPlugin:_test_create_network() called\n")
764+ new_network = db.network_create(self.tenant_id, self.net_name)
765+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
766+ new_network[const.UUID])
767 new_net_dict = self._cisco_ucs_plugin.create_network(
768- self.tenant_id, self.net_name, self.net_id,
769- self.vlan_name, self.vlan_id)
770- self.assertEqual(new_net_dict[const.NET_ID], self.net_id)
771- self.assertEqual(new_net_dict[const.NET_NAME], self.net_name)
772- self.assertEqual(new_net_dict[const.NET_VLAN_NAME], self.vlan_name)
773- self.assertEqual(new_net_dict[const.NET_VLAN_ID], self.vlan_id)
774- self.tearDownNetwork(self.tenant_id, self.net_id)
775+ self.tenant_id, new_network[const.NETWORKNAME],
776+ new_network[const.UUID], self.vlan_name, self.vlan_id,
777+ device_ip=self.device_ip)
778+ self.assertEqual(new_net_dict[const.NET_ID], new_network[const.UUID])
779+ self.assertEqual(new_net_dict[const.NET_NAME],
780+ new_network[const.NETWORKNAME])
781+ self.tearDownNetwork(self.tenant_id, new_network[const.UUID])
782
783 def test_delete_network(self):
784 """
785@@ -61,12 +77,16 @@
786 belonging to the specified tenant.
787 """
788 LOG.debug("UCSVICTestPlugin:test_delete_network() called\n")
789- self._cisco_ucs_plugin.create_network(
790- self.tenant_id, self.net_name, self.net_id,
791- self.vlan_name, self.vlan_id)
792+ new_network = db.network_create(self.tenant_id, self.net_name)
793+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
794+ new_network[const.UUID])
795+ new_net_dict = self._cisco_ucs_plugin.create_network(
796+ self.tenant_id, new_network[const.NETWORKNAME],
797+ new_network[const.UUID], self.vlan_name, self.vlan_id,
798+ device_ip=self.device_ip)
799 new_net_dict = self._cisco_ucs_plugin.delete_network(
800- self.tenant_id, self.net_id)
801- self.assertEqual(new_net_dict[const.NET_ID], self.net_id)
802+ self.tenant_id, new_network[const.UUID], device_ip=self.device_ip)
803+ self.assertEqual(new_net_dict[const.NET_ID], new_network[const.UUID])
804
805 def test_get_network_details(self):
806 """
807@@ -74,15 +94,20 @@
808 spec
809 """
810 LOG.debug("UCSVICTestPlugin:test_get_network_details() called\n")
811- self._cisco_ucs_plugin.create_network(
812- self.tenant_id, self.net_name, self.net_id,
813- self.vlan_name, self.vlan_id)
814+ new_network = db.network_create(self.tenant_id, self.net_name)
815+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
816+ new_network[const.UUID])
817+ new_net_dict = self._cisco_ucs_plugin.create_network(
818+ self.tenant_id, new_network[const.NETWORKNAME],
819+ new_network[const.UUID], self.vlan_name, self.vlan_id,
820+ device_ip=self.device_ip)
821 new_net_dict = self._cisco_ucs_plugin.get_network_details(
822- self.tenant_id, self.net_id)
823- self.assertEqual(new_net_dict[const.NET_ID], self.net_id)
824- self.assertEqual(new_net_dict[const.NET_VLAN_NAME], self.vlan_name)
825- self.assertEqual(new_net_dict[const.NET_VLAN_ID], self.vlan_id)
826- self.tearDownNetwork(self.tenant_id, self.net_id)
827+ self.tenant_id, new_network[const.UUID],
828+ device_ip=self.device_ip)
829+ self.assertEqual(new_net_dict[const.NET_ID], new_network[const.UUID])
830+ self.assertEqual(new_net_dict[const.NET_NAME],
831+ new_network[const.NETWORKNAME])
832+ self.tearDownNetwork(self.tenant_id, new_network[const.UUID])
833
834 def test_get_all_networks(self):
835 """
836@@ -91,18 +116,28 @@
837 the specified tenant.
838 """
839 LOG.debug("UCSVICTestPlugin:test_get_all_networks() called\n")
840+ new_network1 = db.network_create(self.tenant_id, self.net_name)
841+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
842+ new_network1[const.UUID])
843 new_net_dict1 = self._cisco_ucs_plugin.create_network(
844- self.tenant_id, self.net_name, self.net_id,
845- self.vlan_name, self.vlan_id)
846+ self.tenant_id, new_network1[const.NETWORKNAME],
847+ new_network1[const.UUID], self.vlan_name, self.vlan_id,
848+ device_ip=self.device_ip)
849+ new_network2 = db.network_create(self.tenant_id, "test_network2")
850+ cdb.add_vlan_binding("6", "q-000006vlan", new_network2[const.UUID])
851 new_net_dict2 = self._cisco_ucs_plugin.create_network(
852- self.tenant_id, "test_network2",
853- 000006, "q-000006vlan", "6")
854- net_list = self._cisco_ucs_plugin.get_all_networks(self.tenant_id)
855+ self.tenant_id, new_network2[const.NETWORKNAME],
856+ new_network2[const.UUID], "q-000006vlan", "6",
857+ device_ip=self.device_ip)
858+
859+ net_list = self._cisco_ucs_plugin.get_all_networks(
860+ self.tenant_id, device_ip=self.device_ip)
861 net_id_list = [new_net_dict1, new_net_dict2]
862+
863 self.assertTrue(net_list[0] in net_id_list)
864 self.assertTrue(net_list[1] in net_id_list)
865- self.tearDownNetwork(self.tenant_id, new_net_dict1[const.NET_ID])
866- self.tearDownNetwork(self.tenant_id, new_net_dict2[const.NET_ID])
867+ self.tearDownNetwork(self.tenant_id, new_network1[const.UUID])
868+ self.tearDownNetwork(self.tenant_id, new_network2[const.UUID])
869
870 def test_get_all_ports(self):
871 """
872@@ -110,74 +145,81 @@
873 specified Virtual Network.
874 """
875 LOG.debug("UCSVICPlugin:get_all_ports() called\n")
876+ new_network = db.network_create(self.tenant_id, self.net_name)
877+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
878+ new_network[const.UUID])
879 new_net_dict = self._cisco_ucs_plugin.create_network(
880- self.tenant_id, self.net_name, self.net_id,
881- self.vlan_name, self.vlan_id)
882+ self.tenant_id, new_network[const.NETWORKNAME],
883+ new_network[const.UUID], self.vlan_name, self.vlan_id,
884+ device_ip=self.device_ip)
885+ new_port1 = db.port_create(new_network[const.UUID], const.PORT_UP)
886 port_dict1 = self._cisco_ucs_plugin.create_port(
887- self.tenant_id, self.net_id, const.PORT_UP,
888- self.port_id)
889+ self.tenant_id, self.net_id, const.PORT_UP,
890+ new_port1[const.UUID], device_ip=self.device_ip,
891+ ucs_inventory=self._ucs_inventory,
892+ least_rsvd_blade_dict=self._ucs_inventory.\
893+ _get_least_reserved_blade())
894+ new_port2 = db.port_create(new_network[const.UUID], const.PORT_UP)
895 port_dict2 = self._cisco_ucs_plugin.create_port(
896- self.tenant_id, self.net_id,
897- const.PORT_UP, "10")
898+ self.tenant_id, self.net_id, const.PORT_UP,
899+ new_port2[const.UUID], device_ip=self.device_ip,
900+ ucs_inventory=self._ucs_inventory,
901+ least_rsvd_blade_dict=self._ucs_inventory.\
902+ _get_least_reserved_blade())
903 ports_on_net = self._cisco_ucs_plugin.get_all_ports(
904- self.tenant_id, self.net_id)
905+ self.tenant_id, new_net_dict[const.NET_ID],
906+ device_ip=self.device_ip,
907+ ucs_inventory=self._ucs_inventory,
908+ least_rsvd_blade_dict=self._ucs_inventory.\
909+ _get_least_reserved_blade())
910 port_list = [port_dict1, port_dict2]
911- self.assertTrue(port_list[0] in ports_on_net)
912- self.assertTrue(port_list[1] in ports_on_net)
913- self._cisco_ucs_plugin.delete_port(self.tenant_id, self.net_id,
914- self.port_id)
915- self.tearDownNetworkPort(self.tenant_id, new_net_dict[const.NET_ID],
916- port_dict2[const.PORT_ID])
917-
918- def _test_rename_network(self, new_name):
919- """
920- Tests whether symbolic name is updated for the particular
921- Virtual Network.
922- """
923- LOG.debug("UCSVICTestPlugin:_test_rename_network() called\n")
924- self._cisco_ucs_plugin.create_network(self.tenant_id, self.net_name,
925- self.net_id, self.vlan_name,
926- self.vlan_id)
927- new_net_dict = self._cisco_ucs_plugin.rename_network(
928- self.tenant_id, self.net_id, new_name)
929- self.assertEqual(new_net_dict[const.NET_NAME], new_name)
930- self.tearDownNetwork(self.tenant_id, self.net_id)
931-
932- def test_rename_network(self):
933- """
934- Tests rename network.
935- """
936- self._test_rename_network("new_test_network1")
937-
938- def _test_create_port(self, port_state):
939+ self.assertTrue(str(ports_on_net[1]) == str(port_list[1]) or
940+ str(ports_on_net[1]) == str(port_list[0]))
941+ self.assertTrue(str(ports_on_net[0]) == str(port_list[1]) or
942+ str(ports_on_net[0]) == str(port_list[0]))
943+
944+ self._cisco_ucs_plugin.delete_port(
945+ self.tenant_id, new_net_dict[const.NET_ID],
946+ port_dict1[const.PORTID], device_ip=self.device_ip,
947+ ucs_inventory=self._ucs_inventory,
948+ chassis_id=self.chassis_id, blade_id=self.blade_id,
949+ blade_intf_distinguished_name=self.\
950+ blade_intf_distinguished_name,
951+ least_rsvd_blade_dict=self._ucs_inventory.\
952+ _get_least_reserved_blade())
953+ self.tearDownNetworkPort(
954+ self.tenant_id, new_net_dict[const.NET_ID],
955+ port_dict2[const.PORTID])
956+
957+ def test_create_port(self):
958 """
959 Tests creation of a port on the specified Virtual Network.
960 """
961 LOG.debug("UCSVICTestPlugin:_test_create_port() called\n")
962- self._cisco_ucs_plugin.create_network(self.tenant_id, self.net_name,
963- self.net_id, self.vlan_name,
964- self.vlan_id)
965- new_port_dict = self._cisco_ucs_plugin.create_port(
966- self.tenant_id, self.net_id, port_state, self.port_id)
967- self.assertEqual(new_port_dict[const.PORT_ID], self.port_id)
968- self.assertEqual(new_port_dict[const.PORT_STATE], port_state)
969- self.assertEqual(new_port_dict[const.ATTACHMENT], None)
970- profile_name = self._cisco_ucs_plugin._get_profile_name(self.port_id)
971- new_port_profile = new_port_dict[const.PORT_PROFILE]
972- self.assertEqual(new_port_profile[const.PROFILE_NAME], profile_name)
973- self.assertEqual(new_port_profile[const.PROFILE_VLAN_NAME],
974- conf.DEFAULT_VLAN_NAME)
975- self.assertEqual(new_port_profile[const.PROFILE_VLAN_ID],
976- conf.DEFAULT_VLAN_ID)
977- self.tearDownNetworkPort(self.tenant_id, self.net_id, self.port_id)
978-
979- def test_create_port(self):
980- """
981- Tests create port.
982- """
983- self._test_create_port(const.PORT_UP)
984-
985- def _test_delete_port(self, port_state):
986+
987+ new_network = db.network_create(self.tenant_id, self.net_name)
988+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
989+ new_network[const.UUID])
990+ new_net_dict = self._cisco_ucs_plugin.create_network(
991+ self.tenant_id, new_network[const.NETWORKNAME],
992+ new_network[const.UUID], self.vlan_name, self.vlan_id,
993+ device_ip=self.device_ip)
994+ new_port = db.port_create(new_network[const.UUID], const.PORT_UP)
995+ port_dict = self._cisco_ucs_plugin.create_port(
996+ self.tenant_id, self.net_id, const.PORT_UP,
997+ new_port[const.UUID], device_ip=self.device_ip,
998+ ucs_inventory=self._ucs_inventory,
999+ least_rsvd_blade_dict=self._ucs_inventory.\
1000+ _get_least_reserved_blade())
1001+ self.assertEqual(port_dict[const.PORTID], new_port[const.UUID])
1002+ profile_name = self._cisco_ucs_plugin.\
1003+ _get_profile_name(port_dict[const.PORTID])
1004+ self.assertTrue(profile_name != None)
1005+ self.tearDownNetworkPort(
1006+ self.tenant_id, new_net_dict[const.NET_ID],
1007+ port_dict[const.PORTID])
1008+
1009+ def test_delete_port(self):
1010 """
1011 Tests Deletion of a port on a specified Virtual Network,
1012 if the port contains a remote interface attachment,
1013@@ -185,378 +227,255 @@
1014 then the port can be deleted.
1015 """
1016 LOG.debug("UCSVICTestPlugin:_test_delete_port() called\n")
1017- self._cisco_ucs_plugin.create_network(self.tenant_id, self.net_name,
1018- self.net_id, self.vlan_name,
1019- self.vlan_id)
1020- self._cisco_ucs_plugin.create_port(self.tenant_id, self.net_id,
1021- port_state, self.port_id)
1022- self._cisco_ucs_plugin.delete_port(self.tenant_id, self.net_id,
1023- self.port_id)
1024- net = self._cisco_ucs_plugin._get_network(self.tenant_id, self.net_id)
1025- self.assertEqual(net[const.NET_PORTS], {})
1026- self.tearDownNetwork(self.tenant_id, self.net_id)
1027-
1028- def test_delete_port(self):
1029- """
1030- Tests delete port.
1031- """
1032- self._test_delete_port(const.PORT_UP)
1033-
1034- def _test_update_port(self, port_state):
1035- """
1036- Tests Updation of the state of a port on the specified Virtual Network.
1037- """
1038- LOG.debug("UCSVICTestPlugin:_test_update_port() called\n")
1039- self._cisco_ucs_plugin.create_network(self.tenant_id, self.net_name,
1040- self.net_id, self.vlan_name,
1041- self.vlan_id)
1042- self._cisco_ucs_plugin.create_port(self.tenant_id, self.net_id,
1043- port_state, self.port_id)
1044- port = self._cisco_ucs_plugin.update_port(
1045- self.tenant_id, self.net_id,
1046- self.port_id, port_state)
1047- self.assertEqual(port[const.PORT_STATE], port_state)
1048- self.tearDownNetworkPort(self.tenant_id, self.net_id, self.port_id)
1049-
1050- def test_update_port_state_up(self):
1051- """
1052- Tests update port state up
1053- """
1054- self._test_update_port(const.PORT_UP)
1055-
1056- def test_update_port_state_down(self):
1057- """
1058- Tests update port state down
1059- """
1060- self._test_update_port(const.PORT_DOWN)
1061-
1062- def _test_get_port_details_state_up(self, port_state):
1063+ new_network = db.network_create(self.tenant_id, self.net_name)
1064+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
1065+ new_network[const.UUID])
1066+ new_net_dict = self._cisco_ucs_plugin.create_network(
1067+ self.tenant_id, new_network[const.NETWORKNAME],
1068+ new_network[const.UUID], self.vlan_name, self.vlan_id,
1069+ device_ip=self.device_ip)
1070+ new_port = db.port_create(new_network[const.UUID], const.PORT_UP)
1071+ port_dict = self._cisco_ucs_plugin.create_port(
1072+ self.tenant_id, self.net_id, const.PORT_UP,
1073+ new_port[const.UUID], device_ip=self.device_ip,
1074+ ucs_inventory=self._ucs_inventory,
1075+ least_rsvd_blade_dict=self._ucs_inventory.\
1076+ _get_least_reserved_blade())
1077+ port_bind = self._cisco_ucs_plugin.delete_port(
1078+ self.tenant_id, new_net_dict[const.NET_ID],
1079+ port_dict[const.PORTID], device_ip=self.device_ip,
1080+ ucs_inventory=self._ucs_inventory,
1081+ chassis_id=self.chassis_id, blade_id=self.blade_id,
1082+ blade_intf_distinguished_name=self.\
1083+ blade_intf_distinguished_name,
1084+ least_rsvd_blade_dict=self._ucs_inventory.\
1085+ _get_least_reserved_blade())
1086+
1087+ self.assertEqual(port_bind[const.PORTID], new_port[const.UUID])
1088+ self.tearDownNetwork(self.tenant_id, new_net_dict[const.NET_ID])
1089+
1090+ def _test_get_port_details(self, port_state):
1091 """
1092 Tests whether user is able to retrieve a remote interface
1093 that is attached to this particular port when port state is Up.
1094 """
1095- LOG.debug("UCSVICTestPlugin:_test_get_port_details_state_up()" +
1096- "called\n")
1097- self._cisco_ucs_plugin.create_network(self.tenant_id, self.net_name,
1098- self.net_id, self.vlan_name,
1099- self.vlan_id)
1100- self._cisco_ucs_plugin.create_port(self.tenant_id, self.net_id,
1101- port_state, self.port_id)
1102- port = self._cisco_ucs_plugin.get_port_details(
1103- self.tenant_id, self.net_id, self.port_id)
1104- self.assertEqual(port[const.PORT_ID], self.port_id)
1105- self.assertEqual(port[const.PORT_STATE], port_state)
1106- self.assertEqual(port[const.ATTACHMENT], None)
1107- new_port_profile = port[const.PORT_PROFILE]
1108- profile_name = self._cisco_ucs_plugin._get_profile_name(self.port_id)
1109- self.assertEqual(new_port_profile[const.PROFILE_VLAN_NAME],
1110- conf.DEFAULT_VLAN_NAME)
1111- self.assertEqual(new_port_profile[const.PROFILE_VLAN_ID],
1112- conf.DEFAULT_VLAN_ID)
1113- self.assertEqual(new_port_profile[const.PROFILE_NAME], profile_name)
1114- self.tearDownNetworkPort(self.tenant_id, self.net_id, self.port_id)
1115+ LOG.debug("UCSVICTestPlugin:_test_get_port_details() called\n")
1116+ new_network = db.network_create(self.tenant_id, self.net_name)
1117+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
1118+ new_network[const.UUID])
1119+ new_net_dict = self._cisco_ucs_plugin.create_network(
1120+ self.tenant_id, new_network[const.NETWORKNAME],
1121+ new_network[const.UUID], self.vlan_name, self.vlan_id,
1122+ device_ip=self.device_ip)
1123+ new_port = db.port_create(new_network[const.UUID], port_state)
1124+ port_dict = self._cisco_ucs_plugin.create_port(
1125+ self.tenant_id, self.net_id, port_state,
1126+ new_port[const.UUID], device_ip=self.device_ip,
1127+ ucs_inventory=self._ucs_inventory,
1128+ least_rsvd_blade_dict=self._ucs_inventory.\
1129+ _get_least_reserved_blade())
1130
1131- def _test_show_port_state_down(self, port_state):
1132- """
1133- Tests whether user is able to retrieve a remote interface
1134- that is attached to this particular port when port state is down.
1135- """
1136- LOG.debug("UCSVICTestPlugin:_test_show_port_state_down()" +
1137- "called\n")
1138- self._cisco_ucs_plugin.create_network(self.tenant_id, self.net_name,
1139- self.net_id, self.vlan_name,
1140- self.vlan_id)
1141- self._cisco_ucs_plugin.create_port(self.tenant_id, self.net_id,
1142- port_state, self.port_id)
1143- port = self._cisco_ucs_plugin.get_port_details(self.tenant_id,
1144- self.net_id,
1145- self.port_id)
1146- self.assertEqual(port[const.PORT_ID], self.port_id)
1147- self.assertNotEqual(port[const.PORT_STATE], port_state)
1148- self.assertEqual(port[const.ATTACHMENT], None)
1149- new_port_profile = port[const.PORT_PROFILE]
1150- profile_name = self._cisco_ucs_plugin._get_profile_name(self.port_id)
1151- self.assertEqual(new_port_profile[const.PROFILE_VLAN_NAME],
1152- conf.DEFAULT_VLAN_NAME)
1153- self.assertEqual(new_port_profile[const.PROFILE_VLAN_ID],
1154- conf.DEFAULT_VLAN_ID)
1155- self.assertEqual(new_port_profile[const.PROFILE_NAME], profile_name)
1156- self.tearDownNetworkPort(self.tenant_id, self.net_id, self.port_id)
1157+ port_detail = self._cisco_ucs_plugin.get_port_details(
1158+ self.tenant_id, new_net_dict[const.NET_ID],
1159+ port_dict[const.PORTID], device_ip=self.device_ip)
1160+ self.assertEqual(str(port_dict), str(port_detail))
1161+ self.tearDownNetworkPort(
1162+ self.tenant_id, new_net_dict[const.NET_ID],
1163+ port_dict[const.PORTID])
1164
1165 def test_get_port_details_state_up(self):
1166- """
1167- Tests get port details state up
1168- """
1169- self._test_get_port_details_state_up(const.PORT_UP)
1170+ self._test_get_port_details(const.PORT_UP)
1171
1172 def test_show_port_state_down(self):
1173- """
1174- Tests show port state down
1175- """
1176- self._test_show_port_state_down(const.PORT_DOWN)
1177+ self._test_get_port_details(const.PORT_DOWN)
1178
1179 def test_create_port_profile(self):
1180- """
1181- Tests create port profile
1182- """
1183 LOG.debug("UCSVICTestPlugin:test_create_port_profile() called\n")
1184+ new_network = db.network_create(self.tenant_id, self.net_name)
1185+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
1186+ new_network[const.UUID])
1187+ new_port = db.port_create(new_network[const.UUID], const.PORT_UP)
1188+ self._cisco_ucs_plugin._set_ucsm(self.device_ip)
1189 new_port_profile = self._cisco_ucs_plugin._create_port_profile(
1190- self.tenant_id, self.net_id, self.port_id,
1191- self.vlan_name, self.vlan_id)
1192- profile_name = self._cisco_ucs_plugin._get_profile_name(self.port_id)
1193+ self.tenant_id, new_network[const.UUID],
1194+ new_port[const.UUID], self.vlan_name,
1195+ self.vlan_id)
1196+ profile_name = self._cisco_ucs_plugin.\
1197+ _get_profile_name(new_port[const.UUID])
1198 self.assertEqual(new_port_profile[const.PROFILE_NAME], profile_name)
1199 self.assertEqual(new_port_profile[const.PROFILE_VLAN_NAME],
1200- self.vlan_name)
1201+ self.vlan_name)
1202 self.assertEqual(new_port_profile[const.PROFILE_VLAN_ID], self.vlan_id)
1203- self._cisco_ucs_plugin._delete_port_profile(self.port_id, profile_name)
1204+ self._cisco_ucs_plugin._delete_port_profile(new_port[const.UUID],
1205+ profile_name)
1206
1207 def test_delete_port_profile(self):
1208- """
1209- Tests delete port profile
1210- """
1211 LOG.debug("UCSVICTestPlugin:test_delete_port_profile() called\n")
1212+ new_network = db.network_create(self.tenant_id, self.net_name)
1213+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
1214+ new_network[const.UUID])
1215+ new_port = db.port_create(new_network[const.UUID], const.PORT_UP)
1216+ self._cisco_ucs_plugin._set_ucsm(self.device_ip)
1217 self._cisco_ucs_plugin._create_port_profile(
1218- self.tenant_id, self.net_id, self.port_id, self.vlan_name,
1219- self.vlan_id)
1220- profile_name = self._cisco_ucs_plugin._get_profile_name(self.port_id)
1221+ self.tenant_id, new_network[const.UUID],
1222+ new_port[const.UUID], self.vlan_name,
1223+ self.vlan_id)
1224+ profile_name = self._cisco_ucs_plugin.\
1225+ _get_profile_name(new_port[const.UUID])
1226+
1227 counter1 = self._cisco_ucs_plugin._port_profile_counter
1228- self._cisco_ucs_plugin._delete_port_profile(self.port_id,
1229- profile_name)
1230+ self._cisco_ucs_plugin._delete_port_profile(new_port[const.UUID],
1231+ profile_name)
1232 counter2 = self._cisco_ucs_plugin._port_profile_counter
1233- self.assertNotEqual(counter1, counter2)
1234+ self.assertEqual(counter1 - 1, counter2)
1235
1236- def _test_plug_interface(self, remote_interface_id):
1237+ def test_plug_interface(self, remote_interface_id=None,
1238+ new_vlanid=10, new_vlan_name='new_vlan'):
1239 """
1240 Attaches a remote interface to the specified port on the
1241 specified Virtual Network.
1242 """
1243 LOG.debug("UCSVICTestPlugin:_test_plug_interface() called\n")
1244- self._cisco_ucs_plugin.create_network(self.tenant_id, self.net_name,
1245- self.net_id, self.vlan_name,
1246- self.vlan_id)
1247- self._cisco_ucs_plugin.create_port(self.tenant_id, self.net_id,
1248- const.PORT_UP, self.port_id)
1249- self._cisco_ucs_plugin.plug_interface(self.tenant_id, self.net_id,
1250- self.port_id,
1251- remote_interface_id)
1252- port = self._cisco_ucs_plugin._get_port(
1253- self.tenant_id, self.net_id, self.port_id)
1254- self.assertEqual(port[const.ATTACHMENT], remote_interface_id)
1255- port_profile = port[const.PORT_PROFILE]
1256- new_vlan_name = self._cisco_ucs_plugin._get_vlan_name_for_network(
1257- self.tenant_id, self.net_id)
1258- new_vlan_id = self._cisco_ucs_plugin._get_vlan_id_for_network(
1259- self.tenant_id, self.net_id)
1260- self.assertEqual(port_profile[const.PROFILE_VLAN_NAME], new_vlan_name)
1261- self.assertEqual(port_profile[const.PROFILE_VLAN_ID], new_vlan_id)
1262- self.tearDownNetworkPortInterface(self.tenant_id, self.net_id,
1263- self.port_id)
1264-
1265- def test_plug_interface(self):
1266- """
1267- Tests test plug interface
1268- """
1269- self._test_plug_interface("4")
1270-
1271- def _test_unplug_interface(self, remote_interface_id):
1272+ new_network = db.network_create(self.tenant_id, self.net_name)
1273+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
1274+ new_network[const.UUID])
1275+ new_net_dict = self._cisco_ucs_plugin.create_network(
1276+ self.tenant_id, new_network[const.NETWORKNAME],
1277+ new_network[const.UUID], self.vlan_name, self.vlan_id,
1278+ device_ip=self.device_ip)
1279+ new_port = db.port_create(new_network[const.UUID], const.PORT_UP)
1280+ port_dict = self._cisco_ucs_plugin.create_port(
1281+ self.tenant_id, new_net_dict[const.NET_ID],
1282+ const.PORT_UP, new_port[const.UUID],
1283+ device_ip=self.device_ip,
1284+ ucs_inventory=self._ucs_inventory,
1285+ least_rsvd_blade_dict=self._ucs_inventory.\
1286+ _get_least_reserved_blade())
1287+ cdb.update_vlan_binding(new_network[const.UUID],
1288+ str(new_vlanid), new_vlan_name)
1289+ port_bind = self._cisco_ucs_plugin.plug_interface(
1290+ self.tenant_id, new_net_dict[const.NET_ID],
1291+ port_dict[const.PORTID], remote_interface_id,
1292+ device_ip=self.device_ip)
1293+ self.assertEqual(port_bind[const.VLANNAME], new_vlan_name)
1294+ self.assertEqual(port_bind[const.VLANID], new_vlanid)
1295+ self.tearDownNetworkPortInterface(
1296+ self.tenant_id, new_net_dict[const.NET_ID],
1297+ new_port[const.UUID])
1298+
1299+ def test_unplug_interface(self, remote_interface_id=None,
1300+ new_vlanid=10, new_vlan_name='new_vlan'):
1301 """
1302 Tests whether remote interface detaches from the specified port on the
1303 specified Virtual Network.
1304 """
1305 LOG.debug("UCSVICTestPlugin:_test_unplug_interface() called\n")
1306- self._cisco_ucs_plugin.create_network(self.tenant_id, self.net_name,
1307- self.net_id, self.vlan_name,
1308- self.vlan_id)
1309- self._cisco_ucs_plugin.create_port(self.tenant_id, self.net_id,
1310- const.PORT_UP, self.port_id)
1311- self._cisco_ucs_plugin.plug_interface(self.tenant_id, self.net_id,
1312- self.port_id,
1313- remote_interface_id)
1314- self._cisco_ucs_plugin.unplug_interface(self.tenant_id, self.net_id,
1315- self.port_id)
1316- port = self._cisco_ucs_plugin._get_port(
1317- self.tenant_id, self.net_id, self.port_id)
1318- self.assertEqual(port[const.ATTACHMENT], None)
1319- port_profile = port[const.PORT_PROFILE]
1320- self.assertEqual(port_profile[const.PROFILE_VLAN_NAME],
1321- conf.DEFAULT_VLAN_NAME)
1322- self.assertEqual(port_profile[const.PROFILE_VLAN_ID],
1323- conf.DEFAULT_VLAN_ID)
1324- self.tearDownNetworkPort(self.tenant_id, self.net_id, self.port_id)
1325+ new_network = db.network_create(self.tenant_id, self.net_name)
1326+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
1327+ new_network[const.UUID])
1328+ new_net_dict = self._cisco_ucs_plugin.create_network(
1329+ self.tenant_id, new_network[const.NETWORKNAME],
1330+ new_network[const.UUID], self.vlan_name, self.vlan_id,
1331+ device_ip=self.device_ip)
1332+ new_port = db.port_create(new_network[const.UUID], const.PORT_UP)
1333+ port_dict = self._cisco_ucs_plugin.create_port(
1334+ self.tenant_id, new_net_dict[const.NET_ID],
1335+ const.PORT_UP, new_port[const.UUID],
1336+ device_ip=self.device_ip,
1337+ ucs_inventory=self._ucs_inventory,
1338+ least_rsvd_blade_dict=self._ucs_inventory.\
1339+ _get_least_reserved_blade())
1340+ cdb.update_vlan_binding(new_network[const.UUID],
1341+ str(new_vlanid), new_vlan_name)
1342+ self._cisco_ucs_plugin.plug_interface(
1343+ self.tenant_id, new_net_dict[const.NET_ID],
1344+ port_dict[const.PORTID], remote_interface_id,
1345+ device_ip=self.device_ip)
1346
1347- def test_unplug_interface(self):
1348- """
1349- Tests unplug interface
1350- """
1351- self._test_unplug_interface("4")
1352+ port_bind = self._cisco_ucs_plugin.unplug_interface(
1353+ self.tenant_id, new_net_dict[const.NET_ID],
1354+ port_dict[const.PORTID], device_ip=self.device_ip)
1355+ self.assertEqual(port_bind[const.VLANNAME], self.vlan_name)
1356+ self.assertEqual(port_bind[const.VLANID], self.vlan_id)
1357+ self.tearDownNetworkPortInterface(
1358+ self.tenant_id, new_net_dict[const.NET_ID],
1359+ new_port[const.UUID])
1360
1361 def test_get_vlan_name_for_network(self):
1362- """
1363- Tests get vlan name for network
1364- """
1365 LOG.debug("UCSVICTestPlugin:test_get_vlan_name_for_network() called\n")
1366- net = self._cisco_ucs_plugin.create_network(
1367- self.tenant_id, self.net_name, self.net_id,
1368- self.vlan_name, self.vlan_id)
1369- self.assertEqual(net[const.NET_VLAN_NAME], self.vlan_name)
1370- self.tearDownNetwork(self.tenant_id, self.net_id)
1371+ new_network = db.network_create(self.tenant_id, self.net_name)
1372+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
1373+ new_network[const.UUID])
1374+ vlan_bind_name = self._cisco_ucs_plugin._get_vlan_name_for_network(
1375+ self.tenant_id, new_network[const.UUID])
1376+
1377+ self.assertEqual(vlan_bind_name, self.vlan_name)
1378
1379 def test_get_vlan_id_for_network(self):
1380- """
1381- Tests get vlan id for network
1382- """
1383 LOG.debug("UCSVICTestPlugin:test_get_vlan_id_for_network() called\n")
1384- net = self._cisco_ucs_plugin.create_network(
1385- self.tenant_id, self.net_name, self.net_id, self.vlan_name,
1386- self.vlan_id)
1387- self.assertEqual(net[const.NET_VLAN_ID], self.vlan_id)
1388- self.tearDownNetwork(self.tenant_id, self.net_id)
1389-
1390- def test_get_network(self):
1391- """
1392- Tests get network
1393- """
1394- LOG.debug("UCSVICTestPlugin:test_get_network() called\n")
1395- net = self._cisco_ucs_plugin.create_network(
1396- self.tenant_id, self.net_name, self.net_id, self.vlan_name,
1397- self.vlan_id)
1398- self.assertEqual(net[const.NET_ID], self.net_id)
1399- self.tearDownNetwork(self.tenant_id, self.net_id)
1400-
1401- def test_get_port(self):
1402- """
1403- Tests get port
1404- """
1405- LOG.debug("UCSVICTestPlugin:test_get_port() called\n")
1406- self._cisco_ucs_plugin.create_network(self.tenant_id, self.net_name,
1407- self.net_id, self.vlan_name,
1408- self.vlan_id)
1409- new_port_dict = self._cisco_ucs_plugin.create_port(
1410- self.tenant_id, self.net_id,
1411- const.PORT_UP, self.port_id)
1412- self.assertEqual(new_port_dict[const.PORT_ID], self.port_id)
1413- self.tearDownNetworkPort(self.tenant_id, self.net_id, self.port_id)
1414-
1415- def test_get_network_NetworkNotFound(self):
1416- """
1417- Tests get network not found
1418- """
1419+ new_network = db.network_create(self.tenant_id, self.net_name)
1420+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
1421+ new_network[const.UUID])
1422+ vlan_bind_id = self._cisco_ucs_plugin._get_vlan_id_for_network(
1423+ self.tenant_id, new_network[const.UUID])
1424+ self.assertEqual(str(vlan_bind_id), self.vlan_id)
1425+
1426+ def test_show_network_NetworkNotFound(self):
1427 self.assertRaises(exc.NetworkNotFound,
1428- self._cisco_ucs_plugin._get_network,
1429- self.tenant_id, self.net_id)
1430+ self._cisco_ucs_plugin.get_network_details,
1431+ self.tenant_id, self.net_id,
1432+ device_ip=self.device_ip)
1433
1434 def test_delete_network_NetworkNotFound(self):
1435- """
1436- Tests delete network not found
1437- """
1438 self.assertRaises(exc.NetworkNotFound,
1439 self._cisco_ucs_plugin.delete_network,
1440- self.tenant_id, self.net_id)
1441-
1442- def test_delete_port_PortInUse(self):
1443- """
1444- Tests delete port in use
1445- """
1446- self._test_delete_port_PortInUse("4")
1447-
1448- def _test_delete_port_PortInUse(self, remote_interface_id):
1449- """
1450- Tests delete port in use
1451- """
1452- self._cisco_ucs_plugin.create_network(self.tenant_id, self.net_name,
1453- self.net_id, self.vlan_name,
1454- self.vlan_id)
1455- self._cisco_ucs_plugin.create_port(self.tenant_id, self.net_id,
1456- const.PORT_UP, self.port_id)
1457- self._cisco_ucs_plugin.plug_interface(self.tenant_id, self.net_id,
1458- self.port_id,
1459- remote_interface_id)
1460- self.assertRaises(exc.PortInUse, self._cisco_ucs_plugin.delete_port,
1461- self.tenant_id, self.net_id, self.port_id)
1462- self.tearDownNetworkPortInterface(self.tenant_id, self.net_id,
1463- self.port_id)
1464+ self.tenant_id, self.net_id,
1465+ device_ip=self.device_ip)
1466
1467 def test_delete_port_PortNotFound(self):
1468- """
1469- Tests delete port not found
1470- """
1471- self._cisco_ucs_plugin.create_network(self.tenant_id, self.net_name,
1472- self.net_id, self.vlan_name,
1473- self.vlan_id)
1474- self.assertRaises(exc.PortNotFound, self._cisco_ucs_plugin.delete_port,
1475- self.tenant_id, self.net_id, self.port_id)
1476- self.tearDownNetwork(self.tenant_id, self.net_id)
1477-
1478- def test_plug_interface_PortInUse(self):
1479- """
1480- Tests plug interface port in use
1481- """
1482- self._test_plug_interface_PortInUse("6", "5")
1483-
1484- def _test_plug_interface_PortInUse(self, remote_interface_id1,
1485- remote_interface_id2):
1486- """
1487- Tests plug interface port in use
1488- """
1489- LOG.debug("UCSVICTestPlugin:_test_plug_interface_PortInUse() called\n")
1490- self._cisco_ucs_plugin.create_network(self.tenant_id, self.net_name,
1491- self.net_id, self.vlan_name,
1492- self.vlan_id)
1493- self._cisco_ucs_plugin.create_port(self.tenant_id, self.net_id,
1494- const.PORT_UP, self.port_id)
1495- self._cisco_ucs_plugin.plug_interface(self.tenant_id, self.net_id,
1496- self.port_id,
1497- remote_interface_id1)
1498- self.assertRaises(exc.PortInUse, self._cisco_ucs_plugin.plug_interface,
1499- self.tenant_id, self.net_id, self.port_id,
1500- remote_interface_id2)
1501- self.tearDownNetworkPortInterface(self.tenant_id, self.net_id,
1502- self.port_id)
1503-
1504- def test_attachment_exists(self):
1505- """
1506- Tests attachment exists
1507- """
1508- LOG.debug("UCSVICTestPlugin:testValidateAttachmentAlreadyAttached")
1509- self._test_attachment_exists("4")
1510-
1511- def _test_attachment_exists(self, remote_interface_id):
1512- """
1513- Tests attachment exists
1514- """
1515- LOG.debug("UCSVICTestPlugin:_test_validate_attachmentAlreadyAttached")
1516- self._cisco_ucs_plugin.create_network(self.tenant_id, self.net_name,
1517- self.net_id, self.vlan_name,
1518- self.vlan_id)
1519- self._cisco_ucs_plugin.create_port(self.tenant_id, self.net_id,
1520- const.PORT_UP, self.port_id)
1521- self._cisco_ucs_plugin.plug_interface(self.tenant_id, self.net_id,
1522- self.port_id,
1523- remote_interface_id)
1524- self.assertRaises(
1525- exc.PortInUse, self._cisco_ucs_plugin._validate_attachment,
1526- self.tenant_id, self.net_id, self.port_id, remote_interface_id)
1527- self.tearDownNetworkPortInterface(self.tenant_id, self.net_id,
1528- self.port_id)
1529+ new_network = db.network_create(self.tenant_id, self.net_name)
1530+ cdb.add_vlan_binding(str(self.vlan_id), self.vlan_name,
1531+ new_network[const.UUID])
1532+ new_net_dict = self._cisco_ucs_plugin.create_network(
1533+ self.tenant_id, new_network[const.NETWORKNAME],
1534+ new_network[const.UUID], self.vlan_name, self.vlan_id,
1535+ device_ip=self.device_ip)
1536+
1537+ self.assertRaises(c_exc.PortVnicNotFound,
1538+ self._cisco_ucs_plugin.delete_port,
1539+ self.tenant_id, new_net_dict[const.NET_ID],
1540+ self.port_id, device_ip=self.device_ip,
1541+ ucs_inventory=self._ucs_inventory,
1542+ chassis_id=self.chassis_id, blade_id=self.blade_id,
1543+ blade_intf_distinguished_name=self.\
1544+ blade_intf_distinguished_name,
1545+ least_rsvd_blade_dict=self._ucs_inventory.\
1546+ _get_least_reserved_blade())
1547+
1548+ self.tearDownNetwork(self.tenant_id, new_net_dict[const.NET_ID])
1549+
1550+ def tearDown(self):
1551+ """Clear the test environment"""
1552+ # Remove database contents
1553+ db.clear_db()
1554
1555 def tearDownNetwork(self, tenant_id, net_id):
1556- """
1557- Tear down network
1558- """
1559- self._cisco_ucs_plugin.delete_network(tenant_id, net_id)
1560+ self._cisco_ucs_plugin.delete_network(tenant_id, net_id,
1561+ device_ip=self.device_ip)
1562
1563 def tearDownNetworkPort(self, tenant_id, net_id, port_id):
1564- """
1565- Tear down network port
1566- """
1567- self._cisco_ucs_plugin.delete_port(tenant_id, net_id,
1568- port_id)
1569+ self._cisco_ucs_plugin.delete_port(
1570+ tenant_id, net_id, port_id, device_ip=self.device_ip,
1571+ ucs_inventory=self._ucs_inventory,
1572+ chassis_id=self.chassis_id, blade_id=self.blade_id,
1573+ blade_intf_distinguished_name=self.\
1574+ blade_intf_distinguished_name,
1575+ least_rsvd_blade_dict=self._ucs_inventory.\
1576+ _get_least_reserved_blade())
1577 self.tearDownNetwork(tenant_id, net_id)
1578
1579 def tearDownNetworkPortInterface(self, tenant_id, net_id, port_id):
1580- """
1581- Tear down network port interface
1582- """
1583- self._cisco_ucs_plugin.unplug_interface(tenant_id, net_id,
1584- port_id)
1585+ self._cisco_ucs_plugin.unplug_interface(
1586+ tenant_id, net_id, port_id,
1587+ device_ip=self.device_ip)
1588 self.tearDownNetworkPort(tenant_id, net_id, port_id)

Subscribers

People subscribed via source and target branches