From ae890c1e1d6e1d3e6805487b819a47e1483c45ad Mon Sep 17 00:00:00 2001 From: Tamer Ahmed Date: Thu, 16 Apr 2020 18:38:07 -0700 Subject: [PATCH 1/4] [pytest] Add support to populate DUT FDB entries This new PTF plugin and test case that populates DUT FDb entries. It generates n Packets and sends them to DUT vlan IP. The number of distinct MAC to distinct ip addresses is configurable. signed-off-by: Tamer Ahmed --- .../roles/test/files/ptftests/populate_fdb.py | 173 ++++++++++++++++++ tests/fdb/args/__init__.py | 0 tests/fdb/args/populate_fdb_args.py | 35 ++++ tests/fdb/conftest.py | 14 ++ tests/fdb/test_populate_fdb.py | 126 +++++++++++++ 5 files changed, 348 insertions(+) create mode 100644 ansible/roles/test/files/ptftests/populate_fdb.py create mode 100644 tests/fdb/args/__init__.py create mode 100644 tests/fdb/args/populate_fdb_args.py create mode 100644 tests/fdb/test_populate_fdb.py diff --git a/ansible/roles/test/files/ptftests/populate_fdb.py b/ansible/roles/test/files/ptftests/populate_fdb.py new file mode 100644 index 0000000000..2f91144fb5 --- /dev/null +++ b/ansible/roles/test/files/ptftests/populate_fdb.py @@ -0,0 +1,173 @@ +import ipaddress +import json +import logging +import ptf + +# Packet Test Framework imports +import ptf +import ptf.packet as scapy +import ptf.testutils as testutils +from ptf import config +from ptf.base_tests import BaseTest + +logger = logging.getLogger(__name__) + +class PopulateFdb(BaseTest): + ''' + Populate DUT FDB entries + ''' + TCP_DST_PORT = 5000 + TCP_SRC_PORT = 6000 + + def __init__(self): + ''' + class constructor + + Args: + None + + Returns: + None + ''' + BaseTest.__init__(self) + + def setUp(self): + ''' + Sets up Populate FDB instance data + + Args: + None + + Returns: + None + ''' + self.dataplane = ptf.dataplane_instance + self.dataplane.flush() + + self.testParams = testutils.test_params_get() + self.packetCount = self.testParams['packet_count'] + self.startMac = self.testParams['start_mac'] + + self.configFile = self.testParams['config_data'] + with open(self.configFile) as fp: + self.configData = json.load(fp) + + self.dutMac = self.configData['dut_mac'] + self.macToIpRatio = [int(i) for i in self.testParams['mac_to_ip_ratio'].split(':')] + self.assertTrue( + len(self.macToIpRatio) == 2 and self.macToIpRatio[0] > 0 and self.macToIpRatio[1] > 0, + 'Invalid MAC to IP ratio: {0}'.format(self.testParams['mac_to_ip_ratio']) + ) + + if config["log_dir"] is not None: + filename = os.path.join(config["log_dir"], str(self)) + ".pcap" + self.dataplane.start_pcap(filename) + + def tearDown(self): + ''' + Tears down FDB instance data + + Args: + None + + Returns: + None + ''' + if config["log_dir"] is not None: + self.dataplane.stop_pcap() + + def __convertMacToInt(self, mac): + ''' + Converts MAC address to integer + + Args: + mac (str): MAC Address + + Returns: + mac (int): integer representation of MAC address + ''' + return int(mac.translate(None, ":.- "), 16) + + def __convertMacToStr(self, mac): + ''' + Converts MAC address to string + + Args: + mac (int): MAC Address + + Returns: + mac (str): string representation of MAC address + ''' + mac = "{:012x}".format(mac) + return ":".join(mac[i : i + 2] for i in range(0, len(mac), 2)) + + def __prepareVmIp(self): + ''' + Prepares VM IP addresses + + Args: + None + + Returns: + vmIp (dict): Map containing vlan to VM IP address + ''' + vmIp = {} + for vlan, config in self.configData['vlan_interfaces'].items(): + prefixLen = self.configData['vlan_interfaces'][vlan]['prefixlen'] + ipCount = 2**(32 - prefixLen) - 3 + numDistinctIp = self.packetCount * self.macToIpRatio[1] / self.macToIpRatio[0] + self.assertTrue( + ipCount >= numDistinctIp, + 'Vlan network \'{0}\' does not support the requested number of IPs \'{1}\''.format( + ipCount, + numDistinctIp + ) + ) + vmIp[vlan] = ipaddress.ip_address(unicode(config['addr'])) + 1 + + return vmIp + + def __populateDutFdb(self): + ''' + Populates DUT FDB entries + + Args: + None + + Returns: + None + ''' + packet = testutils.simple_tcp_packet( + eth_dst=self.dutMac, + tcp_sport=self.TCP_SRC_PORT, + tcp_dport=self.TCP_DST_PORT + ) + vmIp = self.__prepareVmIp() + macInt = self.__convertMacToInt(self.startMac) + numMac = numIp = 0 + for i in range(self.packetCount): + port = i % len(self.configData['vlan_ports']) + vlan = self.configData['vlan_ports'][port]['vlan'] + + if i % self.macToIpRatio[1] == 0: + mac = self.__convertMacToStr(macInt + i) + numMac += 1 + if i % self.macToIpRatio[0] == 0: + vmIp[vlan] = ipaddress.ip_address(unicode(vmIp[vlan])) + 1 + numIp += 1 + + packet[scapy.Ether].src = mac + packet[scapy.IP].src = str(vmIp[vlan]) + packet[scapy.IP].dst = self.configData['vlan_interfaces'][vlan]['addr'] + testutils.send(self, self.configData['vlan_ports'][port]['index'], packet) + + logger.info( + 'Generated {0} packets with distinct {1} MAC addresses and {2} IP addresses'.format( + self.packetCount, + numMac, + numIp + ) + ) + + def runTest(self): + self.__populateDutFdb() diff --git a/tests/fdb/args/__init__.py b/tests/fdb/args/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/fdb/args/populate_fdb_args.py b/tests/fdb/args/populate_fdb_args.py new file mode 100644 index 0000000000..153ae5654b --- /dev/null +++ b/tests/fdb/args/populate_fdb_args.py @@ -0,0 +1,35 @@ +# Populate FDB Args file + +def add_populate_fdb_args(parser): + ''' + Adding arguments required for populate fdb test cases + + Args: + parser: pytest parser object + + Returns: + None + ''' + parser.addoption( + '--mac_to_ip_ratio', + action='store', + type=str, + default='100:1', + help='VM MAC to IP assigned ratio', + ) + + parser.addoption( + '--start_mac', + action='store', + type=str, + default='00:25:ae:22:11:00', + help='VM start MAC address. Subsequent MAC addresses are increment of 1 on top of start MAC', + ) + + parser.addoption( + '--packet_count', + action='store', + type=int, + default=2000, + help='Number of packets to be created and sent to DUT', + ) diff --git a/tests/fdb/conftest.py b/tests/fdb/conftest.py index e69de29bb2..1304ba91be 100644 --- a/tests/fdb/conftest.py +++ b/tests/fdb/conftest.py @@ -0,0 +1,14 @@ +from args.populate_fdb_args import add_populate_fdb_args + +# FDB pytest arguments +def pytest_addoption(parser): + ''' + Adds option to FDB pytest + + Args: + parser: pytest parser object + + Returns: + None + ''' + add_populate_fdb_args(parser) diff --git a/tests/fdb/test_populate_fdb.py b/tests/fdb/test_populate_fdb.py new file mode 100644 index 0000000000..41cc86ae80 --- /dev/null +++ b/tests/fdb/test_populate_fdb.py @@ -0,0 +1,126 @@ +import json +import logging +import pytest + +from common.platform.ssh_utils import prepare_testbed_ssh_keys as prepareTestbedSshKeys +from ptf_runner import ptf_runner + +logger = logging.getLogger(__name__) + +# Globals +PTFRUNNER_QLEN = 1000 +VXLAN_CONFIG_FILE = '/tmp/vxlan_config.json' + +class TestPopulateFdb: + ''' + TestPopulateFdb populates DUT FDB entries + ''' + @pytest.fixture(scope='class', autouse=True) + def prepareVxlanConfigData(self, duthost, ptfhost): + ''' + Prepares Vxlan Configuration data + + Args: + duthost (AnsibleHost): Device Under Test (DUT) + ptfhost (AnsibleHost): Packet Test Framework (PTF) + + Returns: + None + ''' + mgVlanPorts = [] + mgFacts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] + for vlan, config in mgFacts['minigraph_vlans'].items(): + for port in config['members']: + mgVlanPorts.append({ + 'port': port, + 'vlan': vlan, + 'index': mgFacts['minigraph_port_indices'][port] + }) + + vxlanConfigData = { + 'vlan_ports': mgVlanPorts, + 'vlan_interfaces': {vlan['attachto']: vlan for vlan in mgFacts['minigraph_vlan_interfaces']}, + 'dut_mac': duthost.setup()['ansible_facts']['ansible_Ethernet0']['macaddress'] + } + + with open(VXLAN_CONFIG_FILE, 'w') as file: + file.write(json.dumps(vxlanConfigData, indent=4)) + + logger.info('Copying VxLan config file to {0}'.format(ptfhost.hostname)) + ptfhost.copy(src=VXLAN_CONFIG_FILE, dest='/tmp/') + + @pytest.fixture(scope='class', autouse=True) + def copyPtfDirectory(self, ptfhost): + ''' + Copys PTF directory to PTF host. This class-scope fixture runs once before test start + + Args: + ptfhost (AnsibleHost): Packet Test Framework (PTF) + + Returns: + None + ''' + ptfhost.copy(src="ptftests", dest="/root") + + @pytest.fixture(scope='class', autouse=True) + def removePtfhostIp(self, ptfhost): + ''' + Removes IP assigned to eth inerface of PTF host. This class-scope fixture runs once before test start + + Args: + ptfhost (AnsibleHost): Packet Test Framework (PTF) + + Returns: + None + ''' + ptfhost.script(src='scripts/remove_ip.sh') + + @pytest.fixture(scope='class', autouse=True) + def changePtfhostMacAddresses(self, ptfhost): + ''' + Change MAC addresses (unique) on PTF host. This class-scope fixture runs once before test start + + Args: + ptfhost (AnsibleHost): Packet Test Framework (PTF) + + Returns: + None + ''' + ptfhost.script(src="scripts/change_mac.sh") + + def testPopulateFdb(self, request, duthost, ptfhost): + ''' + Populates DUT FDB entries + + The accepts MAC to IP ratio (default 100:1) and packet count (default 2000). It generates packets with + ratio of distinct MAC addresses to distinct IP addresses as provided. The IP addresses starts from VLAN + address pool. + + Args: + request: pytest request object + duthost (AnsibleHost): Device Under Test (DUT) + ptfhost (AnsibleHost): Packet Test Framework (PTF) + + Returns: + None + ''' + macToIpRatio = request.config.getoption("--mac_to_ip_ratio") + startMac = request.config.getoption("--start_mac") + packetCount = request.config.getoption("--packet_count") + + logger.info('Populate DUT FDB entries') + ptf_runner( + ptfhost, + 'ptftests', + 'populate_fdb.PopulateFdb', + qlen=PTFRUNNER_QLEN, + platform_dir='ptftests', + platform='remote', + params={ + 'start_mac': startMac, + 'config_data': VXLAN_CONFIG_FILE, + 'packet_count': packetCount, + 'mac_to_ip_ratio': macToIpRatio, + }, + log_file='/tmp/populate_fdb.PopulateFdb.log' + ) From 720e141c5f05744c3b116a70e211ebe6c3105edf Mon Sep 17 00:00:00 2001 From: Tamer Ahmed Date: Tue, 28 Apr 2020 17:38:30 -0700 Subject: [PATCH 2/4] make populate fdb utility --- .../roles/test/files/ptftests/populate_fdb.py | 62 ++++---- tests/common/fixtures/populate_fdb.py | 120 ++++++++++++++++ tests/fdb/conftest.py | 5 +- tests/fdb/test_populate_fdb.py | 133 ++---------------- 4 files changed, 165 insertions(+), 155 deletions(-) create mode 100644 tests/common/fixtures/populate_fdb.py diff --git a/ansible/roles/test/files/ptftests/populate_fdb.py b/ansible/roles/test/files/ptftests/populate_fdb.py index 2f91144fb5..e43e66e9eb 100644 --- a/ansible/roles/test/files/ptftests/populate_fdb.py +++ b/ansible/roles/test/files/ptftests/populate_fdb.py @@ -13,14 +13,14 @@ logger = logging.getLogger(__name__) class PopulateFdb(BaseTest): - ''' + """ Populate DUT FDB entries - ''' + """ TCP_DST_PORT = 5000 TCP_SRC_PORT = 6000 def __init__(self): - ''' + """ class constructor Args: @@ -28,11 +28,11 @@ class constructor Returns: None - ''' + """ BaseTest.__init__(self) def setUp(self): - ''' + """ Sets up Populate FDB instance data Args: @@ -40,23 +40,23 @@ def setUp(self): Returns: None - ''' + """ self.dataplane = ptf.dataplane_instance self.dataplane.flush() self.testParams = testutils.test_params_get() - self.packetCount = self.testParams['packet_count'] - self.startMac = self.testParams['start_mac'] + self.packetCount = self.testParams["packet_count"] + self.startMac = self.testParams["start_mac"] - self.configFile = self.testParams['config_data'] + self.configFile = self.testParams["config_data"] with open(self.configFile) as fp: self.configData = json.load(fp) - self.dutMac = self.configData['dut_mac'] - self.macToIpRatio = [int(i) for i in self.testParams['mac_to_ip_ratio'].split(':')] + self.dutMac = self.configData["dut_mac"] + self.macToIpRatio = [int(i) for i in self.testParams["mac_to_ip_ratio"].split(':')] self.assertTrue( len(self.macToIpRatio) == 2 and self.macToIpRatio[0] > 0 and self.macToIpRatio[1] > 0, - 'Invalid MAC to IP ratio: {0}'.format(self.testParams['mac_to_ip_ratio']) + "Invalid MAC to IP ratio: {0}".format(self.testParams["mac_to_ip_ratio"]) ) if config["log_dir"] is not None: @@ -64,7 +64,7 @@ def setUp(self): self.dataplane.start_pcap(filename) def tearDown(self): - ''' + """ Tears down FDB instance data Args: @@ -72,12 +72,12 @@ def tearDown(self): Returns: None - ''' + """ if config["log_dir"] is not None: self.dataplane.stop_pcap() def __convertMacToInt(self, mac): - ''' + """ Converts MAC address to integer Args: @@ -85,11 +85,11 @@ def __convertMacToInt(self, mac): Returns: mac (int): integer representation of MAC address - ''' + """ return int(mac.translate(None, ":.- "), 16) def __convertMacToStr(self, mac): - ''' + """ Converts MAC address to string Args: @@ -97,12 +97,12 @@ def __convertMacToStr(self, mac): Returns: mac (str): string representation of MAC address - ''' + """ mac = "{:012x}".format(mac) return ":".join(mac[i : i + 2] for i in range(0, len(mac), 2)) def __prepareVmIp(self): - ''' + """ Prepares VM IP addresses Args: @@ -110,25 +110,25 @@ def __prepareVmIp(self): Returns: vmIp (dict): Map containing vlan to VM IP address - ''' + """ vmIp = {} - for vlan, config in self.configData['vlan_interfaces'].items(): - prefixLen = self.configData['vlan_interfaces'][vlan]['prefixlen'] + for vlan, config in self.configData["vlan_interfaces"].items(): + prefixLen = self.configData["vlan_interfaces"][vlan]["prefixlen"] ipCount = 2**(32 - prefixLen) - 3 numDistinctIp = self.packetCount * self.macToIpRatio[1] / self.macToIpRatio[0] self.assertTrue( ipCount >= numDistinctIp, - 'Vlan network \'{0}\' does not support the requested number of IPs \'{1}\''.format( + "Vlan network '{0}' does not support the requested number of IPs '{1}'".format( ipCount, numDistinctIp ) ) - vmIp[vlan] = ipaddress.ip_address(unicode(config['addr'])) + 1 + vmIp[vlan] = ipaddress.ip_address(unicode(config["addr"])) + 1 return vmIp def __populateDutFdb(self): - ''' + """ Populates DUT FDB entries Args: @@ -136,7 +136,7 @@ def __populateDutFdb(self): Returns: None - ''' + """ packet = testutils.simple_tcp_packet( eth_dst=self.dutMac, tcp_sport=self.TCP_SRC_PORT, @@ -146,8 +146,8 @@ def __populateDutFdb(self): macInt = self.__convertMacToInt(self.startMac) numMac = numIp = 0 for i in range(self.packetCount): - port = i % len(self.configData['vlan_ports']) - vlan = self.configData['vlan_ports'][port]['vlan'] + port = i % len(self.configData["vlan_ports"]) + vlan = self.configData["vlan_ports"][port]["vlan"] if i % self.macToIpRatio[1] == 0: mac = self.__convertMacToStr(macInt + i) @@ -158,11 +158,11 @@ def __populateDutFdb(self): packet[scapy.Ether].src = mac packet[scapy.IP].src = str(vmIp[vlan]) - packet[scapy.IP].dst = self.configData['vlan_interfaces'][vlan]['addr'] - testutils.send(self, self.configData['vlan_ports'][port]['index'], packet) + packet[scapy.IP].dst = self.configData["vlan_interfaces"][vlan]["addr"] + testutils.send(self, self.configData["vlan_ports"][port]["index"], packet) logger.info( - 'Generated {0} packets with distinct {1} MAC addresses and {2} IP addresses'.format( + "Generated {0} packets with distinct {1} MAC addresses and {2} IP addresses".format( self.packetCount, numMac, numIp diff --git a/tests/common/fixtures/populate_fdb.py b/tests/common/fixtures/populate_fdb.py new file mode 100644 index 0000000000..ccb24c3aed --- /dev/null +++ b/tests/common/fixtures/populate_fdb.py @@ -0,0 +1,120 @@ +import json +import logging +import pytest + +from common.platform.ssh_utils import prepare_testbed_ssh_keys as prepareTestbedSshKeys +from ptf_runner import ptf_runner + +logger = logging.getLogger(__name__) + +class PopulateFdb: + """ + PopulateFdb populates DUT FDB entries + + It accepts MAC to IP ratio (default 100:1) and packet count (default 2000). It generates packets with + ratio of distinct MAC addresses to distinct IP addresses as provided. The IP addresses starts from VLAN + address pool. + """ + PTFRUNNER_QLEN = 1000 + VLAN_CONFIG_FILE = "/tmp/vlan_config.json" + + def __init__(self, request, duthost, ptfhost): + """ + Class constructor + + Args: + request: pytest request object + duthost (AnsibleHost): Device Under Test (DUT) + ptfhost (AnsibleHost): Packet Test Framework (PTF) + + Returns: + None + """ + self.macToIpRatio = request.config.getoption("--mac_to_ip_ratio") + self.startMac = request.config.getoption("--start_mac") + self.packetCount = request.config.getoption("--packet_count") + + self.duthost = duthost + self.ptfhost = ptfhost + + def __prepareVlanConfigData(self): + """ + Prepares Vlan Configuration data + + Args: + duthost (AnsibleHost): Device Under Test (DUT) + ptfhost (AnsibleHost): Packet Test Framework (PTF) + + Returns: + None + """ + mgVlanPorts = [] + mgFacts = self.duthost.minigraph_facts(host=self.duthost.hostname)["ansible_facts"] + for vlan, config in mgFacts["minigraph_vlans"].items(): + for port in config["members"]: + mgVlanPorts.append({ + "port": port, + "vlan": vlan, + "index": mgFacts["minigraph_port_indices"][port] + }) + + vlanConfigData = { + "vlan_ports": mgVlanPorts, + "vlan_interfaces": {vlan["attachto"]: vlan for vlan in mgFacts["minigraph_vlan_interfaces"]}, + "dut_mac": self.duthost.setup()["ansible_facts"]["ansible_Ethernet0"]["macaddress"] + } + + with open(self.VLAN_CONFIG_FILE, 'w') as file: + file.write(json.dumps(vlanConfigData, indent=4)) + + logger.info("Copying VLan config file to {0}".format(self.ptfhost.hostname)) + self.ptfhost.copy(src=self.VLAN_CONFIG_FILE, dest="/tmp/") + + logger.info("Copying ptftests to {0}".format(self.ptfhost.hostname)) + self.ptfhost.copy(src="ptftests", dest="/root") + + def run(self): + """ + Populates DUT FDB entries + + Args: + None + + Returns: + None + """ + self.__prepareVlanConfigData() + + logger.info("Populate DUT FDB entries") + ptf_runner( + self.ptfhost, + "ptftests", + "populate_fdb.PopulateFdb", + qlen=self.PTFRUNNER_QLEN, + platform_dir="ptftests", + platform="remote", + params={ + "start_mac": self.startMac, + "config_data": self.VLAN_CONFIG_FILE, + "packet_count": self.packetCount, + "mac_to_ip_ratio": self.macToIpRatio, + }, + log_file="/tmp/populate_fdb.PopulateFdb.log" + ) + +@pytest.fixture +def populate_fdb(request, duthost, ptfhost): + """ + Populates DUT FDB entries + + Args: + request: pytest request object + duthost (AnsibleHost): Device Under Test (DUT) + ptfhost (AnsibleHost): Packet Test Framework (PTF) + + Returns: + None + """ + populateFdb = PopulateFdb(request, duthost, ptfhost) + + populateFdb.run() diff --git a/tests/fdb/conftest.py b/tests/fdb/conftest.py index 1304ba91be..71cf147fa7 100644 --- a/tests/fdb/conftest.py +++ b/tests/fdb/conftest.py @@ -1,8 +1,9 @@ from args.populate_fdb_args import add_populate_fdb_args +from common.fixtures.populate_fdb import populate_fdb # FDB pytest arguments def pytest_addoption(parser): - ''' + """ Adds option to FDB pytest Args: @@ -10,5 +11,5 @@ def pytest_addoption(parser): Returns: None - ''' + """ add_populate_fdb_args(parser) diff --git a/tests/fdb/test_populate_fdb.py b/tests/fdb/test_populate_fdb.py index 41cc86ae80..961aabd84a 100644 --- a/tests/fdb/test_populate_fdb.py +++ b/tests/fdb/test_populate_fdb.py @@ -1,126 +1,15 @@ -import json -import logging import pytest -from common.platform.ssh_utils import prepare_testbed_ssh_keys as prepareTestbedSshKeys -from ptf_runner import ptf_runner +def test_populate_fdb(populate_fdb): + """ + Populates DUT FDB entries -logger = logging.getLogger(__name__) + Args: + request: pytest request object + duthost (AnsibleHost): Device Under Test (DUT) + ptfhost (AnsibleHost): Packet Test Framework (PTF) -# Globals -PTFRUNNER_QLEN = 1000 -VXLAN_CONFIG_FILE = '/tmp/vxlan_config.json' - -class TestPopulateFdb: - ''' - TestPopulateFdb populates DUT FDB entries - ''' - @pytest.fixture(scope='class', autouse=True) - def prepareVxlanConfigData(self, duthost, ptfhost): - ''' - Prepares Vxlan Configuration data - - Args: - duthost (AnsibleHost): Device Under Test (DUT) - ptfhost (AnsibleHost): Packet Test Framework (PTF) - - Returns: - None - ''' - mgVlanPorts = [] - mgFacts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] - for vlan, config in mgFacts['minigraph_vlans'].items(): - for port in config['members']: - mgVlanPorts.append({ - 'port': port, - 'vlan': vlan, - 'index': mgFacts['minigraph_port_indices'][port] - }) - - vxlanConfigData = { - 'vlan_ports': mgVlanPorts, - 'vlan_interfaces': {vlan['attachto']: vlan for vlan in mgFacts['minigraph_vlan_interfaces']}, - 'dut_mac': duthost.setup()['ansible_facts']['ansible_Ethernet0']['macaddress'] - } - - with open(VXLAN_CONFIG_FILE, 'w') as file: - file.write(json.dumps(vxlanConfigData, indent=4)) - - logger.info('Copying VxLan config file to {0}'.format(ptfhost.hostname)) - ptfhost.copy(src=VXLAN_CONFIG_FILE, dest='/tmp/') - - @pytest.fixture(scope='class', autouse=True) - def copyPtfDirectory(self, ptfhost): - ''' - Copys PTF directory to PTF host. This class-scope fixture runs once before test start - - Args: - ptfhost (AnsibleHost): Packet Test Framework (PTF) - - Returns: - None - ''' - ptfhost.copy(src="ptftests", dest="/root") - - @pytest.fixture(scope='class', autouse=True) - def removePtfhostIp(self, ptfhost): - ''' - Removes IP assigned to eth inerface of PTF host. This class-scope fixture runs once before test start - - Args: - ptfhost (AnsibleHost): Packet Test Framework (PTF) - - Returns: - None - ''' - ptfhost.script(src='scripts/remove_ip.sh') - - @pytest.fixture(scope='class', autouse=True) - def changePtfhostMacAddresses(self, ptfhost): - ''' - Change MAC addresses (unique) on PTF host. This class-scope fixture runs once before test start - - Args: - ptfhost (AnsibleHost): Packet Test Framework (PTF) - - Returns: - None - ''' - ptfhost.script(src="scripts/change_mac.sh") - - def testPopulateFdb(self, request, duthost, ptfhost): - ''' - Populates DUT FDB entries - - The accepts MAC to IP ratio (default 100:1) and packet count (default 2000). It generates packets with - ratio of distinct MAC addresses to distinct IP addresses as provided. The IP addresses starts from VLAN - address pool. - - Args: - request: pytest request object - duthost (AnsibleHost): Device Under Test (DUT) - ptfhost (AnsibleHost): Packet Test Framework (PTF) - - Returns: - None - ''' - macToIpRatio = request.config.getoption("--mac_to_ip_ratio") - startMac = request.config.getoption("--start_mac") - packetCount = request.config.getoption("--packet_count") - - logger.info('Populate DUT FDB entries') - ptf_runner( - ptfhost, - 'ptftests', - 'populate_fdb.PopulateFdb', - qlen=PTFRUNNER_QLEN, - platform_dir='ptftests', - platform='remote', - params={ - 'start_mac': startMac, - 'config_data': VXLAN_CONFIG_FILE, - 'packet_count': packetCount, - 'mac_to_ip_ratio': macToIpRatio, - }, - log_file='/tmp/populate_fdb.PopulateFdb.log' - ) + Returns: + None + """ + pass From 39125eaaa3fe7e0e295f7439d0cefbfceaa48cb8 Mon Sep 17 00:00:00 2001 From: Tamer Ahmed Date: Tue, 28 Apr 2020 17:55:56 -0700 Subject: [PATCH 3/4] elaborating on __populateDutFdb method --- ansible/roles/test/files/ptftests/populate_fdb.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ansible/roles/test/files/ptftests/populate_fdb.py b/ansible/roles/test/files/ptftests/populate_fdb.py index e43e66e9eb..5899b41692 100644 --- a/ansible/roles/test/files/ptftests/populate_fdb.py +++ b/ansible/roles/test/files/ptftests/populate_fdb.py @@ -131,6 +131,9 @@ def __populateDutFdb(self): """ Populates DUT FDB entries + It accepts MAC to IP ratio and packet count. It generates packets withratio of distinct MAC addresses + to distinct IP addresses as provided. The IP addresses starts from VLAN address pool. + Args: None From 709b14d5f583afe525c66862ed574f0b891cae06 Mon Sep 17 00:00:00 2001 From: Tamer Ahmed Date: Wed, 29 Apr 2020 11:40:49 -0700 Subject: [PATCH 4/4] review comments move test_populate_fdb to testbed_seyup dir --- tests/common/fixtures/populate_fdb.py | 10 +++++++++- tests/{fdb => testbed_setup}/args/__init__.py | 0 tests/{fdb => testbed_setup}/args/populate_fdb_args.py | 2 +- tests/{fdb => testbed_setup}/conftest.py | 0 tests/{fdb => testbed_setup}/test_populate_fdb.py | 0 5 files changed, 10 insertions(+), 2 deletions(-) rename tests/{fdb => testbed_setup}/args/__init__.py (100%) rename tests/{fdb => testbed_setup}/args/populate_fdb_args.py (89%) rename tests/{fdb => testbed_setup}/conftest.py (100%) rename tests/{fdb => testbed_setup}/test_populate_fdb.py (100%) diff --git a/tests/common/fixtures/populate_fdb.py b/tests/common/fixtures/populate_fdb.py index ccb24c3aed..54aee84643 100644 --- a/tests/common/fixtures/populate_fdb.py +++ b/tests/common/fixtures/populate_fdb.py @@ -2,7 +2,6 @@ import logging import pytest -from common.platform.ssh_utils import prepare_testbed_ssh_keys as prepareTestbedSshKeys from ptf_runner import ptf_runner logger = logging.getLogger(__name__) @@ -14,6 +13,15 @@ class PopulateFdb: It accepts MAC to IP ratio (default 100:1) and packet count (default 2000). It generates packets with ratio of distinct MAC addresses to distinct IP addresses as provided. The IP addresses starts from VLAN address pool. + + Command line sample: + pytest testbed_setup/test_populate_fdb.py --testbed= --inventory= --testbed_file= \ + --host-pattern={|all} --module-path= --mac_to_ip_ratio=100:1 --packet_count=8000 + + where: + mac_to_ip_ratio: Ratio of distinct MAC addresses to distinct IP addresses assigned to VM + packet_count: Number of packets to be created and sent to DUT + start_mac: VM start MAC address. Subsequent MAC addresses are increment of 1 on top of start MAC """ PTFRUNNER_QLEN = 1000 VLAN_CONFIG_FILE = "/tmp/vlan_config.json" diff --git a/tests/fdb/args/__init__.py b/tests/testbed_setup/args/__init__.py similarity index 100% rename from tests/fdb/args/__init__.py rename to tests/testbed_setup/args/__init__.py diff --git a/tests/fdb/args/populate_fdb_args.py b/tests/testbed_setup/args/populate_fdb_args.py similarity index 89% rename from tests/fdb/args/populate_fdb_args.py rename to tests/testbed_setup/args/populate_fdb_args.py index 153ae5654b..7ca658505d 100644 --- a/tests/fdb/args/populate_fdb_args.py +++ b/tests/testbed_setup/args/populate_fdb_args.py @@ -15,7 +15,7 @@ def add_populate_fdb_args(parser): action='store', type=str, default='100:1', - help='VM MAC to IP assigned ratio', + help='Ratio of distinct MAC addresses to distinct IP addresses assigned to VM', ) parser.addoption( diff --git a/tests/fdb/conftest.py b/tests/testbed_setup/conftest.py similarity index 100% rename from tests/fdb/conftest.py rename to tests/testbed_setup/conftest.py diff --git a/tests/fdb/test_populate_fdb.py b/tests/testbed_setup/test_populate_fdb.py similarity index 100% rename from tests/fdb/test_populate_fdb.py rename to tests/testbed_setup/test_populate_fdb.py