Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lock for EVC deletion #480

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ def execute_consistency(self):
log.info(f"{circuit} enabled but inactive - redeploy")
with circuit.lock:
circuit.deploy()
for circuit_id in stored_circuits:
log.info(f"EVC found in mongodb but unloaded {circuit_id}")
self._load_evc(stored_circuits[circuit_id])

def shutdown(self):
"""Execute when your napp is unloaded.
Expand Down Expand Up @@ -430,17 +427,19 @@ def delete_circuit(self, request: Request) -> JSONResponse:
result = f"circuit_id {circuit_id} not found"
log.debug("delete_circuit result %s %s", result, 404)
raise HTTPException(404, detail=result) from KeyError

log.info("Removing %s", evc)

with evc.lock:
evc.remove_current_flows()
evc.remove_failover_flows(sync=False)
evc.deactivate()
evc.disable()
self.sched.remove(evc)
evc.archive()
evc.remove_uni_tags()
evc.sync()
if not evc.archived:
viniarck marked this conversation as resolved.
Show resolved Hide resolved
evc.remove_current_flows()
evc.remove_failover_flows(sync=False)
evc.deactivate()
evc.disable()
self.sched.remove(evc)
evc.archive()
evc.remove_uni_tags()
evc.sync()

log.info("EVC removed. %s", evc)
result = {"response": f"Circuit {circuit_id} removed"}
status = 200
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class Test(TestCommand):

def run(self):
"""Run tests."""
cmd = f"python3 -m pytest tests/ {self.get_args()}"
cmd = "python3 -m pytest tests/ --cov-report term-missing"
viniarck marked this conversation as resolved.
Show resolved Hide resolved
cmd += f" {self.get_args()}"
try:
check_call(cmd, shell=True)
except CalledProcessError as exc:
Expand All @@ -114,7 +115,8 @@ class TestCoverage(Test):

def run(self):
"""Run tests quietly and display coverage report."""
cmd = f"python3 -m pytest --cov=. tests/ {self.get_args()}"
cmd = "python3 -m pytest --cov=. tests/ --cov-report term-missing"
cmd += f" {self.get_args()}"
try:
check_call(cmd, shell=True)
except CalledProcessError as exc:
Expand Down
13 changes: 6 additions & 7 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,11 @@ def test_execute(self, mock_execute_consistency, mock_log):
mock_log.info.assert_not_called()

@patch('napps.kytos.mef_eline.main.settings')
@patch('napps.kytos.mef_eline.main.Main._load_evc')
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
@patch("napps.kytos.mef_eline.models.evc.EVCDeploy.check_list_traces")
def test_execute_consistency(self, mock_check_list_traces, *args):
"""Test execute_consistency."""
(mongo_controller_upsert_mock, mock_load_evc, mock_settings) = args
(mongo_controller_upsert_mock, mock_settings) = args

stored_circuits = {'1': {'name': 'circuit_1'},
'2': {'name': 'circuit_2'},
Expand Down Expand Up @@ -148,7 +147,6 @@ def test_execute_consistency(self, mock_check_list_traces, *args):
assert evc1.activate.call_count == 1
assert evc1.sync.call_count == 1
assert evc2.deploy.call_count == 1
mock_load_evc.assert_called_with(stored_circuits['3'])

@patch('napps.kytos.mef_eline.main.settings')
@patch('napps.kytos.mef_eline.main.Main._load_evc')
Expand Down Expand Up @@ -1776,8 +1774,8 @@ async def test_delete_archived_evc(
sched_add_mock,
evc_deploy_mock,
remove_current_flows_mock,
mock_remove_tags,
mock_use_uni,
mock_remove_tags,
mock_tags_equal,
mock_check_duplicate
):
Expand All @@ -1787,7 +1785,6 @@ async def test_delete_archived_evc(
mongo_controller_upsert_mock.return_value = True
sched_add_mock.return_value = True
evc_deploy_mock.return_value = True
remove_current_flows_mock.return_value = True
mock_use_uni.return_value = True
mock_tags_equal.return_value = True
mock_check_duplicate.return_value = True
Expand Down Expand Up @@ -1819,14 +1816,16 @@ async def test_delete_archived_evc(
)
assert 201 == response.status_code
assert len(self.napp.circuits) == 1

current_data = response.json()
circuit_id = current_data["circuit_id"]
self.napp.circuits[circuit_id].archive()

response = await self.api_client.delete(
f"{self.base_endpoint}/v2/evc/{circuit_id}"
)
assert 200 == response.status_code
assert mock_remove_tags.call_count == 1
assert mock_remove_tags.call_count == 0
assert remove_current_flows_mock.call_count == 0
assert len(self.napp.circuits) == 0

response = await self.api_client.delete(
Expand Down
Loading