def test_trunk_write(self):
     fc = Fc(self.switch, self.fc_name[1])
     oldtrunk = fc.trunk
     for trunk in self.trunk_values:
         fc.trunk = trunk
         self.assertEqual(trunk, fc.trunk)
     fc.trunk = oldtrunk
 def test_description_write_max254(self):
     fc = Fc(self.switch, self.fc_name[1])
     old = fc.description
     desc = "switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch123456789123456789123456"
     fc.description = desc
     self.assertEqual(desc, fc.description)
     fc.description = old
 def test_analytics_type_write(self):
     fc = Fc(self.switch, self.fc_name[1])
     analytics_type = fc.analytics_type
     values = self.values
     for type in values:
         fc.analytics_type = type
         self.assertEqual(type, fc.analytics_type)
     fc.analytics_type = analytics_type
 def test_trunk_write_invalid(self):
     fc = Fc(self.switch, self.fc_name[2])
     trunk = "asdf"
     with self.assertRaises(CLIError) as e:
         fc.trunk = trunk
     self.assertEqual(
         "The command \" interface " + str(fc.name) +
         " ; switchport trunk mode  " + str(trunk) +
         " \" gave the error \" % Invalid command \".", str(e.exception))
Exemplo n.º 5
0
 def test_speed_write(self):
     fc = Fc(self.switch, self.fc_name[1])
     oldspeed = fc.speed
     for speed in self.speeds_allowed:
         fc.speed = speed
         self.assertEqual(speed, fc.speed)
     if ("--" in oldspeed):
         oldspeed = 'auto'
     fc.speed = oldspeed
Exemplo n.º 6
0
 def test_speed_write_invalid(self):
     fc = Fc(self.switch, self.fc_name[2])
     speed = "asdf"
     with self.assertRaises(CLIError) as e:
         fc.speed = speed
     self.assertEqual(
         "The command \" interface " + str(fc.name) +
         " ; switchport speed  " + str(speed) +
         " \" gave the error \" % Invalid command \".", str(e.exception))
 def test_description_write_beyondmax(self):
     fc = Fc(self.switch, self.fc_name[2])
     desc = "switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678switch12345678912345678912345678"
     with self.assertRaises(CLIError) as e:
         fc.description = desc
     self.assertEqual(
         "The command \" interface " + str(self.fc_name[2]) +
         " ; switchport description  " + str(desc) +
         " \" gave the error \" % String exceeded max length of (254) \".",
         str(e.exception))
 def test_interfaces_write_error(self):
     v = Vsan(switch=self.switch, id=self.vsan_id[2])
     v.create()
     with self.assertRaises(AttributeError) as e:
         v.interfaces = [
             Fc(switch=self.switch, name=self.fc_name[0]),
             Fc(switch=self.switch, name=self.fc_name[1])
         ]
     self.assertEqual("can't set attribute", str(e.exception))
     v.delete()
 def test_status_write(self):
     fc = Fc(self.switch, self.fc_name[1])
     if (fc.status == "sfpAbsent"):
         return
     status = "shutdown"
     fc.status = status
     self.assertEqual("down", fc.status)
     status1 = "no shutdown"
     fc.status = status1
     self.assertIn(fc.status, self.status_values)
 def test_status_write_invalid(self):
     fc = Fc(self.switch, self.fc_name[2])
     status = "asdf"
     with self.assertRaises(CLIError) as e:
         fc.status = status
     self.assertEqual(
         "The command \" terminal dont-ask ; interface " + str(fc.name) +
         " ; " + str(status) +
         " ; no terminal dont-ask \" gave the error \" % Invalid command \".",
         str(e.exception))
 def test_interfaces_read(self):
     v = Vsan(switch=self.switch, id=self.vsan_id[0])
     v.create()
     fc = [
         Fc(switch=self.switch, name=self.fc_name[0]),
         Fc(switch=self.switch, name=self.fc_name[1])
     ]
     v.add_interfaces(fc)
     self.assertEqual(self.fc_name[0], v.interfaces[0].name)
     self.assertEqual(self.fc_name[1], v.interfaces[1].name)
     v.delete()
Exemplo n.º 12
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()
Exemplo n.º 13
0
 def test_transceiver_read(self):
     interfaces = self.switch.interfaces
     sfp_present, sfp_absent = 0, 0
     for key in interfaces:
         if (type(interfaces[key]) is not Fc):
             continue
         fc = Fc(self.switch, key)
         temp = [x for x in dir(fc.transceiver) if not x.startswith('_')]
         self.assertIn(fc.transceiver.sfp_present, [True, False])
         if (fc.transceiver.sfp_present and sfp_present == 0):
             print(str(key) + " transceiver : ")
             for t in temp:
                 print(
                     str(t) + " : " +
                     str(fc.transceiver.__getattribute__(t)))
             sfp_present = 1
         elif ((not fc.transceiver.sfp_present) and sfp_absent == 0):
             print("\n" + str(key) + " transceiver : ")
             for t in temp:
                 print(
                     str(t) + " : " +
                     str(fc.transceiver.__getattribute__(t)))
             sfp_absent = 1
         if sfp_present == 1 and sfp_absent == 1:
             break
Exemplo n.º 14
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()
Exemplo n.º 15
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()
Exemplo n.º 16
0
 def test_addinterfaces_nonexistingvsan(self):
     i = self.vsan_id[7]
     v = Vsan(switch=self.switch, id=i)
     if v.id is not None:
         v.delete()
     with self.assertRaises(VsanNotPresent) as e:
         v.add_interfaces([Fc(switch=self.switch, name=self.fc_name[6])])
     self.assertEqual(
         "VsanNotPresent: Vsan " + str(i) +
         " is not present on the switch.", str(e.exception))
Exemplo n.º 17
0
 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()
Exemplo n.º 18
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()
Exemplo n.º 19
0
 def test_addinterfaces_fc_invalid(self):
     i = self.vsan_id[5]
     v = Vsan(switch=self.switch, id=i)
     v.create()
     for name in self.invalid_fc:
         with self.assertRaises(CLIError) as e:
             fc = Fc(switch=self.switch, name=name)
             v.add_interfaces([fc])
         self.assertEqual(
             'The command " vsan database ; vsan ' + str(i) +
             ' interface ' + str(name) +
             ' " gave the error " Invalid interface format ".',
             str(e.exception))
     v.delete()
Exemplo n.º 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()
Exemplo n.º 21
0
 def test_addinterfaces_fc_multiple(self):
     v = []
     idx = 0
     fcidx = 8
     for i in self.vsan_id[10:]:
         v.append(Vsan(switch=self.switch, id=i))
         v[idx].create()
         fc = Fc(switch=self.switch, name=self.fc_name[fcidx])
         v[idx].add_interfaces([fc])
         self.assertEqual(i, v[idx].id)
         self.assertEqual(self.fc_name[fcidx], v[idx].interfaces[0].name)
         fcidx += 1
         idx += 1
     for vsan in v:
         vsan.delete()
Exemplo n.º 22
0
 def test_counters_read(self):
     interfaces = self.switch.interfaces
     for key in interfaces:
         if(type(interfaces[key]) is not Fc):
             continue
         fc = Fc(self.switch, key)
         temp = [x for x in dir(fc.counters) if not x.startswith('_')]
         none_attr = []
         for t in temp:
             if(fc.counters.__getattribute__(t) is None):
                 none_attr.append(t)
         if(key == "fc1/1"):
             print("fc1/1 Counters : ")
             for t in temp:
                 print(str(t)+" : "+str(fc.counters.__getattribute__(t)))
         print("Counter attributes that returned None : " + str(none_attr))            
Exemplo n.º 23
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
            port=data['port'],
            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
}, {
Exemplo n.º 25
0
 def test_speed_read(self):
     fc = Fc(self.switch, self.fc_name[0])
     # print(fc.speed)
     self.assertIsNotNone(fc.speed)
Exemplo n.º 26
0
 def test_name_read(self):
     fc = Fc(self.switch, self.fc_name[0])
     self.assertEqual(self.fc_name[0], fc.name)
Exemplo n.º 27
0
 def test_name_write_error(self):
     fc = Fc(self.switch, self.fc_name[1])
     with self.assertRaises(AttributeError) as e:
         fc.name = "asdf"
     self.assertEqual("can't set attribute", str(e.exception))
 def test_status_read(self):
     fc = Fc(self.switch, self.fc_name[0])
     self.assertIsNotNone(fc.status)
 def test_trunk_read(self):
     fc = Fc(self.switch, self.fc_name[0])
     self.assertIn(fc.trunk, self.trunk_values)
Exemplo n.º 30
0
 def test_transceiver_write_error(self):
     fc = Fc(self.switch, "fc1/1")
     with self.assertRaises(AttributeError) as e:
         fc.transceiver = []
     self.assertEqual("can't set attribute", str(e.exception))