Skip to content
Snippets Groups Projects
Commit 86c99019 authored by Georgios Katsikas's avatar Georgios Katsikas
Browse files

fix: broken P4 tests

parent d73a9156
No related branches found
No related tags found
1 merge request!54Release 2.0.0
...@@ -44,7 +44,7 @@ class P4Driver(_Driver): ...@@ -44,7 +44,7 @@ class P4Driver(_Driver):
transport port number of the P4Runtime server running on the P4 device transport port number of the P4Runtime server running on the P4 device
**settings : map **settings : map
id : int id : int
P4 device ID (Mandatory) P4 device datapath ID (Mandatory)
name : str name : str
P4 device name (Optional) P4 device name (Optional)
vendor : str vendor : str
......
...@@ -17,9 +17,10 @@ P4 device example configuration. ...@@ -17,9 +17,10 @@ P4 device example configuration.
""" """
from common.tools.object_factory.ConfigRule import json_config_rule_set from common.tools.object_factory.ConfigRule import json_config_rule_set
from common.tools.object_factory.Device import json_device_p4_disabled from common.tools.object_factory.Device import (
json_device_connect_rules, json_device_id, json_device_p4_disabled)
DEVICE_P4_ID = 0 DEVICE_P4_DPID = 0
DEVICE_P4_NAME = 'device:leaf1' DEVICE_P4_NAME = 'device:leaf1'
DEVICE_P4_ADDRESS = '127.0.0.1' DEVICE_P4_ADDRESS = '127.0.0.1'
DEVICE_P4_PORT = '50101' DEVICE_P4_PORT = '50101'
...@@ -29,21 +30,22 @@ DEVICE_P4_SW_VER = 'Stratum' ...@@ -29,21 +30,22 @@ DEVICE_P4_SW_VER = 'Stratum'
DEVICE_P4_PIPECONF = 'org.onosproject.pipelines.fabric' DEVICE_P4_PIPECONF = 'org.onosproject.pipelines.fabric'
DEVICE_P4_WORKERS = 2 DEVICE_P4_WORKERS = 2
DEVICE_P4_GRACE_PERIOD = 60 DEVICE_P4_GRACE_PERIOD = 60
DEVICE_P4_TIMEOUT = 60
DEVICE_P4_UUID = {'device_uuid': {'uuid': DEVICE_P4_NAME}} DEVICE_P4_UUID = DEVICE_P4_NAME
DEVICE_P4_ID = json_device_id(DEVICE_P4_UUID)
DEVICE_P4 = json_device_p4_disabled(DEVICE_P4_UUID) DEVICE_P4 = json_device_p4_disabled(DEVICE_P4_UUID)
DEVICE_P4_CONNECT_RULES = [ DEVICE_P4_CONNECT_RULES = json_device_connect_rules(
json_config_rule_set('_connect/address', DEVICE_P4_ADDRESS), DEVICE_P4_ADDRESS, DEVICE_P4_PORT, {
json_config_rule_set('_connect/port', DEVICE_P4_PORT), 'id': DEVICE_P4_DPID,
json_config_rule_set('_connect/settings', { 'name': DEVICE_P4_NAME,
'id' : int(DEVICE_P4_ID), 'hw-ver': DEVICE_P4_HW_VER,
'name' : DEVICE_P4_NAME, 'sw-ver': DEVICE_P4_SW_VER,
'hw-ver' : DEVICE_P4_HW_VER, 'pipeconf': DEVICE_P4_PIPECONF,
'sw-ver' : DEVICE_P4_SW_VER, 'timeout': DEVICE_P4_TIMEOUT
'pipeconf': DEVICE_P4_PIPECONF }
}), )
]
DEVICE_P4_CONFIG_RULES = [ DEVICE_P4_CONFIG_RULES = [
json_config_rule_set('key1', 'value1'), json_config_rule_set('key1', 'value1'),
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import pytest import pytest
from device.service.drivers.p4.p4_driver import P4Driver from device.service.drivers.p4.p4_driver import P4Driver
from .device_p4 import( from .device_p4 import(
DEVICE_P4_ADDRESS, DEVICE_P4_PORT, DEVICE_P4_ID, DEVICE_P4_NAME, DEVICE_P4_ADDRESS, DEVICE_P4_PORT, DEVICE_P4_DPID, DEVICE_P4_NAME,
DEVICE_P4_VENDOR, DEVICE_P4_HW_VER, DEVICE_P4_SW_VER, DEVICE_P4_VENDOR, DEVICE_P4_HW_VER, DEVICE_P4_SW_VER,
DEVICE_P4_PIPECONF, DEVICE_P4_WORKERS, DEVICE_P4_GRACE_PERIOD) DEVICE_P4_PIPECONF, DEVICE_P4_WORKERS, DEVICE_P4_GRACE_PERIOD)
from .mock_p4runtime_service import MockP4RuntimeService from .mock_p4runtime_service import MockP4RuntimeService
...@@ -37,7 +37,7 @@ def device_driverapi_p4(): ...@@ -37,7 +37,7 @@ def device_driverapi_p4():
_driver = P4Driver( _driver = P4Driver(
address=DEVICE_P4_ADDRESS, address=DEVICE_P4_ADDRESS,
port=DEVICE_P4_PORT, port=DEVICE_P4_PORT,
id=DEVICE_P4_ID, id=DEVICE_P4_DPID,
name=DEVICE_P4_NAME, name=DEVICE_P4_NAME,
vendor=DEVICE_P4_VENDOR, vendor=DEVICE_P4_VENDOR,
hw_ver=DEVICE_P4_HW_VER, hw_ver=DEVICE_P4_HW_VER,
......
...@@ -81,7 +81,7 @@ except ImportError: ...@@ -81,7 +81,7 @@ except ImportError:
#ENABLE_EMULATED = False # set to False to disable tests of Emulated devices #ENABLE_EMULATED = False # set to False to disable tests of Emulated devices
#ENABLE_OPENCONFIG = False # set to False to disable tests of OpenConfig devices #ENABLE_OPENCONFIG = False # set to False to disable tests of OpenConfig devices
#ENABLE_TAPI = False # set to False to disable tests of TAPI devices #ENABLE_TAPI = False # set to False to disable tests of TAPI devices
ENABLE_P4 = False # set to False to disable tests of P4 devices (P4 device not available in GitLab) #ENABLE_P4 = False # set to False to disable tests of P4 devices
ENABLE_OPENCONFIG_CONFIGURE = True ENABLE_OPENCONFIG_CONFIGURE = True
ENABLE_OPENCONFIG_MONITOR = True ENABLE_OPENCONFIG_MONITOR = True
...@@ -917,7 +917,8 @@ def test_device_p4_add_error_cases( ...@@ -917,7 +917,8 @@ def test_device_p4_add_error_cases(
device_client: DeviceClient, # pylint: disable=redefined-outer-name device_client: DeviceClient, # pylint: disable=redefined-outer-name
device_service: DeviceService): # pylint: disable=redefined-outer-name device_service: DeviceService): # pylint: disable=redefined-outer-name
if not ENABLE_P4: pytest.skip('Skipping test: No P4 device has been configured') if not ENABLE_P4: pytest.skip(
'Skipping test: No P4 device has been configured')
with pytest.raises(grpc.RpcError) as e: with pytest.raises(grpc.RpcError) as e:
device_p4_with_extra_rules = copy.deepcopy(DEVICE_P4) device_p4_with_extra_rules = copy.deepcopy(DEVICE_P4)
...@@ -940,13 +941,14 @@ def test_device_p4_add_correct( ...@@ -940,13 +941,14 @@ def test_device_p4_add_correct(
device_service: DeviceService, # pylint: disable=redefined-outer-name device_service: DeviceService, # pylint: disable=redefined-outer-name
p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name
if not ENABLE_P4: pytest.skip('Skipping test: No P4 device has been configured') if not ENABLE_P4: pytest.skip(
'Skipping test: No P4 device has been configured')
device_p4_with_connect_rules = copy.deepcopy(DEVICE_P4) device_p4_with_connect_rules = copy.deepcopy(DEVICE_P4)
device_p4_with_connect_rules['device_config']['config_rules'].extend( device_p4_with_connect_rules['device_config']['config_rules'].extend(
DEVICE_P4_CONNECT_RULES) DEVICE_P4_CONNECT_RULES)
device_client.AddDevice(Device(**device_p4_with_connect_rules)) device_client.AddDevice(Device(**device_p4_with_connect_rules))
driver : _Driver = device_service.driver_instance_cache.get(DEVICE_P4_NAME) driver : _Driver = device_service.driver_instance_cache.get(DEVICE_P4_UUID)
assert driver is not None assert driver is not None
...@@ -956,13 +958,14 @@ def test_device_p4_get( ...@@ -956,13 +958,14 @@ def test_device_p4_get(
device_service: DeviceService, # pylint: disable=redefined-outer-name device_service: DeviceService, # pylint: disable=redefined-outer-name
p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name
if not ENABLE_P4: pytest.skip('Skipping test: No P4 device has been configured') if not ENABLE_P4: pytest.skip(
'Skipping test: No P4 device has been configured')
initial_config = device_client.GetInitialConfig(DeviceId(**DEVICE_P4_UUID)) initial_config = device_client.GetInitialConfig(DeviceId(**DEVICE_P4_ID))
LOGGER.info('initial_config = {:s}'.format( LOGGER.info('initial_config = {:s}'.format(
grpc_message_to_json_string(initial_config))) grpc_message_to_json_string(initial_config)))
device_data = context_client.GetDevice(DeviceId(**DEVICE_P4_UUID)) device_data = context_client.GetDevice(DeviceId(**DEVICE_P4_ID))
LOGGER.info('device_data = {:s}'.format( LOGGER.info('device_data = {:s}'.format(
grpc_message_to_json_string(device_data))) grpc_message_to_json_string(device_data)))
...@@ -972,6 +975,10 @@ def test_device_p4_configure( ...@@ -972,6 +975,10 @@ def test_device_p4_configure(
device_client: DeviceClient, # pylint: disable=redefined-outer-name device_client: DeviceClient, # pylint: disable=redefined-outer-name
device_service: DeviceService, # pylint: disable=redefined-outer-name device_service: DeviceService, # pylint: disable=redefined-outer-name
p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name
if not ENABLE_P4: pytest.skip(
'Skipping test: No P4 device has been configured')
pytest.skip('Skipping test for unimplemented method') pytest.skip('Skipping test for unimplemented method')
...@@ -980,6 +987,10 @@ def test_device_p4_deconfigure( ...@@ -980,6 +987,10 @@ def test_device_p4_deconfigure(
device_client: DeviceClient, # pylint: disable=redefined-outer-name device_client: DeviceClient, # pylint: disable=redefined-outer-name
device_service: DeviceService, # pylint: disable=redefined-outer-name device_service: DeviceService, # pylint: disable=redefined-outer-name
p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name
if not ENABLE_P4: pytest.skip(
'Skipping test: No P4 device has been configured')
pytest.skip('Skipping test for unimplemented method') pytest.skip('Skipping test for unimplemented method')
...@@ -991,6 +1002,6 @@ def test_device_p4_delete( ...@@ -991,6 +1002,6 @@ def test_device_p4_delete(
if not ENABLE_P4: pytest.skip('Skipping test: No P4 device has been configured') if not ENABLE_P4: pytest.skip('Skipping test: No P4 device has been configured')
device_client.DeleteDevice(DeviceId(**DEVICE_P4_UUID)) device_client.DeleteDevice(DeviceId(**DEVICE_P4_ID))
driver : _Driver = device_service.driver_instance_cache.get(DEVICE_P4_NAME) driver : _Driver = device_service.driver_instance_cache.get(DEVICE_P4_UUID)
assert driver is None assert driver is None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment