1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2011, Cisco Systems, Inc.
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
16
# @author: Rohit Agarwalla, Cisco Systems, Inc.
23
from optparse import OptionParser
24
from quantum.plugins.cisco.common import cisco_constants as const
26
import quantum.db.api as db
27
import quantum.db.models
28
import quantum.plugins.cisco.db.l2network_db as l2network_db
29
import quantum.plugins.cisco.db.l2network_models
31
CONF_FILE = "db_conn.ini"
32
LOG.getLogger(const.LOGGER_COMPONENT_NAME)
35
def find_config(basepath):
36
for root, dirs, files in os.walk(basepath):
37
if CONF_FILE in files:
38
return os.path.join(root, CONF_FILE)
42
def db_conf(configfile=None):
43
config = ConfigParser.ConfigParser()
44
if configfile == None:
45
if os.path.exists(CONF_FILE):
46
configfile = CONF_FILE
49
find_config(os.path.abspath(os.path.dirname(__file__)))
50
if configfile == None:
51
raise Exception("Configuration file \"%s\" doesn't exist" %
53
LOG.debug("Using configuration file: %s" % configfile)
54
config.read(configfile)
56
DB_NAME = config.get("DATABASE", "name")
57
DB_USER = config.get("DATABASE", "user")
58
DB_PASS = config.get("DATABASE", "pass")
59
DB_HOST = config.get("DATABASE", "host")
60
options = {"sql_connection": "mysql://%s:%s@%s/%s" % (DB_USER,
61
DB_PASS, DB_HOST, DB_NAME)}
62
db.configure_db(options)
66
def get_all_ucsmbindings(self):
69
for x in ucs_db.get_all_ucsmbinding():
70
LOG.debug("Getting ucsm binding : %s" % x.ucsm_ip)
72
bind_dict["ucsm-ip"] = str(x.ucsm_ip)
73
bind_dict["network-id"] = str(x.network_id)
74
bindings.append(bind_dict)
76
LOG.error("Failed to get all bindings: %s" % str(e))
79
def get_ucsmbinding(self, ucsm_ip):
82
for x in ucs_db.get_ucsmbinding(ucsm_ip):
83
LOG.debug("Getting ucsm binding : %s" % x.ucsm_ip)
85
bind_dict["ucsm-ip"] = str(res.ucsm_ip)
86
bind_dict["network-id"] = str(res.network_id)
87
binding.append(bind_dict)
89
LOG.error("Failed to get binding: %s" % str(e))
92
def create_ucsmbinding(self, ucsm_ip, networ_id):
95
res = ucs_db.add_ucsmbinding(ucsm_ip, networ_id)
96
LOG.debug("Created ucsm binding: %s" % res.ucsm_ip)
97
bind_dict["ucsm-ip"] = str(res.ucsm_ip)
98
bind_dict["network-id"] = str(res.network_id)
101
LOG.error("Failed to create ucsm binding: %s" % str(e))
103
def delete_ucsmbinding(self, ucsm_ip):
105
res = ucs_db.remove_ucsmbinding(ucsm_ip)
106
LOG.debug("Deleted ucsm binding : %s" % res.ucsm_ip)
108
bind_dict["ucsm-ip"] = str(res.ucsm_ip)
111
raise Exception("Failed to delete dynamic vnic: %s" % str(e))
113
def update_ucsmbinding(self, ucsm_ip, network_id):
115
res = ucs_db.update_ucsmbinding(ucsm_ip, network_id)
116
LOG.debug("Updating ucsm binding : %s" % res.ucsm_ip)
118
bind_dict["ucsm-ip"] = str(res.ucsm_ip)
119
bind_dict["network-id"] = str(res.network_id)
122
raise Exception("Failed to update dynamic vnic: %s" % str(e))
124
def get_all_dynamicvnics(self):
127
for x in ucs_db.get_all_dynamicvnics():
128
LOG.debug("Getting dynamic vnic : %s" % x.uuid)
130
vnic_dict["vnic-id"] = str(x.uuid)
131
vnic_dict["device-name"] = x.device_name
132
vnic_dict["blade-id"] = str(x.blade_id)
133
vnics.append(vnic_dict)
135
LOG.error("Failed to get all dynamic vnics: %s" % str(e))
138
def get_dynamicvnic(self, vnic_id):
141
for x in ucs_db.get_dynamicvnic(vnic_id):
142
LOG.debug("Getting dynamic vnic : %s" % x.uuid)
144
vnic_dict["vnic-id"] = str(x.uuid)
145
vnic_dict["device-name"] = x.device_name
146
vnic_dict["blade-id"] = str(x.blade_id)
147
vnic.append(vnic_dict)
149
LOG.error("Failed to get dynamic vnic: %s" % str(e))
152
def create_dynamicvnic(self, device_name, blade_id):
155
res = ucs_db.add_dynamicvnic(device_name, blade_id)
156
LOG.debug("Created dynamic vnic: %s" % res.uuid)
157
vnic_dict["vnic-id"] = str(res.uuid)
158
vnic_dict["device-name"] = res.device_name
159
vnic_dict["blade-id"] = str(res.blade_id)
162
LOG.error("Failed to create dynamic vnic: %s" % str(e))
164
def delete_dynamicvnic(self, vnic_id):
166
res = ucs_db.remove_dynamicvnic(vnic_id)
167
LOG.debug("Deleted dynamic vnic : %s" % res.uuid)
169
vnic_dict["vnic-id"] = str(res.uuid)
172
raise Exception("Failed to delete dynamic vnic: %s" % str(e))
174
def update_dynamicvnic(self, vnic_id, device_name=None, blade_id=None):
176
res = ucs_db.update_dynamicvnic(vnic_id, device_name, blade_id)
177
LOG.debug("Updating dynamic vnic : %s" % res.uuid)
179
vnic_dict["vnic-id"] = str(res.uuid)
180
vnic_dict["device-name"] = res.device_name
181
vnic_dict["blade-id"] = str(res.blade_id)
184
raise Exception("Failed to update dynamic vnic: %s" % str(e))
186
def get_all_blades(self):
189
for x in ucs_db.get_all_blades():
190
LOG.debug("Getting blade : %s" % x.uuid)
192
blade_dict["blade-id"] = str(x.uuid)
193
blade_dict["mgmt-ip"] = str(x.mgmt_ip)
194
blade_dict["mac-addr"] = str(x.mac_addr)
195
blade_dict["chassis-id"] = str(x.chassis_id)
196
blade_dict["ucsm-ip"] = str(x.ucsm_ip)
197
blades.append(blade_dict)
199
LOG.error("Failed to get all blades: %s" % str(e))
202
def get_blade(self, blade_id):
205
for x in ucs_db.get_blade(blade_id):
206
LOG.debug("Getting blade : %s" % x.uuid)
208
blade_dict["blade-id"] = str(x.uuid)
209
blade_dict["mgmt-ip"] = str(x.mgmt_ip)
210
blade_dict["mac-addr"] = str(x.mac_addr)
211
blade_dict["chassis-id"] = str(x.chassis_id)
212
blade_dict["ucsm-ip"] = str(x.ucsm_ip)
213
blade.append(blade_dict)
215
LOG.error("Failed to get all blades: %s" % str(e))
218
def create_blade(self, mgmt_ip, mac_addr, chassis_id, ucsm_ip):
221
res = ucs_db.add_blade(mgmt_ip, mac_addr, chassis_id, ucsm_ip)
222
LOG.debug("Created blade: %s" % res.uuid)
223
blade_dict["blade-id"] = str(res.uuid)
224
blade_dict["mgmt-ip"] = str(res.mgmt_ip)
225
blade_dict["mac-addr"] = str(res.mac_addr)
226
blade_dict["chassis-id"] = str(res.chassis_id)
227
blade_dict["ucsm-ip"] = str(res.ucsm_ip)
230
LOG.error("Failed to create blade: %s" % str(e))
232
def delete_blade(self, blade_id):
234
res = ucs_db.remove_blade(blade_id)
235
LOG.debug("Deleted blade : %s" % res.uuid)
237
blade_dict["blade-id"] = str(res.uuid)
240
raise Exception("Failed to delete blade: %s" % str(e))
242
def update_blade(self, blade_id, mgmt_ip=None, mac_addr=None,\
243
chassis_id=None, ucsm_ip=None):
245
res = ucs_db.update_blade(blade_id, mgmt_ip, mac_addr, \
247
LOG.debug("Updating blade : %s" % res.uuid)
249
blade_dict["blade-id"] = str(res.uuid)
250
blade_dict["mgmt-ip"] = str(res.mgmt_ip)
251
blade_dict["mac-addr"] = str(res.mac_addr)
252
blade_dict["chassis-id"] = str(res.chassis_id)
253
blade_dict["ucsm-ip"] = str(res.ucsm_ip)
256
raise Exception("Failed to update blade: %s" % str(e))
258
def get_all_port_bindings(self):
261
for x in ucs_db.get_all_portbindings():
262
LOG.debug("Getting port binding for port: %s" % x.port_id)
264
port_bind_dict["port-id"] = x.port_id
265
port_bind_dict["dynamic-vnic-id"] = str(x.dynamic_vnic_id)
266
port_bind_dict["portprofile-name"] = x.portprofile_name
267
port_bind_dict["vlan-name"] = x.vlan_name
268
port_bind_dict["vlan-id"] = str(x.vlan_id)
269
port_bind_dict["qos"] = x.qos
270
port_bindings.append(port_bind_dict)
272
LOG.error("Failed to get all port bindings: %s" % str(e))
275
def get_port_binding(self):
278
for x in ucs_db.get_portbinding(port_id):
279
LOG.debug("Getting port binding for port: %s" % x.port_id)
281
port_bind_dict["port-id"] = x.port_id
282
port_bind_dict["dynamic-vnic-id"] = str(x.dynamic_vnic_id)
283
port_bind_dict["portprofile-name"] = x.portprofile_name
284
port_bind_dict["vlan-name"] = x.vlan_name
285
port_bind_dict["vlan-id"] = str(x.vlan_id)
286
port_bind_dict["qos"] = x.qos
287
port_bindings.append(port_bind_dict)
289
LOG.error("Failed to get port binding: %s" % str(e))
292
def create_port_binding(self, port_id, dynamic_vnic_id, portprofile_name, \
293
vlan_name, vlan_id, qos):
296
res = ucs_db.add_portbinding(port_id, dynamic_vnic_id, \
297
portprofile_name, vlan_name, vlan_id, qos)
298
LOG.debug("Created port binding: %s" % res.port_id)
299
port_bind_dict["port-id"] = res.port_id
300
port_bind_dict["dynamic-vnic-id"] = str(res.dynamic_vnic_id)
301
port_bind_dict["portprofile-name"] = res.portprofile_name
302
port_bind_dict["vlan-name"] = res.vlan_name
303
port_bind_dict["vlan-id"] = str(res.vlan_id)
304
port_bind_dict["qos"] = res.qos
305
return port_bind_dict
307
LOG.error("Failed to create port binding: %s" % str(e))
309
def delete_port_binding(self, port_id):
311
res = ucs_db.remove_portbinding(port_id)
312
LOG.debug("Deleted port binding : %s" % res.port_id)
314
port_bind_dict["port-id"] = res.port_id
315
return port_bind_dict
317
raise Exception("Failed to delete port profile: %s" % str(e))
319
def update_port_binding(self, port_id, dynamic_vnic_id, \
320
portprofile_name, vlan_name, vlan_id, qos):
322
res = ucs_db.update_portbinding(port_id, dynamic_vnic_id, \
323
portprofile_name, vlan_name, vlan_id, qos)
324
LOG.debug("Updating port binding: %s" % res.port_id)
326
port_bind_dict["port-id"] = res.port_id
327
port_bind_dict["dynamic-vnic-id"] = str(res.dynamic_vnic_id)
328
port_bind_dict["portprofile-name"] = res.portprofile_name
329
port_bind_dict["vlan-name"] = res.vlan_name
330
port_bind_dict["vlan-id"] = str(res.vlan_id)
331
port_bind_dict["qos"] = res.qos
332
return port_bind_dict
334
raise Exception("Failed to update portprofile binding:%s" % str(e))
337
class QuantumDB(object):
338
def get_all_networks(self, tenant_id):
341
for x in db.network_list(tenant_id):
342
LOG.debug("Getting network: %s" % x.uuid)
344
net_dict["tenant-id"] = x.tenant_id
345
net_dict["net-id"] = str(x.uuid)
346
net_dict["net-name"] = x.name
347
nets.append(net_dict)
349
LOG.error("Failed to get all networks: %s" % str(e))
352
def get_network(self, network_id):
355
for x in db.network_get(network_id):
356
LOG.debug("Getting network: %s" % x.uuid)
358
net_dict["tenant-id"] = x.tenant_id
359
net_dict["net-id"] = str(x.uuid)
360
net_dict["net-name"] = x.name
361
nets.append(net_dict)
363
LOG.error("Failed to get network: %s" % str(e))
366
def create_network(self, tenant_id, net_name):
369
res = db.network_create(tenant_id, net_name)
370
LOG.debug("Created network: %s" % res.uuid)
371
net_dict["tenant-id"] = res.tenant_id
372
net_dict["net-id"] = str(res.uuid)
373
net_dict["net-name"] = res.name
376
LOG.error("Failed to create network: %s" % str(e))
378
def delete_network(self, net_id):
380
net = db.network_destroy(net_id)
381
LOG.debug("Deleted network: %s" % net.uuid)
383
net_dict["net-id"] = str(net.uuid)
386
raise Exception("Failed to delete port: %s" % str(e))
388
def rename_network(self, tenant_id, net_id, new_name):
390
net = db.network_rename(net_id, tenant_id, new_name)
391
LOG.debug("Renamed network: %s" % net.uuid)
393
net_dict["net-id"] = str(net.uuid)
394
net_dict["net-name"] = net.name
397
raise Exception("Failed to rename network: %s" % str(e))
399
def get_all_ports(self, net_id):
402
for x in db.port_list(net_id):
403
LOG.debug("Getting port: %s" % x.uuid)
405
port_dict["port-id"] = str(x.uuid)
406
port_dict["net-id"] = str(x.network_id)
407
port_dict["int-id"] = x.interface_id
408
port_dict["state"] = x.state
409
ports.append(port_dict)
412
LOG.error("Failed to get all ports: %s" % str(e))
414
def get_port(self, port_id):
417
for x in db.port_get(port_id):
418
LOG.debug("Getting port: %s" % x.uuid)
420
port_dict["port-id"] = str(x.uuid)
421
port_dict["net-id"] = str(x.network_id)
422
port_dict["int-id"] = x.interface_id
423
port_dict["state"] = x.state
424
port.append(port_dict)
427
LOG.error("Failed to get port: %s" % str(e))
429
def create_port(self, net_id):
432
port = db.port_create(net_id)
433
LOG.debug("Creating port %s" % port.uuid)
434
port_dict["port-id"] = str(port.uuid)
435
port_dict["net-id"] = str(port.network_id)
436
port_dict["int-id"] = port.interface_id
437
port_dict["state"] = port.state
440
LOG.error("Failed to create port: %s" % str(e))
442
def delete_port(self, port_id):
444
port = db.port_destroy(port_id)
445
LOG.debug("Deleted port %s" % port.uuid)
447
port_dict["port-id"] = str(port.uuid)
450
raise Exception("Failed to delete port: %s" % str(e))
452
def update_port(self, port_id, port_state):
454
port = db.port_set_state(port_id, port_state)
455
LOG.debug("Updated port %s" % port.uuid)
457
port_dict["port-id"] = str(port.uuid)
458
port_dict["net-id"] = str(port.network_id)
459
port_dict["int-id"] = port.interface_id
460
port_dict["state"] = port.state
463
raise Exception("Failed to update port state: %s" % str(e))
466
class L2networkDB(object):
467
def get_all_vlan_bindings(self):
470
for x in l2network_db.get_all_vlan_bindings():
471
LOG.debug("Getting vlan bindings for vlan: %s" % x.vlan_id)
473
vlan_dict["vlan-id"] = str(x.vlan_id)
474
vlan_dict["vlan-name"] = x.vlan_name
475
vlan_dict["net-id"] = str(x.network_id)
476
vlans.append(vlan_dict)
478
LOG.error("Failed to get all vlan bindings: %s" % str(e))
481
def get_vlan_binding(self, network_id):
484
for x in l2network_db.get_vlan_binding(network_id):
485
LOG.debug("Getting vlan binding for vlan: %s" % x.vlan_id)
487
vlan_dict["vlan-id"] = str(x.vlan_id)
488
vlan_dict["vlan-name"] = x.vlan_name
489
vlan_dict["net-id"] = str(x.network_id)
490
vlan.append(vlan_dict)
492
LOG.error("Failed to get vlan binding: %s" % str(e))
495
def create_vlan_binding(self, vlan_id, vlan_name, network_id):
498
res = l2network_db.add_vlan_binding(vlan_id, vlan_name, network_id)
499
LOG.debug("Created vlan binding for vlan: %s" % res.vlan_id)
500
vlan_dict["vlan-id"] = str(res.vlan_id)
501
vlan_dict["vlan-name"] = res.vlan_name
502
vlan_dict["net-id"] = str(res.network_id)
505
LOG.error("Failed to create vlan binding: %s" % str(e))
507
def delete_vlan_binding(self, network_id):
509
res = l2network_db.remove_vlan_binding(network_id)
510
LOG.debug("Deleted vlan binding for vlan: %s" % res.vlan_id)
512
vlan_dict["vlan-id"] = str(res.vlan_id)
515
raise Exception("Failed to delete vlan binding: %s" % str(e))
517
def update_vlan_binding(self, network_id, vlan_id, vlan_name):
519
res = l2network_db.update_vlan_binding(network_id, vlan_id, \
521
LOG.debug("Updating vlan binding for vlan: %s" % res.vlan_id)
523
vlan_dict["vlan-id"] = str(res.vlan_id)
524
vlan_dict["vlan-name"] = res.vlan_name
525
vlan_dict["net-id"] = str(res.network_id)
528
raise Exception("Failed to update vlan binding: %s" % str(e))
530
def get_all_portprofiles(self):
533
for x in l2network_db.get_all_portprofiles():
534
LOG.debug("Getting port profile : %s" % x.uuid)
536
pp_dict["portprofile-id"] = str(x.uuid)
537
pp_dict["portprofile-name"] = x.name
538
pp_dict["vlan-id"] = str(x.vlan_id)
539
pp_dict["qos"] = x.qos
542
LOG.error("Failed to get all port profiles: %s" % str(e))
545
def get_portprofile(self, port_id):
548
for x in l2network_db.get_portprofile(port_id):
549
LOG.debug("Getting port profile : %s" % x.uuid)
551
pp_dict["portprofile-id"] = str(x.uuid)
552
pp_dict["portprofile-name"] = x.name
553
pp_dict["vlan-id"] = str(x.vlan_id)
554
pp_dict["qos"] = x.qos
557
LOG.error("Failed to get port profile: %s" % str(e))
560
def create_portprofile(self, name, vlan_id, qos):
563
res = l2network_db.add_portprofile(name, vlan_id, qos)
564
LOG.debug("Created port profile: %s" % res.uuid)
565
pp_dict["portprofile-id"] = str(res.uuid)
566
pp_dict["portprofile-name"] = res.name
567
pp_dict["vlan-id"] = str(res.vlan_id)
568
pp_dict["qos"] = res.qos
571
LOG.error("Failed to create port profile: %s" % str(e))
573
def delete_portprofile(self, pp_id):
575
res = l2network_db.remove_portprofile(pp_id)
576
LOG.debug("Deleted port profile : %s" % res.uuid)
578
pp_dict["pp-id"] = str(res.uuid)
581
raise Exception("Failed to delete port profile: %s" % str(e))
583
def update_portprofile(self, pp_id, name, vlan_id, qos):
585
res = l2network_db.update_portprofile(pp_id, name, vlan_id, qos)
586
LOG.debug("Updating port profile : %s" % res.uuid)
588
pp_dict["portprofile-id"] = str(res.uuid)
589
pp_dict["portprofile-name"] = res.name
590
pp_dict["vlan-id"] = str(res.vlan_id)
591
pp_dict["qos"] = res.qos
594
raise Exception("Failed to update port profile: %s" % str(e))
596
def get_all_pp_bindings(self):
599
for x in l2network_db.get_all_pp_bindings():
600
LOG.debug("Getting port profile binding: %s" % \
603
ppbinding_dict["portprofile-id"] = str(x.portprofile_id)
604
ppbinding_dict["net-id"] = str(x.network_id)
605
ppbinding_dict["tenant-id"] = x.tenant_id
606
ppbinding_dict["default"] = x.default
607
pp_bindings.append(ppbinding_dict)
609
LOG.error("Failed to get all port profiles: %s" % str(e))
612
def get_pp_binding(self, pp_id):
615
for x in l2network_db.get_pp_binding(pp_id):
616
LOG.debug("Getting port profile binding: %s" % \
619
ppbinding_dict["portprofile-id"] = str(x.portprofile_id)
620
ppbinding_dict["net-id"] = str(x.network_id)
621
ppbinding_dict["tenant-id"] = x.tenant_id
622
ppbinding_dict["default"] = x.default
623
pp_bindings.append(ppbinding_dict)
625
LOG.error("Failed to get port profile binding: %s" % str(e))
628
def create_pp_binding(self, tenant_id, net_id, pp_id, default):
631
res = l2network_db.add_pp_binding(tenant_id, net_id, pp_id, \
633
LOG.debug("Created port profile binding: %s" % res.portprofile_id)
634
ppbinding_dict["portprofile-id"] = str(res.portprofile_id)
635
ppbinding_dict["net-id"] = str(res.network_id)
636
ppbinding_dict["tenant-id"] = res.tenant_id
637
ppbinding_dict["default"] = res.default
638
return ppbinding_dict
640
LOG.error("Failed to create port profile binding: %s" % str(e))
642
def delete_pp_binding(self, pp_id):
644
res = l2network_db.remove_pp_binding(pp_id)
645
LOG.debug("Deleted port profile binding : %s" % res.portprofile_id)
647
ppbinding_dict["portprofile-id"] = str(res.portprofile_id)
648
return ppbinding_dict
650
raise Exception("Failed to delete port profile: %s" % str(e))
652
def update_pp_binding(self, pp_id, tenant_id, net_id, default):
654
res = l2network_db.update_pp_binding(pp_id, tenant_id, net_id,\
656
LOG.debug("Updating port profile binding: %s" % res.portprofile_id)
658
ppbinding_dict["portprofile-id"] = str(res.portprofile_id)
659
ppbinding_dict["net-id"] = str(res.network_id)
660
ppbinding_dict["tenant-id"] = res.tenant_id
661
ppbinding_dict["default"] = res.default
662
return ppbinding_dict
664
raise Exception("Failed to update portprofile binding:%s" % str(e))
667
class UcsDBTest(unittest.TestCase):
669
self.dbtest = UcsDB()
672
def testACreateUcsmBinding(self):
673
binding1 = self.dbtest.create_ucsmbinding("1.2.3.4", "net1")
674
self.assertTrue(binding1["ucsm-ip"] == "1.2.3.4")
675
self.tearDownUcsmBinding()
677
def testBGetAllUcsmBindings(self):
678
binding1 = self.dbtest.create_ucsmbinding("1.2.3.4", "net1")
679
binding2 = self.dbtest.create_ucsmbinding("2.3.4.5", "net1")
680
bindings = self.dbtest.get_all_ucsmbindings()
683
if "net" in x["network-id"]:
685
self.assertTrue(count == 2)
686
self.tearDownUcsmBinding()
688
def testCDeleteUcsmBinding(self):
689
binding1 = self.dbtest.create_ucsmbinding("1.2.3.4", "net1")
690
self.dbtest.delete_ucsmbinding(binding1["ucsm-ip"])
691
bindings = self.dbtest.get_all_ucsmbindings()
694
if "net " in x["network-id"]:
696
self.assertTrue(count == 0)
697
self.tearDownUcsmBinding()
699
def testDUpdateUcsmBinding(self):
700
binding1 = self.dbtest.create_ucsmbinding("1.2.3.4", "net1")
701
binding1 = self.dbtest.update_ucsmbinding(binding1["ucsm-ip"], \
703
bindings = self.dbtest.get_all_ucsmbindings()
706
if "new" in x["network-id"]:
708
self.assertTrue(count == 1)
709
self.tearDownUcsmBinding()
711
def testECreateDynamicVnic(self):
712
blade1 = self.dbtest.create_blade("1.2.3.4", "abcd", "chassis1", \
714
vnic1 = self.dbtest.create_dynamicvnic("eth1", blade1["blade-id"])
715
self.assertTrue(vnic1["device-name"] == "eth1")
716
self.tearDownDyanmicVnic()
718
def testFGetAllDyanmicVnics(self):
719
blade1 = self.dbtest.create_blade("1.2.3.4", "abcd", "chassis1", \
721
vnic1 = self.dbtest.create_dynamicvnic("eth1", blade1["blade-id"])
722
vnic2 = self.dbtest.create_dynamicvnic("eth2", blade1["blade-id"])
723
vnics = self.dbtest.get_all_dynamicvnics()
726
if "eth" in x["device-name"]:
728
self.assertTrue(count == 2)
729
self.tearDownDyanmicVnic()
731
def testGDeleteDyanmicVnic(self):
732
blade1 = self.dbtest.create_blade("1.2.3.4", "abcd", "chassis1", \
734
vnic1 = self.dbtest.create_dynamicvnic("eth1", blade1["blade-id"])
735
self.dbtest.delete_dynamicvnic(vnic1["vnic-id"])
736
vnics = self.dbtest.get_all_dynamicvnics()
739
if "eth " in x["device-name"]:
741
self.assertTrue(count == 0)
742
self.tearDownDyanmicVnic()
744
def testHUpdateDynamicVnic(self):
745
blade1 = self.dbtest.create_blade("1.2.3.4", "abcd", "chassis1", \
747
vnic1 = self.dbtest.create_dynamicvnic("eth1", blade1["blade-id"])
748
vnic1 = self.dbtest.update_dynamicvnic(vnic1["vnic-id"], "neweth1", \
750
vnics = self.dbtest.get_all_dynamicvnics()
753
if "new" in x["device-name"]:
755
self.assertTrue(count == 1)
756
self.tearDownDyanmicVnic()
758
def testICreateUcsBlade(self):
759
blade1 = self.dbtest.create_blade("1.2.3.4", "abcd", "chassis1", \
761
self.assertTrue(blade1["mgmt-ip"] == "1.2.3.4")
762
self.tearDownUcsBlade()
764
def testJGetAllUcsBlade(self):
765
blade1 = self.dbtest.create_blade("1.2.3.4", "abcd", "chassis1", \
767
blade2 = self.dbtest.create_blade("2.3.4.5", "efgh", "chassis1", \
769
blades = self.dbtest.get_all_blades()
772
if "chassis" in x["chassis-id"]:
774
self.assertTrue(count == 2)
775
self.tearDownUcsBlade()
777
def testKDeleteUcsBlade(self):
778
blade1 = self.dbtest.create_blade("1.2.3.4", "abcd", "chassis1", \
780
self.dbtest.delete_blade(blade1["blade-id"])
781
blades = self.dbtest.get_all_blades()
784
if "chassis " in x["chassis-id"]:
786
self.assertTrue(count == 0)
787
self.tearDownUcsBlade()
789
def testLUpdateUcsBlade(self):
790
blade1 = self.dbtest.create_blade("1.2.3.4", "abcd", "chassis1", \
792
blade2 = self.dbtest.update_blade(blade1["blade-id"], "2.3.4.5", \
793
"newabcd", "chassis1", "9.8.7.6")
794
blades = self.dbtest.get_all_blades()
797
if "new" in x["mac-addr"]:
799
self.assertTrue(count == 1)
800
self.tearDownUcsBlade()
802
def testMCreatePortBinding(self):
803
port_bind1 = self.dbtest.create_port_binding("port1", "dv1", "pp1", \
805
self.assertTrue(port_bind1["port-id"] == "port1")
806
self.tearDownPortBinding()
808
def testNGetAllPortBinding(self):
809
port_bind1 = self.dbtest.create_port_binding("port1", "dv1", "pp1", \
811
port_bind2 = self.dbtest.create_port_binding("port2", "dv2", "pp2", \
813
port_bindings = self.dbtest.get_all_port_bindings()
815
for x in port_bindings:
816
if "port" in x["port-id"]:
818
self.assertTrue(count == 2)
819
self.tearDownPortBinding()
821
def testODeletePortBinding(self):
822
port_bind1 = self.dbtest.create_port_binding("port1", "dv1", "pp1", \
824
self.dbtest.delete_port_binding("port1")
825
port_bindings = self.dbtest.get_all_port_bindings()
827
for x in port_bindings:
828
if "port " in x["port-id"]:
830
self.assertTrue(count == 0)
831
self.tearDownPortBinding()
833
def testPUpdatePortBinding(self):
834
port_bind1 = self.dbtest.create_port_binding("port1", "dv1", "pp1", \
836
port_bind1 = self.dbtest.update_port_binding("port1", "newdv1", \
837
"newpp1", "newvlan1", 11, "newqos1")
838
port_bindings = self.dbtest.get_all_port_bindings()
840
for x in port_bindings:
841
if "new" in x["dynamic-vnic-id"]:
843
self.assertTrue(count == 1)
844
self.tearDownPortBinding()
846
def tearDownUcsmBinding(self):
847
print "Tearing Down Ucsm Bindings"
848
binds = self.dbtest.get_all_ucsmbindings()
851
self.dbtest.delete_ucsmbinding(ip)
853
def tearDownDyanmicVnic(self):
854
print "Tearing Down Dynamic Vnics"
855
vnics = self.dbtest.get_all_dynamicvnics()
858
self.dbtest.delete_dynamicvnic(id)
859
self.tearDownUcsBlade()
861
def tearDownUcsBlade(self):
862
print "Tearing Down Blades"
863
blades = self.dbtest.get_all_blades()
865
id = blade["blade-id"]
866
self.dbtest.delete_blade(id)
868
def tearDownPortBinding(self):
869
print "Tearing Down Port Binding"
870
port_bindings = self.dbtest.get_all_port_bindings()
871
for port_binding in port_bindings:
872
id = port_binding["port-id"]
873
self.dbtest.delete_port_binding(id)
876
class L2networkDBTest(unittest.TestCase):
878
self.dbtest = L2networkDB()
881
def testACreateVlanBinding(self):
882
vlan1 = self.dbtest.create_vlan_binding(10, "vlan1", "netid1")
883
self.assertTrue(vlan1["vlan-id"] == "10")
884
self.tearDownVlanBinding()
886
def testBGetAllVlanBindings(self):
887
vlan1 = self.dbtest.create_vlan_binding(10, "vlan1", "netid1")
888
vlan2 = self.dbtest.create_vlan_binding(20, "vlan2", "netid2")
889
vlans = self.dbtest.get_all_vlan_bindings()
892
if "netid" in x["net-id"]:
894
self.assertTrue(count == 2)
895
self.tearDownVlanBinding()
897
def testCDeleteVlanBinding(self):
898
vlan1 = self.dbtest.create_vlan_binding(10, "vlan1", "netid1")
899
self.dbtest.delete_vlan_binding("netid1")
900
vlans = self.dbtest.get_all_vlan_bindings()
903
if "netid " in x["net-id"]:
905
self.assertTrue(count == 0)
906
self.tearDownVlanBinding()
908
def testDUpdateVlanBinding(self):
909
vlan1 = self.dbtest.create_vlan_binding(10, "vlan1", "netid1")
910
vlan1 = self.dbtest.update_vlan_binding("netid1", 11, "newvlan1")
911
vlans = self.dbtest.get_all_vlan_bindings()
914
if "new" in x["vlan-name"]:
916
self.assertTrue(count == 1)
917
self.tearDownVlanBinding()
919
def testICreatePortProfile(self):
920
pp1 = self.dbtest.create_portprofile("portprofile1", 10, "qos1")
921
self.assertTrue(pp1["portprofile-name"] == "portprofile1")
922
self.tearDownPortProfile()
924
def testJGetAllPortProfile(self):
925
pp1 = self.dbtest.create_portprofile("portprofile1", 10, "qos1")
926
pp2 = self.dbtest.create_portprofile("portprofile2", 20, "qos2")
927
pps = self.dbtest.get_all_portprofiles()
930
if "portprofile" in x["portprofile-name"]:
932
self.assertTrue(count == 2)
933
self.tearDownPortProfile()
935
def testKDeletePortProfile(self):
936
pp1 = self.dbtest.create_portprofile("portprofile1", 10, "qos1")
937
self.dbtest.delete_portprofile(pp1["portprofile-id"])
938
pps = self.dbtest.get_all_portprofiles()
941
if "portprofile " in x["portprofile-name"]:
943
self.assertTrue(count == 0)
944
self.tearDownPortProfile()
946
def testLUpdatePortProfile(self):
947
pp1 = self.dbtest.create_portprofile("portprofile1", 10, "qos1")
948
pp1 = self.dbtest.update_portprofile(pp1["portprofile-id"], \
949
"newportprofile1", 20, "qos2")
950
pps = self.dbtest.get_all_portprofiles()
953
if "new" in x["portprofile-name"]:
955
self.assertTrue(count == 1)
956
self.tearDownPortProfile()
958
def testMCreatePortProfileBinding(self):
959
pp_binding1 = self.dbtest.create_pp_binding("t1", "net1", \
961
self.assertTrue(pp_binding1["portprofile-id"] == "portprofile1")
962
self.tearDownPortProfileBinding()
964
def testNGetAllPortProfileBinding(self):
965
pp_binding1 = self.dbtest.create_pp_binding("t1", "net1", \
967
pp_binding2 = self.dbtest.create_pp_binding("t2", "net2", \
969
pp_bindings = self.dbtest.get_all_pp_bindings()
971
for x in pp_bindings:
972
if "portprofile" in x["portprofile-id"]:
974
self.assertTrue(count == 2)
975
self.tearDownPortProfileBinding()
977
def testODeletePortProfileBinding(self):
978
pp_binding1 = self.dbtest.create_pp_binding("t1", "net1", \
980
self.dbtest.delete_pp_binding(pp_binding1["portprofile-id"])
981
pp_bindings = self.dbtest.get_all_pp_bindings()
983
for x in pp_bindings:
984
if "portprofile " in x["portprofile-id"]:
986
self.assertTrue(count == 0)
987
self.tearDownPortProfileBinding()
989
def testPUpdatePortProfileBinding(self):
990
pp_binding1 = self.dbtest.create_pp_binding("t1", "net1", \
992
pp_binding1 = self.dbtest.update_pp_binding("portprofile1", \
993
"newt1", "newnet1", "1")
994
pp_bindings = self.dbtest.get_all_pp_bindings()
996
for x in pp_bindings:
997
if "new" in x["net-id"]:
999
self.assertTrue(count == 1)
1000
self.tearDownPortProfileBinding()
1002
def tearDownVlanBinding(self):
1003
print "Tearing Down Vlan Binding"
1004
vlans = self.dbtest.get_all_vlan_bindings()
1007
self.dbtest.delete_vlan_binding(id)
1009
def tearDownPortProfile(self):
1010
print "Tearing Down Port Profile"
1011
pps = self.dbtest.get_all_portprofiles()
1013
id = pp["portprofile-id"]
1014
self.dbtest.delete_portprofile(id)
1016
def tearDownPortProfileBinding(self):
1017
print "Tearing Down Port Profile Binding"
1018
pp_bindings = self.dbtest.get_all_pp_bindings()
1019
for pp_binding in pp_bindings:
1020
id = pp_binding["portprofile-id"]
1021
self.dbtest.delete_pp_binding(id)
1023
if __name__ == "__main__":
1024
usagestr = "Usage: %prog [OPTIONS] <command> [args]"
1025
parser = OptionParser(usage=usagestr)
1026
parser.add_option("-v", "--verbose", dest="verbose",
1027
action="store_true", default=False, help="turn on verbose logging")
1029
options, args = parser.parse_args()
1032
LOG.basicConfig(level=LOG.DEBUG)
1034
LOG.basicConfig(level=LOG.WARN)
1036
#load the models and db based on the 2nd level plugin argument
1037
if args[0] == "ucs":
1038
ucs_db = __import__("quantum.plugins.cisco.db.ucs_db", \
1039
fromlist=["ucs_db"])
1040
ucs_model = __import__("quantum.plugins.cisco.db.ucs_models", \
1041
fromlist=["ucs_models"])
1046
suite = unittest.TestLoader().loadTestsFromTestCase(L2networkDBTest)
1047
unittest.TextTestRunner(verbosity=2).run(suite)
1048
suite = unittest.TestLoader().loadTestsFromTestCase(UcsDBTest)
1049
unittest.TextTestRunner(verbosity=2).run(suite)