Ejemplo n.º 1
0
    def test_handle_link_up_case_4(self, *args):
        """Test if not path is found a dynamic path is used."""
        (_install_uni_flows_mocked, _install_nni_flows_mocked,
         get_best_path_mocked, deploy_to_path_mocked) = args

        deploy_to_path_mocked.return_value = True

        primary_path = [
            get_link_mocked(endpoint_a_port=9,
                            endpoint_b_port=10,
                            metadata={"s_vlan": 5},
                            status=EntityStatus.UP),
            get_link_mocked(endpoint_a_port=11,
                            endpoint_b_port=12,
                            metadata={"s_vlan": 6},
                            status=EntityStatus.DOWN),
        ]
        backup_path = [
            get_link_mocked(endpoint_a_port=13,
                            endpoint_b_port=14,
                            metadata={"s_vlan": 5},
                            status=EntityStatus.DOWN),
            get_link_mocked(endpoint_a_port=11,
                            endpoint_b_port=12,
                            metadata={"s_vlan": 6},
                            status=EntityStatus.DOWN),
        ]

        # Setup best_path mock
        best_path = Path()
        best_path.append(primary_path[0])
        get_best_path_mocked.return_value = best_path

        attributes = {
            "controller": get_controller_mock(),
            "name": "circuit_name",
            "uni_a": get_uni_mocked(is_valid=True),
            "uni_z": get_uni_mocked(is_valid=True),
            "primary_path": primary_path,
            "backup_path": backup_path,
            "enabled": True,
            "dynamic_backup_path": True
        }

        evc = EVC(**attributes)
        evc.current_path = Path([])

        # storehouse mock
        evc._storehouse.box = Mock()  # pylint: disable=protected-access
        evc._storehouse.box.data = {}  # pylint: disable=protected-access

        current_handle_link_up = evc.handle_link_up(backup_path[0])

        self.assertEqual(get_best_path_mocked.call_count, 0)
        self.assertEqual(deploy_to_path_mocked.call_count, 1)
        deploy_to_path_mocked.assert_called_once_with()
        self.assertTrue(current_handle_link_up)
Ejemplo n.º 2
0
    def test_handle_link_up_case_3(self, _install_uni_flows_mocked,
                                   _install_nni_flows_mocked,
                                   get_best_path_mocked, deploy_to_path_mocked,
                                   deploy_mocked):
        """Test if it is deployed after the backup is up."""
        deploy_mocked.return_value = True
        deploy_to_path_mocked.return_value = True
        primary_path = [
            get_link_mocked(endpoint_a_port=9,
                            endpoint_b_port=10,
                            metadata={"s_vlan": 5},
                            status=EntityStatus.DOWN),
            get_link_mocked(endpoint_a_port=11,
                            endpoint_b_port=12,
                            metadata={"s_vlan": 6},
                            status=EntityStatus.UP),
        ]
        backup_path = [
            get_link_mocked(endpoint_a_port=13,
                            endpoint_b_port=14,
                            metadata={"s_vlan": 5},
                            status=EntityStatus.DOWN),
            get_link_mocked(endpoint_a_port=11,
                            endpoint_b_port=12,
                            metadata={"s_vlan": 6},
                            status=EntityStatus.UP),
        ]
        attributes = {
            "controller": get_controller_mock(),
            "name": "circuit_name",
            "uni_a": get_uni_mocked(is_valid=True),
            "uni_z": get_uni_mocked(is_valid=True),
            "primary_path": primary_path,
            "backup_path": backup_path,
            "enabled": True,
            "dynamic_backup_path": True
        }

        evc = EVC(**attributes)

        # storehouse initialization mock
        evc._storehouse.box = Mock()  # pylint: disable=protected-access
        evc._storehouse.box.data = {}  # pylint: disable=protected-access

        evc.current_path = Path([])
        current_handle_link_up = evc.handle_link_up(backup_path[0])

        self.assertEqual(get_best_path_mocked.call_count, 0)
        self.assertEqual(deploy_mocked.call_count, 0)
        self.assertEqual(deploy_to_path_mocked.call_count, 1)
        deploy_to_path_mocked.assert_called_once_with(evc.backup_path)
        self.assertTrue(current_handle_link_up)
Ejemplo n.º 3
0
    def test_handle_link_up_case_2(self, deploy_to_path_mocked, deploy_mocked):
        """Test if it is changing from backup_path to primary_path."""
        deploy_mocked.return_value = True
        deploy_to_path_mocked.return_value = True
        primary_path = [
            get_link_mocked(
                endpoint_a_port=9,
                endpoint_b_port=10,
                metadata={"s_vlan": 5},
                status=EntityStatus.UP,
            ),
            get_link_mocked(
                endpoint_a_port=11,
                endpoint_b_port=12,
                metadata={"s_vlan": 6},
                status=EntityStatus.UP,
            ),
        ]
        backup_path = [
            get_link_mocked(
                endpoint_a_port=9,
                endpoint_b_port=14,
                metadata={"s_vlan": 5},
                status=EntityStatus.UP,
            ),
            get_link_mocked(
                endpoint_a_port=15,
                endpoint_b_port=12,
                metadata={"s_vlan": 6},
                status=EntityStatus.UP,
            ),
        ]
        attributes = {
            "controller": get_controller_mock(),
            "name": "circuit_10",
            "uni_a": get_uni_mocked(is_valid=True),
            "uni_z": get_uni_mocked(is_valid=True),
            "primary_path": primary_path,
            "backup_path": backup_path,
            "enabled": True,
            "dynamic_backup_path": True,
        }

        evc = EVC(**attributes)
        evc.current_path = evc.backup_path
        deploy_to_path_mocked.reset_mock()
        current_handle_link_up = evc.handle_link_up(primary_path[0])
        self.assertEqual(deploy_mocked.call_count, 0)
        self.assertEqual(deploy_to_path_mocked.call_count, 1)
        deploy_to_path_mocked.assert_called_once_with(evc.primary_path)
        self.assertTrue(current_handle_link_up)
Ejemplo n.º 4
0
    def test_handle_link_up_case_1(self, deploy_to_mocked, deploy_mocked):
        """Test if handle link up do nothing when is using primary path."""
        deploy_mocked.return_value = True
        deploy_to_mocked.return_value = True
        primary_path = [
            get_link_mocked(endpoint_a_port=9,
                            endpoint_b_port=10,
                            metadata={"s_vlan": 5},
                            status=EntityStatus.UP),
            get_link_mocked(endpoint_a_port=11,
                            endpoint_b_port=12,
                            metadata={"s_vlan": 6},
                            status=EntityStatus.UP),
        ]
        backup_path = [
            get_link_mocked(endpoint_a_port=9,
                            endpoint_b_port=10,
                            metadata={"s_vlan": 5},
                            status=EntityStatus.UP),
            get_link_mocked(endpoint_a_port=11,
                            endpoint_b_port=12,
                            metadata={"s_vlan": 6},
                            status=EntityStatus.UP),
        ]
        attributes = {
            "controller": get_controller_mock(),
            "name": "circuit_name",
            "uni_a": get_uni_mocked(is_valid=True),
            "uni_z": get_uni_mocked(is_valid=True),
            "primary_path": primary_path,
            "backup_path": backup_path,
            "enabled": True,
            "dynamic_backup_path": True
        }

        evc = EVC(**attributes)
        evc.current_path = evc.primary_path
        current_handle_link_up = evc.handle_link_up(backup_path[0])
        self.assertEqual(deploy_mocked.call_count, 0)
        self.assertEqual(deploy_to_mocked.call_count, 0)
        self.assertTrue(current_handle_link_up)