| @@ 364-408 (lines=45) @@ | ||
| 361 | assert result[0]["vlan"] == 100 |
|
| 362 | assert result[0]["out"] == {"port": 2, "vlan": 200} |
|
| 363 | ||
| 364 | @patch("napps.amlight.sdntrace_cp.main.get_stored_flows") |
|
| 365 | async def test_get_traces(self, mock_stored_flows): |
|
| 366 | """Test traces rest call.""" |
|
| 367 | payload = [{ |
|
| 368 | "trace": { |
|
| 369 | "switch": { |
|
| 370 | "dpid": "00:00:00:00:00:00:00:01", |
|
| 371 | "in_port": 1 |
|
| 372 | }, |
|
| 373 | "eth": {"dl_vlan": 100}, |
|
| 374 | } |
|
| 375 | }] |
|
| 376 | ||
| 377 | stored_flow = { |
|
| 378 | "id": 1, |
|
| 379 | "flow": { |
|
| 380 | "table_id": 0, |
|
| 381 | "cookie": 84114964, |
|
| 382 | "hard_timeout": 0, |
|
| 383 | "idle_timeout": 0, |
|
| 384 | "priority": 10, |
|
| 385 | "match": {"dl_vlan": 100, "in_port": 1}, |
|
| 386 | "actions": [ |
|
| 387 | {"action_type": "pop_vlan"}, |
|
| 388 | {"action_type": "output", "port": 2}, |
|
| 389 | ], |
|
| 390 | } |
|
| 391 | } |
|
| 392 | ||
| 393 | mock_stored_flows.return_value = { |
|
| 394 | "00:00:00:00:00:00:00:01": [stored_flow] |
|
| 395 | } |
|
| 396 | ||
| 397 | resp = await self.api_client.put(self.traces_endpoint, json=payload) |
|
| 398 | assert resp.status_code == 200 |
|
| 399 | current_data = resp.json() |
|
| 400 | result1 = current_data["result"] |
|
| 401 | ||
| 402 | assert len(result1) == 1 |
|
| 403 | assert len(result1[0]) == 1 |
|
| 404 | assert result1[0][0]["dpid"] == "00:00:00:00:00:00:00:01" |
|
| 405 | assert result1[0][0]["port"] == 1 |
|
| 406 | assert result1[0][0]["type"] == "last" |
|
| 407 | assert result1[0][0]["vlan"] == 100 |
|
| 408 | assert result1[0][0]["out"] == {"port": 2} |
|
| 409 | ||
| 410 | @patch("napps.amlight.sdntrace_cp.main.get_stored_flows") |
|
| 411 | async def test_traces(self, mock_stored_flows): |
|
| @@ 491-534 (lines=44) @@ | ||
| 488 | assert result[2][0]["vlan"] == 100 |
|
| 489 | assert result[2][0]["out"] is None |
|
| 490 | ||
| 491 | @patch("napps.amlight.sdntrace_cp.main.get_stored_flows") |
|
| 492 | async def test_traces_with_loop(self, mock_stored_flows): |
|
| 493 | """Test traces rest call""" |
|
| 494 | payload = [ |
|
| 495 | { |
|
| 496 | "trace": { |
|
| 497 | "switch": { |
|
| 498 | "dpid": "00:00:00:00:00:00:00:01", |
|
| 499 | "in_port": 1 |
|
| 500 | }, |
|
| 501 | "eth": { |
|
| 502 | "dl_vlan": 100 |
|
| 503 | } |
|
| 504 | } |
|
| 505 | } |
|
| 506 | ] |
|
| 507 | ||
| 508 | stored_flow = { |
|
| 509 | "id": 1, |
|
| 510 | "flow": { |
|
| 511 | "table_id": 0, |
|
| 512 | "cookie": 84114964, |
|
| 513 | "hard_timeout": 0, |
|
| 514 | "idle_timeout": 0, |
|
| 515 | "priority": 10, |
|
| 516 | "match": {"dl_vlan": 100, "in_port": 1}, |
|
| 517 | "actions": [{"action_type": "output", "port": 1}], |
|
| 518 | } |
|
| 519 | } |
|
| 520 | ||
| 521 | mock_stored_flows.return_value = { |
|
| 522 | "00:00:00:00:00:00:00:01": [stored_flow], |
|
| 523 | } |
|
| 524 | ||
| 525 | resp = await self.api_client.put(self.traces_endpoint, json=payload) |
|
| 526 | assert resp.status_code == 200 |
|
| 527 | current_data = resp.json() |
|
| 528 | result = current_data["result"] |
|
| 529 | assert len(result) == 1 |
|
| 530 | assert result[0][0]["dpid"] == "00:00:00:00:00:00:00:01" |
|
| 531 | assert result[0][0]["port"] == 1 |
|
| 532 | assert result[0][0]["type"] == "loop" |
|
| 533 | assert result[0][0]["vlan"] == 100 |
|
| 534 | assert result[0][0]["out"] == {"port": 1, "vlan": 100} |
|
| 535 | ||
| 536 | @patch("napps.amlight.sdntrace_cp.main.get_stored_flows") |
|
| 537 | async def test_traces_no_action(self, mock_stored_flows): |
|