ODL_NETWORK = 'network'
ODL_NETWORKS = 'networks'
ODL_SUBNET = 'subnet'
ODL_SUBNETS = 'subnets'
ODL_PORT = 'port'
ODL_PORTS = 'ports'
ODL_SG = 'security_group'
ODL_SGS = 'security_groups'
ODL_SG_RULE = 'security_group_rule'
ODL_SG_RULES = 'security_group_rules'
ODL_ROUTER = 'router'
ODL_ROUTERS = 'routers'
ODL_FLOATINGIP = 'floatingip'
ODL_FLOATINGIPS = 'floatingips'
ODL_QOS = 'qos'
ODL_QOS_POLICY = 'policy'
ODL_QOS_POLICIES = 'policies'
ODL_SFC = 'sfc'
ODL_SFC_FLOW_CLASSIFIER = 'flowclassifier'
ODL_SFC_FLOW_CLASSIFIERS = 'flowclassifiers'
ODL_SFC_PORT_PAIR = 'portpair'
ODL_SFC_PORT_PAIRS = 'portpairs'
ODL_SFC_PORT_PAIR_GROUP = 'portpairgroup'
ODL_SFC_PORT_PAIR_GROUPS = 'portpairgroups'
ODL_SFC_PORT_CHAIN = 'portchain'
ODL_SFC_PORT_CHAINS = 'portchains'
NETWORKING_SFC_FLOW_CLASSIFIER = 'flow_classifier'
NETWORKING_SFC_FLOW_CLASSIFIERS = 'flow_classifiers'
NETWORKING_SFC_PORT_PAIR = 'port_pair'
NETWORKING_SFC_PORT_PAIRS = 'port_pairs'
NETWORKING_SFC_PORT_PAIR_GROUP = 'port_pair_group'
NETWORKING_SFC_PORT_PAIR_GROUPS = 'port_pair_groups'
NETWORKING_SFC_PORT_CHAIN = 'port_chain'
NETWORKING_SFC_PORT_CHAINS = 'port_chains'
ODL_TRUNK = 'trunk'
ODL_TRUNKS = 'trunks'
ODL_L2GATEWAY = 'l2_gateway'
ODL_L2GATEWAYS = 'l2_gateways'
ODL_L2GATEWAY_CONNECTION = 'l2gateway_connection'
ODL_L2GATEWAY_CONNECTIONS = 'l2_gateway_connections'
ODL_BGPVPN = 'bgpvpn'
ODL_BGPVPNS = 'bgpvpns'
ODL_BGPVPN_NETWORK_ASSOCIATION = 'bgpvpn_network_association'
ODL_BGPVPN_NETWORK_ASSOCIATIONS = 'bgpvpn_network_associations'
ODL_BGPVPN_ROUTER_ASSOCIATION = 'bgpvpn_router_association'
ODL_BGPVPN_ROUTER_ASSOCIATIONS = 'bgpvpn_router_associations'
ODL_ML2_MECH_DRIVER_V2 = "opendaylight_v2"
ODL_DEVICE_ID_START = 'OpenDaylight'
ODL_CREATE = 'create'
ODL_UPDATE = 'update'
ODL_DELETE = 'delete'
PENDING = 'pending'
PROCESSING = 'processing'
FAILED = 'failed'
COMPLETED = 'completed'
BEFORE_COMPLETE = 'before_complete'
AFTER_DELETE = 'after_delete'
RESOURCE_URL_MAPPINGS = {
    ODL_QOS_POLICY: "%s/%s" % (ODL_QOS, ODL_QOS_POLICIES),
    ODL_SFC_FLOW_CLASSIFIER: "%s/%s" % (ODL_SFC, ODL_SFC_FLOW_CLASSIFIERS),
    ODL_SFC_PORT_CHAIN: "%s/%s" % (ODL_SFC, ODL_SFC_PORT_CHAINS),
    ODL_SFC_PORT_PAIR: "%s/%s" % (ODL_SFC, ODL_SFC_PORT_PAIRS),
    ODL_SFC_PORT_PAIR_GROUP: "%s/%s" % (ODL_SFC, ODL_SFC_PORT_PAIR_GROUPS)
} class NetworkingODLException(exceptions.NeutronException):
class FullSyncError(NetworkingODLException):
class UnsupportedResourceType(NetworkingODLException):
class PluginMethodNotFound(NetworkingODLException, AttributeError):
class ResourceNotRegistered(FullSyncError): LOG = logging.getLogger(__name__)
def get_pending_or_processing_ops(context, object_uuid, operation=None):
def get_pending_delete_ops_with_parent(context, object_type, parent_id):
def get_all_db_rows(context):
def get_all_db_rows_by_state(context, state):
def get_oldest_pending_db_row_with_lock(context):
def delete_dependency(context, entry):
def update_db_row_state(context, row, state, flush=True):
def update_pending_db_row_retry(context, row, retry_count):
def delete_row(context, row=None, row_id=None, flush=True):
def create_pending_row(context, object_type, object_uuid,
                       operation, data, depending_on=None):
def delete_pending_rows(context, operations_to_delete):
def _update_periodic_task_state(context, expected_state, state, task):
def was_periodic_task_executed_recently(context, task, interval):
def lock_periodic_task(context, task):
def unlock_periodic_task(context, task):
def update_periodic_task(context, task, operation=None):
def delete_rows_by_state_and_time(context, state, time_delta):
def reset_processing_rows(context, max_timedelta): @db_api.retry_if_session_inactive()
@db_api.CONTEXT_WRITER.savepoint
def full_sync(context):
    if not _full_sync_needed(context):
        return

    db.delete_pending_rows(context, _OPS_TO_DELETE_ON_SYNC)

    for resource_type in _ORDERED_ODL_RESOURCES:
        handler = FULL_SYNC_RESOURCES.get(resource_type)
        if handler:
            _sync_resources(context, resource_type, handler)

    journal.record(context, odl_const.ODL_NETWORK, _CANARY_NETWORK_ID,
                   odl_const.ODL_CREATE, _CANARY_NETWORK_DATA) _CLIENT = client.OpenDaylightRestClientGlobal()
LOG = logging.getLogger(__name__)
def journal_recovery(context):
def get_latest_resource(context, row):
def _get_latest_resource(context, row):
def _sync_resource_to_odl(context, row, operation_type, exists_on_odl):
def _handle_existing_resource(context, row):
def _handle_non_existing_resource(context, row): LOG = logging.getLogger(__name__)
L3_RESOURCES = {
    odl_const.ODL_ROUTER: odl_const.ODL_ROUTERS,
    odl_const.ODL_FLOATINGIP: odl_const.ODL_FLOATINGIPS
}
def _record_in_journal(context, object_type, operation, object_id, data):
    def __init__(self):
    def get_plugin_type(self):
    def get_plugin_description(self):
    def create_router(self, context, router):
    def update_router(self, context, router_id, router):
    def delete_router(self, context, router_id):
    def create_floatingip(self, context, floatingip,
                          initial_status=q_const.FLOATINGIP_STATUS_ACTIVE):
    def update_floatingip(self, context, floatingip_id, floatingip):
    def delete_floatingip(self, context, floatingip_id):
    def disassociate_floatingips(self, context, port_id, do_notify=True):
    def add_router_interface(self, context, router_id, interface_info):
    def remove_router_interface(self, context, router_id, interface_info):
    def dvr_deletens_if_no_port(self, context, port_id):
class OpenDaylightL3RouterPlugin(
        extraroute_db.ExtraRoute_db_mixin,
        l3_dvr_db.L3_NAT_with_dvr_db_mixin,
        l3_gwmode_db.L3_NAT_db_mixin,
        l3_agentschedulers_db.L3AgentSchedulerDbMixin): LOG = logging.getLogger(__name__)
    RESOURCES = {
        odl_const.ODL_SG: odl_const.ODL_SGS,
        odl_const.ODL_SG_RULE: odl_const.ODL_SG_RULES,
        odl_const.ODL_NETWORK: odl_const.ODL_NETWORKS,
        odl_const.ODL_SUBNET: odl_const.ODL_SUBNETS,
        odl_const.ODL_PORT: odl_const.ODL_PORTS
    }
        VLAN_TRANSPARENT_NETWORK_TYPES = [p_const.TYPE_VXLAN]
class OpenDaylightMechanismDriver(api.MechanismDriver,
                                  base_driver.ResourceBaseDriver):
    def initialize(self):
    def get_workers(self):
    def _record_in_journal(context, object_type, operation, data=None):
    def create_network_precommit(self, context):
    def create_subnet_precommit(self, context):
    def create_port_precommit(self, context):
    def update_network_precommit(self, context):
    def update_subnet_precommit(self, context):
    def update_port_precommit(self, context):
    def delete_network_precommit(self, context):
    def delete_subnet_precommit(self, context):
    def delete_port_precommit(self, context):
    def _sync_security_group_create_precommit(
            self, context, operation, object_type, res_id, sg_dict):
    def sync_from_callback_precommit(self, context, operation, res_type,
                                     res_id, resource_dict, **kwargs):
    def sync_from_callback_postcommit(self, context, operation, res_type,
                                      res_id, resource_dict, payload):
    def _postcommit(self, context):
    def bind_port(self, port_context):
    def check_vlan_transparency(self, context): class DietTestCase(base.DietTestCase):
class OpenDaylightRestClientFixture(fixtures.Fixture):
class OpenDaylightRestClientGlobalFixture(fixtures.Fixture):
class OpenDaylightFeaturesFixture(fixtures.Fixture):
class OpenDaylightJournalThreadFixture(fixtures.Fixture):
class JournalWorkerPidFileFixture(fixtures.Fixture):
class OpenDaylightPeriodicTaskFixture(fixtures.Fixture):
class OpenDaylightPseudoAgentPrePopulateFixture(
        nl_fixture.CallbackRegistryFixture):
class OpenDaylightFullSyncFixture(fixtures.Fixture):
    def patch(self, target, name, *args, **kwargs):
    def _setUp(self):
    def __init__(self, global_client):
    def _setUp(self):
    def _setUp(self):
    def _setUp(self):
    def remock_atexit(self):
    def _setUp(self):
    def _setUp(self):
    def _setUp(self):
    def _restore(self):
    def _setUp(self): def in_session(fn):
    def wrapper(self, *args, **kwargs):
    def setUp(self):
    def _update_row(self, row):
    def _test_validate_updates(self, first_entry, second_entry, expected_deps,
                               state=None):
    def _test_retry_count(self, retry_num, max_retry,
                          expected_retry_count, expected_state):
    def _test_retry_wrapper(self, decorated_function):
    def _decorated_retry_if_session_inactive(self, context):
    def test_retry_if_session_inactive(self):
    def _test_update_row_state(self, from_state, to_state, dry_flush=False):
    def test_updates_same_object_uuid(self):
    def test_validate_updates_different_object_uuid(self):
    def test_validate_updates_different_object_type(self):
    def test_check_for_older_ops_processing(self):
    def test_get_oldest_pending_row_none_when_no_rows(self):
    def _test_get_oldest_pending_row_none(self, state):
    def test_get_oldest_pending_row_none_when_row_processing(self):
    def test_get_oldest_pending_row_none_when_row_failed(self):
    def test_get_oldest_pending_row_none_when_row_completed(self):
    def test_get_oldest_pending_row(self):
    def test_get_oldest_pending_row_order(self):
    def _test_get_oldest_pending_row_with_dep(self, dep_state):
    def test_get_oldest_pending_row_when_dep_completed(self):
    def test_get_oldest_pending_row_when_dep_failed(self):
    def test_get_oldest_pending_row_returns_parent_when_dep_pending(self):
    def test_get_oldest_pending_row_none_when_dep_processing(self):
    def test_get_oldest_pending_row_retries_exceptions(self):
    def _test_delete_row(self, by_row=False, by_row_id=False, dry_flush=False):
    def test_delete_row_by_row(self):
    def test_delete_row_by_row_id(self):
    def test_delete_row_by_row_without_flushing(self):
    def test_create_pending_row(self):
    def _test_delete_rows_by_state_and_time(self, last_retried, row_retention,
                                            state, expected_rows,
                                            dry_delete=False):
    def test_delete_completed_rows_no_new_rows(self):
    def test_delete_completed_rows_one_new_row(self):
    def test_delete_completed_rows_wrong_state(self):
    def test_delete_completed_rows_individually(self):
    def test_delete_completed_rows_without_flush(self, mock_delete_row):
    def _test_reset_processing_rows(self, last_retried, max_timedelta,
                                    quantity, dry_reset=False):
    def test_reset_processing_rows(self):
    def test_reset_processing_rows_no_new_rows(self):
    def test_reset_processing_rows_individually(self, mock_update_row):
    def test_valid_retry_count(self):
    def test_invalid_retry_count(self):
    def test_update_row_state_to_pending(self):
    def test_update_row_state_to_processing(self):
    def test_update_row_state_to_failed(self):
    def test_update_row_state_to_completed(self):
    def test_update_row_state_to_status_without_flush(self):
    def _test_periodic_task_lock_unlock(self, db_func, existing_state,
                                        expected_state, expected_result,
                                        task='test_task'):
    def test_lock_periodic_task(self):
    def test_lock_periodic_task_fails_when_processing(self):
    def test_unlock_periodic_task(self):
    def test_unlock_periodic_task_fails_when_pending(self):
    def test_multiple_row_tasks(self):
    def _add_tasks(self, tasks):
    def _perform_ops_on_all_rows(self, tasks, to_lock):
    def test_multiple_row_tasks_lock_unlock(self):
class DbTestCase(test_base_db.ODLBaseDbTestCase): TEST_UUID = 'bd8db3a8-2b30-4083-a8b3-b3fd46401142'
TEST_PLUGIN = 'test_plugin'
TEST_RESOURCE1 = 'test_resource1'
TEST_RESOURCE2 = 'test_resource2'
TEST_RESOURCE1_SUFFIX = 'test_resource1s'
TEST_RESOURCE2_SUFFIX = 'test_resource2s'
INVALID_RESOURCE = 'invalid_resource'
INVALID_PLUGIN = 'invalid_plugin'
INVALID_METHOD = 'invalid_method_name'
    RESOURCES = {
        TEST_RESOURCE1: TEST_RESOURCE1_SUFFIX,
        TEST_RESOURCE2: TEST_RESOURCE2_SUFFIX
    }
class TestPlugin(object):
class TestDriver(base_driver.ResourceBaseDriver):
    def get_test_resource1s(self, context):
    def get_test_resource2s(self, context):
    def get_test_resource1(self, context, id_):
    def __init__(self): RETRIABLE_EXCEPTIONS = (db_exc.DBDeadlock, exc.StaleDataError,
                        db_exc.DBConnectionError, db_exc.DBDuplicateEntry,
                        db_exc.RetryRequest)
RETRY_INTERVAL = 0.001
RETRY_MAX = 2
    UPDATE_ROW = [constants.ODL_NETWORK, 'id', constants.ODL_UPDATE,
                  {'test': 'data'}]
class _InnerException(Exception):
class ODLBaseDbTestCase(SqlTestCaseLight):
        class RetryTracker(object):
    def setUp(self):
    def _setup_retry_tracker_table(self):
    def _db_cleanup(self):
    def _test_db_exceptions_handled(self, method, mock_object, expect_retries):
        def _assertRaises(exceptions, method, context, *args, **kwargs):
            def increase_retry_counter_and_except(*args, **kwargs):
    def _assertRetryCount(self, expected_count):
    def _test_retry_exceptions(self, method, mock_object,
                               assert_transaction=True):
from unittest import mock
from neutron_lib import exceptions as nexc
from neutron_lib.plugins import constants as plugin_constants
from neutron_lib.plugins import directory
from networking_odl.common import constants as odl_const
from networking_odl.common import exceptions
from networking_odl.db import db
from networking_odl.journal import full_sync
from networking_odl.journal import recovery
from networking_odl.l3 import l3_odl_v2
from networking_odl.ml2 import mech_driver_v2
from networking_odl.tests import base
from networking_odl.tests.unit.db import test_db
from networking_odl.tests.unit.journal import helper
from networking_odl.tests.unit import test_base_db
#
# Copyright (C) 2016 Red Hat, Inc.
#
#  Licensed under the Apache License, Version 2.0 (the "License"); you may
#  not use this file except in compliance with the License. You may obtain
#  a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#  License for the specific language governing permissions and limitations
#  under the License.
#





class RecoveryTestCase(test_base_db.ODLBaseDbTestCase):
    def setUp(self):
        self.useFixture(

            base.OpenDaylightRestClientGlobalFixture(recovery._CLIENT))