Exemple #1
0
    def test_port_disassociate_ip(self):
        self.context.session.add = mock.Mock()
        self.context.session.delete = mock.Mock()
        mock_ports = [models.Port(id=str(x), network_id="2", ip_addresses=[])
                      for x in xrange(4)]
        mock_address = models.IPAddress(id="1", address=3232235876,
                                        address_readable="192.168.1.100",
                                        subnet_id="1", network_id="2",
                                        version=4, used_by_tenant_id="1")
        mock_assocs = []
        for p in mock_ports:
            assoc = models.PortIpAssociation()
            assoc.port_id = p.id
            assoc.port = p
            assoc.ip_address_id = mock_address.id
            assoc.ip_address = mock_address
            mock_assocs.append(assoc)

        r = db_api.port_disassociate_ip(self.context, mock_ports[1:3],
                                        mock_address)

        self.assertEqual(len(r.associations), 2)
        self.assertEqual(r.associations[0], mock_assocs[0])
        self.assertEqual(r.associations[1], mock_assocs[3])
        self.context.session.add.assert_called_once_with(r)
        self.context.session.delete.assert_has_calls(
            [mock.call(mock_assocs[1]), mock.call(mock_assocs[2])])
Exemple #2
0
def port_associate_ip(context, ports, address, enable_port=None):
    for port in ports:
        assoc = models.PortIpAssociation()
        assoc.port = port
        assoc.ip_address = address
        assoc.enabled = port.id in enable_port if enable_port else False
        context.session.add(assoc)
    return address
Exemple #3
0
def port_associate_ip(context, ports, address, enable_port=None):
    for port in ports:
        assoc = models.PortIpAssociation()
        assoc.port_id = port.id
        assoc.ip_address_id = address.id
        assoc.enabled = port.id in enable_port if enable_port else False
        address.associations.append(assoc)
    context.session.add(address)
    return address
Exemple #4
0
def _port_associate_stub(context, ports, address, **kwargs):
    for port in ports:
        assoc = models.PortIpAssociation()
        assoc.port_id = port.id
        assoc.ip_address_id = address.id
        assoc.port = port
        # NOTE(thomasem): This causes address['associations'] to gain this
        # PortIpAssocation instance.
        assoc.ip_address = address
        assoc.enabled = address.address_type == "fixed"
    return address
Exemple #5
0
 def test_can_be_shared_false(self):
     mock_address = models.IPAddress(id="1", address=3232235876,
                                     address_readable="192.168.1.100",
                                     subnet_id="1", network_id="2",
                                     version=4, used_by_tenant_id="1")
     mock_assocs = []
     for x in xrange(3):
         assoc = models.PortIpAssociation()
         assoc.ip_address_id = mock_address.id
         assoc.ip_address = mock_address
         assoc.enabled = [False, True, False][x]
         mock_assocs.append(assoc)
     r = ip_addresses._can_be_shared(mock_address)
     self.assertFalse(r)
Exemple #6
0
 def _stubs(self, ips, ports):
     with mock.patch("quark.db.api.ip_address_find") as ip_find:
         ip_models = []
         port_models = []
         for port in ports:
             p = models.Port()
             p.update(port)
             port_models.append(p)
             for ip in ips:
                 version = ip.pop("version")
                 ip_mod = models.IPAddress()
                 ip_mod.update(ip)
                 ip_mod.version = version
                 ip_mod.ports = port_models
                 # Set up Port to IP associations
                 assoc = models.PortIpAssociation()
                 assoc.port = p
                 assoc.port_id = p.id
                 assoc.ip_address = ip_mod
                 assoc.ip_address_id = ip_mod.id
                 ip_mod.associations.append(assoc)
                 ip_models.append(ip_mod)
             ip_find.return_value = ip_models
         yield