Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test_sub_port_l2_forwarding] [test issue] TypeError: a bytes-like object is required, not 'str' #7884

Closed
AharonMalkin opened this issue Mar 28, 2023 · 1 comment · Fixed by #8096
Assignees

Comments

@AharonMalkin
Copy link
Contributor

Description
test sub_port_interfaces/test_sub_port_l2_forwarding.py fail over python3 issue:
TypeError: a bytes-like object is required, not 'str'

Steps to reproduce the issue:
run test_sub_port_l2_forwarding.py

Describe the results you received:

def test_sub_port_l2_forwarding(apply_config_on_the_dut, duthosts, rand_one_dut_hostname, test_sub_port,
                                    generate_eth_packets, testbed_params, ptfadapter):
        """Verify sub port doesn't have L2 forwarding capability."""
    
        @contextlib.contextmanager
        def check_no_cpu_packets(duthost, port, packet_fingerprint):
            start_pcap = "tcpdump -i %s -w %s" % (port, PACKET_SAVE_PATH)
            stop_pcap = "pkill -f '%s'" % start_pcap
            start_pcap = "nohup %s &" % start_pcap
    
            duthost.shell(start_pcap)
            try:
                yield
            finally:
                time.sleep(1.0)
                duthost.shell(stop_pcap, module_ignore_errors=True)
    
            with tempfile.NamedTemporaryFile() as tmp_pcap:
                duthost.fetch(src=PACKET_SAVE_PATH, dest=tmp_pcap.name, flat=True)
                received_packets = sniff(offline=tmp_pcap.name)
    
            logging.debug("Packets received from port %s:", port)
            for i, pkt in enumerate(received_packets):
                logging.debug("%d: %s" % (i, utilities.dump_scapy_packet_show_output(pkt)))
    
            packets_with_fingerprint = [_ for _ in received_packets if packet_fingerprint in str(_)]
            pytest_assert(len(packets_with_fingerprint) == 0, "Received packets with fingerprint %s" % packet_fingerprint)
    
        def verify_no_packet_received(ptfadapter, ports, packet_fingerprint):
            for port in ports:
                for packet, _ in ptfadapter.dataplane.packet_queues[(0, port)]:
                    if packet_fingerprint in packet:
                        logging.error("Received packet with fingerprint '%s' on port %s: %s\n", port, packet_fingerprint,
                                      packet)
                        pytest.fail("Received packet on port %s" % port)
    
        duthost = duthosts[rand_one_dut_hostname]
        packets = generate_eth_packets
        ptf_ports_to_check = list(set(_["neighbor_ptf_index"] for _ in list(testbed_params.values())))
        ptfadapter.dataplane.flush()
        for packet in packets:
            with check_no_cpu_packets(duthost, test_sub_port, PACKET_PAYLOAD_FINGERPRINT):
                testutils.send(ptfadapter, testbed_params[test_sub_port]["neighbor_ptf_index"], packet, count=PACKET_COUNT)
                time.sleep(TIME_WAIT_AFTER_SENDING_PACKET)
>               verify_no_packet_received(ptfadapter, ptf_ports_to_check, PACKET_PAYLOAD_FINGERPRINT)
def verify_no_packet_received(ptfadapter, ports, packet_fingerprint):
        for port in ports:
            for packet, _ in ptfadapter.dataplane.packet_queues[(0, port)]:
>               if packet_fingerprint in packet:
E               TypeError: a bytes-like object is required, not 'str'

Describe the results you expected:
test passes without test issues

Additional information you deem important:

Output of show version:

SONiC Software Version: SONiC.202211_RC8.3-696a6a43b_Internal
Distribution: Debian 11.6
Kernel: 5.10.0-18-2-amd64
Build commit: 696a6a43b
Build date: Mon Mar 27 10:50:51 UTC 2023
Built by: sw-r2d2-bot@r-build-sonic-ci03-244

Platform: x86_64-mlnx_msn3800-r0
HwSKU: Mellanox-SN3800-D112C8
ASIC: mellanox
ASIC Count: 1
Serial Number: MT2208X03840
Model Number: MSN3800-CS2FOS
Hardware Revision: A3
Uptime: 13:38:54 up 14 min,  2 users,  load average: 1.35, 1.48, 1.00
Date: Tue 28 Mar 2023 13:38:54

Docker images:
REPOSITORY                                         TAG                               IMAGE ID       SIZE
docker-orchagent                                   202211_RC8.3-696a6a43b_Internal   84055ebb4c77   539MB
docker-orchagent                                   latest                            84055ebb4c77   539MB
docker-fpm-frr                                     202211_RC8.3-696a6a43b_Internal   83d5f57abddb   550MB
docker-fpm-frr                                     latest                            83d5f57abddb   550MB
docker-teamd                                       202211_RC8.3-696a6a43b_Internal   e6b58409a5c6   520MB
docker-teamd                                       latest                            e6b58409a5c6   520MB
docker-macsec                                      latest                            d76f633dda63   522MB
docker-syncd-mlnx                                  202211_RC8.3-696a6a43b_Internal   2bd090589266   939MB
docker-syncd-mlnx                                  latest                            2bd090589266   939MB
docker-platform-monitor                            202211_RC8.3-696a6a43b_Internal   4fcfc27b9bbe   942MB
docker-platform-monitor                            latest                            4fcfc27b9bbe   942MB
docker-sonic-telemetry                             202211_RC8.3-696a6a43b_Internal   be9f9e750657   802MB
docker-sonic-telemetry                             latest                            be9f9e750657   802MB
docker-snmp                                        202211_RC8.3-696a6a43b_Internal   62432cf85f40   549MB
docker-snmp                                        latest                            62432cf85f40   549MB
docker-eventd                                      202211_RC8.3-696a6a43b_Internal   855b7c3d7218   503MB
docker-eventd                                      latest                            855b7c3d7218   503MB
docker-dhcp-relay                                  latest                            c90d1c5967eb   513MB
docker-lldp                                        202211_RC8.3-696a6a43b_Internal   e33be345d3f2   546MB
docker-lldp                                        latest                            e33be345d3f2   546MB
docker-mux                                         202211_RC8.3-696a6a43b_Internal   e9f6fa7ef277   552MB
docker-mux                                         latest                            e9f6fa7ef277   552MB
docker-database                                    202211_RC8.3-696a6a43b_Internal   9cae58961a25   503MB
docker-database                                    latest                            9cae58961a25   503MB
docker-sonic-p4rt                                  202211_RC8.3-696a6a43b_Internal   77b20e5b758d   586MB
docker-sonic-p4rt                                  latest                            77b20e5b758d   586MB
docker-router-advertiser                           202211_RC8.3-696a6a43b_Internal   f3a99688e9df   503MB
docker-router-advertiser                           latest                            f3a99688e9df   503MB
docker-sflow                                       202211_RC8.3-696a6a43b_Internal   780973343beb   479MB
docker-sflow                                       latest                            780973343beb   479MB
docker-nat                                         202211_RC8.3-696a6a43b_Internal   83454bb6925c   481MB
docker-nat                                         latest                            83454bb6925c   481MB
docker-sonic-mgmt-framework                        202211_RC8.3-696a6a43b_Internal   20cfc12ab3c5   612MB
docker-sonic-mgmt-framework                        latest                            20cfc12ab3c5   612MB
@AharonMalkin AharonMalkin changed the title [test_sub_port_l2_forwarding] [test issue] a bytes-like object is required, not 'str' [test_sub_port_l2_forwarding] [test issue] TypeError: a bytes-like object is required, not 'str' Mar 28, 2023
@wsycqyz
Copy link
Contributor

wsycqyz commented Apr 20, 2023

Working on it

@wsycqyz wsycqyz self-assigned this Apr 20, 2023
wsycqyz added a commit that referenced this issue Apr 21, 2023
Summary:
Fixes #7884 [test_sub_port_l2_forwarding] [test issue] TypeError: a bytes-like object is required, not 'str'

What is the motivation for this PR?
test sub_port_interfaces/test_sub_port_l2_forwarding.py fail over python3 issue:
TypeError: a bytes-like object is required, not 'str'

How did you do it?
In Python3, a string cannot work with bytes
Use str to convert bytes to string

How did you verify/test it?
The change can work both in Python2 and Python3.
wangxin pushed a commit that referenced this issue Jun 15, 2023
Fix the issues: #7866 and #7884

What is the motivation for this PR?
Fix the test failure caused by python3 migration

How did you verify/test it?
Run qos sai and test_sub_port_l2_forwarding, and it could pass
mrkcmo pushed a commit to Azarack/sonic-mgmt that referenced this issue Oct 3, 2023
Fix the issues: sonic-net#7866 and sonic-net#7884

What is the motivation for this PR?
Fix the test failure caused by python3 migration

How did you verify/test it?
Run qos sai and test_sub_port_l2_forwarding, and it could pass
AharonMalkin pushed a commit to AharonMalkin/sonic-mgmt that referenced this issue Jan 25, 2024
Summary:
Fixes sonic-net#7884 [test_sub_port_l2_forwarding] [test issue] TypeError: a bytes-like object is required, not 'str'

What is the motivation for this PR?
test sub_port_interfaces/test_sub_port_l2_forwarding.py fail over python3 issue:
TypeError: a bytes-like object is required, not 'str'

How did you do it?
In Python3, a string cannot work with bytes
Use str to convert bytes to string

How did you verify/test it?
The change can work both in Python2 and Python3.
AharonMalkin pushed a commit to AharonMalkin/sonic-mgmt that referenced this issue Jan 25, 2024
Fix the issues: sonic-net#7866 and sonic-net#7884

What is the motivation for this PR?
Fix the test failure caused by python3 migration

How did you verify/test it?
Run qos sai and test_sub_port_l2_forwarding, and it could pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants