kytos-ng / maintenance

Kytos Maintenance Window NApp
https://kytos-ng.github.io/api/maintenance.html
0 stars 7 forks source link

Fix for the bug in Issue #82 #84

Closed HeriLFIU closed 6 months ago

HeriLFIU commented 6 months ago

Closes #82 Closes #63

Summary

I found out that the bug described in issue #82 which would not allow someone to create a MW on an existing interface was due to incorrect filtering of links.

        non_existant_links = list(
            filter(
                lambda interface_id:
                    self.controller.napps[('kytos', 'topology')]
                    .links.get(interface_id)
                    is None,
                window.interfaces
            )
        )

This code should be filtering non_existant_links, but instead it is filtering links with interface data. To fix this I made the following changes:

        non_existant_links = list(
            filter(
                lambda link_id: self.controller.napps[("kytos", "topology")].links.get(
                    link_id
                )
                is None,
                window.links,
            )
        )

Now it is filtering links with the corresponding link data.

Side Note

Added Black for reformatting and linting.

lint run-test-pre: PYTHONHASHSEED='3119339690'
lint run-test: commands[0] | python3 setup.py lint
running lint
Yala is running. It may take several seconds...
INFO: Finished pycodestyle
INFO: Finished isort
INFO: Finished black
INFO: Finished pylint
:) No issues found.
No linter error found.
______________________________________________________________________________ summary ______________________________________________________________________________
  py39: commands succeeded
  coverage: commands succeeded
  lint: commands succeeded
  congratulations :)

Local Tests

To make sure that this was issue and that the correct fix was applied I first created the maintenance window, verified that it was running, and made sure that its status was DOWN and that the reason for this was maintenance.

This is seen in the image below:

Kytos Bug Fixed

The unit tests are also now detecting these sorts of bugs. Four new unit tests were added. Three that test switches, interfaces, and links individually, and one that tests them all together with multiple copies.

As seen in the tests results below, the bug is now being detected by the unit tests:

coverage run-test-pre: PYTHONHASHSEED='3272154321'
coverage run-test: commands[0] | python3 setup.py coverage
running coverage
======================================================================== test session starts ========================================================================
platform linux -- Python 3.9.18, pytest-7.2.1, pluggy-1.4.0
cachedir: .tox/py39/.pytest_cache
rootdir: /home/heriberto/kytos-project/napps/kytos/maintenance, configfile: pytest.ini
plugins: asyncio-0.20.3, cov-4.0.0, anyio-3.6.2
asyncio: mode=auto
collected 53 items                                                                                                                                                  

tests/unit/test_controller.py ......                                                                                                                          [ 11%]
tests/unit/test_main.py F..F...s..........................                                                                                                    [ 75%]
tests/unit/test_models.py ....                                                                                                                                [ 83%]
tests/unit/managers/test_deployer.py ....                                                                                                                     [ 90%]
tests/unit/managers/test_scheduler.py .....                                                                                                                   [100%]

============================================================================= FAILURES ==============================================================================
__________________________________________________________________ TestMain.test_create_mw_case_1 ___________________________________________________________________

self = <maintenance.tests.unit.test_main.TestMain object at 0x7ffb8237a310>, event_loop = <_UnixSelectorEventLoop running=False closed=False debug=False>

    async def test_create_mw_case_1(self, event_loop):
        """Test a successful case of the REST to create."""
        self.napp.controller.loop = event_loop
        url = f"{self.base_endpoint}"
        start = datetime.now(pytz.utc) + timedelta(days=1)
        end = start + timedelta(hours=2)
        self.controller.switches = MagicMock()
        self.controller.get_interface_by_id = MagicMock()
        self.controller.napps[("kytos", "topology")].links = MagicMock()
        switches = {"00:00:00:00:00:00:00:02": 1, "00:00:00:00:00:00:00:03": 2}
        interfaces = {"00:00:00:00:00:00:00:03:3": 1, "00:00:00:00:00:00:00:02:1": 2}
        links = {
            "cf0f4071be426b3f745027f5d22bc61f8312ae86293c9b28e7e66015607a9260": 1,
            "4d42dc0852278accac7d9df15418f6d921db160b13d674029a87cef1b5f67f30": 2,
        }
        self.controller.switches.get.side_effect = switches.get
        get_interface_side_effect = lambda interface_id: interfaces.get(interface_id)
        self.controller.get_interface_by_id.side_effect = get_interface_side_effect
        self.controller.napps[("kytos", "topology")].links.get.side_effect = links.get
        payload = {
            "start": start.strftime(TIME_FMT),
            "end": end.strftime(TIME_FMT),
            "switches": ["00:00:00:00:00:00:00:02", "00:00:00:00:00:00:00:03"],
            "interfaces": ["00:00:00:00:00:00:00:03:3", "00:00:00:00:00:00:00:02:1"],
            "links": [
                "cf0f4071be426b3f745027f5d22bc61f8312ae86293c9b28e7e66015607a9260",
                "4d42dc0852278accac7d9df15418f6d921db160b13d674029a87cef1b5f67f30",
            ],
        }
        response = await self.api.post(url, json=payload)
        current_data = response.json()
>       assert response.status_code == 201, current_data
E       AssertionError: {'code': 400, 'description': "Window contains non-existant items: {'switches': [], 'interfaces': [], 'links': ['00:00:00:00:00:00:00:03:3', '00:00:00:00:00:00:00:02:1']}"}
E       assert 400 == 201
E        +  where 400 = <Response [400 Bad Request]>.status_code

tests/unit/test_main.py:69: AssertionError
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_create_mw_case_4 ___________________________________________________________________

self = <maintenance.tests.unit.test_main.TestMain object at 0x7ffb8237a400>, event_loop = <_UnixSelectorEventLoop running=False closed=False debug=False>

    async def test_create_mw_case_4(self, event_loop):
        """Test a successful case of the REST to create."""
        self.napp.controller.loop = event_loop
        url = f"{self.base_endpoint}"
        start = datetime.now(pytz.utc) + timedelta(days=1)
        end = start + timedelta(hours=2)
        self.controller.napps[("kytos", "topology")].links = MagicMock()
        links = {"cf0f4071be426b3f745027f5d22bc61f8312ae86293c9b28e7e66015607a9260": 1}
        self.controller.napps[("kytos", "topology")].links.get.side_effect = links.get
        payload = {
            "start": start.strftime(TIME_FMT),
            "end": end.strftime(TIME_FMT),
            "links": [
                "cf0f4071be426b3f745027f5d22bc61f8312ae86293c9b28e7e66015607a9260",
            ],
        }
        response = await self.api.post(url, json=payload)
        current_data = response.json()
        assert response.status_code == 201, current_data
>       self.controller.napps[("kytos", "topology")].links.get.assert_called_with(
            "cf0f4071be426b3f745027f5d22bc61f8312ae86293c9b28e7e66015607a9260"
        )

tests/unit/test_main.py:192: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <MagicMock name='mock.links.get' id='140718195629936'>, args = ('cf0f4071be426b3f745027f5d22bc61f8312ae86293c9b28e7e66015607a9260',), kwargs = {}
expected = "get('cf0f4071be426b3f745027f5d22bc61f8312ae86293c9b28e7e66015607a9260')", actual = 'not called.'
error_message = "expected call not found.\nExpected: get('cf0f4071be426b3f745027f5d22bc61f8312ae86293c9b28e7e66015607a9260')\nActual: not called."

    def assert_called_with(self, /, *args, **kwargs):
        """assert that the last call was made with the specified arguments.

        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock."""
        if self.call_args is None:
            expected = self._format_mock_call_signature(args, kwargs)
            actual = 'not called.'
            error_message = ('expected call not found.\nExpected: %s\nActual: %s'
                    % (expected, actual))
>           raise AssertionError(error_message)
E           AssertionError: expected call not found.
E           Expected: get('cf0f4071be426b3f745027f5d22bc61f8312ae86293c9b28e7e66015607a9260')
E           Actual: not called.

/usr/lib/python3.9/unittest/mock.py:898: AssertionError
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
========================================================================= warnings summary ==========================================================================
.tox/py39/src/kytos/kytos/core/config.py:254: 1 warning
tests/unit/test_main.py: 33 warnings
tests/unit/test_models.py: 4 warnings
tests/unit/managers/test_deployer.py: 4 warnings
  /home/heriberto/kytos-project/napps/kytos/maintenance/.tox/py39/src/kytos/kytos/core/config.py:254: UserWarning: Unknown arguments: ['--cov=.', 'tests/', '-rP']
    warnings.warn(f"Unknown arguments: {unknown}")

tests/unit/test_main.py: 33 warnings
tests/unit/test_models.py: 4 warnings
tests/unit/managers/test_deployer.py: 4 warnings
  /home/heriberto/kytos-project/napps/kytos/maintenance/.tox/py39/lib/python3.9/site-packages/starlette/routing.py:850: DeprecationWarning: The `on_event` decorator is deprecated, and will be removed in version 1.0.0. Refer to https://www.starlette.io/lifespan/ for recommended approach.
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================== PASSES ===============================================================================
__________________________________________________________________ TestMain.test_create_mw_case_2 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_create_mw_case_3 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_create_mw_case_5 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_create_mw_case_6 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_create_mw_case_7 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_create_mw_case_9 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_get_mw_case_1 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_get_mw_case_2 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_get_mw_case_3 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_get_mw_case_4 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_remove_mw_case_1 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_remove_mw_case_2 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_remove_mw_case_3 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_update_mw_case_1 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_update_mw_case_2 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_update_mw_case_3 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_update_mw_case_4 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_update_mw_case_5 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_update_mw_case_6 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_update_mw_case_7 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_end_mw_case_1 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_end_mw_case_2 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_end_mw_case_3 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_end_mw_case_4 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_extend_case_1 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_extend_case_2 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_extend_case_3 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_extend_case_4 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_extend_case_5 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_extend_case_6 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_extend_case_7 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
________________________________________________________________________ TestMW.test_as_dict ________________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
_____________________________________________________________________ TestMW.test_start_in_past _____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
___________________________________________________________________ TestMW.test_end_before_start ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
______________________________________________________________________ TestMW.test_items_empty ______________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestDeployer.test_mw_case_1 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestDeployer.test_mw_case_2 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestDeployer.test_mw_case_3 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
___________________________________________________________________ TestDeployer.test_dev_status ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated

---------- coverage: platform linux, python 3.9.18-final-0 -----------
Name                                    Stmts   Miss  Cover
-----------------------------------------------------------
__init__.py                                 0      0   100%
controllers/__init__.py                    55     12    78%
main.py                                   126      9    93%
managers/__init__.py                        3      0   100%
managers/deployer.py                       88      0   100%
managers/scheduler.py                     112     22    80%
models.py                                  66      7    89%
settings.py                                 0      0   100%
tests/__init__.py                           0      0   100%
tests/unit/__init__.py                      0      0   100%
tests/unit/managers/__init__.py             0      0   100%
tests/unit/managers/test_deployer.py      221      0   100%
tests/unit/managers/test_scheduler.py      69      5    93%
tests/unit/test_controller.py              45      0   100%
tests/unit/test_main.py                   450     33    93%
tests/unit/test_models.py                  26      0   100%
-----------------------------------------------------------
TOTAL                                    1261     88    93%

======================================================= 2 failed, 50 passed, 1 skipped, 83 warnings in 5.91s ========================================================

With the fix, the modified unit tests no longer detect the bug (as it is no longer there), as seen below:

coverage run-test-pre: PYTHONHASHSEED='242300129'
coverage run-test: commands[0] | python3 setup.py coverage
running coverage
======================================================================== test session starts ========================================================================
platform linux -- Python 3.9.18, pytest-7.2.1, pluggy-1.4.0
cachedir: .tox/py39/.pytest_cache
rootdir: /home/heriberto/kytos-project/napps/kytos/maintenance, configfile: pytest.ini
plugins: asyncio-0.20.3, cov-4.0.0, anyio-3.6.2
asyncio: mode=auto
collected 53 items                                                                                                                                                  

tests/unit/test_controller.py ......                                                                                                                          [ 11%]
tests/unit/test_main.py .......s..........................                                                                                                    [ 75%]
tests/unit/test_models.py ....                                                                                                                                [ 83%]
tests/unit/managers/test_deployer.py ....                                                                                                                     [ 90%]
tests/unit/managers/test_scheduler.py .....                                                                                                                   [100%]

========================================================================= warnings summary ==========================================================================
.tox/py39/src/kytos/kytos/core/config.py:254: 1 warning
tests/unit/test_main.py: 33 warnings
tests/unit/test_models.py: 4 warnings
tests/unit/managers/test_deployer.py: 4 warnings
  /home/heriberto/kytos-project/napps/kytos/maintenance/.tox/py39/src/kytos/kytos/core/config.py:254: UserWarning: Unknown arguments: ['--cov=.', 'tests/', '-rP']
    warnings.warn(f"Unknown arguments: {unknown}")

tests/unit/test_main.py: 33 warnings
tests/unit/test_models.py: 4 warnings
tests/unit/managers/test_deployer.py: 4 warnings
  /home/heriberto/kytos-project/napps/kytos/maintenance/.tox/py39/lib/python3.9/site-packages/starlette/routing.py:850: DeprecationWarning: The `on_event` decorator is deprecated, and will be removed in version 1.0.0. Refer to https://www.starlette.io/lifespan/ for recommended approach.
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================== PASSES ===============================================================================
__________________________________________________________________ TestMain.test_create_mw_case_1 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_create_mw_case_2 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_create_mw_case_3 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_create_mw_case_4 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_create_mw_case_5 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_create_mw_case_6 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_create_mw_case_7 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_create_mw_case_9 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_get_mw_case_1 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_get_mw_case_2 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_get_mw_case_3 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_get_mw_case_4 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_remove_mw_case_1 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_remove_mw_case_2 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_remove_mw_case_3 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_update_mw_case_1 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_update_mw_case_2 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_update_mw_case_3 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_update_mw_case_4 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_update_mw_case_5 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_update_mw_case_6 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
__________________________________________________________________ TestMain.test_update_mw_case_7 ___________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_end_mw_case_1 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_end_mw_case_2 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_end_mw_case_3 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_end_mw_case_4 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_extend_case_1 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_extend_case_2 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_extend_case_3 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_extend_case_4 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_extend_case_5 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_extend_case_6 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestMain.test_extend_case_7 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
________________________________________________________________________ TestMW.test_as_dict ________________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
_____________________________________________________________________ TestMW.test_start_in_past _____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
___________________________________________________________________ TestMW.test_end_before_start ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
______________________________________________________________________ TestMW.test_items_empty ______________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestDeployer.test_mw_case_1 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestDeployer.test_mw_case_2 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
____________________________________________________________________ TestDeployer.test_mw_case_3 ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated
___________________________________________________________________ TestDeployer.test_dev_status ____________________________________________________________________
------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------
ERROR    kytos.core.api_server:api_server.py:297 Web update - Web UI was not updated

---------- coverage: platform linux, python 3.9.18-final-0 -----------
Name                                    Stmts   Miss  Cover
-----------------------------------------------------------
__init__.py                                 0      0   100%
controllers/__init__.py                    55     12    78%
main.py                                   126     14    89%
managers/__init__.py                        3      0   100%
managers/deployer.py                       88      0   100%
managers/scheduler.py                     112     22    80%
models.py                                  66      7    89%
settings.py                                 0      0   100%
tests/__init__.py                           0      0   100%
tests/unit/__init__.py                      0      0   100%
tests/unit/managers/__init__.py             0      0   100%
tests/unit/managers/test_deployer.py      221      0   100%
tests/unit/managers/test_scheduler.py      69      5    93%
tests/unit/test_controller.py              45      0   100%
tests/unit/test_main.py                   450     10    98%
tests/unit/test_models.py                  26      0   100%
-----------------------------------------------------------
TOTAL                                    1261     70    94%

============================================================ 52 passed, 1 skipped, 83 warnings in 5.38s =============================================================

End-to-End Tests

E2E Test Maintenance

Attaching to kytos-end-to-end-tests_kytos_1
kytos_1        | Starting enhanced syslogd: rsyslogd.
kytos_1        | /etc/openvswitch/conf.db does not exist ... (warning).
kytos_1        | Creating empty database /etc/openvswitch/conf.db.
kytos_1        | Starting ovsdb-server.
kytos_1        | Configuring Open vSwitch system IDs.
kytos_1        | Starting ovs-vswitchd.
kytos_1        | Enabling remote OVSDB managers.
kytos_1        | + '[' -z '' ']'
kytos_1        | + '[' -z '' ']'
kytos_1        | + echo 'There is no NAPPS_PATH specified. Default will be used.'
kytos_1        | + NAPPS_PATH=
kytos_1        | + sed -i 's/STATS_INTERVAL = 60/STATS_INTERVAL = 7/g' /var/lib/kytos/napps/kytos/of_core/settings.py
kytos_1        | There is no NAPPS_PATH specified. Default will be used.
kytos_1        | + sed -i 's/CONSISTENCY_MIN_VERDICT_INTERVAL =.*/CONSISTENCY_MIN_VERDICT_INTERVAL = 60/g' /var/lib/kytos/napps/kytos/flow_manager/settings.py
kytos_1        | + sed -i 's/LINK_UP_TIMER = 10/LINK_UP_TIMER = 1/g' /var/lib/kytos/napps/kytos/topology/settings.py
kytos_1        | + sed -i 's/DEPLOY_EVCS_INTERVAL = 60/DEPLOY_EVCS_INTERVAL = 5/g' /var/lib/kytos/napps/kytos/mef_eline/settings.py
kytos_1        | + sed -i 's/LLDP_LOOP_ACTIONS = \["log"\]/LLDP_LOOP_ACTIONS = \["disable","log"\]/' /var/lib/kytos/napps/kytos/of_lldp/settings.py
kytos_1        | + sed -i 's/LLDP_IGNORED_LOOPS = {}/LLDP_IGNORED_LOOPS = {"00:00:00:00:00:00:00:01": \[\[4, 5\]\]}/' /var/lib/kytos/napps/kytos/of_lldp/settings.py
kytos_1        | + sed -i 's/CONSISTENCY_COOKIE_IGNORED_RANGE =.*/CONSISTENCY_COOKIE_IGNORED_RANGE = [(0xdd00000000000000, 0xdd00000000000009)]/g' /var/lib/kytos/napps/kytos/flow_manager/settings.py
kytos_1        | + sed -i 's/LIVENESS_DEAD_MULTIPLIER =.*/LIVENESS_DEAD_MULTIPLIER = 3/g' /var/lib/kytos/napps/kytos/of_lldp/settings.py
kytos_1        | + kytosd --help
kytos_1        | + sed -i s/WARNING/INFO/g /etc/kytos/logging.ini
kytos_1        | + test -z ''
kytos_1        | + TESTS=tests/
kytos_1        | + test -z ''
kytos_1        | + RERUNS=2
kytos_1        | + python3 scripts/wait_for_mongo.py
kytos_1        | Trying to run hello command on MongoDB...
kytos_1        | Trying to run 'hello' command on MongoDB...
kytos_1        | Trying to run 'hello' command on MongoDB...
kytos_1        | Ran 'hello' command on MongoDB successfully. It's ready!
kytos_1        | + python3 -m pytest --timeout=60 tests/test_e2e_50_maintenance.py::TestE2EMaintenance::test_135_interface_payload_filtering
kytos_1        | ============================= test session starts ==============================
kytos_1        | platform linux -- Python 3.9.2, pytest-7.2.0, pluggy-1.4.0
kytos_1        | rootdir: /tests
kytos_1        | plugins: timeout-2.1.0, rerunfailures-10.2, anyio-3.6.2
kytos_1        | timeout: 60.0s
kytos_1        | timeout method: signal
kytos_1        | timeout func_only: False
kytos_1        | collected 1 item
kytos_1        | 
kytos_1        | tests/test_e2e_50_maintenance.py F                                       [100%]
kytos_1        | 
kytos_1        | =================================== FAILURES ===================================
kytos_1        | ___________ TestE2EMaintenance.test_135_interface_payload_filtering ____________
kytos_1        | 
kytos_1        | self = <tests.test_e2e_50_maintenance.TestE2EMaintenance object at 0x7f2e33434df0>
kytos_1        | 
kytos_1        |     def test_135_interface_payload_filtering(self):
kytos_1        |         self.net.start_controller(clean_config=True, enable_all=True)
kytos_1        |         self.net.wait_switches_connect()
kytos_1        |         time.sleep(10)
kytos_1        |     
kytos_1        |         start = datetime.now(pytz.utc) + timedelta(days=1)
kytos_1        |         end = start + timedelta(hours=2)
kytos_1        |         payload = {
kytos_1        |             "start": start.strftime(TIME_FMT),
kytos_1        |             "end": end.strftime(TIME_FMT),
kytos_1        |             "interfaces": [
kytos_1        |                 "00:00:00:00:00:00:00:01:1",
kytos_1        |             ],
kytos_1        |         }
kytos_1        |         api_url = KYTOS_API + '/maintenance/v1'
kytos_1        |         response = requests.post(api_url, data=json.dumps(payload), headers={'Content-type': 'application/json'})
kytos_1        |         data = response.json()
kytos_1        | >       assert response.status_code == 201, data
kytos_1        | E       AssertionError: {'code': 400, 'description': "Window contains non-existant items: {'switches': [], 'interfaces': [], 'links': ['00:00:00:00:00:00:00:01:1']}"}
kytos_1        | E       assert 400 == 201
kytos_1        | E        +  where 400 = <Response [400]>.status_code
kytos_1        | 
kytos_1        | tests/test_e2e_50_maintenance.py:1303: AssertionError
kytos_1        | ---------------------------- Captured stdout setup -----------------------------
kytos_1        | FAIL to stop kytos after 5 seconds -- Kytos pid still exists.. Force stop!
kytos_1        | ---------------------------- Captured stderr setup -----------------------------
kytos_1        | *** Error setting resource limits. Mininet's performance may be affected.
kytos_1        | Unable to contact the remote controller at 127.0.0.1:6653
kytos_1        | ------------------------------ Captured log setup ------------------------------
kytos_1        | WARNING  mininet:log.py:153 *** Error setting resource limits. Mininet's performance may be affected.
kytos_1        | 
kytos_1        | WARNING  mininet:log.py:153 Unable to contact the remote controller at 127.0.0.1:6653
kytos_1        | ----------------------------- Captured stdout call -----------------------------
kytos_1        | FAIL to stop kytos after 5 seconds -- Kytos pid still exists.. Force stop!
kytos_1        | =============================== warnings summary ===============================
kytos_1        | test_e2e_50_maintenance.py: 17 warnings
kytos_1        |   /usr/lib/python3/dist-packages/mininet/node.py:1121: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
kytos_1        |     return ( StrictVersion( cls.OVSVersion ) <
kytos_1        | 
kytos_1        | test_e2e_50_maintenance.py: 17 warnings
kytos_1        |   /usr/lib/python3/dist-packages/mininet/node.py:1122: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
kytos_1        |     StrictVersion( '1.10' ) )
kytos_1        | 
kytos_1        | -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
kytos_1        | ------------------------------- start/stop times -------------------------------
kytos_1        | test_e2e_50_maintenance.py::TestE2EMaintenance::test_135_interface_payload_filtering: 2024-02-28,22:24:58.660133 - 2024-02-28,22:25:16.144194
kytos_1        | =========================== short test summary info ============================
kytos_1        | FAILED tests/test_e2e_50_maintenance.py::TestE2EMaintenance::test_135_interface_payload_filtering
kytos_1        | ======================= 1 failed, 34 warnings in 51.06s ========================
kytos-end-to-end-tests_kytos_1 exited with code 1
HeriLFIU commented 6 months ago

@viniarck I just fixed the issue, once I finish the End-to-End Tests should I also add them to the PR or are they separate?

HeriLFIU commented 6 months ago

Is black no longer used? The linter seems to be failing for some reason.

HeriLFIU commented 6 months ago

@HeriLFIU, congrats on this contribution. Great bug fix. Regarding e2e, if you post the results here it's fine too. If the existing e2e tests are passing that's already sufficient for this PR.

Now, regarding black, this Napp hasn't had it enabled yet, but it's certainly welcome, since you're at it, let's fully add black #63, that way the linter errors on scrutinizer will be fixed too. To enable black check out an example on flow_manager's setup.cfg file

@viniarck I successfully added Black, and everything seems to be passing now.