Replaces usages of "locals()"

This commit is contained in:
Alessandro Pilotti 2014-02-19 18:19:18 +02:00
parent e1ffd188a5
commit 5a9dbcfbd2
3 changed files with 19 additions and 17 deletions

View File

@ -60,11 +60,10 @@ class InitManager(object):
status = self._get_plugin_status(osutils, instance_id, plugin_name) status = self._get_plugin_status(osutils, instance_id, plugin_name)
if status == plugins_base.PLUGIN_EXECUTION_DONE: if status == plugins_base.PLUGIN_EXECUTION_DONE:
LOG.debug('Plugin \'%(plugin_name)s\' execution already done, ' LOG.debug('Plugin \'%s\' execution already done, skipping',
'skipping' % locals()) plugin_name)
else: else:
LOG.info('Executing plugin \'%(plugin_name)s\'' % LOG.info('Executing plugin \'%s\'', plugin_name)
locals())
try: try:
(status, reboot_required) = plugin.execute(service, (status, reboot_required) = plugin.execute(service,
shared_data) shared_data)
@ -72,8 +71,8 @@ class InitManager(object):
status) status)
return reboot_required return reboot_required
except Exception, ex: except Exception, ex:
LOG.error('plugin \'%(plugin_name)s\' failed ' LOG.error('plugin \'%(plugin_name)s\' failed with error '
'with error \'%(ex)s\'' % locals()) '\'%(ex)s\'', {'plugin_name': plugin_name, 'ex': ex})
LOG.exception(ex) LOG.exception(ex)
def _check_plugin_os_requirements(self, osutils, plugin): def _check_plugin_os_requirements(self, osutils, plugin):

View File

@ -93,14 +93,14 @@ class HttpService(baseopenstackservice.BaseOpenStackService):
def _get_data(self, path): def _get_data(self, path):
norm_path = posixpath.join(CONF.metadata_base_url, path) norm_path = posixpath.join(CONF.metadata_base_url, path)
LOG.debug('Getting metadata from: %(norm_path)s' % locals()) LOG.debug('Getting metadata from: %s', norm_path)
req = urllib2.Request(norm_path) req = urllib2.Request(norm_path)
response = self._get_response(req) response = self._get_response(req)
return response.read() return response.read()
def _post_data(self, path, data): def _post_data(self, path, data):
norm_path = posixpath.join(CONF.metadata_base_url, path) norm_path = posixpath.join(CONF.metadata_base_url, path)
LOG.debug('Posting metadata to: %(norm_path)s' % locals()) LOG.debug('Posting metadata to: %s', norm_path)
req = urllib2.Request(norm_path, data=data) req = urllib2.Request(norm_path, data=data)
self._get_response(req) self._get_response(req)
return True return True

View File

@ -204,7 +204,7 @@ class WindowsUtils(base.BaseOSUtils):
conn = wmi.WMI(moniker='//./root/cimv2') conn = wmi.WMI(moniker='//./root/cimv2')
username_san = self._sanitize_wmi_input(username) username_san = self._sanitize_wmi_input(username)
q = conn.query('SELECT * FROM Win32_Account where name = ' q = conn.query('SELECT * FROM Win32_Account where name = '
'\'%(username_san)s\'' % locals()) '\'%s\'' % username_san)
if len(q) > 0: if len(q) > 0:
return q[0] return q[0]
return None return None
@ -226,10 +226,10 @@ class WindowsUtils(base.BaseOSUtils):
self._set_user_password_expiration(username, password_expires) self._set_user_password_expiration(username, password_expires)
else: else:
if create: if create:
msg = "Create user failed: %(err)s" msg = "Create user failed: %s"
else: else:
msg = "Set user password failed: %(err)s" msg = "Set user password failed: %s"
raise Exception(msg % locals()) raise Exception(msg % err)
def _sanitize_wmi_input(self, value): def _sanitize_wmi_input(self, value):
return value.replace('\'', '\'\'') return value.replace('\'', '\'\'')
@ -359,7 +359,7 @@ class WindowsUtils(base.BaseOSUtils):
adapter_name_san = self._sanitize_wmi_input(adapter_name) adapter_name_san = self._sanitize_wmi_input(adapter_name)
q = conn.query('SELECT * FROM Win32_NetworkAdapter WHERE ' q = conn.query('SELECT * FROM Win32_NetworkAdapter WHERE '
'MACAddress IS NOT NULL AND ' 'MACAddress IS NOT NULL AND '
'Name = \'%(adapter_name_san)s\'' % locals()) 'Name = \'%s\'' % adapter_name_san)
if not len(q): if not len(q):
raise Exception("Network adapter not found") raise Exception("Network adapter not found")
@ -457,7 +457,8 @@ class WindowsUtils(base.BaseOSUtils):
(ret_val,) = service.ChangeStartMode(start_mode) (ret_val,) = service.ChangeStartMode(start_mode)
if ret_val != 0: if ret_val != 0:
raise Exception('Setting service %(service_name)s start mode ' raise Exception('Setting service %(service_name)s start mode '
'failed with return value: %(ret_val)d' % locals()) 'failed with return value: %(ret_val)d' %
{'service_name': service_name, 'ret_val': ret_val})
def start_service(self, service_name): def start_service(self, service_name):
LOG.debug('Starting service %s' % service_name) LOG.debug('Starting service %s' % service_name)
@ -465,7 +466,8 @@ class WindowsUtils(base.BaseOSUtils):
(ret_val,) = service.StartService() (ret_val,) = service.StartService()
if ret_val != 0: if ret_val != 0:
raise Exception('Starting service %(service_name)s failed with ' raise Exception('Starting service %(service_name)s failed with '
'return value: %(ret_val)d' % locals()) 'return value: %(ret_val)d' %
{'service_name': service_name, 'ret_val': ret_val})
def stop_service(self, service_name): def stop_service(self, service_name):
LOG.debug('Stopping service %s' % service_name) LOG.debug('Stopping service %s' % service_name)
@ -473,7 +475,8 @@ class WindowsUtils(base.BaseOSUtils):
(ret_val,) = service.StopService() (ret_val,) = service.StopService()
if ret_val != 0: if ret_val != 0:
raise Exception('Stopping service %(service_name)s failed with ' raise Exception('Stopping service %(service_name)s failed with '
'return value: %(ret_val)d' % locals()) 'return value: %(ret_val)d' %
{'service_name': service_name, 'ret_val': ret_val})
def terminate(self): def terminate(self):
# Wait for the service to start. Polling the service "Started" property # Wait for the service to start. Polling the service "Started" property
@ -552,7 +555,7 @@ class WindowsUtils(base.BaseOSUtils):
(out, err, ret_val) = self.execute_process(args) (out, err, ret_val) = self.execute_process(args)
# Cannot use the return value to determine the outcome # Cannot use the return value to determine the outcome
if err: if err:
raise Exception('Unable to add route: %(err)s' % locals()) raise Exception('Unable to add route: %s' % err)
def check_os_version(self, major, minor, build=0): def check_os_version(self, major, minor, build=0):
vi = Win32_OSVERSIONINFOEX_W() vi = Win32_OSVERSIONINFOEX_W()