コード例 #1
0
class TestPortChannelAttrId(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.interfaces = self.switch.interfaces
        while True:
            self.pc_id = random.randint(1, 256)
            if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
                break
        self.pc = PortChannel(self.switch, self.pc_id)

    def test_id_read(self):
        self.assertEqual(self.pc_id, self.pc.id)

    def test_id_write_error(self):
        with self.assertRaises(AttributeError) as e:
            self.pc.id = 2
        self.assertEqual("can't set attribute", str(e.exception))

    def tearDown(self) -> None:
        self.pc.delete()
        self.assertEqual(self.interfaces.keys(), self.switch.interfaces.keys())
コード例 #2
0
 def setUp(self) -> None:
     log.debug(self.switch.version)
     log.debug(self.switch.ipaddr)
     self.interfaces = self.switch.interfaces
     while True:
         self.pc_id = random.randint(1, 256)
         if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
             break
     self.pc = PortChannel(self.switch, self.pc_id)
コード例 #3
0
class TestPortChannelAttrMode(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.interfaces = self.switch.interfaces
        while True:
            self.pc_id = random.randint(1, 256)
            if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
                break
        self.pc = PortChannel(self.switch, self.pc_id)
        self.mode_values = mode_values

    def test_mode_read(self):
        self.pc.create()
        self.assertIn(self.pc.mode, self.mode_values + ["--"])
        self.pc.delete()

    def test_mode_read_nonexisting(self):
        self.assertIsNone(self.pc.mode)

    def test_mode_write(self):
        self.skipTest("Needs to be fixed")
        self.pc.create()
        oldmode = self.pc.mode
        for mode in self.mode_values:
            self.pc.mode = mode
            self.assertEqual(mode, self.pc.mode)
        if "--" in oldmode:
            oldmode = "auto"
        self.pc.mode = oldmode
        self.pc.delete()

    def test_mode_write_invalid(self):
        mode = "asdf"
        with self.assertRaises(CLIError) as e:
            self.pc.mode = mode
        self.assertEqual(
            'The command " interface port-channel'
            + str(self.pc_id)
            + " ; switchport mode  "
            + str(mode)
            + ' " gave the error " % Invalid command ".',
            str(e.exception),
        )

    def tearDown(self) -> None:
        self.pc.delete()
        self.assertEqual(self.interfaces.keys(), self.switch.interfaces.keys())
コード例 #4
0
class TestPortChannelDelete(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.interfaces = self.switch.interfaces
        while True:
            self.pc_id = random.randint(1, 256)
            if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
                break
        self.pc = PortChannel(self.switch, self.pc_id)

    def test_delete_nonexisting(self):
        self.assertIsNone(self.pc.channel_mode)
        self.pc.delete()  # no error
        self.assertIsNone(self.pc.channel_mode)

    def test_delete(self):
        self.pc.create()
        self.assertIsNotNone(self.pc.channel_mode)
        self.pc.delete()
        self.assertIsNone(self.pc.channel_mode)

    def tearDown(self) -> None:
        self.pc.delete()
        self.assertEqual(self.interfaces.keys(), self.switch.interfaces.keys())
コード例 #5
0
class TestPortChannelAttrTrunk(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.interfaces = self.switch.interfaces
        while True:
            self.pc_id = random.randint(1, 256)
            if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
                break
        self.pc = PortChannel(self.switch, self.pc_id)
        self.trunk_values = trunk_values

    def test_trunk_read(self):
        self.pc.create()
        self.assertIn(self.pc.trunk, self.trunk_values)
        self.pc.delete()

    def test_trunk_read_nonexisting(self):
        self.assertIsNone(self.pc.trunk)

    def test_trunk_write(self):
        self.pc.create()
        oldtrunk = self.pc.trunk
        for trunk in self.trunk_values:
            self.pc.trunk = trunk
            self.assertEqual(trunk, self.pc.trunk)
        self.pc.trunk = oldtrunk
        self.pc.delete()

    def test_trunk_write_invalid(self):
        trunk = "asdf"
        with self.assertRaises(CLIError) as e:
            self.pc.trunk = trunk
        self.assertEqual(
            'The command " interface port-channel'
            + str(self.pc_id)
            + " ; switchport trunk mode  "
            + str(trunk)
            + ' " gave the error " % Invalid command ".',
            str(e.exception),
        )

    def tearDown(self) -> None:
        self.pc.delete()
        self.assertEqual(self.interfaces.keys(), self.switch.interfaces.keys())
コード例 #6
0
 def setUp(self) -> None:
     log.debug(self.switch.version)
     log.debug(self.switch.ipaddr)
     self.interfaces = self.switch.interfaces
     while True:
         self.pc_id = random.randint(1, 256)
         if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
             break
     self.pc = PortChannel(self.switch, self.pc_id)
     while True:
         k, v = random.choice(list(self.interfaces.items()))
         if type(v) is Fc:
             self.fc = v
             log.debug(k)
             break
コード例 #7
0
class TestPortChannelAttrStatus(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.interfaces = self.switch.interfaces
        while True:
            self.pc_id = random.randint(1, 256)
            if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
                break
        self.pc = PortChannel(self.switch, self.pc_id)

    def test_status_read(self):
        self.pc.create()
        self.assertEqual("noOperMembers", self.pc.status)
        self.pc.delete()

    def test_status_read_nonexisting(self):
        self.assertIsNone(self.pc.status)

    def test_status_write(self):
        self.pc.create()
        status = "shutdown"
        self.pc.status = status
        self.assertEqual("down", self.pc.status)
        status1 = "no shutdown"
        self.pc.status = status1
        self.assertEqual("noOperMembers", self.pc.status)
        self.pc.delete()

    def test_status_write_invalid(self):
        status = "asdf"
        with self.assertRaises(CLIError) as e:
            self.pc.status = status
        self.assertEqual(
            'The command " terminal dont-ask ; interface port-channel' +
            str(self.pc_id) + " ; " + str(status) +
            ' ; no terminal dont-ask " gave the error " % Invalid command ".',
            str(e.exception),
        )

    def tearDown(self) -> None:
        self.pc.delete()
        self.assertEqual(self.interfaces.keys(), self.switch.interfaces.keys())
コード例 #8
0
 def test_create_invalid(self):
     for i in [0, 257]:
         with self.assertRaises(InvalidPortChannelRange) as e:
             pc = PortChannel(self.switch, i)
         self.assertEqual(
             "InvalidPortChannelRange: Port channel id " + str(i) +
             " is invalid, id should range from 1 to 256",
             str(e.exception),
         )
コード例 #9
0
 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.fc = self.vsandb[1].interfaces[1]  ## fc interface from vsan 1
     self.interfaces = self.switch.interfaces
     while True:
         self.pc_id = get_random_id(1, 256)
         if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
             break
     self.pc = PortChannel(self.switch, self.pc_id)
     self.invalid_fc = Fc(
         self.switch,
         "fc48/48")  ## matches fc pattern but is not present on switch
コード例 #10
0
 def test_addinterfaces_portchannelnotpresent(self):
     i = self.vsan_id[9]
     v = Vsan(switch=self.switch, id=i)
     v.create()
     pc = PortChannel(self.switch, self.pc_id[6])
     with self.assertRaises(CLIError) as e:
         v.add_interfaces([pc])
     self.assertEqual(
         'The command " vsan database ; vsan ' + str(i) +
         ' interface port-channel' + str(self.pc_id[6]) +
         ' " gave the error " Invalid range ".', str(e.exception))
     v.delete()
コード例 #11
0
class TestPortChannelCreate(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.interfaces = self.switch.interfaces
        while True:
            self.pc_id = random.randint(1, 256)
            if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
                break
        self.pc = PortChannel(self.switch, self.pc_id)

    def test_create(self):
        self.pc.create()
        self.assertIsNotNone(self.pc.channel_mode)
        self.pc.delete()

    def test_create_invalid(self):
        for i in [0, 257]:
            with self.assertRaises(InvalidPortChannelRange) as e:
                pc = PortChannel(self.switch, i)
            self.assertEqual(
                "InvalidPortChannelRange: Port channel id " + str(i) +
                " is invalid, id should range from 1 to 256",
                str(e.exception),
            )

    def tearDown(self) -> None:
        self.pc.delete()
        self.assertEqual(self.interfaces.keys(), self.switch.interfaces.keys())
コード例 #12
0
 def test_addinterfaces_type_error(self):
     v = Vsan(switch=self.switch, id=self.vsan_id[0])
     v.create()
     fc = Fc(switch=self.switch, name=self.fc_name[0])
     with self.assertRaises(TypeError) as e:
         v.add_interfaces(fc)
     self.assertEqual("'Fc' object is not iterable", str(e.exception))
     pc = PortChannel(self.switch, self.pc_id[0])
     with self.assertRaises(TypeError) as e:
         v.add_interfaces(pc)
     self.assertEqual("'PortChannel' object is not iterable",
                      str(e.exception))
     v.delete()
コード例 #13
0
class TestPortChannelAttrCounters(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.interfaces = self.switch.interfaces
        while True:
            self.pc_id = random.randint(1, 256)
            if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
                break
        self.pc = PortChannel(self.switch, self.pc_id)

    def test_counters_read_nonexisting(self):
        with self.assertRaises(CLIError) as e:
            log.debug(self.pc.counters.__getattribute__("brief"))
        self.assertIn("Invalid range", str(e.exception))
        self.pc.delete()

    def test_counters_read(self):
        self.pc.create()
        self.assertIsNotNone(self.pc.counters,
                             "pc.counters did not get counter objects")
        dir_counters = [
            x for x in dir(self.pc.counters) if not x.startswith("_")
        ]
        for t in dir_counters:
            val = self.pc.counters.__getattribute__(t)
            log.debug(str(t) + " " + str(val))
            if t is not "other_stats":
                self.assertIsNotNone(val)
            else:
                self.assertIsNone(val)
        self.pc.delete()

    def test_counters_write_error(self):
        with self.assertRaises(AttributeError) as e:
            self.pc.counters = "mds"
        self.assertEqual("can't set attribute", str(e.exception))

    def test_counters_clear(self):
        self.skipTest("Needs to be fixed")
        self.pc.counters.clear()

    def tearDown(self) -> None:
        self.pc.delete()
        self.assertEqual(self.interfaces.keys(), self.switch.interfaces.keys())
コード例 #14
0
 def test_addinterfaces_repeated(self):
     v = Vsan(switch=self.switch, id=self.vsan_id[8])
     v.create()
     fc1 = Fc(switch=self.switch, name=self.fc_name[7])
     pc = PortChannel(self.switch, self.pc_id[5])
     pc.create()
     v.add_interfaces([fc1, fc1, fc1, fc1])
     self.assertEqual(fc1.name, v.interfaces[0].name)
     pc.delete()
     v.delete()
コード例 #15
0
class TestPortChannelAttrMembers(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.interfaces = self.switch.interfaces
        while True:
            self.pc_id = random.randint(1, 256)
            if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
                break
        self.pc = PortChannel(self.switch, self.pc_id)

    def test_members_read_nonexisting(self):
        self.assertIsNone(self.pc.members)

    def test_members_read(self):
        self.pc.create()
        while True:
            k, v = random.choice(list(self.interfaces.items()))
            if type(v) is Fc:
                fc = v
                log.debug(k)
                break
        try:
            self.pc.add_members([fc])
        except CLIError as c:
            if "port not compatible" in c.message:
                self.skipTest(
                    "Skipping test as as port not compatible. Please rerun the test cases"
                )
        self.assertIn(fc.name, self.pc.members)
        self.pc.delete()

    def test_members_write_error(self):
        with self.assertRaises(AttributeError) as e:
            self.pc.members = []
        self.assertEqual("can't set attribute", str(e.exception))

    def tearDown(self) -> None:
        self.pc.delete()
        self.assertEqual(self.interfaces.keys(), self.switch.interfaces.keys())
コード例 #16
0
 def test_add_members(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)
     log.debug("Zone Members To Add : " + str(members))
     log.debug("Zone Members Added : " + str(self.z.members))
     self.assertEqual(len(members), len(self.z.members))
コード例 #17
0
 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()
コード例 #18
0
 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)
コード例 #19
0
 def test_addinterfaces_splitlist(self):
     v = Vsan(switch=self.switch, id=self.vsan_id[3])
     v.create()
     fc1 = Fc(switch=self.switch, name=self.fc_name[2])
     fc2 = Fc(switch=self.switch, name=self.fc_name[3])
     pc = PortChannel(self.switch, self.pc_id[2])
     pc.create()
     v.add_interfaces([fc1])
     v.add_interfaces([fc2])
     v.add_interfaces([pc])
     self.assertEqual(fc1.name, v.interfaces[0].name)
     self.assertEqual(fc2.name, v.interfaces[1].name)
     self.assertEqual(pc.name, v.interfaces[2].name)
     pc.delete()
     v.delete()
コード例 #20
0
 def test_addinterfaces(self):
     v = Vsan(switch=self.switch, id=self.vsan_id[1])
     v.create()
     fc = Fc(switch=self.switch, name=self.fc_name[1])
     v.add_interfaces([fc])
     self.assertEqual(fc.name, v.interfaces[0].name)
     v.delete()
     v = Vsan(switch=self.switch, id=self.vsan_id[2])
     v.create()
     pc = PortChannel(self.switch, self.pc_id[1])
     pc.create()
     v.add_interfaces([pc])
     self.assertEqual(pc.name, v.interfaces[0].name)
     pc.delete()
     v.delete()
コード例 #21
0
class TestVsanAddInterfaces(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.fc = self.vsandb[1].interfaces[1]  ## fc interface from vsan 1
        self.interfaces = self.switch.interfaces
        while True:
            self.pc_id = get_random_id(1, 256)
            if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
                break
        self.pc = PortChannel(self.switch, self.pc_id)
        self.invalid_fc = Fc(
            self.switch,
            "fc48/48")  ## matches fc pattern but is not present on switch

    def test_addinterfaces_type_error(self):
        self.v.create()
        with self.assertRaises(TypeError) as e:
            self.v.add_interfaces(self.fc)
        self.assertIn("object is not iterable", str(e.exception))
        self.v.delete()

    def test_addinterfaces(self):
        self.v.create()
        self.pc.create()
        self.v.add_interfaces([self.fc, self.pc])
        self.assertEqual(self.fc.name, self.v.interfaces[0].name)
        self.assertEqual(self.pc.name, self.v.interfaces[1].name)
        self.pc.delete()
        self.v.delete()

    def test_addinterfaces_fc_invalid(self):
        self.v.create()
        with self.assertRaises(CLIError) as e:
            self.v.add_interfaces([self.invalid_fc])
        self.assertIn("Invalid interface format", str(e.exception))
        self.v.delete()

    def test_addinterfaces_invalid(self):
        self.v.create()
        with self.assertRaises(AttributeError) as e:
            self.v.add_interfaces("asdfg")
        self.assertEqual("'str' object has no attribute 'name'",
                         str(e.exception))
        self.v.delete()

    def test_addinterfaces_nonexistingvsan(self):
        with self.assertRaises(VsanNotPresent) as e:
            self.v.add_interfaces([self.fc])
        self.assertEqual(
            "VsanNotPresent: Vsan " + str(self.id) +
            " is not present on the switch.",
            str(e.exception),
        )

    def test_addinterfaces_repeated(self):
        self.v.create()
        self.pc.create()
        self.v.add_interfaces(
            [self.fc, self.fc,
             self.pc])  ## self.fc even though repeated will not be added
        self.assertEqual(self.fc.name, self.v.interfaces[0].name)
        self.assertEqual(2, len(self.v.interfaces))
        self.pc.delete()
        self.v.delete()

    def test_addinterfaces_portchannelnotpresent(self):
        self.v.create()
        with self.assertRaises(CLIError) as e:
            self.v.add_interfaces([self.pc])
        self.assertRegex(
            str(e.exception),
            ".*The command.*vsan database ; vsan " + str(self.id) +
            " interface port-channel" + str(self.pc.id) +
            ".*gave the error.*Invalid range .*",
        )
        self.v.delete()

    def tearDown(self) -> None:
        if self.v.id is not None:
            self.v.delete()
        if self.pc.channel_mode is not None:
            self.pc.delete()
        self.vsandb[1].add_interfaces([self.fc])
        self.assertEqual(self.vsandb.keys(), self.switch.vsans.keys())
コード例 #22
0
class TestPortChannelRemoveMembers(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.interfaces = self.switch.interfaces
        while True:
            self.pc_id = random.randint(1, 256)
            if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
                break
        self.pc = PortChannel(self.switch, self.pc_id)
        while True:
            k, v = random.choice(list(self.interfaces.items()))
            if type(v) is Fc and v.status not in ["up", "trunking"]:
                self.fc = v
                log.debug(k)
                break

    def test_remove_members_paramtype(self):
        self.pc.create()
        self.pc.add_members([self.fc])
        with self.assertRaises(TypeError) as e:
            self.pc.remove_members(self.fc)
        self.assertEqual("'Fc' object is not iterable", str(e.exception))
        self.pc.delete()

    def test_remove_members_one(self):
        self.pc.create()
        while True:
            k, v = random.choice(list(self.interfaces.items()))
            if (type(v) is Fc and k != self.fc.name
                    and v.status not in ["up", "trunking"]):
                fc2 = v
                log.debug(k)
                break
        try:
            self.pc.add_members([self.fc, fc2])
        except CLIError as c:
            if "port not compatible" in c.message:
                self.skipTest(
                    "Skipping test as as port not compatible. Please rerun the test cases"
                )
        self.pc.remove_members([self.fc])
        # print(self.fc.name, self.pc.members)
        self.assertNotIn(self.fc.name, self.pc.members)
        self.assertIn(fc2.name, self.pc.members)
        self.pc.delete()

    def test_remove_members_multiple(self):
        self.pc.create()
        while True:
            k, v = random.choice(list(self.interfaces.items()))
            if (type(v) is Fc and k != self.fc.name
                    and v.status not in ["up", "trunking"]):
                fc2 = v
                log.debug(k)
                break
        try:
            self.pc.add_members([self.fc, fc2])
        except CLIError as c:
            if "port not compatible" in c.message:
                self.skipTest(
                    "Skipping test as as port not compatible. Please rerun the test cases"
                )
        self.pc.remove_members([self.fc, fc2])
        self.assertEquals(self.pc.members, {})
        self.pc.delete()

    def test_remove_members_nonexistingpc(self):
        with self.assertRaises(PortChannelNotPresent) as e:
            self.pc.remove_members([self.fc])
        self.assertEqual(
            "PortChannelNotPresent: Port channel " + str(self.pc_id) +
            " is not present on the switch, please create the PC first",
            str(e.exception),
        )

    def test_remove_members_nonexisting(self):
        self.pc.create()
        with self.assertRaises(CLIError) as e:
            self.pc.remove_members([self.fc])
        self.assertEqual(
            'The command " interface ' + str(self.fc.name) +
            " ; no channel-group " + str(self.pc_id) + ' " gave the error " ' +
            str(self.fc.name) + ': not part of port-channel ".',
            str(e.exception),
        )
        self.pc.delete()

    def tearDown(self) -> None:
        self.pc.delete()
        self.assertEqual(self.interfaces.keys(), self.switch.interfaces.keys())
コード例 #23
0
 def test_addinterfaces_list(self):
     v = Vsan(switch=self.switch, id=self.vsan_id[4])
     v.create()
     fc1 = Fc(switch=self.switch, name=self.fc_name[4])
     fc2 = Fc(switch=self.switch, name=self.fc_name[5])
     pc4 = PortChannel(self.switch, self.pc_id[3])
     pc5 = PortChannel(self.switch, self.pc_id[4])
     pc4.create()
     pc5.create()
     l = [fc1, fc2, pc4, pc5]
     v.add_interfaces(l)
     self.assertEqual(fc1.name, v.interfaces[0].name)
     self.assertEqual(fc2.name, v.interfaces[1].name)
     self.assertEqual(pc4.name, v.interfaces[2].name)
     self.assertEqual(pc5.name, v.interfaces[3].name)
     pc4.delete()
     pc5.delete()
     v.delete()
コード例 #24
0
class TestPortChannelAttrDescription(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.interfaces = self.switch.interfaces
        while True:
            self.pc_id = random.randint(1, 256)
            if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
                break
        self.pc = PortChannel(self.switch, self.pc_id)

    def test_description_read(self):
        self.pc.create()
        self.assertIsNotNone(self.pc.description)
        self.pc.delete()

    def test_description_read_nonexisting(self):
        with self.assertRaises(CLIError) as e:
            log.debug(self.pc.description)
        self.assertIn("Invalid range", str(e.exception))

    def test_description_write_max254(self):
        self.pc.create()
        old = self.pc.description
        desc = "switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch123456789123456789123456"
        self.pc.description = desc
        self.assertEqual(desc, self.pc.description)
        self.pc.description = old
        self.pc.delete()

    def test_description_write_beyondmax(self):
        desc = "switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678"
        with self.assertRaises(CLIError) as e:
            self.pc.description = desc
        self.assertIn("String exceeded max length of (254)", str(e.exception))
        self.pc.delete()

    def tearDown(self) -> None:
        self.pc.delete()
        self.assertEqual(self.interfaces.keys(), self.switch.interfaces.keys())
コード例 #25
0
            timeout=data['timeout'],
            verify_ssl=False)

import sys

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'
コード例 #26
0
    port=p,
    timeout=30,
    verify_ssl=False,
)

# Instantiating Vsan object with id 2
v = Vsan(sw, 2)

# Creating vsan
v.create()

# Creating Fc object for interface fc1/3
int13 = Fc(sw, "fc1/3")

# 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
コード例 #27
0
class TestPortChannelAttrChannelMode(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.interfaces = self.switch.interfaces
        while True:
            self.pc_id = random.randint(1, 256)
            if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
                break
        self.pc = PortChannel(self.switch, self.pc_id)
        self.channel_mode_values = channel_mode_values

    def test_channel_mode_read_nonexisting(self):
        self.assertIsNone(self.pc.channel_mode)

    def test_channel_mode_read(self):
        self.pc.create()
        self.assertIn(self.pc.channel_mode, self.channel_mode_values)
        self.pc.delete()

    def test_channel_mode_write_nonexisting(self):
        with self.assertRaises(PortChannelNotPresent) as e:
            self.pc.channel_mode = self.channel_mode_values[0]
        self.assertEqual(
            "PortChannelNotPresent: Port channel "
            + str(self.pc_id)
            + " is not present on the switch, please create the PC first",
            str(e.exception),
        )

    def test_channel_mode_write(self):
        self.pc.create()
        for mode in self.channel_mode_values:
            self.pc.channel_mode = mode
            self.assertEqual(mode, self.pc.channel_mode)
        self.pc.delete()

    def test_channel_mode_write_invalid(self):
        channel_mode = "asdf"
        self.pc.create()
        with self.assertRaises(InvalidChannelMode) as e:
            self.pc.channel_mode = channel_mode
        self.assertEqual(
            "InvalidChannelMode: Invalid channel mode ("
            + str(channel_mode)
            + "), Valid values are: on,active",
            str(e.exception),
        )
        self.pc.delete()

    def tearDown(self) -> None:
        self.pc.delete()
        self.assertEqual(self.interfaces.keys(), self.switch.interfaces.keys())
コード例 #28
0
class TestPortChannelAddMembers(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.interfaces = self.switch.interfaces
        while True:
            self.pc_id = random.randint(1, 256)
            if "port-channel" + str(self.pc_id) not in self.interfaces.keys():
                break
        self.pc = PortChannel(self.switch, self.pc_id)
        while True:
            k, v = random.choice(list(self.interfaces.items()))
            if type(v) is Fc:
                self.fc = v
                log.debug(k)
                break

    def test_add_members_paramtype(self):
        self.pc.create()
        with self.assertRaises(TypeError) as e:
            self.pc.add_members(self.fc)
        self.assertEqual("'Fc' object is not iterable", str(e.exception))
        self.pc.delete()

    def test_add_members_one(self):
        self.pc.create()
        try:
            self.pc.add_members([self.fc])
        except CLIError as c:
            if "port not compatible" in c.message:
                self.skipTest(
                    "Skipping test as as port not compatible. Please rerun the test cases"
                )
        self.assertIn(self.fc.name, self.pc.members)
        self.pc.delete()

    def test_add_members_multiple(self):
        self.pc.create()
        while True:
            k, v = random.choice(list(self.interfaces.items()))
            if type(v) is Fc and k != self.fc.name:
                fc2 = v
                log.debug(k)
                break
        try:
            self.pc.add_members([self.fc, fc2])
        except CLIError as c:
            if "port not compatible" in c.message:
                self.skipTest(
                    "Skipping test as as port not compatible. Please rerun the test cases"
                )
        self.assertIn(self.fc.name, self.pc.members)
        self.assertIn(fc2.name, self.pc.members)
        self.pc.delete()

    def test_add_members_nonexisting(self):
        with self.assertRaises(PortChannelNotPresent) as e:
            self.pc.add_members([self.fc])
        self.assertEqual(
            "PortChannelNotPresent: Port channel "
            + str(self.pc_id)
            + " is not present on the switch, please create the PC first",
            str(e.exception),
        )

    def test_add_members_invalidfc(self):
        invalidfc = "fc48/48"  ### check
        fc1 = Fc(self.switch, invalidfc)
        self.pc.create()
        with self.assertRaises(CLIError) as e:
            self.pc.add_members([fc1])
        self.assertEqual(
            'The command " interface '
            + str(invalidfc)
            + " ; channel-group "
            + str(self.pc_id)
            + ' force " gave the error " Invalid interface format ".',
            str(e.exception),
        )
        self.pc.delete()

    def test_add_members_invalid(self):
        self.pc.create()
        with self.assertRaises(AttributeError) as e:
            self.pc.add_members(["fc1/1"])
        self.assertEqual("'str' object has no attribute 'name'", str(e.exception))
        self.pc.delete()

    def tearDown(self) -> None:
        self.pc.delete()
        self.assertCountEqual(self.interfaces.keys(), self.switch.interfaces.keys())