Fix bulk floating ip ext to show uuid and fixed_ip
The bulk floating ip extension was not showing the instance_uuid or the fixed_ip properly due to a missing join and an ommision when the extension was first created. This updates the extension to display all of the relevant data. Change-Id: I81c2c742a7eed134b5452c19da0cc55811c009ab Closes-Bug: #1360426
This commit is contained in:
parent
a949f64073
commit
cc02d56ca8
|
@ -3,6 +3,7 @@
|
|||
{
|
||||
"address": "10.10.10.3",
|
||||
"instance_uuid": null,
|
||||
"fixed_ip": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"project_id": null
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<item>
|
||||
<interface>eth0</interface>
|
||||
<instance_uuid>None</instance_uuid>
|
||||
<fixed_ip>None</fixed_ip>
|
||||
<project_id>None</project_id>
|
||||
<pool>nova</pool>
|
||||
<address>10.10.10.3</address>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
{
|
||||
"address": "10.10.10.1",
|
||||
"instance_uuid": null,
|
||||
"fixed_ip": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"project_id": null
|
||||
|
@ -10,6 +11,7 @@
|
|||
{
|
||||
"address": "10.10.10.2",
|
||||
"instance_uuid": null,
|
||||
"fixed_ip": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"project_id": null
|
||||
|
@ -17,6 +19,7 @@
|
|||
{
|
||||
"address": "10.10.10.3",
|
||||
"instance_uuid": null,
|
||||
"fixed_ip": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"project_id": null
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<item>
|
||||
<interface>eth0</interface>
|
||||
<instance_uuid>None</instance_uuid>
|
||||
<fixed_ip>None</fixed_ip>
|
||||
<project_id>None</project_id>
|
||||
<pool>nova</pool>
|
||||
<address>10.10.10.1</address>
|
||||
|
@ -10,6 +11,7 @@
|
|||
<item>
|
||||
<interface>eth0</interface>
|
||||
<instance_uuid>None</instance_uuid>
|
||||
<fixed_ip>None</fixed_ip>
|
||||
<project_id>None</project_id>
|
||||
<pool>nova</pool>
|
||||
<address>10.10.10.2</address>
|
||||
|
@ -17,6 +19,7 @@
|
|||
<item>
|
||||
<interface>eth0</interface>
|
||||
<instance_uuid>None</instance_uuid>
|
||||
<fixed_ip>None</fixed_ip>
|
||||
<project_id>None</project_id>
|
||||
<pool>nova</pool>
|
||||
<address>10.10.10.3</address>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
{
|
||||
"address": "10.10.10.3",
|
||||
"instance_uuid": null,
|
||||
"fixed_ip": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"project_id": null
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
{
|
||||
"address": "10.10.10.1",
|
||||
"instance_uuid": null,
|
||||
"fixed_ip": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"project_id": null
|
||||
|
@ -10,6 +11,7 @@
|
|||
{
|
||||
"address": "10.10.10.2",
|
||||
"instance_uuid": null,
|
||||
"fixed_ip": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"project_id": null
|
||||
|
@ -17,6 +19,7 @@
|
|||
{
|
||||
"address": "10.10.10.3",
|
||||
"instance_uuid": null,
|
||||
"fixed_ip": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"project_id": null
|
||||
|
|
|
@ -63,14 +63,17 @@ class FloatingIPBulkController(object):
|
|||
|
||||
for floating_ip in floating_ips:
|
||||
instance_uuid = None
|
||||
fixed_ip = None
|
||||
if floating_ip.fixed_ip:
|
||||
instance_uuid = floating_ip.fixed_ip.instance_uuid
|
||||
fixed_ip = str(floating_ip.fixed_ip.address)
|
||||
|
||||
result = {'address': str(floating_ip['address']),
|
||||
'pool': floating_ip['pool'],
|
||||
'interface': floating_ip['interface'],
|
||||
'project_id': floating_ip['project_id'],
|
||||
'instance_uuid': instance_uuid}
|
||||
result = {'address': str(floating_ip.address),
|
||||
'pool': floating_ip.pool,
|
||||
'interface': floating_ip.interface,
|
||||
'project_id': floating_ip.project_id,
|
||||
'instance_uuid': instance_uuid,
|
||||
'fixed_ip': fixed_ip}
|
||||
floating_ip_info['floating_ip_info'].append(result)
|
||||
|
||||
return floating_ip_info
|
||||
|
|
|
@ -68,14 +68,17 @@ class FloatingIPBulkController(object):
|
|||
|
||||
for floating_ip in floating_ips:
|
||||
instance_uuid = None
|
||||
fixed_ip = None
|
||||
if floating_ip.fixed_ip:
|
||||
instance_uuid = floating_ip.fixed_ip.instance_uuid
|
||||
fixed_ip = str(floating_ip.fixed_ip.address)
|
||||
|
||||
result = {'address': str(floating_ip['address']),
|
||||
'pool': floating_ip['pool'],
|
||||
'interface': floating_ip['interface'],
|
||||
'project_id': floating_ip['project_id'],
|
||||
'instance_uuid': instance_uuid}
|
||||
result = {'address': str(floating_ip.address),
|
||||
'pool': floating_ip.pool,
|
||||
'interface': floating_ip.interface,
|
||||
'project_id': floating_ip.project_id,
|
||||
'instance_uuid': instance_uuid,
|
||||
'fixed_ip': fixed_ip}
|
||||
floating_ip_info['floating_ip_info'].append(result)
|
||||
|
||||
return floating_ip_info
|
||||
|
|
|
@ -947,7 +947,9 @@ def _floating_ip_get_all(context, session=None):
|
|||
|
||||
@require_admin_context
|
||||
def floating_ip_get_all(context):
|
||||
floating_ip_refs = _floating_ip_get_all(context).all()
|
||||
floating_ip_refs = _floating_ip_get_all(context).\
|
||||
options(joinedload('fixed_ip')).\
|
||||
all()
|
||||
if not floating_ip_refs:
|
||||
raise exception.NoFloatingIpsDefined()
|
||||
return floating_ip_refs
|
||||
|
@ -956,8 +958,9 @@ def floating_ip_get_all(context):
|
|||
@require_admin_context
|
||||
def floating_ip_get_all_by_host(context, host):
|
||||
floating_ip_refs = _floating_ip_get_all(context).\
|
||||
filter_by(host=host).\
|
||||
all()
|
||||
filter_by(host=host).\
|
||||
options(joinedload('fixed_ip')).\
|
||||
all()
|
||||
if not floating_ip_refs:
|
||||
raise exception.FloatingIpNotFoundForHost(host=host)
|
||||
return floating_ip_refs
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
import netaddr
|
||||
from oslo.config import cfg
|
||||
import webob
|
||||
|
@ -21,6 +22,7 @@ from nova.api.openstack.compute.plugins.v3 import floating_ips_bulk as\
|
|||
fipbulk_v21
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova import objects
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
|
||||
|
@ -78,12 +80,41 @@ class FloatingIPBulkV21(test.TestCase):
|
|||
'pool': CONF.default_floating_pool,
|
||||
'interface': CONF.public_interface,
|
||||
'project_id': None,
|
||||
'instance_uuid': None}
|
||||
'instance_uuid': None,
|
||||
'fixed_ip': None}
|
||||
for ip_addr in netaddr.IPNetwork(ip_range).iter_hosts()]
|
||||
response = {'floating_ip_info': ip_info}
|
||||
|
||||
self.assertEqual(res_dict, response)
|
||||
|
||||
@mock.patch('nova.objects.FloatingIPList.get_all')
|
||||
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_list_ip_by_host(self):
|
||||
ip_range = '192.168.1.1/28'
|
||||
self._setup_floating_ips(ip_range)
|
||||
|
|
|
@ -4340,7 +4340,23 @@ class FloatingIpTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
|||
float_ips = [self._create_floating_ip({'address': addr})
|
||||
for addr in addresses]
|
||||
self._assertEqualListsOfObjects(float_ips,
|
||||
db.floating_ip_get_all(self.ctxt))
|
||||
db.floating_ip_get_all(self.ctxt),
|
||||
ignored_keys="fixed_ip")
|
||||
|
||||
def test_floating_ip_get_all_associated(self):
|
||||
instance = db.instance_create(self.ctxt, {'uuid': 'fake'})
|
||||
float_ip = self._create_floating_ip({'address': '1.1.1.1'})
|
||||
fixed_ip = self._create_fixed_ip({'address': '2.2.2.2',
|
||||
'instance_uuid': instance.uuid})
|
||||
db.floating_ip_fixed_ip_associate(self.ctxt,
|
||||
float_ip.address,
|
||||
fixed_ip,
|
||||
'host')
|
||||
float_ips = db.floating_ip_get_all(self.ctxt)
|
||||
self.assertEqual(1, len(float_ips))
|
||||
self.assertEqual(float_ip.address, float_ips[0].address)
|
||||
self.assertEqual(fixed_ip, float_ips[0].fixed_ip.address)
|
||||
self.assertEqual(instance.uuid, float_ips[0].fixed_ip.instance_uuid)
|
||||
|
||||
def test_floating_ip_get_all_not_found(self):
|
||||
self.assertRaises(exception.NoFloatingIpsDefined,
|
||||
|
@ -4363,7 +4379,8 @@ class FloatingIpTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
|||
|
||||
for host, float_ips in hosts_with_float_ips.iteritems():
|
||||
real_float_ips = db.floating_ip_get_all_by_host(self.ctxt, host)
|
||||
self._assertEqualListsOfObjects(float_ips, real_float_ips)
|
||||
self._assertEqualListsOfObjects(float_ips, real_float_ips,
|
||||
ignored_keys="fixed_ip")
|
||||
|
||||
def test_floating_ip_get_all_by_host_not_found(self):
|
||||
self.assertRaises(exception.FloatingIpNotFoundForHost,
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
"instance_uuid": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"fixed_ip": null,
|
||||
"project_id": null
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<item>
|
||||
<interface>eth0</interface>
|
||||
<instance_uuid>None</instance_uuid>
|
||||
<fixed_ip>None</fixed_ip>
|
||||
<project_id>None</project_id>
|
||||
<pool>nova</pool>
|
||||
<address>10.10.10.3</address>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
"instance_uuid": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"fixed_ip": null,
|
||||
"project_id": null
|
||||
},
|
||||
{
|
||||
|
@ -12,6 +13,7 @@
|
|||
"instance_uuid": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"fixed_ip": null,
|
||||
"project_id": null
|
||||
},
|
||||
{
|
||||
|
@ -19,7 +21,8 @@
|
|||
"instance_uuid": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"fixed_ip": null,
|
||||
"project_id": null
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<item>
|
||||
<interface>eth0</interface>
|
||||
<instance_uuid>None</instance_uuid>
|
||||
<fixed_ip>None</fixed_ip>
|
||||
<project_id>None</project_id>
|
||||
<pool>nova</pool>
|
||||
<address>10.10.10.1</address>
|
||||
|
@ -10,6 +11,7 @@
|
|||
<item>
|
||||
<interface>eth0</interface>
|
||||
<instance_uuid>None</instance_uuid>
|
||||
<fixed_ip>None</fixed_ip>
|
||||
<project_id>None</project_id>
|
||||
<pool>nova</pool>
|
||||
<address>10.10.10.2</address>
|
||||
|
@ -18,6 +20,7 @@
|
|||
<interface>eth0</interface>
|
||||
<instance_uuid>None</instance_uuid>
|
||||
<project_id>None</project_id>
|
||||
<fixed_ip>None</fixed_ip>
|
||||
<pool>nova</pool>
|
||||
<address>10.10.10.3</address>
|
||||
</item>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
{
|
||||
"address": "10.10.10.3",
|
||||
"instance_uuid": null,
|
||||
"fixed_ip": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"project_id": null
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
{
|
||||
"address": "10.10.10.1",
|
||||
"instance_uuid": null,
|
||||
"fixed_ip": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"project_id": null
|
||||
|
@ -10,6 +11,7 @@
|
|||
{
|
||||
"address": "10.10.10.2",
|
||||
"instance_uuid": null,
|
||||
"fixed_ip": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"project_id": null
|
||||
|
@ -17,6 +19,7 @@
|
|||
{
|
||||
"address": "10.10.10.3",
|
||||
"instance_uuid": null,
|
||||
"fixed_ip": null,
|
||||
"interface": "eth0",
|
||||
"pool": "nova",
|
||||
"project_id": null
|
||||
|
|
Loading…
Reference in New Issue