# Path: networking_vsphere/db/ovsvapp_db.py
# LOG = log.getLogger(__name__)
# RETRY = "0"
# GIVE_UP = "-1"
# SUCCESS = "1"
# def _generate_vcenter_cluster_allocations(session, vcenter, cluster):
# def _initialize_lvids_for_cluster(port_info):
# def _try_to_obtain_local_vlan(session, port_info, assign):
# def get_local_vlan(port_info, assign=True):
# def check_to_reclaim_local_vlan(port_info):
# def release_local_vlan(net_info):
# def get_stale_local_vlans_for_network(network_id):
# def update_and_get_cluster_lock(vcenter_id, cluster_id):
# def release_cluster_lock(vcenter_id, cluster_id):
# def reset_cluster_threshold(vcenter_id, cluster_id):
# def set_cluster_threshold(vcenter_id, cluster_id):
# def _admin_check(context, action):
#     def get_ovsvapp_cluster(self, context, vcenter_id, fields=None):
#     def get_ovsvapp_clusters(self, context, filters=None, fields=None):
#     def create_ovsvapp_cluster(self, context, ovsvapp_cluster):
#     def update_ovsvapp_cluster(self, context, id, ovsvapp_cluster):
#     def get_ovsvapp_mitigated_cluster(self, context, vcenter_id, fields=None):
#     def update_ovsvapp_mitigated_cluster(self, context, id,
#                                          ovsvapp_mitigated_cluster):
#     def get_ovsvapp_mitigated_clusters(self, context, filters=None,
#                                        fields=None):
#     def delete_ovsvapp_mitigated_cluster(self, context, id, filters=None):
# class OVSvAppClusterDbMixin(ovsvapp_cluster.OVSvAppClusterPluginBase):
# class OVSvAppMitigatedClusterDbMixin(vapp_mc.OVSvAppMitigatedClusterPluginBase,
#                                      common_db_mixin.CommonDbMixin):


import mock
from neutron.tests.unit import testlib_api
from networking_vsphere.db import ovsvapp_db

    def test_release_local_vlan_already_released_network(self):
        net1_port_info = self._form_port_info_dict(
            'fake_vcenter', 'fake_cluster', 'net1')
        with mock.patch('networking_vsphere.db.ovsvapp_db.'
                        'LOG.error') as error_log:
            ovsvapp_db.release_local_vlan(net1_port_info)
            self.assertTrue(error_log.called)

    def test_release_local_vlan(self):
        net1_port_info = self._form_port_info_dict(
            'fake_vcenter', 'fake_cluster', 'net1')
        # Allocate network.
        ovsvapp_db.get_local_vlan(net1_port_info)

        # Setup for release.
        lvid = ovsvapp_db.check_to_reclaim_local_vlan(net1_port_info)
        self.assertEqual(1, lvid)
        with mock.patch('networking_vsphere.db.ovsvapp_db.'
                        'LOG.error') as error_log:
            ovsvapp_db.release_local_vlan(net1_port_info)
            self.assertFalse(error_log.called)

    def test_get_stale_local_vlans_for_network(self):
        net1_port1_info = self._form_port_info_dict(
            'fake_vcenter', 'fake_cluster1', 'net1')
        ovsvapp_db.get_local_vlan(net1_port1_info)

        net1_port2_info = self._form_port_info_dict(
            'fake_vcenter', 'fake_cluster2', 'net1')

# Path: networking_vsphere/db/ovsvapp_db.py
# LOG = log.getLogger(__name__)
# RETRY = "0"
# GIVE_UP = "-1"
# SUCCESS = "1"
# def _generate_vcenter_cluster_allocations(session, vcenter, cluster):
# def _initialize_lvids_for_cluster(port_info):
# def _try_to_obtain_local_vlan(session, port_info, assign):
# def get_local_vlan(port_info, assign=True):
# def check_to_reclaim_local_vlan(port_info):
# def release_local_vlan(net_info):
# def get_stale_local_vlans_for_network(network_id):
# def update_and_get_cluster_lock(vcenter_id, cluster_id):
# def release_cluster_lock(vcenter_id, cluster_id):
# def reset_cluster_threshold(vcenter_id, cluster_id):
# def set_cluster_threshold(vcenter_id, cluster_id):
# def _admin_check(context, action):
#     def get_ovsvapp_cluster(self, context, vcenter_id, fields=None):
#     def get_ovsvapp_clusters(self, context, filters=None, fields=None):
#     def create_ovsvapp_cluster(self, context, ovsvapp_cluster):
#     def update_ovsvapp_cluster(self, context, id, ovsvapp_cluster):
#     def get_ovsvapp_mitigated_cluster(self, context, vcenter_id, fields=None):
#     def update_ovsvapp_mitigated_cluster(self, context, id,
#                                          ovsvapp_mitigated_cluster):
#     def get_ovsvapp_mitigated_clusters(self, context, filters=None,
#                                        fields=None):
#     def delete_ovsvapp_mitigated_cluster(self, context, id, filters=None):
# class OVSvAppClusterDbMixin(ovsvapp_cluster.OVSvAppClusterPluginBase):
# class OVSvAppMitigatedClusterDbMixin(vapp_mc.OVSvAppMitigatedClusterPluginBase,
#                                      common_db_mixin.CommonDbMixin):


# Path: networking_vsphere/tests/unit/ml2/test_ovsvapp_db.py
import mock
from neutron.tests.unit import testlib_api
from networking_vsphere.db import ovsvapp_db


    def test_release_local_vlan_already_released_network(self):
        net1_port_info = self._form_port_info_dict(
            'fake_vcenter', 'fake_cluster', 'net1')
        with mock.patch('networking_vsphere.db.ovsvapp_db.'
                        'LOG.error') as error_log:
            ovsvapp_db.release_local_vlan(net1_port_info)
            self.assertTrue(error_log.called)

    def test_release_local_vlan(self):
        net1_port_info = self._form_port_info_dict(
            'fake_vcenter', 'fake_cluster', 'net1')
        # Allocate network.
        ovsvapp_db.get_local_vlan(net1_port_info)

        # Setup for release.
        lvid = ovsvapp_db.check_to_reclaim_local_vlan(net1_port_info)
        self.assertEqual(1, lvid)
        with mock.patch('networking_vsphere.db.ovsvapp_db.'
                        'LOG.error') as error_log:
            ovsvapp_db.release_local_vlan(net1_port_info)
            self.assertFalse(error_log.called)

    def test_get_stale_local_vlans_for_network(self):
        net1_port1_info = self._form_port_info_dict(
            'fake_vcenter', 'fake_cluster1', 'net1')
        ovsvapp_db.get_local_vlan(net1_port1_info)

        net1_port2_info = self._form_port_info_dict(
            'fake_vcenter', 'fake_cluster2', 'net1')

        ovsvapp_db.get_local_vlan(net1_port2_info)