Merge lp:~rackspace-titan/nova/minram-mindisk into lp:~hudson-openstack/nova/trunk

Proposed by Naveed Massjouni
Status: Rejected
Rejected by: Brian Waldon
Proposed branch: lp:~rackspace-titan/nova/minram-mindisk
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 557 lines (+327/-1)
10 files modified
nova/api/openstack/create_instance_helper.py (+4/-0)
nova/api/openstack/images.py (+6/-0)
nova/api/openstack/schemas/v1.1/image.rng (+6/-0)
nova/api/openstack/views/images.py (+5/-0)
nova/compute/api.py (+5/-0)
nova/exception.py (+8/-0)
nova/image/glance.py (+1/-1)
nova/tests/api/openstack/test_images.py (+189/-0)
nova/tests/image/test_glance.py (+12/-0)
nova/tests/test_compute.py (+91/-0)
To merge this branch: bzr merge lp:~rackspace-titan/nova/minram-mindisk
Reviewer Review Type Date Requested Status
Dan Prince (community) Approve
Chris Behrens (community) Approve
Brian Waldon (community) Approve
Review via email: mp+76491@code.launchpad.net

Description of the change

This addresses Bug #819990 Add minDisk minRam to OSAPI image details. It also enforces the minram and mindisk constraints if they exist. Corresponding tests have been added.

To post a comment you must log in.
Revision history for this message
Brian Waldon (bcwaldon) wrote :

Can you change the new exception names to InstanceTypeDiskTooSmall and InstanceTypeMemoryTooSmall? I think keeping the term 'flavor' limited to the OSAPI view is a good thing to do here.

It looks like we only test passing image filters through to the image service, not that the image service actually does something with them. If you see a way we can test that, I would love to see it :) It's not a blocker for my Approve, though.

review: Needs Fixing
Revision history for this message
Naveed Massjouni (ironcamel) wrote :

Good point. Fixed.

Revision history for this message
Brian Waldon (bcwaldon) wrote :

Thanks guys.

review: Approve
Revision history for this message
Chris Behrens (cbehrens) wrote :

Looks good. Minor thing. I'd like to see the tests that call compute_api.create() (in test_compute) destroy the instances that it created when done, otherwise stale data is left in the sqllite database. You can see examples in the other test_compute tests.

review: Needs Fixing
Revision history for this message
Alex Meade (alex-meade) wrote :

good point, I am on it

Revision history for this message
Chris Behrens (cbehrens) wrote :

Thanks!

review: Approve
Revision history for this message
Dan Prince (dan-prince) wrote :

Looks good.

review: Approve
Revision history for this message
Brian Waldon (bcwaldon) wrote :

Merged through gerrit.

Unmerged revisions

1585. By Alex Meade

Added the deleting of servers that were created in tests

1584. By Alex Meade

fixed incorrect exception names

1583. By Naveed Massjouni

Changing FlavorMemoryTooSmall/FlavorDiskTooSmall exceptions to
InstanceTypeMemoryTooSmall/InstanceTypeDiskTooSmall.

1582. By Naveed Massjouni

pep8

1581. By Naveed Massjouni

More tests.

1580. By Naveed Massjouni

Adding tests for minram/mindisk.

1579. By Naveed Massjouni

Honor the min_ram and min_disk attributes of images when creating a server

1578. By Naveed Massjouni

removing print

1577. By Naveed Massjouni

Merge from trunk

1576. By Alex Meade

Added support for filtering images with minRam and minDisk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'nova/api/openstack/create_instance_helper.py'
--- nova/api/openstack/create_instance_helper.py 2011-09-15 14:07:58 +0000
+++ nova/api/openstack/create_instance_helper.py 2011-09-22 19:53:25 +0000
@@ -187,6 +187,10 @@
187 config_drive=config_drive,))187 config_drive=config_drive,))
188 except quota.QuotaError as error:188 except quota.QuotaError as error:
189 self._handle_quota_error(error)189 self._handle_quota_error(error)
190 except exception.InstanceTypeMemoryTooSmall as error:
191 raise exc.HTTPBadRequest(explanation=unicode(error))
192 except exception.InstanceTypeDiskTooSmall as error:
193 raise exc.HTTPBadRequest(explanation=unicode(error))
190 except exception.ImageNotFound as error:194 except exception.ImageNotFound as error:
191 msg = _("Can not find requested image")195 msg = _("Can not find requested image")
192 raise exc.HTTPBadRequest(explanation=msg)196 raise exc.HTTPBadRequest(explanation=msg)
193197
=== modified file 'nova/api/openstack/images.py'
--- nova/api/openstack/images.py 2011-09-20 21:11:49 +0000
+++ nova/api/openstack/images.py 2011-09-22 19:53:25 +0000
@@ -41,6 +41,8 @@
41 'changes-since': 'changes-since',41 'changes-since': 'changes-since',
42 'server': 'property-instance_ref',42 'server': 'property-instance_ref',
43 'type': 'property-image_type',43 'type': 'property-image_type',
44 'minRam': 'min_ram',
45 'minDisk': 'min_disk',
44}46}
4547
4648
@@ -239,6 +241,10 @@
239 image_elem.set('status', str(image_dict['status']))241 image_elem.set('status', str(image_dict['status']))
240 if 'progress' in image_dict:242 if 'progress' in image_dict:
241 image_elem.set('progress', str(image_dict['progress']))243 image_elem.set('progress', str(image_dict['progress']))
244 if 'minRam' in image_dict:
245 image_elem.set('minRam', str(image_dict['minRam']))
246 if 'minDisk' in image_dict:
247 image_elem.set('minDisk', str(image_dict['minDisk']))
242 if 'server' in image_dict:248 if 'server' in image_dict:
243 server_elem = self._create_server_node(image_dict['server'])249 server_elem = self._create_server_node(image_dict['server'])
244 image_elem.append(server_elem)250 image_elem.append(server_elem)
245251
=== modified file 'nova/api/openstack/schemas/v1.1/image.rng'
--- nova/api/openstack/schemas/v1.1/image.rng 2011-08-25 16:05:53 +0000
+++ nova/api/openstack/schemas/v1.1/image.rng 2011-09-22 19:53:25 +0000
@@ -9,6 +9,12 @@
9 <attribute name="progress"> <text/> </attribute>9 <attribute name="progress"> <text/> </attribute>
10 </optional>10 </optional>
11 <optional>11 <optional>
12 <attribute name="minDisk"> <text/> </attribute>
13 </optional>
14 <optional>
15 <attribute name="minRam"> <text/> </attribute>
16 </optional>
17 <optional>
12 <element name="server">18 <element name="server">
13 <attribute name="id"> <text/> </attribute>19 <attribute name="id"> <text/> </attribute>
14 <zeroOrMore>20 <zeroOrMore>
1521
=== modified file 'nova/api/openstack/views/images.py'
--- nova/api/openstack/views/images.py 2011-09-20 20:21:06 +0000
+++ nova/api/openstack/views/images.py 2011-09-22 19:53:25 +0000
@@ -161,6 +161,11 @@
161161
162 if detail:162 if detail:
163 image["metadata"] = image_obj.get("properties", {})163 image["metadata"] = image_obj.get("properties", {})
164 if 'min_ram' in image_obj:
165 image["minRam"] = image_obj.get("min_ram") or 0
166
167 if 'min_disk' in image_obj:
168 image["minDisk"] = image_obj.get("min_disk") or 0
164169
165 return image170 return image
166171
167172
=== modified file 'nova/compute/api.py'
--- nova/compute/api.py 2011-09-21 21:00:53 +0000
+++ nova/compute/api.py 2011-09-22 19:53:25 +0000
@@ -219,6 +219,11 @@
219 image_href)219 image_href)
220 image = image_service.show(context, image_id)220 image = image_service.show(context, image_id)
221221
222 if instance_type['memory_mb'] < int(image.get('min_ram', 0)):
223 raise exception.InstanceTypeMemoryTooSmall()
224 if instance_type['local_gb'] < int(image.get('min_disk', 0)):
225 raise exception.InstanceTypeDiskTooSmall()
226
222 config_drive_id = None227 config_drive_id = None
223 if config_drive and config_drive is not True:228 if config_drive and config_drive is not True:
224 # config_drive is volume id229 # config_drive is volume id
225230
=== modified file 'nova/exception.py'
--- nova/exception.py 2011-09-16 02:53:42 +0000
+++ nova/exception.py 2011-09-22 19:53:25 +0000
@@ -810,3 +810,11 @@
810 if message is None:810 if message is None:
811 message = _("1 or more Zones could not complete the request")811 message = _("1 or more Zones could not complete the request")
812 super(ZoneRequestError, self).__init__(message=message)812 super(ZoneRequestError, self).__init__(message=message)
813
814
815class InstanceTypeMemoryTooSmall(NovaException):
816 message = _("Instance type's memory is too small for requested image.")
817
818
819class InstanceTypeDiskTooSmall(NovaException):
820 message = _("Instance type's disk is too small for requested image.")
813821
=== modified file 'nova/image/glance.py'
--- nova/image/glance.py 2011-09-20 18:56:15 +0000
+++ nova/image/glance.py 2011-09-22 19:53:25 +0000
@@ -404,7 +404,7 @@
404 'container_format', 'checksum', 'id',404 'container_format', 'checksum', 'id',
405 'name', 'created_at', 'updated_at',405 'name', 'created_at', 'updated_at',
406 'deleted_at', 'deleted', 'status',406 'deleted_at', 'deleted', 'status',
407 'is_public']407 'min_disk', 'min_ram', 'is_public']
408 output = {}408 output = {}
409 for attr in IMAGE_ATTRIBUTES:409 for attr in IMAGE_ATTRIBUTES:
410 output[attr] = image_meta.get(attr)410 output[attr] = image_meta.get(attr)
411411
=== modified file 'nova/tests/api/openstack/test_images.py'
--- nova/tests/api/openstack/test_images.py 2011-09-21 20:17:05 +0000
+++ nova/tests/api/openstack/test_images.py 2011-09-22 19:53:25 +0000
@@ -113,6 +113,7 @@
113 self.assertDictMatch(expected_image, actual_image)113 self.assertDictMatch(expected_image, actual_image)
114114
115 def test_get_image_v1_1(self):115 def test_get_image_v1_1(self):
116 self.maxDiff = None
116 request = webob.Request.blank('/v1.1/fake/images/124')117 request = webob.Request.blank('/v1.1/fake/images/124')
117 app = fakes.wsgi_app(fake_auth_context=self._get_fake_context())118 app = fakes.wsgi_app(fake_auth_context=self._get_fake_context())
118 response = request.get_response(app)119 response = request.get_response(app)
@@ -133,6 +134,8 @@
133 "created": NOW_API_FORMAT,134 "created": NOW_API_FORMAT,
134 "status": "SAVING",135 "status": "SAVING",
135 "progress": 0,136 "progress": 0,
137 "minDisk": 0,
138 "minRam": 0,
136 'server': {139 'server': {
137 'id': '42',140 'id': '42',
138 "links": [{141 "links": [{
@@ -542,6 +545,8 @@
542 'created': NOW_API_FORMAT,545 'created': NOW_API_FORMAT,
543 'status': 'ACTIVE',546 'status': 'ACTIVE',
544 'progress': 100,547 'progress': 100,
548 'minDisk': 0,
549 'minRam': 0,
545 "links": [{550 "links": [{
546 "rel": "self",551 "rel": "self",
547 "href": "http://localhost/v1.1/fake/images/123",552 "href": "http://localhost/v1.1/fake/images/123",
@@ -567,6 +572,8 @@
567 'created': NOW_API_FORMAT,572 'created': NOW_API_FORMAT,
568 'status': 'SAVING',573 'status': 'SAVING',
569 'progress': 0,574 'progress': 0,
575 'minDisk': 0,
576 'minRam': 0,
570 'server': {577 'server': {
571 'id': '42',578 'id': '42',
572 "links": [{579 "links": [{
@@ -603,6 +610,8 @@
603 'created': NOW_API_FORMAT,610 'created': NOW_API_FORMAT,
604 'status': 'SAVING',611 'status': 'SAVING',
605 'progress': 0,612 'progress': 0,
613 'minDisk': 0,
614 'minRam': 0,
606 'server': {615 'server': {
607 'id': '42',616 'id': '42',
608 "links": [{617 "links": [{
@@ -639,6 +648,8 @@
639 'created': NOW_API_FORMAT,648 'created': NOW_API_FORMAT,
640 'status': 'ACTIVE',649 'status': 'ACTIVE',
641 'progress': 100,650 'progress': 100,
651 'minDisk': 0,
652 'minRam': 0,
642 'server': {653 'server': {
643 'id': '42',654 'id': '42',
644 "links": [{655 "links": [{
@@ -675,6 +686,8 @@
675 'created': NOW_API_FORMAT,686 'created': NOW_API_FORMAT,
676 'status': 'ERROR',687 'status': 'ERROR',
677 'progress': 0,688 'progress': 0,
689 'minDisk': 0,
690 'minRam': 0,
678 'server': {691 'server': {
679 'id': '42',692 'id': '42',
680 "links": [{693 "links": [{
@@ -711,6 +724,8 @@
711 'created': NOW_API_FORMAT,724 'created': NOW_API_FORMAT,
712 'status': 'DELETED',725 'status': 'DELETED',
713 'progress': 0,726 'progress': 0,
727 'minDisk': 0,
728 'minRam': 0,
714 'server': {729 'server': {
715 'id': '42',730 'id': '42',
716 "links": [{731 "links": [{
@@ -747,6 +762,8 @@
747 'created': NOW_API_FORMAT,762 'created': NOW_API_FORMAT,
748 'status': 'DELETED',763 'status': 'DELETED',
749 'progress': 0,764 'progress': 0,
765 'minDisk': 0,
766 'minRam': 0,
750 'server': {767 'server': {
751 'id': '42',768 'id': '42',
752 "links": [{769 "links": [{
@@ -780,6 +797,8 @@
780 'created': NOW_API_FORMAT,797 'created': NOW_API_FORMAT,
781 'status': 'ACTIVE',798 'status': 'ACTIVE',
782 'progress': 100,799 'progress': 100,
800 'minDisk': 0,
801 'minRam': 0,
783 "links": [{802 "links": [{
784 "rel": "self",803 "rel": "self",
785 "href": "http://localhost/v1.1/fake/images/130",804 "href": "http://localhost/v1.1/fake/images/130",
@@ -810,6 +829,30 @@
810 controller.index(request)829 controller.index(request)
811 self.mox.VerifyAll()830 self.mox.VerifyAll()
812831
832 def test_image_filter_with_min_ram(self):
833 image_service = self.mox.CreateMockAnything()
834 context = self._get_fake_context()
835 filters = {'min_ram': '0'}
836 image_service.index(context, filters=filters).AndReturn([])
837 self.mox.ReplayAll()
838 request = webob.Request.blank('/v1.1/images?minRam=0')
839 request.environ['nova.context'] = context
840 controller = images.ControllerV11(image_service=image_service)
841 controller.index(request)
842 self.mox.VerifyAll()
843
844 def test_image_filter_with_min_disk(self):
845 image_service = self.mox.CreateMockAnything()
846 context = self._get_fake_context()
847 filters = {'min_disk': '7'}
848 image_service.index(context, filters=filters).AndReturn([])
849 self.mox.ReplayAll()
850 request = webob.Request.blank('/v1.1/images?minDisk=7')
851 request.environ['nova.context'] = context
852 controller = images.ControllerV11(image_service=image_service)
853 controller.index(request)
854 self.mox.VerifyAll()
855
813 def test_image_filter_with_status(self):856 def test_image_filter_with_status(self):
814 image_service = self.mox.CreateMockAnything()857 image_service = self.mox.CreateMockAnything()
815 context = self._get_fake_context()858 context = self._get_fake_context()
@@ -1369,6 +1412,152 @@
1369 server_root = root.find('{0}server'.format(NS))1412 server_root = root.find('{0}server'.format(NS))
1370 self.assertEqual(server_root, None)1413 self.assertEqual(server_root, None)
13711414
1415 def test_show_with_min_ram(self):
1416 serializer = images.ImageXMLSerializer()
1417
1418 fixture = {
1419 'image': {
1420 'id': 1,
1421 'name': 'Image1',
1422 'created': self.TIMESTAMP,
1423 'updated': self.TIMESTAMP,
1424 'status': 'ACTIVE',
1425 'progress': 80,
1426 'minRam': 256,
1427 'server': {
1428 'id': '1',
1429 'links': [
1430 {
1431 'href': self.SERVER_HREF,
1432 'rel': 'self',
1433 },
1434 {
1435 'href': self.SERVER_BOOKMARK,
1436 'rel': 'bookmark',
1437 },
1438 ],
1439 },
1440 'metadata': {
1441 'key1': 'value1',
1442 },
1443 'links': [
1444 {
1445 'href': self.IMAGE_HREF % 1,
1446 'rel': 'self',
1447 },
1448 {
1449 'href': self.IMAGE_BOOKMARK % 1,
1450 'rel': 'bookmark',
1451 },
1452 ],
1453 },
1454 }
1455
1456 output = serializer.serialize(fixture, 'show')
1457 print output
1458 root = etree.XML(output)
1459 xmlutil.validate_schema(root, 'image')
1460 image_dict = fixture['image']
1461
1462 for key in ['name', 'id', 'updated', 'created', 'status', 'progress',
1463 'minRam']:
1464 self.assertEqual(root.get(key), str(image_dict[key]))
1465
1466 link_nodes = root.findall('{0}link'.format(ATOMNS))
1467 self.assertEqual(len(link_nodes), 2)
1468 for i, link in enumerate(image_dict['links']):
1469 for key, value in link.items():
1470 self.assertEqual(link_nodes[i].get(key), value)
1471
1472 metadata_root = root.find('{0}metadata'.format(NS))
1473 metadata_elems = metadata_root.findall('{0}meta'.format(NS))
1474 self.assertEqual(len(metadata_elems), 1)
1475 for i, metadata_elem in enumerate(metadata_elems):
1476 (meta_key, meta_value) = image_dict['metadata'].items()[i]
1477 self.assertEqual(str(metadata_elem.get('key')), str(meta_key))
1478 self.assertEqual(str(metadata_elem.text).strip(), str(meta_value))
1479
1480 server_root = root.find('{0}server'.format(NS))
1481 self.assertEqual(server_root.get('id'), image_dict['server']['id'])
1482 link_nodes = server_root.findall('{0}link'.format(ATOMNS))
1483 self.assertEqual(len(link_nodes), 2)
1484 for i, link in enumerate(image_dict['server']['links']):
1485 for key, value in link.items():
1486 self.assertEqual(link_nodes[i].get(key), value)
1487
1488 def test_show_with_min_disk(self):
1489 serializer = images.ImageXMLSerializer()
1490
1491 fixture = {
1492 'image': {
1493 'id': 1,
1494 'name': 'Image1',
1495 'created': self.TIMESTAMP,
1496 'updated': self.TIMESTAMP,
1497 'status': 'ACTIVE',
1498 'progress': 80,
1499 'minDisk': 5,
1500 'server': {
1501 'id': '1',
1502 'links': [
1503 {
1504 'href': self.SERVER_HREF,
1505 'rel': 'self',
1506 },
1507 {
1508 'href': self.SERVER_BOOKMARK,
1509 'rel': 'bookmark',
1510 },
1511 ],
1512 },
1513 'metadata': {
1514 'key1': 'value1',
1515 },
1516 'links': [
1517 {
1518 'href': self.IMAGE_HREF % 1,
1519 'rel': 'self',
1520 },
1521 {
1522 'href': self.IMAGE_BOOKMARK % 1,
1523 'rel': 'bookmark',
1524 },
1525 ],
1526 },
1527 }
1528
1529 output = serializer.serialize(fixture, 'show')
1530 print output
1531 root = etree.XML(output)
1532 xmlutil.validate_schema(root, 'image')
1533 image_dict = fixture['image']
1534
1535 for key in ['name', 'id', 'updated', 'created', 'status', 'progress',
1536 'minDisk']:
1537 self.assertEqual(root.get(key), str(image_dict[key]))
1538
1539 link_nodes = root.findall('{0}link'.format(ATOMNS))
1540 self.assertEqual(len(link_nodes), 2)
1541 for i, link in enumerate(image_dict['links']):
1542 for key, value in link.items():
1543 self.assertEqual(link_nodes[i].get(key), value)
1544
1545 metadata_root = root.find('{0}metadata'.format(NS))
1546 metadata_elems = metadata_root.findall('{0}meta'.format(NS))
1547 self.assertEqual(len(metadata_elems), 1)
1548 for i, metadata_elem in enumerate(metadata_elems):
1549 (meta_key, meta_value) = image_dict['metadata'].items()[i]
1550 self.assertEqual(str(metadata_elem.get('key')), str(meta_key))
1551 self.assertEqual(str(metadata_elem.text).strip(), str(meta_value))
1552
1553 server_root = root.find('{0}server'.format(NS))
1554 self.assertEqual(server_root.get('id'), image_dict['server']['id'])
1555 link_nodes = server_root.findall('{0}link'.format(ATOMNS))
1556 self.assertEqual(len(link_nodes), 2)
1557 for i, link in enumerate(image_dict['server']['links']):
1558 for key, value in link.items():
1559 self.assertEqual(link_nodes[i].get(key), value)
1560
1372 def test_index(self):1561 def test_index(self):
1373 serializer = images.ImageXMLSerializer()1562 serializer = images.ImageXMLSerializer()
13741563
13751564
=== modified file 'nova/tests/image/test_glance.py'
--- nova/tests/image/test_glance.py 2011-09-20 18:56:15 +0000
+++ nova/tests/image/test_glance.py 2011-09-22 19:53:25 +0000
@@ -127,6 +127,8 @@
127 'name': 'test image',127 'name': 'test image',
128 'is_public': False,128 'is_public': False,
129 'size': None,129 'size': None,
130 'min_disk': None,
131 'min_ram': None,
130 'location': None,132 'location': None,
131 'disk_format': None,133 'disk_format': None,
132 'container_format': None,134 'container_format': None,
@@ -157,6 +159,8 @@
157 'name': 'test image',159 'name': 'test image',
158 'is_public': False,160 'is_public': False,
159 'size': None,161 'size': None,
162 'min_disk': None,
163 'min_ram': None,
160 'location': None,164 'location': None,
161 'disk_format': None,165 'disk_format': None,
162 'container_format': None,166 'container_format': None,
@@ -287,6 +291,8 @@
287 'name': 'TestImage %d' % (i),291 'name': 'TestImage %d' % (i),
288 'properties': {},292 'properties': {},
289 'size': None,293 'size': None,
294 'min_disk': None,
295 'min_ram': None,
290 'location': None,296 'location': None,
291 'disk_format': None,297 'disk_format': None,
292 'container_format': None,298 'container_format': None,
@@ -330,6 +336,8 @@
330 'name': 'TestImage %d' % (i),336 'name': 'TestImage %d' % (i),
331 'properties': {},337 'properties': {},
332 'size': None,338 'size': None,
339 'min_disk': None,
340 'min_ram': None,
333 'location': None,341 'location': None,
334 'disk_format': None,342 'disk_format': None,
335 'container_format': None,343 'container_format': None,
@@ -382,6 +390,8 @@
382 'name': 'image1',390 'name': 'image1',
383 'is_public': True,391 'is_public': True,
384 'size': None,392 'size': None,
393 'min_disk': None,
394 'min_ram': None,
385 'location': None,395 'location': None,
386 'disk_format': None,396 'disk_format': None,
387 'container_format': None,397 'container_format': None,
@@ -416,6 +426,8 @@
416 'name': 'image10',426 'name': 'image10',
417 'is_public': True,427 'is_public': True,
418 'size': None,428 'size': None,
429 'min_disk': None,
430 'min_ram': None,
419 'location': None,431 'location': None,
420 'disk_format': None,432 'disk_format': None,
421 'container_format': None,433 'container_format': None,
422434
=== modified file 'nova/tests/test_compute.py'
--- nova/tests/test_compute.py 2011-09-21 20:59:40 +0000
+++ nova/tests/test_compute.py 2011-09-22 19:53:25 +0000
@@ -20,6 +20,8 @@
20Tests For Compute20Tests For Compute
21"""21"""
2222
23from copy import copy
24
23from nova import compute25from nova import compute
24from nova import context26from nova import context
25from nova import db27from nova import db
@@ -1394,3 +1396,92 @@
1394 self.assertEqual(self.compute_api._volume_size(inst_type,1396 self.assertEqual(self.compute_api._volume_size(inst_type,
1395 'swap'),1397 'swap'),
1396 swap_size)1398 swap_size)
1399
1400
1401class ComputeTestMinRamMinDisk(test.TestCase):
1402 def setUp(self):
1403 super(ComputeTestMinRamMinDisk, self).setUp()
1404 self.compute = utils.import_object(FLAGS.compute_manager)
1405 self.compute_api = compute.API()
1406 self.context = context.RequestContext('fake', 'fake')
1407 self.fake_image = {
1408 'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}}
1409
1410 def test_create_with_too_little_ram(self):
1411 """Test an instance type with too little memory"""
1412
1413 inst_type = instance_types.get_default_instance_type()
1414 inst_type['memory_mb'] = 1
1415
1416 def fake_show(*args):
1417 img = copy(self.fake_image)
1418 img['min_ram'] = 2
1419 return img
1420 self.stubs.Set(fake_image._FakeImageService, 'show', fake_show)
1421
1422 self.assertRaises(exception.InstanceTypeMemoryTooSmall,
1423 self.compute_api.create, self.context, inst_type, None)
1424
1425 # Now increase the inst_type memory and make sure all is fine.
1426 inst_type['memory_mb'] = 2
1427 ref = self.compute_api.create(self.context, inst_type, None)
1428 self.assertTrue(ref)
1429
1430 db.instance_destroy(self.context, ref[0]['id'])
1431
1432 def test_create_with_too_little_disk(self):
1433 """Test an instance type with too little disk space"""
1434
1435 inst_type = instance_types.get_default_instance_type()
1436 inst_type['local_gb'] = 1
1437
1438 def fake_show(*args):
1439 img = copy(self.fake_image)
1440 img['min_disk'] = 2
1441 return img
1442 self.stubs.Set(fake_image._FakeImageService, 'show', fake_show)
1443
1444 self.assertRaises(exception.InstanceTypeDiskTooSmall,
1445 self.compute_api.create, self.context, inst_type, None)
1446
1447 # Now increase the inst_type disk space and make sure all is fine.
1448 inst_type['local_gb'] = 2
1449 ref = self.compute_api.create(self.context, inst_type, None)
1450 self.assertTrue(ref)
1451
1452 db.instance_destroy(self.context, ref[0]['id'])
1453
1454 def test_create_just_enough_ram_and_disk(self):
1455 """Test an instance type with just enough ram and disk space"""
1456
1457 inst_type = instance_types.get_default_instance_type()
1458 inst_type['local_gb'] = 2
1459 inst_type['memory_mb'] = 2
1460
1461 def fake_show(*args):
1462 img = copy(self.fake_image)
1463 img['min_ram'] = 2
1464 img['min_disk'] = 2
1465 return img
1466 self.stubs.Set(fake_image._FakeImageService, 'show', fake_show)
1467
1468 ref = self.compute_api.create(self.context, inst_type, None)
1469 self.assertTrue(ref)
1470
1471 db.instance_destroy(self.context, ref[0]['id'])
1472
1473 def test_create_with_no_ram_and_disk_reqs(self):
1474 """Test an instance type with no min_ram or min_disk"""
1475
1476 inst_type = instance_types.get_default_instance_type()
1477 inst_type['local_gb'] = 1
1478 inst_type['memory_mb'] = 1
1479
1480 def fake_show(*args):
1481 return copy(self.fake_image)
1482 self.stubs.Set(fake_image._FakeImageService, 'show', fake_show)
1483
1484 ref = self.compute_api.create(self.context, inst_type, None)
1485 self.assertTrue(ref)
1486
1487 db.instance_destroy(self.context, ref[0]['id'])