Skip to content

Commit

Permalink
Merge "Merge server create for scheduler hint extension"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Jul 17, 2018
2 parents 116b090 + 71f1fbc commit 4d6c48d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 156 deletions.
27 changes: 0 additions & 27 deletions nova/api/openstack/compute/scheduler_hints.py

This file was deleted.

9 changes: 7 additions & 2 deletions nova/api/openstack/compute/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from nova.api.openstack.compute import helpers
from nova.api.openstack.compute import keypairs
from nova.api.openstack.compute import multiple_create
from nova.api.openstack.compute import scheduler_hints
from nova.api.openstack.compute.schemas import servers as schema_servers
from nova.api.openstack.compute.views import servers as views_servers
from nova.api.openstack import wsgi
Expand Down Expand Up @@ -72,7 +71,6 @@ class ServersController(wsgi.Controller):
config_drive.server_create,
keypairs.server_create,
multiple_create.server_create,
scheduler_hints.server_create,
]

@staticmethod
Expand Down Expand Up @@ -440,6 +438,13 @@ def create(self, req, body):
create_kwargs['security_groups'] = list(
set(create_kwargs['security_groups']))

scheduler_hints = {}
if 'os:scheduler_hints' in body:
scheduler_hints = body['os:scheduler_hints']
elif 'OS-SCH-HNT:scheduler_hints' in body:
scheduler_hints = body['OS-SCH-HNT:scheduler_hints']
create_kwargs['scheduler_hints'] = scheduler_hints

availability_zone = server_dict.pop("availability_zone", None)

if api_version_request.is_supported(req, min_version='2.52'):
Expand Down
127 changes: 0 additions & 127 deletions nova/tests/unit/api/openstack/compute/test_scheduler_hints.py

This file was deleted.

56 changes: 56 additions & 0 deletions nova/tests/unit/api/openstack/compute/test_serversV21.py
Original file line number Diff line number Diff line change
Expand Up @@ -3714,6 +3714,34 @@ def fake_instance_destroy(context, uuid, constraint):
test_group = objects.InstanceGroup.get_by_uuid(ctxt, test_group.uuid)
self.assertIn(server['id'], test_group.members)

def _test_create_instance_with_group_hint(self, hint,
hint_name='os:scheduler_hints'):
def fake_instance_destroy(context, uuid, constraint):
return fakes.stub_instance(1)

def fake_create(*args, **kwargs):
self.assertEqual(kwargs['scheduler_hints'], hint)
return ([fakes.stub_instance(1)], '')

self.stub_out('nova.compute.api.API.create', fake_create)
self.stub_out('nova.db.instance_destroy', fake_instance_destroy)
self.body[hint_name] = hint
self.req.body = jsonutils.dump_as_bytes(self.body)
return self.controller.create(self.req, body=self.body).obj['server']

def test_create_instance_with_group_hint_legacy(self):
self._test_create_instance_with_group_hint(
{'different_host': '9c47bf55-e9d8-42da-94ab-7f9e80cd1857'},
hint_name='OS-SCH-HNT:scheduler_hints')

def test_create_server_with_different_host_hint(self):
self._test_create_instance_with_group_hint(
{'different_host': '9c47bf55-e9d8-42da-94ab-7f9e80cd1857'})

self._test_create_instance_with_group_hint(
{'different_host': ['9c47bf55-e9d8-42da-94ab-7f9e80cd1857',
'82412fa6-0365-43a9-95e4-d8b20e00c0de']})

def test_create_instance_with_group_hint_group_not_found(self):
def fake_instance_destroy(context, uuid, constraint):
return fakes.stub_instance(1)
Expand All @@ -3732,6 +3760,34 @@ def test_create_instance_with_group_hint_wrong_uuid_format(self):
self.assertRaises(exception.ValidationError,
self.controller.create, self.req, body=self.body)

def test_create_server_bad_hints_non_dict(self):
sch_hints = ['os:scheduler_hints', 'OS-SCH-HNT:scheduler_hints']
for hint in sch_hints:
self.body[hint] = 'non-dict'
self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(exception.ValidationError,
self.controller.create, self.req, body=self.body)

def test_create_server_bad_hints_long_group(self):
self.body['os:scheduler_hints'] = {
'group': 'a' * 256}
self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(exception.ValidationError,
self.controller.create, self.req, body=self.body)

def test_create_server_with_bad_different_host_hint(self):
self.body['os:scheduler_hints'] = {
'different_host': 'non-server-id'}
self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(exception.ValidationError,
self.controller.create, self.req, body=self.body)

self.body['os:scheduler_hints'] = {
'different_host': ['non-server-id01', 'non-server-id02']}
self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(exception.ValidationError,
self.controller.create, self.req, body=self.body)

@mock.patch.object(compute_api.API, 'create',
side_effect=exception.PortInUse(port_id=uuids.port))
def test_create_instance_with_neutronv2_port_in_use(self, mock_create):
Expand Down

0 comments on commit 4d6c48d

Please sign in to comment.