diff --git a/cloudbaseinit/init.py b/cloudbaseinit/init.py index 6adebe1a..c5331fc3 100644 --- a/cloudbaseinit/init.py +++ b/cloudbaseinit/init.py @@ -70,7 +70,7 @@ class InitManager(object): self._set_plugin_status(osutils, instance_id, plugin_name, status) return reboot_required - except Exception, ex: + except Exception as ex: LOG.error('plugin \'%(plugin_name)s\' failed with error ' '\'%(ex)s\'', {'plugin_name': plugin_name, 'ex': ex}) LOG.exception(ex) @@ -124,7 +124,7 @@ class InitManager(object): if reboot_required and CONF.allow_reboot: try: osutils.reboot() - except Exception, ex: + except Exception as ex: LOG.error('reboot failed with error \'%s\'' % ex) elif CONF.stop_service_on_exit: osutils.terminate() diff --git a/cloudbaseinit/metadata/factory.py b/cloudbaseinit/metadata/factory.py index 6cfdcb19..e6acc858 100644 --- a/cloudbaseinit/metadata/factory.py +++ b/cloudbaseinit/metadata/factory.py @@ -47,7 +47,7 @@ def get_metadata_service(): try: if service.load(): return service - except Exception, ex: + except Exception as ex: LOG.error("Failed to load metadata service '%s'" % class_path) LOG.exception(ex) raise Exception("No available service found") diff --git a/cloudbaseinit/metadata/services/ec2service.py b/cloudbaseinit/metadata/services/ec2service.py index c52bc83a..412c90ef 100644 --- a/cloudbaseinit/metadata/services/ec2service.py +++ b/cloudbaseinit/metadata/services/ec2service.py @@ -51,7 +51,7 @@ class EC2Service(base.BaseMetadataService): try: self.get_host_name() return True - except Exception, ex: + except Exception as ex: LOG.exception(ex) LOG.debug('Metadata not found at URL \'%s\'' % CONF.ec2_metadata_base_url) diff --git a/cloudbaseinit/metadata/services/maasservice.py b/cloudbaseinit/metadata/services/maasservice.py index 117ce462..20cacced 100644 --- a/cloudbaseinit/metadata/services/maasservice.py +++ b/cloudbaseinit/metadata/services/maasservice.py @@ -59,7 +59,7 @@ class MaaSHttpService(base.BaseMetadataService): try: self._get_data('%s/meta-data/' % self._metadata_version) return True - except Exception, ex: + except Exception as ex: LOG.exception(ex) LOG.debug('Metadata not found at URL \'%s\'' % CONF.maas_metadata_url) diff --git a/cloudbaseinit/osutils/windows.py b/cloudbaseinit/osutils/windows.py index 66a65b7f..4e0b58ee 100644 --- a/cloudbaseinit/osutils/windows.py +++ b/cloudbaseinit/osutils/windows.py @@ -593,7 +593,7 @@ class WindowsUtils(base.BaseOSUtils): time.sleep(1) LOG.info('Waiting for sysprep completion. ' 'GeneralizationState: %d' % gen_state) - except WindowsError, ex: + except WindowsError as ex: if ex.winerror == 2: LOG.debug('Sysprep data not found in the registry, ' 'skipping sysprep completion check.') diff --git a/cloudbaseinit/plugins/windows/fileexecutils.py b/cloudbaseinit/plugins/windows/fileexecutils.py index faf33a88..dba60777 100644 --- a/cloudbaseinit/plugins/windows/fileexecutils.py +++ b/cloudbaseinit/plugins/windows/fileexecutils.py @@ -57,5 +57,5 @@ def exec_file(file_path): LOG.debug('User_data stderr:\n%s' % err) return ret_val - except Exception, ex: + except Exception as ex: LOG.warning('An error occurred during file execution: \'%s\'' % ex) diff --git a/cloudbaseinit/plugins/windows/userdata.py b/cloudbaseinit/plugins/windows/userdata.py index a2bc5386..3ab2a8fa 100644 --- a/cloudbaseinit/plugins/windows/userdata.py +++ b/cloudbaseinit/plugins/windows/userdata.py @@ -106,7 +106,7 @@ class UserDataPlugin(base.BasePlugin): new_user_handlers) else: ret_val = user_data_plugin.process(part) - except Exception, ex: + except Exception as ex: LOG.error('Exception during multipart part handling: ' '%(content_type)s, %(filename)s' % {'content_type': part.get_content_type(), diff --git a/cloudbaseinit/plugins/windows/userdataplugins/shellscript.py b/cloudbaseinit/plugins/windows/userdataplugins/shellscript.py index 91908c0f..cc4cfe0d 100644 --- a/cloudbaseinit/plugins/windows/userdataplugins/shellscript.py +++ b/cloudbaseinit/plugins/windows/userdataplugins/shellscript.py @@ -36,7 +36,7 @@ class ShellScriptPlugin(base.BaseUserDataPlugin): f.write(part.get_payload()) return fileexecutils.exec_file(target_path) - except Exception, ex: + except Exception as ex: LOG.warning('An error occurred during user_data execution: \'%s\'' % ex) finally: diff --git a/cloudbaseinit/plugins/windows/userdatautils.py b/cloudbaseinit/plugins/windows/userdatautils.py index 4f7ac869..9d4915c5 100644 --- a/cloudbaseinit/plugins/windows/userdatautils.py +++ b/cloudbaseinit/plugins/windows/userdatautils.py @@ -69,7 +69,7 @@ def execute_user_data_script(user_data): LOG.debug('User_data stderr:\n%s' % err) return ret_val - except Exception, ex: + except Exception as ex: LOG.warning('An error occurred during user_data execution: \'%s\'' % ex) finally: diff --git a/cloudbaseinit/utils/dhcp.py b/cloudbaseinit/utils/dhcp.py index c9b090cc..22efe28e 100644 --- a/cloudbaseinit/utils/dhcp.py +++ b/cloudbaseinit/utils/dhcp.py @@ -108,7 +108,7 @@ def _bind_dhcp_client_socket(s, max_bind_attempts, bind_retry_interval): try: s.bind(('', 68)) break - except socket.error, ex: + except socket.error as ex: if (bind_attempts >= max_bind_attempts or ex.errno not in [48, 10048]): raise diff --git a/cloudbaseinit/utils/network.py b/cloudbaseinit/utils/network.py index 13edad56..f5cd5c19 100644 --- a/cloudbaseinit/utils/network.py +++ b/cloudbaseinit/utils/network.py @@ -60,6 +60,6 @@ def check_metadata_ip_route(metadata_url): gateway, interface_index, 10) - except Exception, ex: + except Exception as ex: # Ignore it LOG.exception(ex) diff --git a/cloudbaseinit/utils/windows/network.py b/cloudbaseinit/utils/windows/network.py index 69fd2500..39eae06b 100644 --- a/cloudbaseinit/utils/windows/network.py +++ b/cloudbaseinit/utils/windows/network.py @@ -58,7 +58,7 @@ def _get_registry_dhcp_server(adapter_name): if dhcp_server == "255.255.255.255": dhcp_server = None return dhcp_server - except Exception, ex: + except Exception as ex: # Not found if ex.errno != 2: raise diff --git a/cloudbaseinit/utils/windows/winrmconfig.py b/cloudbaseinit/utils/windows/winrmconfig.py index 6f8ad81a..b505c2f9 100644 --- a/cloudbaseinit/utils/windows/winrmconfig.py +++ b/cloudbaseinit/utils/windows/winrmconfig.py @@ -103,7 +103,7 @@ class WinRMConfig(object): session = self._get_wsman_session() try: return session.Get(resource_uri) - except pywintypes.com_error, ex: + except pywintypes.com_error as ex: if len(ex.excepinfo) > 5 and ex.excepinfo[5] == -2144108544: return None else: