Exemplo n.º 1
0
 def __handleMellanoxDut(self):
     '''
     Handle Mellanox DUT reboot when upgrading from SONiC-OS-201803 to SONiC-OS-201811
     '''
     if self.newSonicImage is not None and \
        self.rebootType == 'fast-reboot' and \
        isMellanoxDevice(self.duthost):
         logger.info('Handle Mellanox platform')
         nextImage = self.duthost.shell('sonic_installer list | grep Next | cut -f2 -d " "')['stdout']
         if 'SONiC-OS-201803' in self.currentImage and 'SONiC-OS-201811' in nextImage:
             self.__runScript(['upgrade_mlnx_fw.sh'], self.duthost)
Exemplo n.º 2
0
def get_vxlan_srcport_range_enabled(duthost):
    if not isMellanoxDevice(duthost):
        return False
    dut_platform = duthost.facts["platform"]
    dut_hwsku = duthost.facts["hwsku"]
    sai_profile = "/usr/share/sonic/device/%s/%s/sai.profile" % (dut_platform,
                                                                 dut_hwsku)
    cmd = "grep SAI_VXLAN_SRCPORT_RANGE_ENABLE {} | cut -d'=' -f2".format(
        sai_profile)
    vxlan_srcport_range_enabled = duthost.shell(cmd)["stdout"].strip() == "1"

    return vxlan_srcport_range_enabled
Exemplo n.º 3
0
    def dutConfig(self, request, duthosts, rand_one_dut_hostname):
        """
            Build DUT host config pertaining to QoS SAI tests

            Args:
                request (Fixture): pytest request object
                duthost (AnsibleHost): Device Under Test (DUT)

            Returns:
                dutConfig (dict): Map of DUT config containing dut interfaces, test port IDs, test port IPs, and
                    test ports
        """
        duthost = duthosts[rand_one_dut_hostname]
        dutLagInterfaces = []
        mgFacts = duthost.minigraph_facts(
            host=duthost.hostname)["ansible_facts"]

        for _, lag in mgFacts["minigraph_portchannels"].items():
            for intf in lag["members"]:
                dutLagInterfaces.append(
                    mgFacts["minigraph_port_indices"][intf])

        testPortIds = set(mgFacts["minigraph_port_indices"][port]
                          for port in mgFacts["minigraph_ports"].keys())
        testPortIds -= set(dutLagInterfaces)
        if isMellanoxDevice(duthost):
            # The last port is used for up link from DUT switch
            testPortIds -= {len(mgFacts["minigraph_port_indices"]) - 1}
        testPortIds = sorted(testPortIds)

        # get current DUT port IPs
        dutPortIps = {}
        for portConfig in mgFacts["minigraph_interfaces"]:
            if ipaddress.ip_interface(portConfig['peer_addr']).ip.version == 4:
                portIndex = mgFacts["minigraph_port_indices"][
                    portConfig["attachto"]]
                if portIndex in testPortIds:
                    dutPortIps.update({portIndex: portConfig["peer_addr"]})

        testPortIps = self.__assignTestPortIps(mgFacts)
        # restore currently assigned IPs
        testPortIps.update(dutPortIps)

        testPorts = self.__buildTestPorts(request, testPortIds, testPortIps)
        yield {
            "dutInterfaces": {
                index: port
                for port, index in mgFacts["minigraph_port_indices"].items()
            },
            "testPortIds": testPortIds,
            "testPortIps": testPortIps,
            "testPorts": testPorts,
        }
Exemplo n.º 4
0
def fake_storm(request, duthosts, rand_one_dut_hostname):
    """
    Enable/disable fake storm based on platform and input parameters

    Args:
        request: pytest request object
        duthosts: AnsibleHost instance for multi DUT
        rand_one_dut_hostname: hostname of DUT

    Returns:
        fake_storm: False/True
    """
    duthost = duthosts[rand_one_dut_hostname]
    return request.config.getoption('--fake-storm') if not isMellanoxDevice(duthost) else False
Exemplo n.º 5
0
    def disablePacketAging(self, duthost, stopServices):
        """
            disable packet aging on DUT host

            Args:
                duthost (AnsibleHost): Device Under Test (DUT)
                stopServices (Fxiture): stopServices fixture is required to run prior to disabling packet aging

            Returns:
                None
        """
        if isMellanoxDevice(duthost):
            logger.info("Disable Mellanox packet aging")
            duthost.copy(src="qos/files/mellanox/packets_aging.py", dest="/tmp")
            duthost.command("docker cp /tmp/packets_aging.py syncd:/")
            duthost.command("docker exec syncd python /packets_aging.py disable")

        yield

        if isMellanoxDevice(duthost):
            logger.info("Enable Mellanox packet aging")
            duthost.command("docker exec syncd python /packets_aging.py enable")
            duthost.command("docker exec syncd rm -rf /packets_aging.py")
Exemplo n.º 6
0
def enable_packet_aging(duthost):
    """
    Enable packet aging feature (only on MLNX switches)

    Args:
        duthost (AnsibleHost): Device Under Test (DUT)

    Returns:
        N/A
    """
    if isMellanoxDevice(duthost):
        duthost.copy(src="qos/files/mellanox/packets_aging.py", dest="/tmp")
        duthost.command("docker cp /tmp/packets_aging.py syncd:/")
        duthost.command("docker exec syncd python /packets_aging.py enable")
        duthost.command("docker exec syncd rm -rf /packets_aging.py")
Exemplo n.º 7
0
    def dutQosConfig(self, duthosts, enum_frontend_asic_index,
                     rand_one_dut_hostname, dutConfig, ingressLosslessProfile,
                     ingressLossyProfile, egressLosslessProfile,
                     egressLossyProfile, sharedHeadroomPoolSize, tbinfo):
        """
            Prepares DUT host QoS configuration

            Args:
                duthost (AnsibleHost): Device Under Test (DUT)
                ingressLosslessProfile (Fxiture): ingressLosslessProfile fixture is required to run prior to collecting
                    QoS configuration

            Returns:
                QoSConfig (dict): Map containing DUT host QoS configuration
        """
        duthost = duthosts[rand_one_dut_hostname]
        dut_asic = duthost.asic_instance(enum_frontend_asic_index)
        mgFacts = duthost.get_extended_minigraph_facts(tbinfo)
        pytest_assert("minigraph_hwsku" in mgFacts, "Could not find DUT SKU")

        profileName = ingressLosslessProfile["profileName"]
        if self.isBufferInApplDb(dut_asic):
            profile_pattern = "^BUFFER_PROFILE_TABLE\:pg_lossless_(.*)_profile$"
        else:
            profile_pattern = "^BUFFER_PROFILE\|pg_lossless_(.*)_profile"
        m = re.search(profile_pattern, profileName)
        pytest_assert(m.group(1), "Cannot find port speed/cable length")

        portSpeedCableLength = m.group(1)

        qosConfigs = {}
        with open(r"qos/files/qos.yml") as file:
            qosConfigs = yaml.load(file, Loader=yaml.FullLoader)

        vendor = duthost.facts["asic_type"]
        hostvars = duthost.host.options['variable_manager']._hostvars[
            duthost.hostname]
        dutAsic = None
        for asic in self.SUPPORTED_ASIC_LIST:
            vendorAsic = "{0}_{1}_hwskus".format(vendor, asic)
            if vendorAsic in hostvars.keys(
            ) and mgFacts["minigraph_hwsku"] in hostvars[vendorAsic]:
                dutAsic = asic
                break

        pytest_assert(dutAsic, "Cannot identify DUT ASIC type")

        if isMellanoxDevice(duthost):
            current_file_dir = os.path.dirname(os.path.realpath(__file__))
            sub_folder_dir = os.path.join(current_file_dir, "files/mellanox/")
            if sub_folder_dir not in sys.path:
                sys.path.append(sub_folder_dir)
            import qos_param_generator
            qpm = qos_param_generator.QosParamMellanox(
                qosConfigs['qos_params']['mellanox'], dutAsic,
                portSpeedCableLength, dutConfig, ingressLosslessProfile,
                ingressLossyProfile, egressLosslessProfile, egressLossyProfile,
                sharedHeadroomPoolSize)
            qosParams = qpm.run()
        else:
            qosParams = qosConfigs['qos_params'][dutAsic]

        yield {
            "param": qosParams,
            "portSpeedCableLength": portSpeedCableLength,
        }
Exemplo n.º 8
0
    def dutConfig(self, request, duthosts, rand_one_dut_hostname, tbinfo,
                  enum_frontend_asic_index):
        """
            Build DUT host config pertaining to QoS SAI tests

            Args:
                request (Fixture): pytest request object
                duthost (AnsibleHost): Device Under Test (DUT)

            Returns:
                dutConfig (dict): Map of DUT config containing dut interfaces,
                test port IDs, test port IPs, and test ports
        """
        duthost = duthosts[rand_one_dut_hostname]
        dut_asic = duthost.asic_instance(enum_frontend_asic_index)
        dutLagInterfaces = []
        dutPortIps = {}
        testPortIps = {}

        mgFacts = duthost.get_extended_minigraph_facts(tbinfo)
        topo = tbinfo["topo"]["name"]

        testPortIds = []
        # LAG ports in T1 TOPO need to be removed in Mellanox devices
        if topo in self.SUPPORTED_T0_TOPOS or isMellanoxDevice(duthost):
            pytest_assert(not duthost.sonichost.is_multi_asic,
                          "Fixture not supported on T0 multi ASIC")
            for _, lag in mgFacts["minigraph_portchannels"].items():
                for intf in lag["members"]:
                    dutLagInterfaces.append(
                        mgFacts["minigraph_ptf_indices"][intf])

            testPortIds = set(mgFacts["minigraph_ptf_indices"][port]
                              for port in mgFacts["minigraph_ports"].keys())
            testPortIds -= set(dutLagInterfaces)
            if isMellanoxDevice(duthost):
                # The last port is used for up link from DUT switch
                testPortIds -= {len(mgFacts["minigraph_ptf_indices"]) - 1}
            testPortIds = sorted(testPortIds)

            # get current DUT port IPs
            dutPortIps = {}
            for portConfig in mgFacts["minigraph_interfaces"]:
                if ipaddress.ip_interface(
                        portConfig['peer_addr']).ip.version == 4:
                    portIndex = mgFacts["minigraph_ptf_indices"][
                        portConfig["attachto"]]
                    if portIndex in testPortIds:
                        dutPortIps.update({portIndex: portConfig["peer_addr"]})

            testPortIps = self.__assignTestPortIps(mgFacts)

        elif topo in self.SUPPORTED_T1_TOPOS:
            for iface, addr in dut_asic.get_active_ip_interfaces().items():
                if iface.startswith("Ethernet"):
                    portIndex = mgFacts["minigraph_ptf_indices"][iface]
                    dutPortIps.update({portIndex: addr["peer_ipv4"]})
                elif iface.startswith("PortChannel"):
                    portName = next(
                        iter(mgFacts["minigraph_portchannels"][iface]
                             ["members"]))
                    portIndex = mgFacts["minigraph_ptf_indices"][portName]
                    dutPortIps.update({portIndex: addr["peer_ipv4"]})

            testPortIds = sorted(dutPortIps.keys())
        else:
            raise Exception("Unsupported testbed type - {}".format(topo))

        # restore currently assigned IPs
        testPortIps.update(dutPortIps)

        testPorts = self.__buildTestPorts(request, testPortIds, testPortIps)
        yield {
            "dutInterfaces": {
                index: port
                for port, index in mgFacts["minigraph_ptf_indices"].items()
            },
            "testPortIds": testPortIds,
            "testPortIps": testPortIps,
            "testPorts": testPorts,
        }
def ptf_params(duthost, creds, tbinfo, upgrade_type):

    reboot_command = get_reboot_command(duthost, upgrade_type)
    if duthost.facts['platform'] == 'x86_64-kvm_x86_64-r0':
        reboot_limit_in_seconds = 200
    elif 'warm-reboot' in reboot_command:
        if isMellanoxDevice(duthost):
            reboot_limit_in_seconds = 1
        else:
            reboot_limit_in_seconds = 0
    else:
        reboot_limit_in_seconds = 30

    mg_facts = duthost.get_extended_minigraph_facts(tbinfo)
    lo_v6_prefix = ""
    for intf in mg_facts["minigraph_lo_interfaces"]:
        ipn = ipaddr.IPNetwork(intf['addr'])
        if ipn.version == 6:
            lo_v6_prefix = str(
                ipaddr.IPNetwork(intf['addr'] + '/64').network) + '/64'
            break

    mgFacts = duthost.get_extended_minigraph_facts(tbinfo)
    vm_hosts = [
        attr['mgmt_addr']
        for dev, attr in mgFacts['minigraph_devices'].items()
        if attr['hwsku'] == 'Arista-VM'
    ]
    sonicadmin_alt_password = duthost.host.options[
        'variable_manager']._hostvars[duthost.hostname].get(
            "ansible_altpassword")
    vlan_ip_range = dict()
    for vlan in mgFacts['minigraph_vlan_interfaces']:
        if type(ipaddress.ip_network(vlan['subnet'])) is ipaddress.IPv4Network:
            vlan_ip_range[vlan['attachto']] = vlan['subnet']
    ptf_params = {
        "verbose":
        False,
        "dut_username":
        creds.get('sonicadmin_user'),
        "dut_password":
        creds.get('sonicadmin_password'),
        "alt_password":
        sonicadmin_alt_password,
        "dut_hostname":
        duthost.host.options['inventory_manager'].get_host(
            duthost.hostname).vars['ansible_host'],
        "reboot_limit_in_seconds":
        reboot_limit_in_seconds,
        "reboot_type":
        reboot_command,
        "portchannel_ports_file":
        TMP_VLAN_PORTCHANNEL_FILE,
        "vlan_ports_file":
        TMP_VLAN_FILE,
        "ports_file":
        TMP_PORTS_FILE,
        "dut_mac":
        duthost.facts["router_mac"],
        "default_ip_range":
        "192.168.100.0/18",
        "vlan_ip_range":
        json.dumps(vlan_ip_range),
        "lo_v6_prefix":
        lo_v6_prefix,
        "arista_vms":
        vm_hosts,
        "setup_fdb_before_test":
        True,
        "target_version":
        "Unknown"
    }
    return ptf_params