|
10 | 10 | # License for the specific language governing permissions and limitations
|
11 | 11 | # under the License.
|
12 | 12 |
|
| 13 | +import ddt |
13 | 14 | import mock
|
14 | 15 |
|
15 | 16 | from nova.api.openstack.placement import lib as plib
|
|
23 | 24 | from nova.tests import uuidsentinel as uuids
|
24 | 25 |
|
25 | 26 |
|
| 27 | +@ddt.ddt |
26 | 28 | class TestUtils(test.NoDBTestCase):
|
27 | 29 |
|
28 | 30 | def setUp(self):
|
@@ -462,6 +464,42 @@ def test_process_use_force_hosts(self):
|
462 | 464 | )
|
463 | 465 | self.assertEqual(expected_querystring, resources.to_querystring())
|
464 | 466 |
|
| 467 | + @ddt.data( |
| 468 | + # Test single hint that we are checking for. |
| 469 | + {'group': [uuids.fake]}, |
| 470 | + # Test hint we care about and some other random hint. |
| 471 | + {'same_host': [uuids.fake], 'fake-hint': ['fake-value']}, |
| 472 | + # Test multiple hints we are checking for. |
| 473 | + {'same_host': [uuids.server1], 'different_host': [uuids.server2]}) |
| 474 | + def test_resources_from_request_spec_no_limit_based_on_hint(self, hints): |
| 475 | + """Tests that there is no limit applied to the |
| 476 | + GET /allocation_candidates query string if a given scheduler hint |
| 477 | + is in the request spec. |
| 478 | + """ |
| 479 | + flavor = objects.Flavor(vcpus=1, |
| 480 | + memory_mb=1024, |
| 481 | + root_gb=15, |
| 482 | + ephemeral_gb=0, |
| 483 | + swap=0) |
| 484 | + fake_spec = objects.RequestSpec( |
| 485 | + flavor=flavor, scheduler_hints=hints) |
| 486 | + expected = utils.ResourceRequest() |
| 487 | + expected._rg_by_id[None] = plib.RequestGroup( |
| 488 | + use_same_provider=False, |
| 489 | + resources={ |
| 490 | + 'VCPU': 1, |
| 491 | + 'MEMORY_MB': 1024, |
| 492 | + 'DISK_GB': 15, |
| 493 | + }, |
| 494 | + ) |
| 495 | + expected._limit = None |
| 496 | + resources = utils.resources_from_request_spec(fake_spec) |
| 497 | + self.assertResourceRequestsEqual(expected, resources) |
| 498 | + expected_querystring = ( |
| 499 | + 'resources=DISK_GB%3A15%2CMEMORY_MB%3A1024%2CVCPU%3A1' |
| 500 | + ) |
| 501 | + self.assertEqual(expected_querystring, resources.to_querystring()) |
| 502 | + |
465 | 503 | @mock.patch('nova.compute.utils.is_volume_backed_instance',
|
466 | 504 | return_value=False)
|
467 | 505 | def test_resources_from_flavor_no_bfv(self, mock_is_bfv):
|
|
0 commit comments