Merge "Added metadata for server"

This commit is contained in:
Jenkins 2012-06-06 19:14:23 +00:00 committed by Gerrit Code Review
commit f7f30ee692
3 changed files with 40 additions and 2 deletions

View File

@ -274,6 +274,38 @@ class InstanceViewTests(test.TestCase):
self.assertEquals(res.context['instance'].volumes[1].device,
"/dev/hdk")
@test.create_stubs({api: ("server_get", "volume_instance_list",
"flavor_get", "server_security_groups")})
def test_instance_details_metadata(self):
server = self.servers.first()
api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
api.volume_instance_list(IsA(http.HttpRequest),
server.id).AndReturn([])
api.flavor_get(IsA(http.HttpRequest),
server.flavor['id']).AndReturn(self.flavors.first())
api.server_security_groups(IsA(http.HttpRequest),
server.id).AndReturn(self.security_groups.list())
self.mox.ReplayAll()
url = reverse('horizon:nova:instances_and_volumes:instances:detail',
args=[server.id])
tg = InstanceDetailTabs(self.request, instance=server)
qs = "?%s=%s" % (tg.param_name, tg.get_tab("overview").get_id())
res = self.client.get(url + qs)
# Key name
self.assertContains(res, "<dd>keyName</dd>", 1)
# Meta data
self.assertContains(res, "<dt>someMetaLabel</dt>", 1)
self.assertContains(res, "<dd>someMetaData</dd>", 1)
# Test escaping of html characters in names
self.assertContains(res, "<dt>some&lt;b&gt;html&lt;/b&gt;label</dt>",
1)
self.assertContains(res, "<dd>&lt;!--</dd>", 1)
self.assertContains(res, "<dt>empty</dt>", 1)
self.assertContains(res, "<dd><em>N/A</em></dd>", 1)
def test_instance_log(self):
server = self.servers.first()
CONSOLE_OUTPUT = 'output'

View File

@ -67,10 +67,14 @@
<hr class="header_rule">
<dl>
<dt>{% trans "Key Name" %}</dt>
<dd>{% if instance.key_name %}{{ instance.key_name }}{% else %}<em>None</em>{% endif %}</dd>
<dd>{{ instance.key_name|default:"<em>None</em>" }}</dd>
{% url horizon:nova:images_and_snapshots:images:detail instance.image.id as image_url %}
<dt>{% trans "Image Name" %}</dt>
<dd><a href="{{ image_url }}">{{ instance.image_name }}</a></dd>
{% for key, value in instance.metadata.items %}
<dt>{{ key|force_escape }}</dt>
<dd>{{ value|force_escape|default:"<em>N/A</em>" }}</dd>
{% endfor%}
</dl>
</div>

View File

@ -81,7 +81,9 @@ SERVER_DATA = """
"name": "%(name)s",
"created": "2012-02-28T19:51:17Z",
"tenant_id": "%(tenant_id)s",
"metadata": {}
"metadata": {"someMetaLabel": "someMetaData",
"some<b>html</b>label": "<!--",
"empty": ""}
}
}
"""