def _test_list_ips_associated(self, req, mock_get): instance_uuid = uuids.instance fixed_address = "10.0.0.1" floating_address = "192.168.0.1" fixed_ip = objects.FixedIP(instance_uuid=instance_uuid, address=fixed_address) floating_ip = objects.FloatingIP(address=floating_address, fixed_ip=fixed_ip, pool=CONF.default_floating_pool, interface=CONF.public_interface, project_id=None) floating_list = objects.FloatingIPList(objects=[floating_ip]) mock_get.return_value = floating_list res_dict = self.controller.index(req) ip_info = [{ 'address': floating_address, 'pool': CONF.default_floating_pool, 'interface': CONF.public_interface, 'project_id': None, 'instance_uuid': instance_uuid, 'fixed_ip': fixed_address }] response = {'floating_ip_info': ip_info} self.assertEqual(res_dict, response)
def _from_db_object(context, fixedip, db_fixedip, expected_attrs=None): if expected_attrs is None: expected_attrs = [] for field in fixedip.fields: if field == 'default_route': # NOTE(danms): This field is only set when doing a # FixedIPList.get_by_network() because it's a relatively # special-case thing, so skip it here continue if field not in FIXED_IP_OPTIONAL_ATTRS: fixedip[field] = db_fixedip[field] # NOTE(danms): Instance could be deleted, and thus None if 'instance' in expected_attrs: fixedip.instance = objects.Instance._from_db_object( context, objects.Instance(context), db_fixedip['instance']) if db_fixedip['instance'] else None if 'network' in expected_attrs: fixedip.network = objects.Network._from_db_object( context, objects.Network(context), db_fixedip['network']) if db_fixedip['network'] else None if 'virtual_interface' in expected_attrs: db_vif = db_fixedip['virtual_interface'] vif = objects.VirtualInterface._from_db_object( context, objects.VirtualInterface(context), db_fixedip['virtual_interface']) if db_vif else None fixedip.virtual_interface = vif if 'floating_ips' in expected_attrs: fixedip.floating_ips = obj_base.obj_make_list( context, objects.FloatingIPList(context), objects.FloatingIP, db_fixedip['floating_ips']) fixedip._context = context fixedip.obj_reset_changes() return fixedip
def test_list_ips_associated(self, mock_get): instance_uuid = "fake-uuid" fixed_address = "10.0.0.1" floating_address = "192.168.0.1" fixed_ip = objects.FixedIP(instance_uuid=instance_uuid, address=fixed_address) floating_ip = objects.FloatingIP(address=floating_address, fixed_ip=fixed_ip, pool=CONF.default_floating_pool, interface=CONF.public_interface, project_id=None) floating_list = objects.FloatingIPList(objects=[floating_ip]) mock_get.return_value = floating_list req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips-bulk', use_admin_context=True) res_dict = self.controller.index(req) ip_info = [{ 'address': floating_address, 'pool': CONF.default_floating_pool, 'interface': CONF.public_interface, 'project_id': None, 'instance_uuid': instance_uuid, 'fixed_ip': fixed_address }] response = {'floating_ip_info': ip_info} self.assertEqual(res_dict, response)
def _test_is_multi_host_network_has_project_id(self, is_multi_host, fip_get): network = objects.Network( id=123, project_id=self.context.project_id, multi_host=is_multi_host) fip_get.return_value = [ objects.FixedIP(instance_uuid=FAKE_UUID, network=network, floating_ips=objects.FloatingIPList())] instance = objects.Instance(uuid=FAKE_UUID) result, floats = self.network_api._get_multi_addresses(self.context, instance) self.assertEqual(is_multi_host, result)