def test_activate_multiple(self): v = Vsan(self.switch, self.vsan_id[2]) v.create() zoneset = ZoneSet(self.switch, v, self.zoneset_name[2] ) zoneset.create() zone = Zone(self.switch, v, self.zone_name[2]) zone.create() zone.add_members(self.zone_members) zoneset.add_members([zone]) zoneset.activate(True) self.assertTrue(zoneset.is_active()) zoneset1 = ZoneSet(self.switch, v, self.zoneset_name[3] ) zoneset1.create() zoneset1.add_members([zone]) zoneset1.activate(True) self.assertTrue(zoneset1.is_active()) self.assertFalse(zoneset.is_active()) zone.delete() zoneset.delete() zoneset1.delete() v.delete()
class TestZoneDelete(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.vsandb = self.switch.vsans while True: self.id = get_random_id() if self.id not in self.vsandb.keys(): break self.v = Vsan(switch=self.switch, id=self.id) self.v.create() self.z = Zone(self.switch, "test_zone", self.id) def test_delete(self): self.z.create() self.assertEqual("test_zone", self.z.name) self.z.delete() with self.assertRaises(CLIError) as e: self.z.name self.assertIn("Zone not present", str(e.exception)) def test_delete_nonexisting(self): with self.assertRaises(CLIError) as e: self.z.delete() self.assertIn("Zone not present", str(e.exception)) def tearDown(self) -> None: self.v.delete()
def test_create(self): v = Vsan(self.switch, self.vsan_id[1]) v.create() zonename = self.zone_name[0] z = Zone(self.switch, v, zonename) z.create() self.assertEqual(zonename, z.name) z.delete() v.delete()
def test_create_name_max(self): v = Vsan(self.switch, self.vsan_id[5]) v.create() name = self.zone_name_max z = Zone(self.switch, v, name) z.create() self.assertEqual(name, z.name) z.delete() v.delete()
def test_add_members(self): v = Vsan(self.switch,self.vsan_id[1]) v.create() z = Zone(self.switch, v, self.zone_name[1]) z.create() members = self.members_list z.add_members(members) self.assertEqual(len(members),len(z.members)) print("Zone Members : "+str(z.members)) z.delete() v.delete()
def test_delete_nonexisting(self): i = self.vsan_id[1] zonename = self.zone_name[1] v = Vsan(self.switch, i) v.create() z = Zone(self.switch, v, zonename) with self.assertRaises(CLIError) as e: z.delete() self.assertEqual( 'The command " no zone name ' + str(zonename) + ' vsan ' + str(i) + ' " gave the error " Zone not present ".', str(e.exception)) v.delete()
def test_remove_members(self): v = Vsan(self.switch,self.vsan_id[1]) v.create() z = Zone(self.switch, v, self.zone_name[1]) z.create() members = self.members_list z.add_members(members) self.assertIsNotNone(z.members) z.remove_members(members) self.assertIsNone(z.members) z.delete() v.delete()
def test_add_members_error_fcalias(self): i = self.vsan_id[6] v = Vsan(self.switch,i) v.create() name = self.zone_name[6] z = Zone(self.switch, v, name) z.create() members = [{'fcalias': 'somefcalias'}] with self.assertRaises(CLIError) as e: z.add_members(members) self.assertEqual('The command " zone name '+str(name)+' vsan '+str(i)+' ; member fcalias somefcalias " gave the error " Alias not present ".',str(e.exception)) z.delete() v.delete()
def test_add_members_dict(self): i = self.vsan_id[0] v = Vsan(self.switch, i) v.create() z = Zone(self.switch, v, self.zone_name[0]) z.create() members = self.members_dict self.switch.config('fcalias name somefcalias vsan '+str(i)) z.add_members(members) self.assertEqual(len(members),len(z.members)) print("Zone Members : "+str(z.members)) z.delete() v.delete()
def test_add_members_error_fwwn(self): i = self.vsan_id[5] v = Vsan(self.switch,i) v.create() name = self.zone_name[5] z = Zone(self.switch, v, name) z.create() members = [{'fwwn': '11:12:13:14:15:16:17:18:19'}] with self.assertRaises(CLIError) as e: z.add_members(members) self.assertEqual('The command " zone name '+str(name)+' vsan '+str(i)+' ; member fwwn 11:12:13:14:15:16:17:18:19 " gave the error " % Invalid command ".',str(e.exception)) z.delete() v.delete()
def test_add_members_error_fcid(self): i = self.vsan_id[4] v = Vsan(self.switch,i) v.create() name = self.zone_name[4] z = Zone(self.switch, v, name) z.create() members = [{'fcid': '0x123'}] with self.assertRaises(CLIError) as e: z.add_members(members) self.assertEqual('The command " zone name '+str(name)+' vsan '+str(i)+' ; member fcid 0x123 " gave the error " Invalid FCID ".',str(e.exception)) z.delete() v.delete()
def test_add_members_error_ip(self): i = self.vsan_id[3] v = Vsan(self.switch,i) v.create() name = self.zone_name[3] z = Zone(self.switch, v, name) z.create() members = [{'ip-address': '1.1.1.1.1'}] with self.assertRaises(CLIError) as e: z.add_members(members) self.assertEqual('The command " zone name '+str(name)+' vsan '+str(i)+' ; member ip-address 1.1.1.1.1 " gave the error " % Invalid ip address ".',str(e.exception)) z.delete() v.delete()
def test_add_members_error_pwwn(self): i = self.vsan_id[2] v = Vsan(self.switch,i) v.create() name = self.zone_name[2] z = Zone(self.switch, v, name) z.create() members = [{'pwwn': '50:08:01:60:08:9f:4d:00:01'}] with self.assertRaises(CLIError) as e: z.add_members(members) self.assertEqual('The command " zone name '+str(name)+' vsan '+str(i)+' ; member pwwn 50:08:01:60:08:9f:4d:00:01 " gave the error " % Invalid command ".',str(e.exception)) z.delete() v.delete()
def test_remove_members_nonexisting(self): i = self.vsan_id[0] v = Vsan(self.switch, i) v.create() zone = Zone(self.switch, v, self.zone_name[0]) zone.create() zoneset = ZoneSet(self.switch, v, self.zoneset_name[0]) self.assertIsNone(zoneset.members) with self.assertRaises(CLIError) as e: zoneset.remove_members([zone]) self.assertEqual('The command " zoneset name '+str(zoneset.name)+' vsan '+str(i)+' ; no member '+str(zone.name)+' " gave the error " Zone not present ".',str(e.exception)) zone.delete() zoneset.delete() v.delete()
def test_remove_members_dict(self): i = self.vsan_id[0] v = Vsan(self.switch, i) v.create() z = Zone(self.switch, v, self.zone_name[0]) z.create() self.switch.config('fcalias name somefcalias vsan '+str(i)) members = self.members_dict z.add_members(members) self.assertIsNotNone(z.members) z.remove_members(members) self.assertIsNone(z.members) z.delete() v.delete()
def test_add_members(self): v = Vsan(self.switch, self.vsan_id[1]) v.create() zone1 = Zone(self.switch, v, self.zone_name[1]) zone2 = Zone(self.switch, v, self.zone_name[2]) zone1.create() zone2.create() zoneset = ZoneSet(self.switch, v, self.zoneset_name[1]) members = [zone1, zone2] zoneset.add_members(members) self.assertEqual([zone.name for zone in members],list(zoneset.members.keys())) zone1.delete() zone2.delete() zoneset.delete() v.delete()
def test_activate_zonehasnomembers(self): v = Vsan(self.switch, self.vsan_id[1]) v.create() zoneset = ZoneSet(self.switch, v, self.zoneset_name[1] ) zoneset.create() zone = Zone(self.switch, v, self.zone_name[1]) zone.create() zoneset.add_members([zone]) zoneset.activate(True) # not activated since zone has no members self.assertFalse(zoneset.is_active()) zone.delete() zoneset.delete() v.delete()
def test_remove_members(self): v = Vsan(self.switch, self.vsan_id[1]) v.create() zone1 = Zone(self.switch, v, self.zone_name[1]) zone2 = Zone(self.switch, v, self.zone_name[2]) zone1.create() zone2.create() zoneset = ZoneSet(self.switch, v, self.zoneset_name[1]) zoneset.add_members([zone1, zone2]) self.assertIsNotNone(zoneset.members) zoneset.remove_members([zone1, zone2]) self.assertIsNone(zoneset.members) zoneset.delete() zone1.delete() zone2.delete() v.delete()
{ "ip-address": "1.1.1.1" }, { "symbolic-nodename": "symbnodename" }, { "fwwn": "11:12:13:14:15:16:17:18" }, { "fcid": "0x123456" }, ] # Adding members to zone z.add_members(memlist) # Display zone name, vsan id, members print("Zone name: " + z.name) print("Vsan id: " + str(z.vsan.id)) print("Zone members: " + str(z.members)) # Removing members from zone z.remove_members(memlist) # Deleting zone z.delete() # Deleting vsan v.delete()
class TestZoneRemoveMembers(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.vsandb = self.switch.vsans while True: self.id = get_random_id() if self.id not in self.vsandb.keys(): break self.v = Vsan(switch=self.switch, id=self.id) self.v.create() self.z = Zone(self.switch, "test_zone", self.id) self.z.create() 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) def test_remove_members_list(self): members = [] for v in list(self.switch.interfaces.values()): if type(v) is Fc: members.append(v) break while True: pc_id = get_random_id(1, 256) if "port-channel" + str(pc_id) not in self.switch.interfaces.keys(): break members.append(PortChannel(self.switch, pc_id)) members.append("10:99:88:90:76:88:99:ef") self.z.add_members(members) self.assertIsNotNone(self.z.members) self.z.remove_members(members) self.assertEqual([], self.z.members) self.z.delete() def test_remove_members_notpresent(self): members = ["10:99:88:90:76:88:99:ef"] self.assertEqual([], self.z.members) with self.assertRaises(CLIError) as e: self.z.remove_members(members) self.assertIn("Member not present", str(e.exception)) self.z.delete() def test_remove_members_zone_notpresent(self): self.z.delete() members = ["10:99:88:90:76:88:99:ef"] with self.assertRaises(CLIError) as e: self.z.remove_members(members) self.assertIn("Zone not present", str(e.exception)) def tearDown(self) -> None: self.v.delete()