nebius/SWE-bench-extra huggingface dataset:
Repository: kytos/kytos

Issue:
Remove hard dependency on github for UI
# The Issue

In order to execute `kytosd`, the kytos needs to be able to download the UI from github. This download may be inaccessible, either from github being unavailable, firewall blocking github, or DNS unable to find github.

# Proposed Solution

- Allow for executing kytos without running the web server for the UI, while still running the web server for the api.
- Provide a different mechanism to couple the Web server for the UI to the controller.

Comments:

Patch:
diff --git a/kytos/core/api_server.py b/kytos/core/api_server.py
index f10c3b0..ccc0c80 100644
--- a/kytos/core/api_server.py
+++ b/kytos/core/api_server.py
@@ -200,7 +200,10 @@ class APIServer:
 
     def web_ui(self):
         """Serve the index.html page for the admin-ui."""
-        return send_file(f"{self.flask_dir}/index.html")
+        index_path = f"{self.flask_dir}/index.html"
+        if os.path.exists(index_path):
+            return send_file(index_path)
+        return f"File '{index_path}' not found.", HTTPStatus.NOT_FOUND.value
 
     def update_web_ui(self, version='latest', force=True):
         """Update the static files for the Web UI.
@@ -227,6 +230,9 @@ class APIServer:
                 package = urlretrieve(uri)[0]
             except HTTPError:
                 return f"Uri not found {uri}."
+            except URLError:
+                self.log.warning("Error accessing URL %s.", uri)
+                return f"Error accessing URL {uri}."
 
             # test downloaded zip file
             zip_ref = zipfile.ZipFile(package, 'r')


Test patch:
diff --git a/tests/unit/test_core/test_api_server.py b/tests/unit/test_core/test_api_server.py
index 1d98e71..20ff2bd 100644
--- a/tests/unit/test_core/test_api_server.py
+++ b/tests/unit/test_core/test_api_server.py
@@ -113,13 +113,23 @@ class TestAPIServer(unittest.TestCase):
             self.assertEqual(response.json, expected_json)
             self.assertEqual(response.status_code, 200)
 
+    @patch('os.path')
     @patch('kytos.core.api_server.send_file')
-    def test_web_ui(self, mock_send_file):
+    def test_web_ui__success(self, mock_send_file, ospath_mock):
         """Test web_ui method."""
+        ospath_mock.exists.return_value = True
         self.api_server.web_ui()
 
         mock_send_file.assert_called_with('flask_dir/index.html')
 
+    @patch('os.path')
+    def test_web_ui__error(self, ospath_mock):
+        """Test web_ui method."""
+        ospath_mock.exists.return_value = False
+        _, error = self.api_server.web_ui()
+
+        self.assertEqual(error, 404)
+
     @patch('kytos.core.api_server.urlretrieve')
     @patch('kytos.core.api_server.urlopen')
     @patch('zipfile.ZipFile')
Repository: kytos/kytos

Issue:
Improve key generation for mock `Link.metadata`
The following test code in does not sufficiently expose kytos/pathfinder#64:

https://github.com/kytos/kytos/blob/c67933ccecd8c87eab9a7d527312956841959b97/kytos/lib/helpers.py#L34-L40

This change is to address the problem of the referenced bug not showing up for single-letter link attribute names.

Comments:

Patch:
diff --git a/kytos/lib/helpers.py b/kytos/lib/helpers.py
index 1f9b771..5c12f86 100644
--- a/kytos/lib/helpers.py
+++ b/kytos/lib/helpers.py
@@ -36,7 +36,7 @@ def get_link_mock(endpoint_a, endpoint_b):
     link = create_autospec(Link)
     link.endpoint_a = endpoint_a
     link.endpoint_b = endpoint_b
-    link.metadata = {"A": 0}
+    link.metadata = {"A": 0, "BB": 0.0, "CCC": "test"}
     return link
 
 


Test patch:
diff --git a/tests/unit/test_lib/test_helpers.py b/tests/unit/test_lib/test_helpers.py
index 253fe54..48b339d 100644
--- a/tests/unit/test_lib/test_helpers.py
+++ b/tests/unit/test_lib/test_helpers.py
@@ -41,7 +41,8 @@ class TestHelpers(TestCase):
 
         self.assertEqual(link_mock.endpoint_a, endpoint_a)
         self.assertEqual(link_mock.endpoint_b, endpoint_b)
-        self.assertEqual(link_mock.metadata, {"A": 0})
+        self.assertEqual(link_mock.metadata, {"A": 0, "BB": 0.0,
+                                              "CCC": "test"})
 
     def test_switch_mock(self):
         """Test switch mock."""
Repository: kytos/python-openflow

Issue:
Fix tests
I ran bisect assigning zeros to default DPID value and it lead to d207690facd4844557fb7d53aebbd5d2fb66a414 (added a new basic type: dpid).

Comments:

Patch:
diff --git a/pyof/foundation/basic_types.py b/pyof/foundation/basic_types.py
index 297baa2..a3b5461 100644
--- a/pyof/foundation/basic_types.py
+++ b/pyof/foundation/basic_types.py
@@ -130,10 +130,11 @@ class DPID(GenericType):
         self._value = ':'.join(bytes)
 
     def pack(self, value=None):
-        buffer = b''
-        for value in self._value.split(":"):
-            buffer += struct.pack('!B', int(value, 16))
-        return buffer
+        if isinstance(value, type(self)):
+            return value.pack()
+        if value is None:
+            value = self._value
+        return struct.pack('!8B', *[int(v, 16) for v in value.split(':')])
 
 
 class Char(GenericType):
diff --git a/pyof/v0x01/controller2switch/features_reply.py b/pyof/v0x01/controller2switch/features_reply.py
index 8dff843..33f5541 100644
--- a/pyof/v0x01/controller2switch/features_reply.py
+++ b/pyof/v0x01/controller2switch/features_reply.py
@@ -62,7 +62,7 @@ class SwitchFeatures(GenericMessage):
 
         Args:
             xid (int): xid to be used on the message header.
-            datapath_id (int): UBInt64 datapath unique ID.
+            datapath_id (str or :class:`.DPID`): datapath unique ID.
                 The lower 48-bits are for MAC address, while
                 the upper 16-bits are implementer-defined.
             n_buffers (int): UBInt32 max packets buffered at once.


Test patch:
diff --git a/tests/v0x01/test_controller2switch/test_features_reply.py b/tests/v0x01/test_controller2switch/test_features_reply.py
index 2728ded..3f56325 100644
--- a/tests/v0x01/test_controller2switch/test_features_reply.py
+++ b/tests/v0x01/test_controller2switch/test_features_reply.py
@@ -1,5 +1,5 @@
 """Echo request message tests."""
-from pyof.foundation.basic_types import HWAddress
+from pyof.foundation.basic_types import HWAddress, DPID
 from pyof.v0x01.common.phy_port import PhyPort, PortConfig, PortState
 from pyof.v0x01.controller2switch.features_reply import FeaturesReply
 from tests.test_struct import TestStruct
@@ -19,8 +19,9 @@ class TestFeaturesReply(TestStruct):
 
 
 def _get_kwargs():
-    return {'xid': 2, 'datapath_id': 1, 'n_buffers': 256, 'n_tables': 254,
-            'capabilities': 0x000000c7, 'actions': 4095, 'ports': _get_ports()}
+    return {'xid': 2, 'datapath_id': DPID('00:00:00:00:00:00:00:01'),
+            'n_buffers': 256, 'n_tables': 254, 'capabilities': 0x000000c7,
+            'actions': 4095, 'ports': _get_ports()}
 
 
 def _get_ports():
Repository: kytos/python-openflow

Issue:
Fix Header's random xid
One single random value is used during all code execution.

Comments:

Patch:
diff --git a/pyof/v0x01/common/header.py b/pyof/v0x01/common/header.py
index 1e62b87..c0489e5 100644
--- a/pyof/v0x01/common/header.py
+++ b/pyof/v0x01/common/header.py
@@ -73,7 +73,7 @@ class Header(GenericStruct):
     length = UBInt16()
     xid = UBInt32()
 
-    def __init__(self, message_type=None, length=None, xid=randint(0, MAXID)):
+    def __init__(self, message_type=None, length=None, xid=None):
         """The constructor takes the optional parameters below.
 
         Args:
@@ -84,4 +84,4 @@ class Header(GenericStruct):
         super().__init__()
         self.message_type = message_type
         self.length = length
-        self.xid = xid
+        self.xid = randint(0, MAXID) if xid is None else xid


Test patch:
diff --git a/tests/v0x01/test_common/test_header.py b/tests/v0x01/test_common/test_header.py
index 003621c..3c01fd8 100644
--- a/tests/v0x01/test_common/test_header.py
+++ b/tests/v0x01/test_common/test_header.py
@@ -1,6 +1,7 @@
 """Testing Header structure."""
 import os
 import unittest
+from unittest.mock import patch
 
 from pyof.v0x01.common.header import Header, Type
 
@@ -43,3 +44,9 @@ class TestHeader(unittest.TestCase):
         self.assertEqual(self.message.version, 1)
 
         f.close()
+
+    @patch('pyof.v0x01.common.header.randint')
+    def test_random_xid(self, m):
+        """Each Header instantiations without xid should call randint."""
+        Header(), Header()  # noqa
+        self.assertEqual(m.call_count, 2)
Repository: kytos/python-openflow

Issue:
OF 1.3 Compliance: additional ENUM attribute
File: `v0x04/common/action.py`

`class ActionType(Enum):`

There is a enum attribute that is not present in 1.3 spec with duplicate value. Remove `OFPAT_EXPERIMENTER` and keep only `OFPAT_VENDOR`

```
    OFPAT_EXPERIMENTER = 0xffff
    OFPAT_VENDOR = 0xffff
```

Comments:

Patch:
diff --git a/pyof/v0x04/common/action.py b/pyof/v0x04/common/action.py
index 9b550a2..dba4ad0 100644
--- a/pyof/v0x04/common/action.py
+++ b/pyof/v0x04/common/action.py
@@ -72,7 +72,6 @@ class ActionType(Enum):
     OFPAT_POP_PBB = 27
     #: Experimenter type
     OFPAT_EXPERIMENTER = 0xffff
-    OFPAT_VENDOR = 0xffff
 
 
 class ControllerMaxLen(Enum):
diff --git a/pyof/v0x04/common/port.py b/pyof/v0x04/common/port.py
index db3b41c..41b5be3 100644
--- a/pyof/v0x04/common/port.py
+++ b/pyof/v0x04/common/port.py
@@ -44,7 +44,7 @@ class PortNo(Enum):
     #: Wildcard port used only for flow mod (delete) and flow stats requests.
     #: Selects all flows regardless of output port (including flows with no
     #: output port).
-    OFPP_NONE = 0xffffffff
+    OFPP_ANY = 0xffffffff
 
 
 class PortConfig(GenericBitMask):
diff --git a/pyof/v0x04/controller2switch/packet_out.py b/pyof/v0x04/controller2switch/packet_out.py
index e23fc87..1520f85 100644
--- a/pyof/v0x04/controller2switch/packet_out.py
+++ b/pyof/v0x04/controller2switch/packet_out.py
@@ -13,7 +13,7 @@ __all__ = ('PacketOut',)
 # Classes
 
 #: in_port valid virtual port values, for validation
-_VIRT_IN_PORTS = (PortNo.OFPP_LOCAL, PortNo.OFPP_CONTROLLER, PortNo.OFPP_NONE)
+_VIRT_IN_PORTS = (PortNo.OFPP_LOCAL, PortNo.OFPP_CONTROLLER, PortNo.OFPP_ANY)
 
 
 class PacketOut(GenericMessage):


Test patch:
diff --git a/tests/v0x04/test_controller2switch/test_packet_out.py b/tests/v0x04/test_controller2switch/test_packet_out.py
index 733fff2..803eb1a 100644
--- a/tests/v0x04/test_controller2switch/test_packet_out.py
+++ b/tests/v0x04/test_controller2switch/test_packet_out.py
@@ -23,7 +23,7 @@ class TestPacketOut(TestStruct):
         super().setUpClass()
         super().set_raw_dump_file('v0x04', 'ofpt_packet_out')
         super().set_raw_dump_object(PacketOut, xid=80, buffer_id=5,
-                                    in_port=PortNo.OFPP_NONE)
+                                    in_port=PortNo.OFPP_ANY)
         super().set_minimum_size(24)
 
     def test_valid_virtual_in_ports(self):
@@ -34,7 +34,7 @@ class TestPacketOut(TestStruct):
             raise self.skipTest(NO_RAW)
         else:
             valid = (PortNo.OFPP_LOCAL, PortNo.OFPP_CONTROLLER,
-                     PortNo.OFPP_NONE)
+                     PortNo.OFPP_ANY)
             msg = self.get_raw_object()
             for in_port in valid:
                 msg.in_port = in_port
Repository: kytos/python-openflow

Issue:
OF 1.3 Compliance: Missing attribute 
File: `v0x04/common/action.py`

`class ActionPopMPLS(GenericStruct):`

The attribute `pad[2]` is missing:
`pad = Pad(2)`

Comments:

Patch:
diff --git a/pyof/v0x04/common/action.py b/pyof/v0x04/common/action.py
index 9b550a2..78d6004 100644
--- a/pyof/v0x04/common/action.py
+++ b/pyof/v0x04/common/action.py
@@ -72,7 +72,6 @@ class ActionType(Enum):
     OFPAT_POP_PBB = 27
     #: Experimenter type
     OFPAT_EXPERIMENTER = 0xffff
-    OFPAT_VENDOR = 0xffff
 
 
 class ControllerMaxLen(Enum):
@@ -254,6 +253,8 @@ class ActionPopMPLS(GenericStruct):
     length = UBInt16(8)
     #: Ethertype
     ethertype = UBInt16()
+    #: Padding
+    pad = Pad(2)
 
     def __init__(self, ethertype=None):
         """Action structure for OFPAT_POP_MPLS.
diff --git a/pyof/v0x04/common/port.py b/pyof/v0x04/common/port.py
index db3b41c..41b5be3 100644
--- a/pyof/v0x04/common/port.py
+++ b/pyof/v0x04/common/port.py
@@ -44,7 +44,7 @@ class PortNo(Enum):
     #: Wildcard port used only for flow mod (delete) and flow stats requests.
     #: Selects all flows regardless of output port (including flows with no
     #: output port).
-    OFPP_NONE = 0xffffffff
+    OFPP_ANY = 0xffffffff
 
 
 class PortConfig(GenericBitMask):
diff --git a/pyof/v0x04/controller2switch/packet_out.py b/pyof/v0x04/controller2switch/packet_out.py
index e23fc87..1520f85 100644
--- a/pyof/v0x04/controller2switch/packet_out.py
+++ b/pyof/v0x04/controller2switch/packet_out.py
@@ -13,7 +13,7 @@ __all__ = ('PacketOut',)
 # Classes
 
 #: in_port valid virtual port values, for validation
-_VIRT_IN_PORTS = (PortNo.OFPP_LOCAL, PortNo.OFPP_CONTROLLER, PortNo.OFPP_NONE)
+_VIRT_IN_PORTS = (PortNo.OFPP_LOCAL, PortNo.OFPP_CONTROLLER, PortNo.OFPP_ANY)
 
 
 class PacketOut(GenericMessage):


Test patch:
diff --git a/tests/v0x04/test_controller2switch/test_packet_out.py b/tests/v0x04/test_controller2switch/test_packet_out.py
index 733fff2..803eb1a 100644
--- a/tests/v0x04/test_controller2switch/test_packet_out.py
+++ b/tests/v0x04/test_controller2switch/test_packet_out.py
@@ -23,7 +23,7 @@ class TestPacketOut(TestStruct):
         super().setUpClass()
         super().set_raw_dump_file('v0x04', 'ofpt_packet_out')
         super().set_raw_dump_object(PacketOut, xid=80, buffer_id=5,
-                                    in_port=PortNo.OFPP_NONE)
+                                    in_port=PortNo.OFPP_ANY)
         super().set_minimum_size(24)
 
     def test_valid_virtual_in_ports(self):
@@ -34,7 +34,7 @@ class TestPacketOut(TestStruct):
             raise self.skipTest(NO_RAW)
         else:
             valid = (PortNo.OFPP_LOCAL, PortNo.OFPP_CONTROLLER,
-                     PortNo.OFPP_NONE)
+                     PortNo.OFPP_ANY)
             msg = self.get_raw_object()
             for in_port in valid:
                 msg.in_port = in_port
Repository: kytos/python-openflow

Issue:
packetOut validation needs fix
packetOut validation of in_port is not working correctly and needs fix so it can pass the tests properly.

Comments:

Patch:
diff --git a/pyof/v0x01/controller2switch/packet_out.py b/pyof/v0x01/controller2switch/packet_out.py
index 5996d47..ad906e3 100644
--- a/pyof/v0x01/controller2switch/packet_out.py
+++ b/pyof/v0x01/controller2switch/packet_out.py
@@ -112,13 +112,20 @@ class PacketOut(GenericMessage):
             self.actions_len = ListOfActions(self.actions).get_size()
 
     def _validate_in_port(self):
-        port = self.in_port
-        valid = True
-        if isinstance(port, Port):
-            if port not in _VIRT_IN_PORTS:
-                valid = False
-        elif isinstance(port, int) and (port < 1 or port >=
-                                        Port.OFPP_MAX.value):
-            valid = False
-        if not valid:
-            raise ValidationError('{} is not a valid input port.'.format(port))
+        """Validate in_port attribute.
+
+        A valid port is either:
+
+            * Greater than 0 and less than or equals to Port.OFPP_MAX
+            * One of the valid virtual ports: Port.OFPP_LOCAL,
+              Port.OFPP_CONTROLLER or Port.OFPP_NONE
+
+        Raises:
+            ValidationError: If in_port is an invalid port.
+
+        """
+        is_valid_range = self.in_port > 0 and self.in_port <= Port.OFPP_MAX
+        is_valid_virtual_in_ports = self.in_port in _VIRT_IN_PORTS
+
+        if (is_valid_range or is_valid_virtual_in_ports) is False:
+            raise ValidationError(f'{self.in_port} is not a valid input port.')


Test patch:
diff --git a/tests/v0x01/test_controller2switch/test_packet_out.py b/tests/v0x01/test_controller2switch/test_packet_out.py
index 00ea797..7a277ee 100644
--- a/tests/v0x01/test_controller2switch/test_packet_out.py
+++ b/tests/v0x01/test_controller2switch/test_packet_out.py
@@ -45,14 +45,14 @@ class TestPacketOut(TestStruct):
 
     def test_valid_physical_in_ports(self):
         """Physical port limits from 1.0.0 spec."""
-        max_valid = int(Port.OFPP_MAX.value) - 1
+        max_valid = int(Port.OFPP_MAX.value)
         for in_port in (1, max_valid):
             self.message.in_port = in_port
             self.assertTrue(self.message.is_valid())
 
     def test_invalid_physical_in_port(self):
         """Physical port limits from 1.0.0 spec."""
-        max_valid = int(Port.OFPP_MAX.value) - 1
+        max_valid = int(Port.OFPP_MAX.value)
         for in_port in (-1, 0, max_valid + 1, max_valid + 2):
             self.message.in_port = in_port
             self.assertFalse(self.message.is_valid())