Appending [Instance_ID] in instance name for

Floating IP association form in case the instance name
is not unique. Screenshot can be seen at: https://pzt.me/8ud1

Fixes bug 944477

Change-Id: I28692a9c39b95b143c92dc2ac7fbcc40c7dab3e7
This commit is contained in:
Tihomir Trifonov
2012-03-01 16:13:30 +02:00
parent eb724878fa
commit dff4efaa05
2 changed files with 48 additions and 1 deletions

View File

@@ -59,7 +59,20 @@ class AssociateView(forms.ModalFormView):
exceptions.handle(self.request, exceptions.handle(self.request,
_('Unable to retrieve instance list.'), _('Unable to retrieve instance list.'),
redirect=redirect) redirect=redirect)
instances = [(server.id, server.name) for server in servers] instances = []
for server in servers:
# FIXME(ttrifonov): show IP in case of non-unique names
# to be removed when nova can support unique names
server_name = server.name
if any(s.id != server.id and
s.name == server.name for s in servers):
# duplicate instance name
server_name = "%s [%s]" % (server.name, server.id)
instances.append((server.id, server_name))
# Sort instances for easy browsing
instances = sorted(instances, key=lambda x: x[1])
return {'floating_ip_id': self.object.id, return {'floating_ip_id': self.object.id,
'floating_ip': self.object.ip, 'floating_ip': self.object.ip,
'instances': instances} 'instances': instances}

View File

@@ -21,6 +21,7 @@
from django import http from django import http
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from mox import IsA from mox import IsA
from copy import deepcopy
from horizon import api from horizon import api
from horizon import test from horizon import test
@@ -51,3 +52,36 @@ class AccessAndSecurityTests(test.TestCase):
sec_groups) sec_groups)
self.assertItemsEqual(res.context['floating_ips_table'].data, self.assertItemsEqual(res.context['floating_ips_table'].data,
floating_ips) floating_ips)
def test_association(self):
floating_ip = self.floating_ips.first()
servers = self.servers.list()
# Add duplicate instance name to test instance name with [IP]
# change id and private IP
server3 = api.nova.Server(self.servers.first(), self.request)
server3.id = 101
server3.addresses = deepcopy(server3.addresses)
server3.addresses['private'][0]['addr'] = "10.0.0.5"
self.servers.add(server3)
self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
self.mox.StubOutWithMock(api, 'server_list')
api.tenant_floating_ip_get(IsA(http.HttpRequest),
floating_ip.id).AndReturn(floating_ip)
api.server_list(IsA(http.HttpRequest)).AndReturn(servers)
self.mox.ReplayAll()
res = self.client.get(
reverse("horizon:nova:access_and_security:"
"floating_ips:associate",
args=[floating_ip.id]))
self.assertTemplateUsed(res,
'nova/access_and_security/'
'floating_ips/associate.html')
self.assertContains(res, '<option value="1">server_1 [1]'
'</option>')
self.assertContains(res, '<option value="101">server_1 [101]'
'</option>')
self.assertContains(res, '<option value="2">server_2</option>')