# Path: apic_ml2/neutron/db/port_ha_ipaddress_binding.py
# LOG = logging.getLogger(__name__)
# class HAIPAddressToPortAssocation(model_base.BASEV2):
# class PortForHAIPAddress(object):
# class HAIPOwnerDbMixin(object):
#     def _get_ha_ipaddress(self, port_id, ipaddress, session=None):
#     def get_port_for_ha_ipaddress(self, ipaddress, network_id,
#                                   session=None):
#     def get_ha_ipaddresses_for_port(self, port_id, session=None):
#     def set_port_id_for_ha_ipaddress(self, port_id, ipaddress, session=None):
#     def delete_port_id_for_ha_ipaddress(self, port_id, ipaddress,
#                                         session=None):
#     def get_ha_port_associations(self):
#     def __init__(self):
#     def _get_plugin(self):
#     def update_ip_owner(self, ip_owner_info):


import mock
from neutron import context
from neutron.tests.unit import testlib_api
from oslo_db import exception as exc
from oslo_utils import importutils
from apic_ml2.neutron.db import port_ha_ipaddress_binding as ha
                                                    self.ha_ip1)
        self.port_haip.set_port_id_for_ha_ipaddress(self.port1['id'],
                                                    self.ha_ip2)
        ha_ips = self.port_haip.get_ha_ipaddresses_for_port(self.port1['id'])
        self.assertEqual(sorted([self.ha_ip1, self.ha_ip2]), ha_ips)

    def test_idempotent(self):
        self.port_haip.set_port_id_for_ha_ipaddress(self.port1['id'],
                                                    self.ha_ip1)
        obj = self.port_haip.set_port_id_for_ha_ipaddress(self.port1['id'],
                                                          self.ha_ip1)
        self.assertEqual(self.port1['id'], obj['port_id'])
        self.assertEqual(self.ha_ip1, obj['ha_ip_address'])

    def test_set_non_existing_port(self):
        self.assertRaises(exc.DBReferenceError,
                          self.port_haip.set_port_id_for_ha_ipaddress,
                          "fake", self.ha_ip1)

    def test_delete_non_existing_entry(self):
        self.port_haip.set_port_id_for_ha_ipaddress(self.port1['id'],
                                                    self.ha_ip1)
        result = self.port_haip.delete_port_id_for_ha_ipaddress(
            self.port1['id'], "fake")
        self.assertEqual(0, result)
        result = self.port_haip.delete_port_id_for_ha_ipaddress("fake",
                                                                self.ha_ip1)
        self.assertEqual(0, result)

    def test_ip_owner_update(self):

# Path: apic_ml2/neutron/db/port_ha_ipaddress_binding.py
# LOG = logging.getLogger(__name__)
# class HAIPAddressToPortAssocation(model_base.BASEV2):
# class PortForHAIPAddress(object):
# class HAIPOwnerDbMixin(object):
#     def _get_ha_ipaddress(self, port_id, ipaddress, session=None):
#     def get_port_for_ha_ipaddress(self, ipaddress, network_id,
#                                   session=None):
#     def get_ha_ipaddresses_for_port(self, port_id, session=None):
#     def set_port_id_for_ha_ipaddress(self, port_id, ipaddress, session=None):
#     def delete_port_id_for_ha_ipaddress(self, port_id, ipaddress,
#                                         session=None):
#     def get_ha_port_associations(self):
#     def __init__(self):
#     def _get_plugin(self):
#     def update_ip_owner(self, ip_owner_info):


# Path: apic_ml2/neutron/tests/unit/db/test_port_ha_ipaddress_binding.py
import mock
from neutron import context
from neutron.tests.unit import testlib_api
from oslo_db import exception as exc
from oslo_utils import importutils
from apic_ml2.neutron.db import port_ha_ipaddress_binding as ha

                                                    self.ha_ip1)
        self.port_haip.set_port_id_for_ha_ipaddress(self.port1['id'],
                                                    self.ha_ip2)
        ha_ips = self.port_haip.get_ha_ipaddresses_for_port(self.port1['id'])
        self.assertEqual(sorted([self.ha_ip1, self.ha_ip2]), ha_ips)

    def test_idempotent(self):
        self.port_haip.set_port_id_for_ha_ipaddress(self.port1['id'],
                                                    self.ha_ip1)
        obj = self.port_haip.set_port_id_for_ha_ipaddress(self.port1['id'],
                                                          self.ha_ip1)
        self.assertEqual(self.port1['id'], obj['port_id'])
        self.assertEqual(self.ha_ip1, obj['ha_ip_address'])

    def test_set_non_existing_port(self):
        self.assertRaises(exc.DBReferenceError,
                          self.port_haip.set_port_id_for_ha_ipaddress,
                          "fake", self.ha_ip1)

    def test_delete_non_existing_entry(self):
        self.port_haip.set_port_id_for_ha_ipaddress(self.port1['id'],
                                                    self.ha_ip1)
        result = self.port_haip.delete_port_id_for_ha_ipaddress(
            self.port1['id'], "fake")
        self.assertEqual(0, result)
        result = self.port_haip.delete_port_id_for_ha_ipaddress("fake",
                                                                self.ha_ip1)
        self.assertEqual(0, result)

    def test_ip_owner_update(self):

        mixin = ha.HAIPOwnerDbMixin()