Ejemplo n.º 1
0
class TestDeviceAliasAttrLocked(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.old = self.d.distribute
        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_locked_values(self):
        self.assertIn(self.d.locked, [True, False])

    def test_locked_write_error(self):
        with self.assertRaises(AttributeError) as e:
            self.d.locked = True
        self.assertEqual("can't set attribute", str(e.exception))

    def test_acquire_lock(self):
        # Verify that lock is not acquired first
        self.assertFalse(self.d.locked)
        # Verify that distribute is set
        if not self.old:
            self.d.distribute = True
            self.assertTrue(self.d.distribute)
        self.switch.config("device-alias database ; device-alias name " +
                           self.name + " pwwn " + self.pwwn)
        self.assertTrue(self.d.locked)
        self.d.clear_lock()
        self.assertFalse(self.d.locked)
        self.d.distribute = self.old
        self.assertFalse(self.d.locked)

    def tearDown(self) -> None:
        self.d.distribute = self.old
        self.assertEqual(self.d.distribute, self.old)
        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)
        finally:
            self.assertFalse(self.d.locked)
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 def test_delete_emptydb(self):
     d = DeviceAlias(self.switch)
     d.clear_database()
     with self.assertRaises(CLIError) as e:
         d.delete(self.nonexisting)
     self.assertEqual(
         'The command " device-alias database ; no device-alias name ' +
         str(self.nonexisting) +
         ' " 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))
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_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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
 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)
from tests.test_zone.test_zoneattractivedbzonesetname import *
TestZoneAttrActivedbZonesetName.switch = sw
TestZoneAttrActivedbZonesetName.vsan_id = vsan_id
TestZoneAttrActivedbZonesetName.zone_name = zone_name

from tests.test_zone.test_zoneattrmaxdbsize import *
TestZoneAttrMaxdbSize.switch = sw
TestZoneAttrMaxdbSize.vsan_id = vsan_id
TestZoneAttrMaxdbSize.zone_name = zone_name

from tests.test_zone.test_zoneattreffectivedbsize import *
TestZoneAttrEffectivedbSize.switch = sw
TestZoneAttrEffectivedbSize.vsan_id = vsan_id
TestZoneAttrEffectivedbSize.zone_name = zone_name

from tests.test_zone.test_zoneattreffectivedbsizepercentage import *
TestZoneAttrEffectivedbSizePercentage.switch = sw
TestZoneAttrEffectivedbSizePercentage.vsan_id = vsan_id
TestZoneAttrEffectivedbSizePercentage.zone_name = zone_name

from tests.test_zone.test_zoneattrstatus import *
TestZoneAttrStatus.switch = sw
TestZoneAttrStatus.vsan_id = vsan_id
TestZoneAttrStatus.zone_name = zone_name

suite = unittest.TestLoader().discover('tests.test_zone', 'test_zone*.py')
unittest.TextTestRunner(verbosity=2).run(suite)

d.delete(da_name)
Ejemplo n.º 11
0
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
d.create(old)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
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)
Ejemplo n.º 15
0
# Activating zoneset
zoneset.activate(True)

# Display zoneset information
print("Zoneset name: " + zoneset.name)
print("Vsan id: " + str(zoneset.vsan.id))
print("Zoneset members: " + str(zoneset.members))
print("Activation: " + zonese.is_active())

# Removing members from zoneset
zoneset.remove_members([z])

# Deleting zoneset
zoneset.delete()

# Removing members from zone
z.remove_members(memlist)

# Deleting zone
z.delete()

# Deleting vsan
v.delete()

# Deleting device alias
d.delete("da1")

# Deleting port channel
pc1.delete()
 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)