def test_bulk_create(self, bulk): fixed_ips = [fixed_ip.FixedIP(address='192.168.1.1'), fixed_ip.FixedIP(address='192.168.1.2')] fixed_ip.FixedIPList.bulk_create(self.context, fixed_ips) bulk.assert_called_once_with(self.context, [{'address': '192.168.1.1'}, {'address': '192.168.1.2'}])
def test_create(self, create): create.return_value = fake_fixed_ip fixedip = fixed_ip.FixedIP(address='1.2.3.4') fixedip.create(self.context) create.assert_called_once_with( self.context, {'address': '1.2.3.4'}) self._compare(fixedip, fake_fixed_ip)
def test_disassociate(self, disassociate): fixedip = fixed_ip.FixedIP(context=self.context, address='1.2.3.4', instance_uuid='fake-uuid') fixedip.obj_reset_changes() fixedip.disassociate() disassociate.assert_called_once_with(self.context, '1.2.3.4') self.assertIsNone(fixedip.instance_uuid)
def test_save(self, update): update.return_value = fake_fixed_ip fixedip = fixed_ip.FixedIP(context=self.context, address='1.2.3.4', instance_uuid='fake-uuid') self.assertRaises(exception.ObjectActionError, fixedip.save) fixedip.obj_reset_changes(['address']) fixedip.save() update.assert_called_once_with(self.context, '1.2.3.4', {'instance_uuid': 'fake-uuid'})
def disassociate(cls, context, address): db_fixed = db.floating_ip_disassociate(context, address) floating = FloatingIP( context=context, address=address, fixed_ip_id=db_fixed['id'], fixed_ip=fixed_ip.FixedIP._from_db_object( context, fixed_ip.FixedIP(), db_fixed, expected_attrs=['network'])) return floating
def test_get_count_by_project(self): instance = instance_obj.Instance(context=self.context, uuid=uuids.instance, project_id=self.context.project_id) instance.create() ip = fixed_ip.FixedIP(context=self.context, address='192.168.1.1', instance_uuid=instance.uuid) ip.create() self.assertEqual(1, fixed_ip.FixedIPList.get_count_by_project( self.context, self.context.project_id))
def _test_is_multi_host_network_has_no_project_id(self, is_multi_host, net_get, fip_get): net_get.return_value = network_obj.Network(id=123, project_id=None, multi_host=is_multi_host) fip_get.return_value = [ fixed_ip_obj.FixedIP(network_id=123, instance_uuid=FAKE_UUID) ] instance = {'uuid': FAKE_UUID} result = self.network_api._is_multi_host(self.context, instance) self.assertEqual(is_multi_host, result)
def _from_db_object(context, floatingip, db_floatingip, expected_attrs=None): if expected_attrs is None: expected_attrs = [] for field in floatingip.fields: if field not in FLOATING_IP_OPTIONAL_ATTRS: floatingip[field] = db_floatingip[field] if 'fixed_ip' in expected_attrs: floatingip.fixed_ip = fixed_ip.FixedIP._from_db_object( context, fixed_ip.FixedIP(), db_floatingip['fixed_ip']) floatingip._context = context floatingip.obj_reset_changes() return floatingip
def test_delete(self, update): """ PF9 function :param update: :return: """ update.return_value = fake_fixed_ip fixedip = fixed_ip.FixedIP(context=self.context, address='1.2.3.4', instance_uuid='fake-uuid') fixedip.delete(self.context) update.assert_called_once_with(self.context, '1.2.3.4', {'deleted': True})
def associate(cls, context, floating_address, fixed_address, host): db_fixed = db.floating_ip_fixed_ip_associate(context, floating_address, fixed_address, host) if db_fixed is None: return None floating = FloatingIP( context=context, address=floating_address, host=host, fixed_ip_id=db_fixed['id'], fixed_ip=fixed_ip.FixedIP._from_db_object( context, fixed_ip.FixedIP(), db_fixed, expected_attrs=['network'])) return floating
def test_floating_ips_do_not_lazy_load(self): fixedip = fixed_ip.FixedIP() self.assertRaises(NotImplementedError, lambda: fixedip.floating_ips)
def test_save_no_fixedip(self, update): update.return_value = fake_floating_ip floatingip = floating_ip.FloatingIP(context=self.context, id=123) floatingip.fixed_ip = fixed_ip.FixedIP(context=self.context, id=456) self.assertNotIn('fixed_ip', update.calls[1])