Beispiel #1
0
def TestNetworkPolicy(si, options):
    print("Testing network policy")
    networkSystem = host.GetHostSystem(si).GetConfigManager().networkSystem
    # Setup
    networkSystem.AddVirtualSwitch(vswitchName=options.vsName)

    pgSpec = vim.host.PortGroup.Specification(
        name=options.pgName,
        vlanId=0,
        vswitchName=options.vsName,
        policy=vim.host.NetworkPolicy(
            security=vim.host.NetworkPolicy.SecurityPolicy(
                allowPromiscuous=True, macChanges=True, forgedTransmits=True)))

    print("Test 1: Adding port group %s with policy: %s" %
          (options.pgName, str(pgSpec.GetPolicy())))
    networkSystem.AddPortGroup(pgSpec)

    portgroup = FindPGroup(si, options.pgName)
    if not portgroup:
        raise Exception("Unable to find the port group in the network info")

    if not ValidateNetworkSecurityPolicy(
            pgSpec.GetPolicy().GetSecurity(),
            portgroup.GetComputedPolicy().GetSecurity()):
        raise Exception("NetworkSecurityPolicy config doesn't match runtime")
    print("Test 1: NetworkPolicy config matches runtime: PASS")
Beispiel #2
0
def TestRemoveVirtualSwitch(si, options):
    '''
      Test NetworkSystem.removeVirtualSwitch.
      Check for possible exceptions.
   '''

    print("Testing vim.host.NetworkSystem.removeVirtualSwitch")

    networkSystem = host.GetHostSystem(si).GetConfigManager().networkSystem
    # Setup
    networkSystem.AddVirtualSwitch(vswitchName=options.vsName)

    print("Test1: Removing non-existent virtual switch")
    try:
        # Using this name, because TestAddVirtualSwitch guarantees that it can not be created
        networkSystem.RemoveVirtualSwitch(
            vswitchName="123456789012345678901234567890123")
        print("Test1: Removing non-existent virtual switch: FAILED")
    except vim.fault.NotFound as e:
        print(
            "Test1: Removing non-existent virtual switch failed with vim.fault.NotFound as expected: PASS"
        )
    else:
        raise Exception(
            "Removing non-existent virtual switch didn't fail as expected")

    print("Test2: Removing virtual switch " + options.vsName)
    networkSystem.RemoveVirtualSwitch(vswitchName=options.vsName)
    print("Test2: Removing virtual switch: PASS")
Beispiel #3
0
 def __init__(self, si):
    self._si = si
    self._hostSystem = host.GetHostSystem(si)
    self._configMgr = host.GetHostConfigManager(si)
    self._storageSystem = self._configMgr.GetStorageSystem()
    self._vFlashManager = self._configMgr.GetVFlashManager()
    self._datastoreSystem = self._configMgr.GetDatastoreSystem()
Beispiel #4
0
def TEST_PnicStatus(si, pnic, expected):
    failReason = ""
    print("  TESTCASE: TestPnicStatus (pnic=" + pnic + " expected=" +
          expected + ")")
    failed = False

    mgr = host.GetHostSystem(si).GetConfigManager().iscsiManager

    try:
        status = mgr.QueryPnicStatus(pnic)

        if expected != "":
            if UTIL_HasFault(status, expected) != True:
                failReason = "expected", expected, "NOT FOUND in fault list",
                failed = True
        else:
            if status.reason:
                failReason = "expected success, got failure=", status.reason.faultMessage[
                    0].key
                failed = True

    except Exception as e:
        failReason = "EXCEPTION: " + e
        failed = True

    if failed:
        print("    --- FAIL --- (%s)" % failReason)
        GLOBAL_STATUS = False
        if ABORT_ON_FAIL:
            exit(0)
        return False
    else:
        print("    --- PASS ---")
        return True
Beispiel #5
0
def main():
   #
   # Open connection with host
   #
   hs = host.GetHostSystem(si)
   verbose = (args.GetKeyValue("verbose") == True)

   #
   # Run plugin tests.
   #
   vslmsvcPlugginTest = VslmsvcPlugginTests(verbose);
   vslmsvcPlugginTest.runTests()

   #
   # Report test results.
   #
   if (verbose):
      Log(" tests = " + str(vslmsvcPlugginTest.testCount()))
      Log(" failures = " + str(vslmsvcPlugginTest.testFailureCount()))
   if (vslmsvcPlugginTest.testFailureCount()):
      resultsMessage = str(vslmsvcPlugginTest.testFailureCount()) +\
                       " Vslmsvc Pluggin Test Failures:\n"
      for message in vslmsvcPlugginTest.errorMessages:
         resultsMessage += message + "\n"
   else:
      resultsMessage = "All tests passed."

   if(verbose):
      Log(resultsMessage)
   else:
      raise Exception(resultsMessage)
Beispiel #6
0
def TestVnicUpdate(si, uuid):
    print("Testing vnic update of backing and ipCfg in the same spec")
    networkSystem = host.GetHostSystem(si).GetConfigManager().networkSystem
    # create a dummy vnic
    netCfg = Vim.Host.NetworkConfig()
    dvPort = Vim.Dvs.PortConnection(portKey = "1000",
                 connectionCookie = 5,
                 switchUuid = uuid)
    ipCfg = GenerateIPConfig("192.168.10.2")
    vnicSpec = Vim.Host.VirtualNic.Specification(ip = ipCfg,
                distributedVirtualPort = dvPort)
    try:
        vmknic = networkSystem.AddVirtualNic("", nic = vnicSpec)
    except Exception:
        print("Failed to add dummy vmknic to dvs")
        raise
    # Invoke update network config with the same backing.
    newIp = "192.168.10.3"
    newIpCfg = GenerateIPConfig(newIp)
    newVnicSpec = Vim.Host.VirtualNic.Specification(ip = newIpCfg)
    try:
        networkSystem.UpdateVirtualNic(vmknic, nic = newVnicSpec)
    except Exception as e:
        print("Test 1: Test to check UpdateVirtualNic for vnic update failed")
        raise
    # Validate that the ip actually changed.
    newVnics = networkSystem.GetNetworkInfo().GetVnic()
    for newVnic in newVnics:
        if newVnic.GetDevice() == vmknic:
            if newVnic.GetSpec().GetIp().GetIpAddress() != newIp:
                raise Exception("Test 1: Ip address not updated failed")
    CleanupVmknic(networkSystem, vmknic)
    print("Test1: Test to check UpdateVirtualNic for vnic update passed")
    return
Beispiel #7
0
def GetDatastore(si, dsName):
    hs = host.GetHostSystem(si)
    datastores = hs.GetDatastore()
    for ds in datastores:
        if ds.name == dsName:
            return ds
    raise Exception("Error looking up datastore: %s" % dsName)
Beispiel #8
0
def checkInitialState(si):
    """
    Checks if there a WOL capable free uplinks in the system
    """
    networkSystem = host.GetHostSystem(si).configManager.networkSystem
    networkInfo = networkSystem.GetNetworkInfo()
    freePnics = getFreeUplinks(networkInfo)
    return freePnics
Beispiel #9
0
def VALIDATE_ValidateLeak(config, si, iscsiList):
    ns = host.GetHostSystem(si).GetConfigManager().networkSystem

    loop = 0
    while True:
        hint = ns.QueryNetworkHint()
        loop = loop + 1
        print("LOOP: %s" % loop)
Beispiel #10
0
def GetHostSystem(hostname):
    if options.vcHost:
        dcRef = GetDatacenter(options.dcName)
        searchIndex = si.content.searchIndex
        hostSystem = searchIndex.FindByIp(dcRef, hostname, False) or \
        searchIndex.FindByDnsName(dcRef, hostname, False)
    else:
        hostSystem = host.GetHostSystem(si)
    return hostSystem
Beispiel #11
0
def TestQueryVnicStatus(si, vmhbaList):
    print("TESTCASE: TestQueryVnicStatus")

    iscsiManager = host.GetHostSystem(si).GetConfigManager().iscsiManager
    networkSystem = host.GetHostSystem(si).GetConfigManager().networkSystem
    """ POSITIVE TEST 1 - Verify TestQueryVnicStatus is correct """
    print("  TEST: TestQueryVnicStatus - positive test 1")
    netVnicList = networkSystem.networkInfo.vnic
    for netVnic in netVnicList:
        print("   %s" % netVnic.GetDevice())
        iscsiMatch = 0

        for vmhba in vmhbaList:
            iscsiVnicList = iscsiManager.QueryBoundVnics(vmhba)
            for iscsiVnic in iscsiVnicList:
                if netVnic.GetDevice() == iscsiVnic.vnicDevice:
                    iscsiMatch = 1
                    break
            if iscsiMatch == 1:
                break

        iscsiStatus = iscsiManager.QueryVnicStatus(netVnic.GetDevice())
        if loglevel >= 1:
            print("*** IscsiStatus = %s" % iscsiStatus)

        found = 0
        for faultCode in iscsiStatus.reason:
            if loglevel >= 1:
                print("*** reason = %s" % faultCode)

            if (isinstance(faultCode, Vim.Fault.IscsiFaultVnicInUse)):
                found = 1

        if found == 1:
            if iscsiMatch == 1:
                print("    --- PASS ---")
            else:
                print("    --- FAIL ---")
        else:
            if iscsiMatch == 1:
                print("    --- FAIL ---")
            else:
                print("    --- PASS ---")
Beispiel #12
0
def FindPGroup(si, pgName):
    '''
      Find a port group in the NetworkSystem.
      This exercises the properties of the NetworkSystem MO, also.
   '''
    networkInfo = host.GetHostSystem(
        si).GetConfigManager().GetNetworkSystem().networkInfo
    pgroups = networkInfo.GetPortgroup()
    for portgroup in pgroups:
        if portgroup.GetSpec().GetName() == pgName:
            return portgroup
    return None
Beispiel #13
0
def FindVSwitch(si, vsName):
    '''
      Find a virtual switch in the NetworkSystem.
      This exercises the properties of the NetworkSystem MO, also.
   '''
    networkInfo = host.GetHostSystem(
        si).GetConfigManager().GetNetworkSystem().networkInfo
    vswitches = networkInfo.GetVswitch()
    for vswitch in vswitches:
        if vswitch.name == vsName:
            return vswitch
    return None
Beispiel #14
0
 def GetDS(self, dsName=None):
     dsList = host.GetHostSystem(self._si).GetDatastore()
     if len(dsList) == 0:
         return None
     if dsName is None:
         return dsList[0]
     for item in dsList:
         try:
             if item.GetSummary().GetName() == dsName:
                 return item
         except Vmodl.Fault.ManagedObjectNotFound:
             pass
     return None
Beispiel #15
0
def TestUpdateVirtualSwitch(si, options):
    print("Testing update virtual switch")
    networkSystem = host.GetHostSystem(si).GetConfigManager().networkSystem

    #TestUpdateVirtualSwitch: Setup
    vsSpec = vim.host.VirtualSwitch.Specification(mtu=1500, numPorts=100)
    print("Adding virtual switch %s with 100 ports and MTU=1500" %
          (options.vsName))
    networkSystem.AddVirtualSwitch(vswitchName=options.vsName, spec=vsSpec)

    print("Test 1: Updating the virtual switch to 150 ports and MTU=1000")
    vsNewSpec = vim.host.VirtualSwitch.Specification(mtu=1280, numPorts=150)
    networkSystem.UpdateVirtualSwitch(vswitchName=options.vsName,
                                      spec=vsNewSpec)
    vswitch = FindVSwitch(si, options.vsName)
    if not vswitch:
        raise Exception("Virtual switch not found in NetworkInfo")
    if not ValidateVirtualSwitchSpec(vsNewSpec, vswitch.GetSpec()):
        raise Exception("Virtual switch spec doesn't match runtime")
    print("Test 1: Updating the virtual switch: PASS")

    print("Test 2: Updating non-existent virtual switch")
    try:
        # Using this name, because TestAddVirtualSwitch guarantees that it can not be created
        networkSystem.UpdateVirtualSwitch(
            vswitchName="123456789012345678901234567890123", spec=vsSpec)
        print("Test 2: Updating non-existent virtual switch: FAILED")
    except vim.fault.NotFound as e:
        print(
            "Test 2: Updating non-existent virtual switch failed with vim.fault.NotFound as expected: PASS"
        )
    else:
        raise Exception(
            "Updating non-existent virtual switch didn't fail as expected")

    print("Test 3: Updating virtual switch with wrong values")
    try:
        vsNewSpec = vim.host.VirtualSwitch.Specification(
            mtu=1,  # minimum is 1280
            numPorts=150)
        networkSystem.UpdateVirtualSwitch(vswitchName=options.vsName,
                                          spec=vsNewSpec)
        print("Test 3: Updating virtual switch with wrong values: FAILED")
    except vim.fault.PlatformConfigFault as e:
        print(
            "Test 3: Updating virtual switch with wrong values failed with vim.fault.PlatformConfigFault as expected: PASS"
        )
    else:
        raise Exception(
            "Updating virtual switch with wrong values didn't fail as expected"
        )
Beispiel #16
0
def TestVmknics(si, uuid):
    # Add vmknic to a latebinding portgroup with binding on host.
    networkSystem = host.GetHostSystem(si).GetConfigManager().networkSystem
    ipCfg = GenerateIPConfig("1.1.1.2")
    dvPort = Vim.Dvs.PortConnection(portgroupKey = "pg1",
                 switchUuid = uuid)
    spec = Vim.Host.VirtualNic.Specification(ip = ipCfg,
               distributedVirtualPort = dvPort)
    try:
        vmknic = networkSystem.AddVirtualNic("", spec)
    except Exception:
        print("Failed to add a vmknic to a ephemeral portgroup")
        raise
    print("Test 1: Add a vmknic to a ephemeral portgroup: PASS")

    # Edit vmknic to bind to a latebinding portgroup.
    dvPort = Vim.Dvs.PortConnection(portgroupKey = "pg3",
                 switchUuid = uuid)
    spec = Vim.Host.VirtualNic.Specification(ip = ipCfg,
               distributedVirtualPort = dvPort)
    try:
        networkSystem.UpdateVirtualNic(vmknic, spec)
    except Exception:
        print("Failed to reconnect a vmknic to a latebinding portgroup")
        raise
    print("Test 2: Reconnect a vmknic to a latebinding portgroup: PASS")

    # Edit vmknic to bind to a port that exists.
    dvPort = Vim.Dvs.PortConnection(portKey = "1000",
                 connectionCookie = 5,
                 switchUuid = uuid)
    spec = Vim.Host.VirtualNic.Specification(ip = ipCfg,
               distributedVirtualPort = dvPort)
    try:
        networkSystem.UpdateVirtualNic(vmknic, spec)
    except Exception:
        print("Failed to reconnect a vmknic to a dvPort")
        raise
    print("Test 3: Reconnect a vmknic to a dvPort: PASS")

    # Edit vmknic to bind to an early binding portgroup. This should fail.
    dvPort = Vim.Dvs.PortConnection(portgroupKey = "pg2",
                 switchUuid = uuid)
    spec = Vim.Host.VirtualNic.Specification(ip = ipCfg,
               distributedVirtualPort = dvPort)
    try:
        networkSystem.UpdateVirtualNic(vmknic, spec)
    except Exception:
        print("Test 4: Reconnect a vmknic to an earlybinding portgroup: PASS")
    CleanupVmknic(networkSystem, vmknic)
    return
Beispiel #17
0
def GetParams(hostName, userName, password):
    try:
        siHost = Connect(host=hostName,
                         user=userName,
                         pwd=password,
                         version="vim.version.version9")
    except vim.fault.HostConnectFault as e:
        Log("Failed to connect to %s" % hostName)
        raise

    atexit.register(Disconnect, siHost)
    hostSystem = host.GetHostSystem(siHost)
    advOpts = hostSystem.configManager.advancedOption
    return siHost, hostSystem, advOpts
Beispiel #18
0
def AttachPnic(si, name, pnic):
    """
    Attach a pnic to the vswitch
    """
    networkSystem = host.GetHostSystem(si).configManager.networkSystem
    bondBridge = Vim.Host.VirtualSwitch.BondBridge(nicDevice=[pnic])
    spec = Vim.Host.VirtualSwitch.Specification(numPorts=128,
                                                bridge=bondBridge)
    vswitchConfig = Vim.Host.VirtualSwitch.Config(changeOperation="edit",
                                                  name=name,
                                                  spec=spec)
    netCfg = Vim.Host.NetworkConfig()
    netCfg.vswitch.append(vswitchConfig)
    vnicList = networkSystem.UpdateNetworkConfig(netCfg, "modify")
Beispiel #19
0
def HostdMemSize(si):
    # Get hostd virtual memory size in KB
    # Note: This indirectly test the SystemDebugManager, and PyVmomiServer code
    #       used by SystemDebugManager
    hostSystem = host.GetHostSystem(si)
    internalCfgMgr = hostSystem.RetrieveInternalConfigManager()
    if not internalCfgMgr.systemDebugManager:
        return 0

    procInfos = internalCfgMgr.systemDebugManager.QueryProcessInfo()
    for procInfo in procInfos:
        if procInfo.processKey == 'hostd':
            return procInfo.virtualMemSize
    return 0
Beispiel #20
0
    def setUp(self):
        """
      Setting test suite
      """
        global vsi
        import vmware.vsi as vsi

        options = get_options()

        self.si = SmartConnect(host=self.options.host,
                               user=self.options.user,
                               pwd=self.options.password)
        self.hostSystem = host.GetHostSystem(self.si)
        self.nvdimmSystem = self.hostSystem.GetConfigManager().GetNvdimmSystem(
        )
Beispiel #21
0
def GetParams(hostName, userName, password):
    try:
        siHost = Connect(host=hostName,
                         user=userName,
                         pwd=password,
                         version="vim.version.version9")
    except vim.fault.HostConnectFault:
        Log("Failed to connect to %s" % hostName)
        raise

    atexit.register(Disconnect, siHost)
    perfManager = siHost.RetrieveContent().perfManager
    hostSystem = host.GetHostSystem(siHost)
    hbrManager = siHost.RetrieveInternalContent().hbrManager
    return siHost, perfManager, hostSystem, hbrManager
Beispiel #22
0
def GetDatastore(si, name):
    """
    Returns the non-UUID datastore name for the supplied name.

    The supplied name is a string that specifies the datastore.  It is
    either a UUID or non-UUID name.  This function will do the
    conversion from UUID to non-UUID name if necessary, as well as
    validate that the datastore actually exists.
    """

    hs = host.GetHostSystem(si)
    datastores = hs.GetDatastore()
    name = name.replace('/vmfs/volumes/', '')
    for ds in datastores:
        if (ds.name == name
                or ds.info.url.replace('/vmfs/volumes/', '') == name):
            return ds.name
    raise Exception('Error looking up datastore: %s' % name)
Beispiel #23
0
def CleanupVswitchSetup(si, name, vnicName):
    """
    Cleanup the vswitch test setup
    """
    networkSystem = host.GetHostSystem(si).configManager.networkSystem
    vswitchConfig = Vim.Host.VirtualSwitch.Config(changeOperation="remove",
                                                  name=name)
    pgSpec = Vim.Host.PortGroup.Specification(name=name,
                                              policy=Vim.Host.NetworkPolicy(),
                                              vswitchName=name)
    pgConfig = Vim.Host.PortGroup.Config(changeOperation="remove", spec=pgSpec)
    vnicConfig = Vim.Host.VirtualNic.Config(changeOperation="remove",
                                            device=vnicName)
    netCfg = Vim.Host.NetworkConfig()
    netCfg.vswitch.append(vswitchConfig)
    netCfg.portgroup.append(pgConfig)
    netCfg.vnic.append(vnicConfig)
    vnicList = networkSystem.UpdateNetworkConfig(netCfg, "modify")
    print("Cleaned up setup")
Beispiel #24
0
def TestRemovePortGroup(si, options):
    '''
      Test NetworkSystem.removePortGroup.
      Check for possible exceptions.
   '''

    print("Testing vim.host.NetworkSystem.removePortGroup")
    networkSystem = host.GetHostSystem(si).GetConfigManager().networkSystem
    # Setup
    networkSystem.AddVirtualSwitch(vswitchName=options.vsName)
    spec = vim.host.PortGroup.Specification(name=options.pgName,
                                            vlanId=0,
                                            vswitchName=options.vsName,
                                            policy=vim.host.NetworkPolicy())
    networkSystem.AddPortGroup(portgrp=spec)

    print("Test1: Removing port group " + options.pgName)
    networkSystem.RemovePortGroup(options.pgName)
    print("Test1: Remove port group: PASS")
Beispiel #25
0
def TestUpdatePortGroup(si, options):
    print("Testing update port group")
    networkSystem = host.GetHostSystem(si).GetConfigManager().networkSystem

    # Setup
    networkSystem.AddVirtualSwitch(vswitchName=options.vsName)

    spec = vim.host.PortGroup.Specification(name=options.pgName,
                                            vlanId=0,
                                            vswitchName=options.vsName,
                                            policy=vim.host.NetworkPolicy())
    networkSystem.AddPortGroup(portgrp=spec)

    newName = options.pgName + "2"
    print("Test1: Try updating port group " + options.pgName +
          " in virtual switch " + options.vsName)
    newSpec = vim.host.PortGroup.Specification(name=newName,
                                               vlanId=1,
                                               vswitchName=options.vsName,
                                               policy=CreateNetworkPolicy())
    networkSystem.UpdatePortGroup(pgName=options.pgName, portgrp=newSpec)
    portgroup = FindPGroup(si, newName)
    if not portgroup:
        raise Exception("Unable to find the port group in the network info")
    if not ValidatePortGroupSpec(newSpec, portgroup):
        raise Exception("Port group spec doesn't match runtime")
    print("Test1: Updating port group: PASS")

    print("Test 2: Updating non-existent port group")
    try:
        # Using this name, because TestAddVirtualSwitch guarantees that it can not be created
        networkSystem.UpdatePortGroup(pgName=options.pgName + "3",
                                      portgrp=newSpec)
        print("Test 2: Updating non-existent port group: FAILED")
    except vim.fault.NotFound as e:
        print(
            "Test 2: Updating non-existent port group failed with vim.fault.NotFound as expected: PASS"
        )
    else:
        raise Exception(
            "Updating non-existent port group didn't fail as expected")
Beispiel #26
0
def TestQueryBoundVnics(si, vmhbaList):
    print("TESTCASE: TestQueryBoundVnics")

    iscsiManager = host.GetHostSystem(si).GetConfigManager().iscsiManager
    """ POSITIVE TEST 1 - Get validate vmhba's bound vnic """
    print("  TEST: TestQueryBoundVnics - positive test 1")
    for vmhba in vmhbaList:
        vnics = iscsiManager.QueryBoundVnics(vmhba)
        for vnic in vnics:
            print("    %s -> %s", (vmhba, vnic.vnicDevice))
            if loglevel >= 1:
                print("*** IscsiPortInfo = %s" % vnic)
        print("    --- PASS ---")
    """ NEGATIVE TEST 1 - Get invalidate vmhba's bound vnic """
    print("  TEST: TestQueryBoundVnics - negative test 1")
    bad_adapter = "blah"
    try:
        vnics = iscsiManager.QueryBoundVnics(bad_adapter)
        print("    --- FAIL ---")
    except Exception:
        print("    --- PASS ---")
Beispiel #27
0
def TestUpdateNetworkConfigPnicsExtended(si, uuid, pnicList):
    # Test to verify if nic ordering is working correctly.
    # Generate three pnicSpecs.
    # 1 - No portgroup or port specified.
    # 2 - Portgroup specified.
    # 3 - Port specified.
    print("Test updateNetwork config for multiple uplinks")
    networkSystem = host.GetHostSystem(si).GetConfigManager().networkSystem
    op = "modify"
    UnlinkPnics(networkSystem, uuid)
    pnicSpec1 = Vim.Dvs.HostMember.PnicSpec(pnicDevice = pnicList[0])
    pnicSpec2 = Vim.Dvs.HostMember.PnicSpec(pnicDevice = pnicList[1],
                    uplinkPortgroupKey = "pg5")
    pnicSpec3 = Vim.Dvs.HostMember.PnicSpec(pnicDevice = pnicList[2],
                    uplinkPortKey = "3")
    pnicBacking = Vim.Dvs.HostMember.PnicBacking(pnicSpec = [pnicSpec1, pnicSpec2, pnicSpec3])
    spec = Vim.Host.HostProxySwitch.Specification(backing = pnicBacking)
    proxyCfg = Vim.Host.HostProxySwitch.Config(changeOperation = "edit",
                                               spec = spec,
                                               uuid = uuid)
    netCfg = Vim.Host.NetworkConfig()
    netCfg.GetProxySwitch().append(proxyCfg)
    try:
        result = networkSystem.UpdateNetworkConfig(netCfg, op)
    except Exception:
        print("Test 1: Caught exception suitable pnic unavailable: FAIL")
        raise
    print("Test 1: Add 3 nics: PASS")

    UnlinkPnics(networkSystem, uuid)
    pnicBacking = Vim.Dvs.HostMember.PnicBacking(pnicSpec = [pnicSpec1, pnicSpec2, pnicSpec3])
    proxyCfg.GetSpec().SetBacking(pnicBacking)
    netCfg = Vim.Host.NetworkConfig()
    netCfg.GetProxySwitch().append(proxyCfg)
    try:
        result = networkSystem.UpdateNetworkConfig(netCfg, op)
    except Exception:
        print("Test 2: Caught exception suitable pnic unavailable: FAIL")
        raise
    print("Test 2: Add 3 nics in different order: PASS")
Beispiel #28
0
def TestDerivedNetworkPolicy(si, options):
    print("Testing derived NetworkPolicy for portgroup")
    networkSystem = host.GetHostSystem(si).GetConfigManager().networkSystem

    #TestDerivedNetworkPolicy AddVirtualSwitch
    vsSpec = vim.host.VirtualSwitch.Specification(mtu=1500,
                                                  numPorts=100,
                                                  policy=CreateNetworkPolicy())
    print("Test 1: Adding virtual switch %s with policy: %s" %
          (options.vsName, str(vsSpec.GetPolicy())))
    networkSystem.AddVirtualSwitch(vswitchName=options.vsName, spec=vsSpec)

    #TestDerivedNetworkPolicy AddPortGroup
    pgSpec = vim.host.PortGroup.Specification(
        name=options.pgName,
        vlanId=0,
        vswitchName=options.vsName,
        policy=vim.host.NetworkPolicy(
            nicTeaming=vim.host.NetworkPolicy.NicTeamingPolicy(
                failureCriteria=vim.host.NetworkPolicy.NicFailureCriteria()),
            security=vim.host.NetworkPolicy.SecurityPolicy(),
            shapingPolicy=vim.host.NetworkPolicy.TrafficShapingPolicy(),
            offloadPolicy=vim.host.NetOffloadCapabilities()))
    print("Test 1: Adding port group " + options.pgName +
          " to virtual switch " + options.vsName)
    networkSystem.AddPortGroup(pgSpec)

    #TestDerivedNetworkPolicy GetnetworkInfo
    portgroup = FindPGroup(si, options.pgName)
    if not portgroup:
        raise Exception("Unable to find the port group in the network info")

    if not ValidateNetworkPolicy(vsSpec.GetPolicy(),
                                 portgroup.GetComputedPolicy()):
        raise Exception(
            "Portgroup with derived NetworkPolicy config doesn't match runtime"
        )
    print(
        "Test 1: Portgroup with derived NetworkPolicy config matches runtime: PASS"
    )
Beispiel #29
0
def main(argv):
    """
    Test does the following.
    - Creates a DVS.
      Creates a dvport and an uplink port
      Verifies mac management policy scenarios
    """
    global options
    options = get_options()
    dvsUuidList = []
    transactionIndex = 0
    global pnicList
    pnicList = GetPnics(options.nic)
    global si
    si = SmartConnect(host=options.host,
                      user=options.user,
                      pwd=options.password)
    atexit.register(Disconnect, si)
    if (options.vmName == None):
        options.vmName = "testVM"
    networkSystem = host.GetHostSystem(si).GetConfigManager().networkSystem
    networkSystem.Refresh()
    try:
        print("cleaning up")
        cleanup(None)
    except Exception as e:
        print(e)
        print("checked for vm from previous run")
    try:
        TestMacManagementProp()
    except Exception as e:
        print("Got exception during execution")
        print(e)
        traceback.print_exc()
        cleanup(dvsUuidList)
        return -1
    cleanup(dvsUuidList)
    print("DONE.")
    return 0
Beispiel #30
0
def TestAddVirtualSwitch(si, options):
    '''
      Test NetworkSystem.addVirtualSwitch.
      Check for possible exceptions.
   '''

    print("Testing vim.host.NetworkSystem.addVirtualSwitch")

    networkSystem = host.GetHostSystem(si).GetConfigManager().networkSystem

    print("Test1: Adding virtual switch " + options.vsName)
    networkSystem.AddVirtualSwitch(vswitchName=options.vsName)
    if not FindVSwitch(si, options.vsName):
        raise Exception("Unable to find the switch in the network info")
    print("Test1: Adding virtual switch: PASS")

    print("Test2: Adding virtual switch " + options.vsName + " again")
    try:
        networkSystem.AddVirtualSwitch(vswitchName=options.vsName)
        print("Test2: Adding virtual switch again: FAILED")
    except vim.fault.AlreadyExists as e:
        print(
            "Test2: Adding virtual switch again failed with vim.fault.AlreadyExists as expected: PASS"
        )
    else:
        raise Exception("Create duplicate vswitch didn't fail as expected")

    print("Test3: Adding virtual switch with name too big")
    try:
        # vswitchName with 33 characters - according to Vmodl maximum is 32
        networkSystem.AddVirtualSwitch(
            vswitchName="123456789012345678901234567890123")
        print("Test3: Adding virtual switch: FAILED")
    except vmodl.fault.InvalidArgument as e:
        print(
            "Test3: Adding virtual switch failed with vim.fault.InvalidArgument as expected: PASS"
        )
    else:
        raise Exception("Didn't fail as expected")