Add Server Detail and Metadata tests

Change-Id: Ic5386478a706ee5af8301315bfd3a2842af5a781
This commit is contained in:
Dan Smith 2012-09-07 10:16:54 -07:00
parent 37cc45b8fd
commit 85923aa53d
21 changed files with 319 additions and 2 deletions

View File

@ -0,0 +1,56 @@
{
"servers": [
{
"accessIPv4": "",
"accessIPv6": "",
"addresses": {
"private": [
{
"addr": "192.168.0.3",
"version": 4
}
]
},
"created": "2012-09-07T16:56:37Z",
"flavor": {
"id": "1",
"links": [
{
"href": "http://openstack.example.com/openstack/flavors/1",
"rel": "bookmark"
}
]
},
"hostId": "16d193736a5cfdb60c697ca27ad071d6126fa13baeb670fc9d10645e",
"id": "05184ba3-00ba-4fbc-b7a2-03b62b884931",
"image": {
"id": "70a599e0-31e7-49b7-b260-868f441e862b",
"links": [
{
"href": "http://openstack.example.com/openstack/images/70a599e0-31e7-49b7-b260-868f441e862b",
"rel": "bookmark"
}
]
},
"links": [
{
"href": "http://openstack.example.com/v2/openstack/servers/05184ba3-00ba-4fbc-b7a2-03b62b884931",
"rel": "self"
},
{
"href": "http://openstack.example.com/openstack/servers/05184ba3-00ba-4fbc-b7a2-03b62b884931",
"rel": "bookmark"
}
],
"metadata": {
"My Server Name": "Apache1"
},
"name": "new-server-test",
"progress": 0,
"status": "ACTIVE",
"tenant_id": "openstack",
"updated": "2012-09-07T16:56:37Z",
"user_id": "fake"
}
]
}

View File

@ -0,0 +1,21 @@
<?xml version='1.0' encoding='UTF-8'?>
<servers xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1">
<server status="ACTIVE" updated="2012-09-07T17:11:46Z" hostId="1b3afbff40723a9649091142a647b83eb6e5b49973239cdeb3d1973c" name="new-server-test" created="2012-09-07T17:11:45Z" userId="fake" tenantId="openstack" accessIPv4="" accessIPv6="" progress="0" id="7c3c0f79-343e-4b99-93bc-2ade47641e64">
<image id="70a599e0-31e7-49b7-b260-868f441e862b">
<atom:link href="http://openstack.example.com/openstack/images/70a599e0-31e7-49b7-b260-868f441e862b" rel="bookmark"/>
</image>
<flavor id="1">
<atom:link href="http://openstack.example.com/openstack/flavors/1" rel="bookmark"/>
</flavor>
<metadata>
<meta key="My Server Name">Apache1</meta>
</metadata>
<addresses>
<network id="private">
<ip version="4" addr="192.168.0.3"/>
</network>
</addresses>
<atom:link href="http://openstack.example.com/v2/openstack/servers/7c3c0f79-343e-4b99-93bc-2ade47641e64" rel="self"/>
<atom:link href="http://openstack.example.com/openstack/servers/7c3c0f79-343e-4b99-93bc-2ade47641e64" rel="bookmark"/>
</server>
</servers>

View File

@ -0,0 +1,5 @@
{
"metadata" : {
"foo" : "Foo Value"
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://docs.openstack.org/compute/api/v1.1">
<meta key="foo">Foo Value</meta>
</metadata>

View File

@ -0,0 +1,5 @@
{
"metadata": {
"foo": "Foo Value"
}
}

View File

@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<metadata xmlns="http://docs.openstack.org/compute/api/v1.1">
<meta key="foo">Foo Value</meta>
</metadata>

View File

@ -0,0 +1,5 @@
{
"meta" : {
"foo" : "Bar Value"
}
}

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<meta xmlns="http://docs.openstack.org/compute/api/v1.1" key="foo">Bar Value</meta>

View File

@ -0,0 +1,5 @@
{
"meta": {
"foo": "Bar Value"
}
}

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<meta xmlns="http://docs.openstack.org/compute/api/v1.1" key="foo">Bar Value</meta>

View File

@ -0,0 +1,56 @@
{
"servers": [
{
"accessIPv4": "",
"accessIPv6": "",
"addresses": {
"private": [
{
"addr": "%(ip)s",
"version": 4
}
]
},
"created": "%(timestamp)s",
"flavor": {
"id": "1",
"links": [
{
"href": "%(host)s/openstack/flavors/1",
"rel": "bookmark"
}
]
},
"hostId": "%(hostid)s",
"id": "%(uuid)s",
"image": {
"id": "%(uuid)s",
"links": [
{
"href": "%(host)s/openstack/images/%(uuid)s",
"rel": "bookmark"
}
]
},
"links": [
{
"href": "%(host)s/v2/openstack/servers/%(uuid)s",
"rel": "self"
},
{
"href": "%(host)s/openstack/servers/%(uuid)s",
"rel": "bookmark"
}
],
"metadata": {
"My Server Name": "Apache1"
},
"name": "new-server-test",
"progress": 0,
"status": "ACTIVE",
"tenant_id": "openstack",
"updated": "%(timestamp)s",
"user_id": "fake"
}
]
}

View File

@ -0,0 +1,21 @@
<?xml version='1.0' encoding='UTF-8'?>
<servers xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1">
<server status="ACTIVE" updated="%(timestamp)s" hostId="%(hostid)s" name="new-server-test" created="%(timestamp)s" userId="fake" tenantId="openstack" accessIPv4="" accessIPv6="" progress="0" id="%(id)s">
<image id="%(uuid)s">
<atom:link href="%(host)s/openstack/images/%(uuid)s" rel="bookmark"/>
</image>
<flavor id="1">
<atom:link href="%(host)s/openstack/flavors/1" rel="bookmark"/>
</flavor>
<metadata>
<meta key="My Server Name">Apache1</meta>
</metadata>
<addresses>
<network id="private">
<ip version="4" addr="%(ip)s"/>
</network>
</addresses>
<atom:link href="%(host)s/v2/openstack/servers/%(uuid)s" rel="self"/>
<atom:link href="%(host)s/openstack/servers/%(uuid)s" rel="bookmark"/>
</server>
</servers>

View File

@ -0,0 +1,5 @@
{
"metadata" : {
"foo" : "%(value)s"
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://docs.openstack.org/compute/api/v1.1">
<meta key="foo">%(value)s</meta>
</metadata>

View File

@ -0,0 +1,5 @@
{
"metadata" : {
"foo" : "%(value)s"
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://docs.openstack.org/compute/api/v1.1">
<meta key="foo">%(value)s</meta>
</metadata>

View File

@ -0,0 +1,5 @@
{
"meta" : {
"foo" : "%(value)s"
}
}

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<meta xmlns="http://docs.openstack.org/compute/api/v1.1" key="foo">%(value)s</meta>

View File

@ -0,0 +1,5 @@
{
"meta": {
"foo": "%(value)s"
}
}

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<meta xmlns="http://docs.openstack.org/compute/api/v1.1" key="foo">%(value)s</meta>

View File

@ -157,6 +157,10 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
if match.groups(): if match.groups():
matched_value = match.groups()[0] matched_value = match.groups()[0]
else: else:
if isinstance(expected, basestring):
# NOTE(danms): Ignore whitespace in this comparison
expected = expected.strip()
result = result.strip()
if expected != result: if expected != result:
raise NoMatch(_('Values do not match:\n' raise NoMatch(_('Values do not match:\n'
'%(expected)s\n%(result)s') % locals()) '%(expected)s\n%(result)s') % locals())
@ -217,6 +221,9 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
def _do_put(self, url, name, subs): def _do_put(self, url, name, subs):
return self._do_post(url, name, subs, method='PUT') return self._do_post(url, name, subs, method='PUT')
def _do_delete(self, url):
return self._get_response(url, 'DELETE')
class VersionsSampleJsonTest(ApiSampleTestBase): class VersionsSampleJsonTest(ApiSampleTestBase):
def test_servers_get(self): def test_servers_get(self):
@ -229,8 +236,8 @@ class VersionsSampleXmlTest(VersionsSampleJsonTest):
ctype = 'xml' ctype = 'xml'
class ServersSampleJsonTest(ApiSampleTestBase): class ServersSampleBase(ApiSampleTestBase):
def test_servers_post(self): def _post_server(self):
subs = { subs = {
'image_id': fake.get_valid_image_id(), 'image_id': fake.get_valid_image_id(),
'host': self._get_host(), 'host': self._get_host(),
@ -240,6 +247,11 @@ class ServersSampleJsonTest(ApiSampleTestBase):
subs = self._get_regexes() subs = self._get_regexes()
return self._verify_response('server-post-resp', subs, response) return self._verify_response('server-post-resp', subs, response)
class ServersSampleJsonTest(ServersSampleBase):
def test_servers_post(self):
return self._post_server()
def test_servers_get(self): def test_servers_get(self):
uuid = self.test_servers_post() uuid = self.test_servers_post()
response = self._do_get('servers/%s' % uuid) response = self._do_get('servers/%s' % uuid)
@ -252,6 +264,20 @@ class ServersSampleXmlTest(ServersSampleJsonTest):
ctype = 'xml' ctype = 'xml'
class ServersDetailJsonTest(ServersSampleBase):
def test_servers_detail_get(self):
uuid = self._post_server()
response = self._do_get('servers/detail')
self.assertEqual(response.status, 200)
subs = self._get_regexes()
subs['hostid'] = '[a-f0-9]+'
return self._verify_response('server-detail-get-resp', subs, response)
class ServersDetailXmlTest(ServersDetailJsonTest):
ctype = 'xml'
class ServersSampleAllExtensionJsonTest(ServersSampleJsonTest): class ServersSampleAllExtensionJsonTest(ServersSampleJsonTest):
all_extensions = True all_extensions = True
@ -260,6 +286,73 @@ class ServersSampleAllExtensionXmlTest(ServersSampleXmlTest):
all_extensions = True all_extensions = True
class ServersMetadataJsonTest(ServersSampleBase):
def _create_and_set(self, subs):
uuid = self._post_server()
response = self._do_put('servers/%s/metadata' % uuid,
'server-metadata-all-req',
subs)
self.assertEqual(response.status, 200)
self._verify_response('server-metadata-all-resp', subs, response)
return uuid
def test_metadata_put_all(self):
"""Test setting all metadata for a server"""
subs = {'value': 'Foo Value'}
return self._create_and_set(subs)
def test_metadata_post_all(self):
"""Test updating all metadata for a server"""
subs = {'value': 'Foo Value'}
uuid = self._create_and_set(subs)
subs['value'] = 'Bar Value'
response = self._do_post('servers/%s/metadata' % uuid,
'server-metadata-all-req',
subs)
self.assertEqual(response.status, 200)
self._verify_response('server-metadata-all-resp', subs, response)
def test_metadata_get_all(self):
"""Test getting all metadata for a server"""
subs = {'value': 'Foo Value'}
uuid = self._create_and_set(subs)
response = self._do_get('servers/%s/metadata' % uuid)
self.assertEqual(response.status, 200)
self._verify_response('server-metadata-all-resp', subs, response)
def test_metadata_put(self):
"""Test putting an individual metadata item for a server"""
subs = {'value': 'Foo Value'}
uuid = self._create_and_set(subs)
subs['value'] = 'Bar Value'
response = self._do_put('servers/%s/metadata/foo' % uuid,
'server-metadata-req',
subs)
self.assertEqual(response.status, 200)
return self._verify_response('server-metadata-resp', subs, response)
def test_metadata_get(self):
"""Test getting an individual metadata item for a server"""
subs = {'value': 'Foo Value'}
uuid = self._create_and_set(subs)
response = self._do_get('servers/%s/metadata/foo' % uuid)
self.assertEqual(response.status, 200)
return self._verify_response('server-metadata-resp', subs, response)
def test_metadata_delete(self):
"""Test deleting an individual metadata item for a server"""
subs = {'value': 'Foo Value'}
uuid = self._create_and_set(subs)
response = self._do_delete('servers/%s/metadata/foo' % uuid)
self.assertEqual(response.status, 204)
self.assertEqual(response.read(), '')
class ServersMetadataXmlTest(ServersMetadataJsonTest):
ctype = 'xml'
class ExtensionsSampleJsonTest(ApiSampleTestBase): class ExtensionsSampleJsonTest(ApiSampleTestBase):
all_extensions = True all_extensions = True