def test_create(self): d = DeviceAlias(self.switch) d.create(self.new) self.assertEqual(self.new, d.database) keys = list(self.new.keys()) for k in keys: d.delete(k)
class TestDeviceAliasClearDatabase(unittest.TestCase): def __init__(self, testName, sw): super().__init__(testName) self.switch = sw def setUp(self) -> None: log.debug(self.switch.version) log.debug(self.switch.ipaddr) self.d = DeviceAlias(self.switch) self.olddb = self.d.database if self.olddb is None: self.name = get_random_string() self.pwwn = get_random_pwwn() self.d.create({self.name: self.pwwn}) newdb = self.d.database self.assertIn(self.name, newdb.keys()) self.assertEqual(self.pwwn, newdb[self.name]) # def test_clear_database(self): # self.d.clear_database() # self.assertIsNone(self.d.database) def tearDown(self) -> None: if self.olddb is not None: currdb = self.d.database if currdb == self.olddb: pass else: self.d.create(self.olddb)
def test_delete(self): d = DeviceAlias(self.switch) d.create(self.new) keys = list(self.new.keys()) d.delete(keys[0]) self.assertIsNone(d.database.get(keys[0])) keys.remove(keys[0]) for k in keys: d.delete(k)
class TestDeviceAliasDelete(unittest.TestCase): def __init__(self, testName, sw): super().__init__(testName) self.switch = sw def setUp(self) -> None: log.debug(self.switch.version) log.debug(self.switch.ipaddr) self.d = DeviceAlias(self.switch) self.olddb = self.d.database if self.olddb is None: self.name = get_random_string() self.pwwn = get_random_pwwn() else: while True: self.name = get_random_string() self.pwwn = get_random_pwwn() if ( self.name not in self.olddb.keys() and self.pwwn not in self.olddb.values() ): break log.debug({self.name: self.pwwn}) def test_delete(self): self.d.create({self.name: self.pwwn}) newdb = self.d.database self.assertIn(self.name, newdb.keys()) self.assertEqual(self.pwwn, newdb[self.name]) self.d.delete(self.name) newdb = self.d.database if newdb is not None: self.assertNotIn(self.name, newdb.keys()) self.assertNotIn(self.pwwn, newdb.values()) def test_delete_nonexisting(self): db = self.d.database while True: somename = get_random_string() if db is None or somename not in db.keys(): break with self.assertRaises(CLIError) as e: self.d.delete(somename) self.assertIn("Device Alias not present", str(e.exception)) def tearDown(self) -> None: try: self.d.delete(self.name) except CLIError as c: if "Device Alias not present" not in c.message: self.fail("Tear down failed: " + c.message) enddb = self.d.database if enddb is not None: self.assertEqual(enddb, self.olddb)
def test_create_name_invalidfirstchar(self): d = DeviceAlias(self.switch) name = list(self.new_invalidfirstchar.keys())[0] pwwn = list(self.new_invalidfirstchar.values())[0] with self.assertRaises(CLIError) as e: d.create(self.new_invalidfirstchar) self.assertEqual( "The command \" device-alias database ; device-alias name " + str(name) + " pwwn " + str(pwwn) + " ; \" gave the error \" Illegal first character. Name must start with a letter \".", str(e.exception)) d.clear_lock()
def test_create_name_beyondmax(self): d = DeviceAlias(self.switch) name = list(self.new_beyondmax.keys())[0] pwwn = list(self.new_beyondmax.values())[0] with self.assertRaises(CLIError) as e: d.create(self.new_beyondmax) self.maxDiff = 1000 self.assertEqual( "The command \" device-alias database ; device-alias name " + str(name) + " pwwn " + str(pwwn) + " ; \" gave the error \" % String exceeded max length of (64) \".", str(e.exception))
def test_create_name_invalid(self): d = DeviceAlias(self.switch) name = list(self.new_invalidname.keys())[0] pwwn = list(self.new_invalidname.values())[0] with self.assertRaises(CLIError) as e: d.create(self.new_invalidname) self.assertEqual( "The command \" device-alias database ; device-alias name " + str(name) + " pwwn " + str(pwwn) + " ; \" gave the error \" Illegal character present in the name \".", str(e.exception)) d.clear_lock()
class TestDeviceAliasAttrDatabase(unittest.TestCase): def __init__(self, testName, sw): super().__init__(testName) self.switch = sw def setUp(self) -> None: log.debug(self.switch.version) log.debug(self.switch.ipaddr) self.d = DeviceAlias(self.switch) currdb = self.d.database if currdb is None: self.name = get_random_string() self.pwwn = get_random_pwwn() else: while True: self.name = get_random_string() self.pwwn = get_random_pwwn() if self.name not in currdb.keys() and self.pwwn not in currdb.values(): break log.debug({self.name: self.pwwn}) def test_database_read(self): log.debug("Starting test test_database_read") self.d.create({self.name: self.pwwn}) newdb = self.d.database self.assertIn(self.name, newdb.keys()) self.assertEqual(self.pwwn, newdb[self.name]) self.d.delete(self.name) newdb = self.d.database if newdb is not None: self.assertNotIn(self.name, newdb.keys()) self.assertNotIn(self.pwwn, newdb.values()) def test_database_write_error(self): log.debug("Starting test test_database_write_error") with self.assertRaises(AttributeError) as e: self.d.database = {self.name: self.pwwn} self.assertEqual("can't set attribute", str(e.exception)) def tearDown(self) -> None: try: self.d.delete(self.name) newdb = self.d.database if newdb is not None: self.assertNotIn(self.name, newdb.keys()) self.assertNotIn(self.pwwn, newdb.values()) except CLIError as c: if "Device Alias not present" not in c.message: # raise CLIError(c.args) raise CLIError(c.command, c.message)
def test_delete_nonexisting(self): d = DeviceAlias(self.switch) d.create(self.new1) keys = list(self.new1.keys()) d.delete(keys[0]) with self.assertRaises(CLIError) as e: d.delete(keys[0]) self.assertEqual( 'The command " device-alias database ; no device-alias name ' + str(keys[0]) + ' " gave the error " Device Alias not present\nPlease use \'show device-alias session rejected\' to display the rejected set of commands and for the device-alias best-practices recommendation. ".', str(e.exception)) keys.remove(keys[0]) for k in keys: d.delete(k)
def test_create_name_existing(self): d = DeviceAlias(self.switch) d.create(self.new_existingname) name = list(self.existingname.keys())[0] pwwn = list(self.existingname.values())[0] with self.assertLogs(level='INFO') as l: d.create(self.existingname) self.assertEqual( 'INFO:mdssdk.devicealias:The command : device-alias database ; device-alias name ' + str(name) + ' pwwn ' + str(pwwn) + ' ; was not executed because Device Alias already present', l.output[0]) keys = list(self.new_existingname.keys()) for k in keys: d.delete(k)
def test_remove_members_dict(self): fc_name = "" for k, v in list(self.switch.interfaces.items()): if type(v) is Fc: fc_name = k break while True: pc_id = get_random_id(1, 256) if "port-channel" + str(pc_id) not in self.switch.interfaces.keys(): break pc = PortChannel(self.switch, pc_id) d = DeviceAlias(self.switch) olddb = d.database if olddb is None: da_name = get_random_string() da_pwwn = get_random_pwwn() else: while True: da_name = get_random_string() da_pwwn = get_random_pwwn() if da_name not in olddb.keys() and da_pwwn not in olddb.values(): break d.create({da_name: da_pwwn}) members = [ {"pwwn": "50:08:01:60:08:9f:4d:00"}, {"interface": fc_name}, {"device-alias": da_name}, {"ip-address": "1.1.1.1"}, {"symbolic-nodename": "symbnodename"}, {"fwwn": "11:12:13:14:15:16:17:18"}, {"fcid": "0x123456"}, {"interface": pc.name}, {"fcalias": "somefcalias"}, ] self.switch.config("fcalias name somefcalias vsan " + str(self.id)) self.z.add_members(members) mem = self.z.members self.assertIsNotNone(self.z.members) self.z.remove_members(members) self.assertEqual([], self.z.members) d.delete(da_name)
# Display the database, mode, distribute, locked print("Device Alias Database") print(d.database) print("Mode : " + d.mode) print("Distribute : " + str(d.distribute)) print("Locked : " + str(d.locked)) old = d.database d.clear_database() # Adding new device alias new = { "device1": "21:00:00:0e:1e:30:34:a5", "device2": "21:00:00:0e:1e:30:3c:c5" } d.create(new) prnt("Clearing database\nDatabase after adding new entry") print(d.database) # Renaming the device alias d.rename("device1", "device_new_name") print("Database after renaming device alias device1 as device_new_name") print(d.database) # Deleting device alias d.delete("device_new_name") d.delete("device2") # Recreating original database
class TestDeviceAliasCreate(unittest.TestCase): def __init__(self, testName, sw): super().__init__(testName) self.switch = sw def setUp(self) -> None: log.debug(self.switch.version) log.debug(self.switch.ipaddr) self.d = DeviceAlias(self.switch) self.olddb = self.d.database if self.olddb is None: self.name = get_random_string() self.pwwn = get_random_pwwn() else: while True: self.name = get_random_string() self.pwwn = get_random_pwwn() if ( self.name not in self.olddb.keys() and self.pwwn not in self.olddb.values() ): break log.debug({self.name: self.pwwn}) def test_create(self): self.d.create({self.name: self.pwwn}) newdb = self.d.database self.assertIn(self.name, newdb.keys()) self.assertEqual(self.pwwn, newdb[self.name]) self.d.delete(self.name) newdb = self.d.database if newdb is not None: self.assertNotIn(self.name, newdb.keys()) self.assertNotIn(self.pwwn, newdb.values()) def test_create_name_invalid(self): invalid_name = { "da1&": get_random_pwwn() } # da name a-zA-Z1-9 - _ $ ^ 64chars max name = list(invalid_name.keys())[0] pwwn = list(invalid_name.values())[0] with self.assertRaises(CLIError) as e: self.d.create(invalid_name) self.assertEqual( 'The command " device-alias database ; device-alias name ' + str(name) + " pwwn " + str(pwwn) + ' ; " gave the error " Illegal character present in the name ".', str(e.exception), ) self.d.clear_lock() def test_create_name_invalidfirstchar(self): invalidfirstchar = {"1da": "53:66:61:01:0e:00:01:ff"} name = list(invalidfirstchar.keys())[0] pwwn = list(invalidfirstchar.values())[0] with self.assertRaises(CLIError) as e: self.d.create(invalidfirstchar) self.assertEqual( 'The command " device-alias database ; device-alias name ' + str(name) + " pwwn " + str(pwwn) + ' ; " gave the error " Illegal first character. Name must start with a letter ".', str(e.exception), ) self.d.clear_lock() def test_create_name_beyondmax(self): beyondmax = { "da123456789123456789123456789123456789123456789123456789123456789": get_random_pwwn() } name = list(beyondmax.keys())[0] pwwn = list(beyondmax.values())[0] with self.assertRaises(CLIError) as e: self.d.create(beyondmax) self.assertEqual( 'The command " device-alias database ; device-alias name ' + str(name) + " pwwn " + str(pwwn) + ' ; " gave the error " % String exceeded max length of (64) ".', str(e.exception), ) def test_create_pwwn_existing(self): self.d.create({self.name: self.pwwn}) newdb = self.d.database self.assertIn(self.name, newdb.keys()) self.assertEqual(self.pwwn, newdb[self.name]) newname = get_random_string() with self.assertRaises(CLIError) as e: self.d.create({newname: self.pwwn}) self.assertIn( "Another device-alias already present with the same pwwn", str(e.exception) ) # DB should not be updated with the new name self.assertIn(self.name, newdb.keys()) self.assertEqual(self.pwwn, newdb[self.name]) self.d.delete(self.name) def test_create_name_existing(self): self.d.create({self.name: self.pwwn}) newdb = self.d.database self.assertIn(self.name, newdb.keys()) self.assertEqual(self.pwwn, newdb[self.name]) newpwwn = get_random_pwwn() with self.assertRaises(CLIError) as e: self.d.create({self.name: newpwwn}) self.assertIn("Device Alias already present", str(e.exception)) # DB should not be updated with the new pwwn self.assertIn(self.name, newdb.keys()) self.assertEqual(self.pwwn, newdb[self.name]) self.d.delete(self.name) def tearDown(self) -> None: try: self.d.delete(self.name) except CLIError as c: if "Device Alias not present" not in c.message: self.fail("Tear down failed: " + c.message) enddb = self.d.database if enddb is not None: self.assertEqual(enddb, self.olddb)
class TestDeviceAliasRename(unittest.TestCase): def __init__(self, testName, sw): super().__init__(testName) self.switch = sw def setUp(self) -> None: log.debug(self.switch.version) log.debug(self.switch.ipaddr) self.d = DeviceAlias(self.switch) self.olddb = self.d.database if self.olddb is None: self.name = get_random_string() self.pwwn = get_random_pwwn() else: while True: self.name = get_random_string() self.pwwn = get_random_pwwn() if ( self.name not in self.olddb.keys() and self.pwwn not in self.olddb.values() ): break log.debug({self.name: self.pwwn}) def test_rename(self): self.d.create({self.name: self.pwwn}) newdb = self.d.database self.assertIn(self.name, newdb.keys()) self.assertEqual(self.pwwn, newdb[self.name]) while True: self.newname_to_replace = get_random_string() if self.newname_to_replace not in newdb.keys(): break self.d.rename(oldname=self.name, newname=self.newname_to_replace) chkdb = self.d.database self.assertIn(self.newname_to_replace, chkdb.keys()) self.assertEqual(self.pwwn, chkdb[self.newname_to_replace]) self.assertNotIn(self.name, chkdb.keys()) self.d.delete(self.newname_to_replace) chkdb = self.d.database if chkdb is not None: self.assertNotIn(self.newname_to_replace, chkdb.keys()) self.assertNotIn(self.pwwn, chkdb.values()) self.assertNotIn(self.name, chkdb.keys()) def test_rename_not_present(self): self.d.create({self.name: self.pwwn}) newdb = self.d.database self.assertIn(self.name, newdb.keys()) self.assertEqual(self.pwwn, newdb[self.name]) while True: self.newname_to_replace = get_random_string() if self.newname_to_replace not in newdb.keys(): break with self.assertRaises(CLIError) as e: self.d.rename(oldname=self.newname_to_replace, newname=self.name) self.assertIn("Device Alias not present", str(e.exception)) self.d.delete(self.name) chkdb = self.d.database if chkdb is not None: self.assertNotIn(self.newname_to_replace, chkdb.keys()) self.assertNotIn(self.pwwn, chkdb.values()) self.assertNotIn(self.name, chkdb.keys()) def test_rename_already_present(self): self.d.create({self.name: self.pwwn}) newdb = self.d.database self.assertIn(self.name, newdb.keys()) self.assertEqual(self.pwwn, newdb[self.name]) with self.assertRaises(CLIError) as e: self.d.rename(oldname=self.name, newname=self.name) self.assertIn( "Target device-alias name already in use. Please specify a new name.", str(e.exception), ) self.d.delete(self.name) chkdb = self.d.database if chkdb is not None: self.assertNotIn(self.pwwn, chkdb.values()) self.assertNotIn(self.name, chkdb.keys()) def test_rename_invalid(self): self.d.create({self.name: self.pwwn}) newdb = self.d.database self.assertIn(self.name, newdb.keys()) self.assertEqual(self.pwwn, newdb[self.name]) invalid_name = "da1&" # da name a-zA-Z1-9 - _ $ ^ 64chars max with self.assertRaises(CLIError) as e: self.d.rename(oldname=self.name, newname=invalid_name) self.assertIn("Illegal character present in the name", str(e.exception)) self.d.clear_lock() self.d.delete(self.name) chkdb = self.d.database if chkdb is not None: self.assertNotIn(self.pwwn, chkdb.values()) self.assertNotIn(self.name, chkdb.keys()) def tearDown(self) -> None: try: self.d.delete(self.name) except CLIError as c: if "Device Alias not present" not in c.message: self.fail("Tear down failed: " + c.message) enddb = self.d.database if enddb is not None: self.assertEqual(enddb, self.olddb)
def test_database_read(self): d = DeviceAlias(self.switch) d.create(self.new) self.assertEquals(self.new, d.database) for da in self.new.keys(): d.delete(da)
def test_create_name_max(self): d = DeviceAlias(self.switch) name = list(self.new_max.keys())[0] d.create(self.new_max) self.assertEqual(self.new_max, d.database) d.delete(name)
sys.stdout = open('test_zone_output.txt', 'wt') vsan_id = [2, 3, 4, 5, 6, 7, 8, 9] zone_name = ["zone" + str(i) for i in range(1, 9)] from mdssdk.fc import Fc from mdssdk.devicealias import DeviceAlias from mdssdk.portchannel import PortChannel fc = Fc(sw, "fc1/48") pc = PortChannel(sw, 1) d = DeviceAlias(sw) da_name = 'hello' da_pwwn = '40:66:61:01:0e:00:01:ff' d.create({da_name: da_pwwn}) members_dict = [{ 'pwwn': '50:08:01:60:08:9f:4d:00' }, { 'pwwn': '50:08:01:60:08:9f:4d:01' }, { 'interface': fc.name }, { 'device-alias': da_name }, { 'ip-address': '1.1.1.1' }, { 'symbolic-nodename': 'symbnodename' }, { 'fwwn': '11:12:13:14:15:16:17:18'
# Instantiating PortChannel object 1 pc1 = PortChannel(sw, 1) # Creating port channel pc1.create() # Adding interfaces to vsan 2 v.add_interfaces([int13, pc1]) # Instantiating DeviceAlias object d = DeviceAlias(sw) new = {"da1": "60:66:61:01:0e:00:01:ff"} # Adding new device alias d.create(new) # Instantiate zone object z = Zone(sw, "zone1", v.id) # Create new zone z.create() # Configuring fcalias sw.config("fcalias name somefcalias vsan " + str(v.id)) memlist = [ { "pwwn": "50:08:01:60:08:9f:4d:00" }, {