Skip to content

Commit

Permalink
Add support for no imageRef parameter, for supporting boot-from-volume
Browse files Browse the repository at this point in the history
  • Loading branch information
cyli committed Oct 17, 2014
1 parent ff38183 commit b6042e7
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 14 deletions.
31 changes: 18 additions & 13 deletions mimic/canned_responses/nova.py
Expand Up @@ -21,7 +21,7 @@ def server_template(tenant_id, server_info, server_id, status, current_time,
def url(suffix):
return str(URLPath.fromString(compute_uri_prefix).child(suffix))

server_template = {
template = {
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": None,
Expand Down Expand Up @@ -62,17 +62,6 @@ def url(suffix):
},
"hostId": "33ccb6c82f3625748b6f2338f54d8e9df07cc583251e001355569056",
"id": server_id,
"image": {
"id": server_info['imageRef'],
"links": [
{
"href": url("{0}/images/{1}".format(
tenant_id, server_info['imageRef']
)),
"rel": "bookmark"
}
]
},
"links": [
{
"href": url("v2/{0}/servers/{1}".format(
Expand All @@ -93,7 +82,23 @@ def url(suffix):
"updated": current_time,
"user_id": "170454"
}
return server_template

if server_info.get("imageRef"):
template['image'] = {
"id": server_info['imageRef'],
"links": [
{
"href": url("{0}/images/{1}".format(
tenant_id, server_info['imageRef']
)),
"rel": "bookmark"
}
]
}
else:
template['image'] = ''

return template


def create_server(tenant_id, server_info, server_id, compute_uri_prefix,
Expand Down
70 changes: 69 additions & 1 deletion mimic/test/test_nova.py
Expand Up @@ -20,7 +20,9 @@ class ResponseGenerationTests(SynchronousTestCase):
def test_server_template(self):
"""
:obj:`server_template` generates a JSON object representing an
individual Nova server.
individual Nova server. This includes a dictionary for the ``image``
parameter that contains the ID and some links, if ``imageRef`` is
provided in the server info
"""

input_server_info = {
Expand Down Expand Up @@ -119,6 +121,72 @@ def test_server_template(self):
self.assertEquals(json.dumps(expectation, indent=2),
json.dumps(actual, indent=2))

def _test_server_template_without_image(self, input_server_info):
"""
Helper function to test generation of a server template with an empty
image.
"""
counter = itertools.count(1)

compute_service_uri_prefix = (
"http://mimic.example.com/services/region/compute/"
)

actual = server_template("some_tenant", input_server_info,
"some_server_id", "some_status",
"the_current_time",
lambda: next(counter),
compute_service_uri_prefix)

self.assertEquals("", actual['image'])

def test_server_template_with_blank_imageRef(self):
"""
:obj:`server_template` generates a JSON object representing an
individual Nova server, but the ``image`` parameter is empty if
``imageRef`` in the server info is blank.
"""
self._test_server_template_without_image({
"flavorRef": "some_flavor",
"imageRef": "",
"name": "some_server_name",
"metadata": {
"some_key": "some_value",
"some_other_key": "some_other_value",
}
})

def test_server_template_with_null_imageRef(self):
"""
:obj:`server_template` generates a JSON object representing an
individual Nova server, but the ``image`` parameter is empty if
``imageRef`` in the server info is null.
"""
self._test_server_template_without_image({
"flavorRef": "some_flavor",
"imageRef": None,
"name": "some_server_name",
"metadata": {
"some_key": "some_value",
"some_other_key": "some_other_value",
}
})

def test_server_template_with_no_imageRef(self):
"""
:obj:`server_template` generates a JSON object representing an
individual Nova server, but the ``image`` parameter is empty if
no ``imageRef`` is provided in the server info.
"""
self._test_server_template_without_image({
"flavorRef": "some_flavor",
"name": "some_server_name",
"metadata": {
"some_key": "some_value",
"some_other_key": "some_other_value",
}
})


class NovaAPITests(SynchronousTestCase):

Expand Down

0 comments on commit b6042e7

Please sign in to comment.