kytos-ng / of_core

Kytos Main OpenFlow Network Application (NApp)
MIT License
0 stars 5 forks source link

Introduce or reuse an exception when trying to get a `Flow` object from dict given an unregistered Experimenter Action #105

Open viniarck opened 1 year ago

viniarck commented 1 year ago

Currently, it's expected that the supported experimenter actions is properly registered, which our kytos-ng/noviflow, does correctly.

However, if either a new experimenter action is introduced in the future and it's incorrectly registered, of_core isn't gracefully raising a different exception, making it harder for clients like flow_manager to capture this. Some methods from of_core ActionFactoryBase they might also fail open so leaving room for consistency check problems since it'll incorrectly don't install an action. So, having this a bit more explicitly to fail at least when it comes to the serialization is probably better.

For instance, here's an example of a mistaken registered action:

2023-02-23 16:19:31,304 - ERROR [kytos.core.controller] (Thread-92) Exception on /api/kytos/flow_manager/v2/flows/00:00:00:00:00:00:00:01 [POST]
Traceback (most recent call last):
  File "/home/viniarck/repos/kytos/.direnv/python-3.9.15/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/viniarck/repos/kytos/.direnv/python-3.9.15/lib/python3.9/site-packages/flask/app.py", line 1519, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/viniarck/repos/kytos/.direnv/python-3.9.15/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/viniarck/repos/kytos/.direnv/python-3.9.15/lib/python3.9/site-packages/flask/app.py", line 1517, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/viniarck/repos/kytos/.direnv/python-3.9.15/lib/python3.9/site-packages/flask/app.py", line 1503, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/viniarck/repos/napps/napps/kytos/flow_manager/main.py", line 558, in add
    return self._send_flow_mods_from_request(dpid, "add")
  File "/home/viniarck/repos/napps/napps/kytos/flow_manager/main.py", line 621, in _send_flow_mods_from_request
    self._install_flows(command, flows_dict, [switch], reraise_conn=not force)
  File "/home/viniarck/repos/napps/napps/kytos/flow_manager/main.py", line 651, in _install_flows
    flow = serializer.from_dict(flow_dict, switch)
  File "/home/viniarck/repos/napps/napps/kytos/of_core/v0x04/flow.py", line 375, in from_dict
    action = cls._action_factory.from_dict(action_dict)
  File "/home/viniarck/repos/napps/napps/kytos/of_core/flow.py", line 331, in from_dict
    action_class = cls._action_class[action_type]
KeyError: 'push_int'