Merge "VMware: Handle concurrent registrations of the VC extension"

This commit is contained in:
Zuul 2017-12-01 01:43:27 +00:00 committed by Gerrit Code Review
commit 6936dbc8d3
2 changed files with 26 additions and 7 deletions

View File

@ -2055,6 +2055,18 @@ class VMwareAPIVMTestCase(test.NoDBTestCase,
'find_extension',
constants.EXTENSION_KEY)
def test_register_extension_concurrent(self):
def fake_call_method(module, method, *args, **kwargs):
if method == "find_extension":
return None
elif method == "register_extension":
raise vexc.VimFaultException(['InvalidArgument'], 'error')
else:
raise Exception()
with (mock.patch.object(
self.conn._session, '_call_method', fake_call_method)):
self.conn._register_openstack_extension()
def test_list_instances(self):
instances = self.conn.list_instances()
self.assertEqual(0, len(instances))

View File

@ -183,16 +183,23 @@ class VMwareVCDriver(driver.ComputeDriver):
def _register_openstack_extension(self):
# Register an 'OpenStack' extension in vCenter
LOG.debug('Registering extension %s with vCenter',
constants.EXTENSION_KEY)
os_extension = self._session._call_method(vim_util, 'find_extension',
constants.EXTENSION_KEY)
if os_extension is None:
LOG.debug('Extension does not exist. Registering type %s.',
constants.EXTENSION_TYPE_INSTANCE)
self._session._call_method(vim_util, 'register_extension',
constants.EXTENSION_KEY,
constants.EXTENSION_TYPE_INSTANCE)
try:
self._session._call_method(vim_util, 'register_extension',
constants.EXTENSION_KEY,
constants.EXTENSION_TYPE_INSTANCE)
LOG.info('Registered extension %s with vCenter',
constants.EXTENSION_KEY)
except vexc.VimFaultException as e:
with excutils.save_and_reraise_exception() as ctx:
if 'InvalidArgument' in e.fault_list:
LOG.debug('Extension %s already exists.',
constants.EXTENSION_KEY)
ctx.reraise = False
else:
LOG.debug('Extension %s already exists.', constants.EXTENSION_KEY)
def cleanup(self, context, instance, network_info, block_device_info=None,
destroy_disks=True, migrate_data=None, destroy_vifs=True):