Browse Source

Remove 'create_db_entry_for_new_instance'

This is a hangover from the cells v1 days. It's no longer necessary.

Change-Id: I4f89f75493468a51a759a870bcd215c7ac3fd311
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
changes/45/778545/2
Stephen Finucane 8 months ago
parent
commit
61256b4f78
  1. 35
      nova/compute/api.py
  2. 8
      nova/tests/unit/api/openstack/compute/test_availability_zone.py
  3. 35
      nova/tests/unit/api/openstack/compute/test_servers.py
  4. 26
      nova/tests/unit/compute/test_api.py

35
nova/compute/api.py

@ -1336,10 +1336,11 @@ class API(base.Base):
instance.trusted_certs = self._retrieve_trusted_certs_object(
context, trusted_certs)
instance = self.create_db_entry_for_new_instance(context,
instance_type, boot_meta, instance, security_groups,
block_device_mapping, num_instances, i,
shutdown_terminate, create_instance=False)
self._populate_instance_for_create(
context, instance, boot_meta, i,
security_groups, instance_type,
num_instances, shutdown_terminate)
block_device_mapping = (
self._bdm_validate_set_size_and_instance(context,
instance, instance_type, block_device_mapping,
@ -1964,32 +1965,6 @@ class API(base.Base):
tag.resource_id = resource_id
return instance_tags
# This method remains because cellsv1 uses it in the scheduler
def create_db_entry_for_new_instance(self, context, instance_type, image,
instance, security_group, block_device_mapping, num_instances,
index, shutdown_terminate=False, create_instance=True):
"""Create an entry in the DB for this new instance,
including any related table updates (such as security group,
etc).
This is called by the scheduler after a location for the
instance has been determined.
:param create_instance: Determines if the instance is created here or
just populated for later creation. This is done so that this code
can be shared with cellsv1 which needs the instance creation to
happen here. It should be removed and this method cleaned up when
cellsv1 is a distant memory.
"""
self._populate_instance_for_create(context, instance, image, index,
security_group, instance_type,
num_instances, shutdown_terminate)
if create_instance:
instance.create()
return instance
def _check_multiple_instances_with_neutron_ports(self,
requested_networks):
"""Check whether multiple instances are created from port id(s)."""

8
nova/tests/unit/api/openstack/compute/test_availability_zone.py

@ -203,14 +203,14 @@ class ServersControllerCreateTestV21(test.TestCase):
fakes.stub_out_nw_api(self)
self._set_up_controller()
def create_db_entry_for_new_instance(*args, **kwargs):
instance = args[4]
def _populate_instance_for_create(*args, **kwargs):
instance = args[2]
instance.uuid = FAKE_UUID
return instance
self.useFixture(fixtures.GlanceFixture(self))
self.stub_out('nova.compute.api.API.create_db_entry_for_new_instance',
create_db_entry_for_new_instance)
self.stub_out('nova.compute.api.API._populate_instance_for_create',
_populate_instance_for_create)
def _set_up_controller(self):
self.controller = servers_v21.ServersController()

35
nova/tests/unit/api/openstack/compute/test_servers.py

@ -5860,12 +5860,13 @@ class ServersControllerCreateTest(test.TestCase):
}
}
def create_db_entry_for_new_instance(*args, **kwargs):
instance = args[4]
def _populate_instance_for_create(*args, **kwargs):
instance = args[2]
self.instance_cache_by_uuid[instance.uuid] = instance
return instance
self.stub_out('nova.compute.api.API.create_db_entry_for_new_instance',
create_db_entry_for_new_instance)
self.stub_out('nova.compute.api.API._populate_instance_for_create',
_populate_instance_for_create)
res = self.controller.create(self.req, body=body).obj
instance_uuids = self.instance_cache_by_uuid.keys()
@ -5890,12 +5891,13 @@ class ServersControllerCreateTest(test.TestCase):
}
}
def create_db_entry_for_new_instance(*args, **kwargs):
instance = args[4]
def _populate_instance_for_create(*args, **kwargs):
instance = args[2]
self.instance_cache_by_uuid[instance.uuid] = instance
return instance
self.stub_out('nova.compute.api.API.create_db_entry_for_new_instance',
create_db_entry_for_new_instance)
self.stub_out('nova.compute.api.API._populate_instance_for_create',
_populate_instance_for_create)
res = self.controller.create(self.req, body=body).obj
instance_uuids = self.instance_cache_by_uuid.keys()
@ -5906,13 +5908,13 @@ class ServersControllerCreateTest(test.TestCase):
"""Test creating multiple instances with asking for
reservation_id
"""
def create_db_entry_for_new_instance(*args, **kwargs):
instance = args[4]
def _populate_instance_for_create(*args, **kwargs):
instance = args[2]
self.instance_cache_by_uuid[instance.uuid] = instance
return instance
self.stub_out('nova.compute.api.API.create_db_entry_for_new_instance',
create_db_entry_for_new_instance)
self.stub_out('nova.compute.api.API._populate_instance_for_create',
_populate_instance_for_create)
image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
flavor_ref = 'http://localhost/123/flavors/3'
body = {
@ -6036,12 +6038,13 @@ class ServersControllerCreateTest(test.TestCase):
}
}
def create_db_entry_for_new_instance(*args, **kwargs):
instance = args[4]
def _populate_instance_for_create(*args, **kwargs):
instance = args[2]
self.instance_cache_by_uuid[instance.uuid] = instance
return instance
self.stub_out('nova.compute.api.API.create_db_entry_for_new_instance',
create_db_entry_for_new_instance)
self.stub_out('nova.compute.api.API._populate_instance_for_create',
_populate_instance_for_create)
res = self.controller.create(self.req, body=body).obj
instance_uuids = self.instance_cache_by_uuid.keys()
self.assertIn(res["server"]["id"], instance_uuids)

26
nova/tests/unit/compute/test_api.py

@ -4914,11 +4914,12 @@ class _ComputeAPIUnitTestMixIn(object):
new=mock.MagicMock())
@mock.patch('nova.compute.utils.check_num_instances_quota')
@mock.patch('nova.network.security_group_api')
@mock.patch.object(self.compute_api,
'create_db_entry_for_new_instance')
@mock.patch.object(
self.compute_api, '_populate_instance_for_create',
new=mock.MagicMock())
@mock.patch.object(self.compute_api,
'_bdm_validate_set_size_and_instance')
def do_test(mock_bdm_v, mock_cdb, mock_sg, mock_cniq, mock_get_vols):
def do_test(mock_bdm_v, mock_sg, mock_cniq, mock_get_vols):
mock_cniq.return_value = 1
self.compute_api._provision_instances(self.context,
inst_type,
@ -4954,16 +4955,17 @@ class _ComputeAPIUnitTestMixIn(object):
mock_im, mock_instance, mock_br, mock_rs, mock_get_dp):
@mock.patch.object(self.compute_api, '_get_volumes_for_bdms')
@mock.patch.object(self.compute_api,
'_create_reqspec_buildreq_instmapping',
new=mock.MagicMock())
@mock.patch.object(
self.compute_api, '_create_reqspec_buildreq_instmapping',
new=mock.MagicMock())
@mock.patch('nova.compute.utils.check_num_instances_quota')
@mock.patch('nova.network.security_group_api')
@mock.patch.object(self.compute_api,
'create_db_entry_for_new_instance')
@mock.patch.object(
self.compute_api, '_populate_instance_for_create',
new=mock.Mock())
@mock.patch.object(self.compute_api,
'_bdm_validate_set_size_and_instance')
def do_test(mock_bdm_v, mock_cdb, mock_sg, mock_cniq, mock_get_vols):
def do_test(mock_bdm_v, mock_sg, mock_cniq, mock_get_vols):
mock_cniq.return_value = 1
self.compute_api._provision_instances(self.context,
instance_type,
@ -5283,9 +5285,9 @@ class _ComputeAPIUnitTestMixIn(object):
@mock.patch('nova.network.security_group_api'
'.populate_security_groups')
@mock.patch.object(compute_api, 'objects')
@mock.patch.object(self.compute_api,
'create_db_entry_for_new_instance',
new=mock.MagicMock())
@mock.patch.object(
self.compute_api, '_populate_instance_for_create',
new=mock.MagicMock())
@mock.patch.object(self.compute_api,
'_bdm_validate_set_size_and_instance',
new=mock.MagicMock())

Loading…
Cancel
Save