kytos-ng / mef_eline

Kytos NApp to create and manage point-to-point L2 circuits
https://kytos-ng.github.io/api/mef_eline.html
MIT License
0 stars 8 forks source link

get_metadata("s_vlan").value, AttributeError: 'NoneType' object has no attribute 'value' #203

Closed viniarck closed 1 year ago

viniarck commented 2 years ago

This is a known-issue that has been hit before, and I've just hit it again, but I think we haven't mapped on mef_eline:

There are cases when when removing flows, after a EVC gets deployed, that tries to get the s_vlan metadata, but it's not there. I'll map this issue just so we can fix this, ideally in this release. I've reproduced this when I tried to update a circuit:

{
    "name": "epl",
    "service_level": 7,
    "dynamic_backup_path": true,
    "uni_a": {
        "interface_id": "00:00:00:00:00:00:00:01:1"
    },
    "uni_z": {
       "interface_id": "00:00:00:00:00:00:00:03:1"
    },
    "primary_constraints": {
        "spf_attribute": "hop",
        "mandatory_metrics": {
            "ownership": "red"
        }
    },
    "secondary_constraints": {
        "spf_attribute": "hop",
        "mandatory_metrics": {
            "ownership": "blue"
        }
    }
}
{
    "secondary_constraints": {
        "mandatory_metrics": {
            "ownership": "blue"
        }
    },
    "primary_constraints": {
        "mandatory_metrics": {
            "ownership": "red"
        }
    }
}
2022-10-11 10:39:17,969 - INFO [kytos.napps.kytos/mef_eline] [evc.py:625:deploy_to_path] (Thread-137) EVC(f752fce5716740, epl) was deployed.
2022-10-11 10:39:17,976 - ERROR [kytos.core.helpers] [helpers.py:151:handler_context_apm] (thread_pool_app_2) listen_to handler: <function Main.on_evc_deployed at 0x7f6c8477aa60>, args:
(<Main(mef_eline, started 140099283056320)>, KytosEvent('kytos/mef_eline.deployed', {'evc_id': 'f752fce5716740'}, 0)) traceback: Traceback (most recent call last):,   File "/home/viniarc
k/repos/kytos/kytos/core/helpers.py", line 146, in handler_context_apm,     result = handler(*args),   File "/home/viniarck/repos/napps/napps/kytos/mef_eline/main.py", line 737, in on_ev
c_deployed,     self.handle_evc_deployed(event),   File "/home/viniarck/repos/napps/napps/kytos/mef_eline/main.py", line 745, in handle_evc_deployed,     evc.setup_failover_path(),   Fil
e "/home/viniarck/repos/napps/napps/kytos/mef_eline/models/evc.py", line 649, in setup_failover_path,     self.remove_path_flows(self.failover_path),   File "/home/viniarck/repos/napps/n
apps/kytos/mef_eline/models/evc.py", line 521, in remove_path_flows,     for dpid, flows in self._prepare_uni_flows(path, skip_in=True).items():,   File "/home/viniarck/repos/napps/napps
/kytos/mef_eline/models/evc.py", line 791, in _prepare_uni_flows,     out_vlan_a = path[0].get_metadata("s_vlan").value, AttributeError: 'NoneType' object has no attribute 'value',
2022-10-11 10:39:36,743 - INFO [werkzeug] [_internal.py:225:_log] (Thread-150) 127.0.0.1 - - [11/Oct/2022 10:39:36] "GET /api/kytos/mef_eline/v2/evc/f752fce5716740 HTTP/1.1" 200 -
viniarck commented 2 years ago

@italovalcy originally reported this on https://github.com/kytos-ng/topology/issues/106, but then we added protection on core with this PR so topology doesn't hit the same traceback, but on mef_eline we still need to fix the root cause.

viniarck commented 2 years ago

Full steps to reproduce, I'm using this ring topology:

class MyTopo(Topo): "Simple topology example."

def build(self):
    "Create custom topo."

    # Add hosts and switches
    h1 = self.addHost("h1")
    h11 = self.addHost("h11")
    h2 = self.addHost("h2")
    h3 = self.addHost("h3")

    s1 = self.addSwitch("s1")
    s2 = self.addSwitch("s2")
    s3 = self.addSwitch("s3")

    self.addLink(h1, s1)
    self.addLink(h11, s1)
    self.addLink(h2, s2)
    self.addLink(h3, s3)

    self.addLink(s1, s2)
    self.addLink(s2, s3)
    self.addLink(s1, s3)

topos = {"mytopo": (lambda: MyTopo())}


- Create circuit:

echo '{ "name": "epl", "service_level": 7, "dynamic_backup_path": true, "uni_a": { "interface_id": "00:00:00:00:00:00:00:01:1" }, "uni_z": { "interface_id": "00:00:00:00:00:00:00:03:1" }, "primary_constraints": { "mandatory_metrics": { "ownership": "red" } }, "secondary_constraints": { "mandatory_metrics": { "ownership": "blue" } } }' | http localhost:8181/api/kytos/m ef_eline/v2/evc/

HTTP/1.0 201 CREATED Access-Control-Allow-Origin: * Content-Length: 32 Content-Type: application/json Date: Tue, 11 Oct 2022 14:05:10 GMT Server: Werkzeug/2.0.3 Python/3.9.12

{ "circuit_id": "eaa4b510ca3649" }

- Update the circuit with its id

echo '{ "secondary_constraints": { "mandatory_metrics": { "ownership": "blue" } }, "primary_constraints": { "mandatory_metrics": { "ownership": "red" } } }' | http PATCH localhost:8181 /api/kytos/mef_eline/v2/evc/eaa4b510ca3649

HTTP/1.0 200 OK Access-Control-Allow-Origin: * Content-Length: 3165 Content-Type: application/json Date: Tue, 11 Oct 2022 14:06:32 GMT Server: Werkzeug/2.0.3 Python/3.9.12

{ "eaa4b510ca3649": { "active": true, "archived": false, "backup_links": [], "backup_path": [], "bandwidth": 0, "circuit_scheduler": [], "creation_time": "2022-10-11T14:05:10", "current_path": [ { "active": true, "enabled": true, "endpoint_a": { "active": true, "enabled": true, "id": "00:00:00:00:00:00:00:01:3", "link": "78282c4d5b579265f04ebadc4405ca1b49628eb1d684bb45e5d0607fa8b713d0", "lldp": true, "mac": "ca:9b:0a:5f:e6:88", "metadata": {}, "name": "s1-eth3", "nni": true, "port_number": 3, "speed": 1250000000.0, "switch": "00:00:00:00:00:00:00:01", "type": "interface", "uni": false }, "endpoint_b": { "active": true, "enabled": true, "id": "00:00:00:00:00:00:00:02:2", "link": "78282c4d5b579265f04ebadc4405ca1b49628eb1d684bb45e5d0607fa8b713d0", "lldp": true, "mac": "3a:7b:ff:4c:60:a6", "metadata": {}, "name": "s2-eth2", "nni": true, "port_number": 2, "speed": 1250000000.0, "switch": "00:00:00:00:00:00:00:02", "type": "interface", "uni": false }, "id": "78282c4d5b579265f04ebadc4405ca1b49628eb1d684bb45e5d0607fa8b713d0", "metadata": { "s_vlan": { "tag_type": 1, "value": 3487 } } }, { "active": true, "enabled": true, "endpoint_a": { "active": true, "enabled": true, "id": "00:00:00:00:00:00:00:02:3", "link": "4d42dc0852278accac7d9df15418f6d921db160b13d674029a87cef1b5f67f30", "lldp": true, "mac": "36:12:4c:6c:f8:57", "metadata": {}, "name": "s2-eth3", "nni": true, "port_number": 3, "speed": 1250000000.0, "switch": "00:00:00:00:00:00:00:02", "type": "interface", "uni": false }, "endpoint_b": { "active": true, "enabled": true, "id": "00:00:00:00:00:00:00:03:2", "link": "4d42dc0852278accac7d9df15418f6d921db160b13d674029a87cef1b5f67f30", "lldp": true, "mac": "e2:a8:83:f1:76:c5", "metadata": {}, "name": "s3-eth2", "nni": true, "port_number": 2, "speed": 1250000000.0, "switch": "00:00:00:00:00:00:00:03", "type": "interface", "uni": false }, "id": "4d42dc0852278accac7d9df15418f6d921db160b13d674029a87cef1b5f67f30", "metadata": { "s_vlan": { "tag_type": 1, "value": 2232 } } } ], "dynamic_backup_path": true, "enabled": true, "end_date": null, "failover_path": [ { "active": true, "enabled": true, "endpoint_a": { "active": true, "enabled": true, "id": "00:00:00:00:00:00:00:01:4", "link": "c8b55359990f89a5849813dc348d30e9e1f991bad1dcb7f82112bd35429d9b07", "lldp": true, "mac": "96:af:8f:bd:6b:66", "metadata": {}, "name": "s1-eth4", "nni": true, "port_number": 4, "speed": 1250000000.0, "switch": "00:00:00:00:00:00:00:01", "type": "interface", "uni": false }, "endpoint_b": { "active": true, "enabled": true, "id": "00:00:00:00:00:00:00:03:3", "link": "c8b55359990f89a5849813dc348d30e9e1f991bad1dcb7f82112bd35429d9b07", "lldp": true, "mac": "e2:d2:7d:70:18:d5", "metadata": {}, "name": "s3-eth3", "nni": true, "port_number": 3, "speed": 1250000000.0, "switch": "00:00:00:00:00:00:00:03", "type": "interface", "uni": false }, "id": "c8b55359990f89a5849813dc348d30e9e1f991bad1dcb7f82112bd35429d9b07", "metadata": {} } ], "id": "eaa4b510ca3649", "metadata": {}, "name": "epl", "owner": null, "primary_constraints": { "mandatory_metrics": { "ownership": "red" } }, "primary_links": [], "primary_path": [], "queue_id": null, "request_time": "2022-10-11T14:05:10", "sb_priority": null, "secondary_constraints": { "mandatory_metrics": { "ownership": "blue" } }, "service_level": 7, "start_date": "2022-10-11T14:05:10", "uni_a": { "interface_id": "00:00:00:00:00:00:00:01:1", "tag": null }, "uni_z": { "interface_id": "00:00:00:00:00:00:00:03:1", "tag": null } } }