From 521370459cd57976e3d71e2ecd42e444cd559d98 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 19 May 2016 15:34:59 -0700 Subject: [PATCH] Py3 exclude list (#3698) * Fix a few modules to pass syntax checks under python3 * Move from a whitelist of modules to check for python3 compat to a blacklist --- .travis.yml | 84 +++++++++++++++++++++++++- cloud/azure/azure.py | 22 +++---- cloud/azure/azure_rm_storageaccount.py | 6 +- cloud/linode/linode.py | 16 ++--- windows/win_feature.py | 4 +- windows/win_get_url.py | 2 +- 6 files changed, 106 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index a45074b89f4..7628d91f4dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,86 @@ addons: - python2.4 - python2.6 - python3.5 +env: + global: + # 77 modules. Let's whittle this down! + - PY3_EXCLUDE_LIST="cloud/amazon/cloudformation.py + cloud/amazon/ec2_ami.py + cloud/amazon/ec2_asg.py + cloud/amazon/ec2_eip.py + cloud/amazon/ec2_elb_lb.py + cloud/amazon/ec2_elb.py + cloud/amazon/ec2_group.py + cloud/amazon/ec2_key.py + cloud/amazon/ec2_lc.py + cloud/amazon/ec2_metric_alarm.py + cloud/amazon/ec2.py + cloud/amazon/ec2_scaling_policy.py + cloud/amazon/ec2_snapshot.py + cloud/amazon/ec2_vol.py + cloud/amazon/ec2_vpc_net.py + cloud/amazon/ec2_vpc.py + cloud/amazon/elasticache.py + cloud/amazon/elasticache_subnet_group.py + cloud/amazon/iam_cert.py + cloud/amazon/iam_policy.py + cloud/amazon/iam.py + cloud/amazon/rds_param_group.py + cloud/amazon/rds.py + cloud/amazon/rds_subnet_group.py + cloud/amazon/route53.py + cloud/amazon/s3.py + cloud/digital_ocean/digital_ocean_domain.py + cloud/digital_ocean/digital_ocean.py + cloud/digital_ocean/digital_ocean_sshkey.py + cloud/docker/docker_container.py + cloud/docker/docker_image_facts.py + cloud/docker/docker_login.py + cloud/google/gce_lb.py + cloud/google/gce_net.py + cloud/google/gce_pd.py + cloud/google/gce.py + cloud/google/gc_storage.py + cloud/openstack/_glance_image.py + cloud/openstack/_keystone_user.py + cloud/openstack/_nova_compute.py + cloud/openstack/_nova_keypair.py + cloud/openstack/_quantum_floating_ip_associate.py + cloud/openstack/_quantum_floating_ip.py + cloud/openstack/_quantum_network.py + cloud/openstack/_quantum_router_gateway.py + cloud/openstack/_quantum_router_interface.py + cloud/openstack/_quantum_router.py + cloud/openstack/_quantum_subnet.py + cloud/rackspace/rax_cbs_attachments.py + cloud/rackspace/rax_cbs.py + cloud/rackspace/rax_cdb_database.py + cloud/rackspace/rax_cdb.py + cloud/rackspace/rax_cdb_user.py + cloud/rackspace/rax_clb_nodes.py + cloud/rackspace/rax_clb.py + cloud/rackspace/rax_dns.py + cloud/rackspace/rax_dns_record.py + cloud/rackspace/rax_facts.py + cloud/rackspace/rax_files_objects.py + cloud/rackspace/rax_files.py + cloud/rackspace/rax_keypair.py + cloud/rackspace/rax_meta.py + cloud/rackspace/rax_network.py + cloud/rackspace/rax.py + cloud/rackspace/rax_queue.py + cloud/rackspace/rax_scaling_group.py + cloud/rackspace/rax_scaling_policy.py + cloud/vmware/vsphere_guest.py + packaging/os/apt.py + packaging/os/apt_repository.py + packaging/os/redhat_subscription.py + packaging/os/rhn_register.py + packaging/os/yum.py + utilities/helper/accelerate.py + utilities/logic/async_status.py + utilities/logic/async_wrapper.py + utilities/logic/wait_for.py" before_install: - git config user.name "ansible" - git config user.email "ansible@ansible.com" @@ -22,8 +102,8 @@ script: - python2.4 -m compileall -fq cloud/amazon/_ec2_ami_search.py cloud/amazon/ec2_facts.py - python2.6 -m compileall -fq . - python2.7 -m compileall -fq . - - python3.4 -m compileall -fq system/ commands/ source_control/ inventory/ files/ databases/ network/ - - python3.5 -m compileall -fq system/ commands/ source_control/ inventory/ files/ databases/ network/ + - python3.4 -m compileall -fq . -x $(echo "$PY3_EXCLUDE_LIST"| tr ' ' '|') + - python3.5 -m compileall -fq . -x $(echo "$PY3_EXCLUDE_LIST"| tr ' ' '|') - ansible-validate-modules --exclude 'utilities/' . #- ansible-validate-modules --exclude 'cloud/amazon/ec2_lc\.py|cloud/amazon/ec2_scaling_policy\.py|cloud/amazon/ec2_scaling_policy\.py|cloud/amazon/ec2_asg\.py|cloud/azure/azure\.py|packaging/os/rhn_register\.py|network/openswitch/ops_template\.py|system/hostname\.py|utilities/' . #- ./test-docs.sh core diff --git a/cloud/azure/azure.py b/cloud/azure/azure.py index bcd98d70772..89ab576ea14 100644 --- a/cloud/azure/azure.py +++ b/cloud/azure/azure.py @@ -298,7 +298,7 @@ def _delete_disks_when_detached(azure, wait_timeout, disk_names): if disk.attached_to is None: azure.delete_disk(disk.name, True) disk_names.remove(disk_name) - except AzureException, e: + except AzureException as e: module.fail_json(msg="failed to get or delete disk, error was: %s" % (disk_name, str(e))) finally: signal.alarm(0) @@ -356,7 +356,7 @@ def create_virtual_machine(module, azure): result = azure.create_hosted_service(service_name=name, label=name, location=location) _wait_for_completion(azure, result, wait_timeout, "create_hosted_service") changed = True - except AzureException, e: + except AzureException as e: module.fail_json(msg="failed to create the new service, error was: %s" % str(e)) try: @@ -427,13 +427,13 @@ def create_virtual_machine(module, azure): virtual_network_name=virtual_network_name) _wait_for_completion(azure, result, wait_timeout, "create_virtual_machine_deployment") changed = True - except AzureException, e: + except AzureException as e: module.fail_json(msg="failed to create the new virtual machine, error was: %s" % str(e)) try: deployment = azure.get_deployment_by_name(service_name=name, deployment_name=name) return (changed, urlparse(deployment.url).hostname, deployment) - except AzureException, e: + except AzureException as e: module.fail_json(msg="failed to lookup the deployment information for %s, error was: %s" % (name, str(e))) @@ -461,9 +461,9 @@ def terminate_virtual_machine(module, azure): disk_names = [] try: deployment = azure.get_deployment_by_name(service_name=name, deployment_name=name) - except AzureMissingException, e: + except AzureMissingException as e: pass # no such deployment or service - except AzureException, e: + except AzureException as e: module.fail_json(msg="failed to find the deployment, error was: %s" % str(e)) # Delete deployment @@ -476,13 +476,13 @@ def terminate_virtual_machine(module, azure): role_props = azure.get_role(name, deployment.name, role.role_name) if role_props.os_virtual_hard_disk.disk_name not in disk_names: disk_names.append(role_props.os_virtual_hard_disk.disk_name) - except AzureException, e: + except AzureException as e: module.fail_json(msg="failed to get the role %s, error was: %s" % (role.role_name, str(e))) try: result = azure.delete_deployment(name, deployment.name) _wait_for_completion(azure, result, wait_timeout, "delete_deployment") - except AzureException, e: + except AzureException as e: module.fail_json(msg="failed to delete the deployment %s, error was: %s" % (deployment.name, str(e))) # It's unclear when disks associated with terminated deployment get detatched. @@ -490,14 +490,14 @@ def terminate_virtual_machine(module, azure): # become detatched by polling the list of remaining disks and examining the state. try: _delete_disks_when_detached(azure, wait_timeout, disk_names) - except (AzureException, TimeoutError), e: + except (AzureException, TimeoutError) as e: module.fail_json(msg=str(e)) try: # Now that the vm is deleted, remove the cloud service result = azure.delete_hosted_service(service_name=name) _wait_for_completion(azure, result, wait_timeout, "delete_hosted_service") - except AzureException, e: + except AzureException as e: module.fail_json(msg="failed to delete the service %s, error was: %s" % (name, str(e))) public_dns_name = urlparse(deployment.url).hostname @@ -605,7 +605,7 @@ class Wrapper(object): while wait_timeout > time.time(): try: return f() - except AzureException, e: + except AzureException as e: if not str(e).lower().find("temporary redirect") == -1: time.sleep(5) pass diff --git a/cloud/azure/azure_rm_storageaccount.py b/cloud/azure/azure_rm_storageaccount.py index 7282551ae4f..eaea0bc7a1d 100644 --- a/cloud/azure/azure_rm_storageaccount.py +++ b/cloud/azure/azure_rm_storageaccount.py @@ -241,7 +241,7 @@ class AzureRMStorageAccount(AzureRMModuleBase): self.log('Checking name availability for {0}'.format(self.name)) try: response = self.storage_client.storage_accounts.check_name_availability(self.name) - except AzureHttpError, e: + except AzureHttpError as e: self.log('Error attempting to validate name.') self.fail("Error checking name availability: {0}".format(str(e))) if not response.name_available: @@ -384,7 +384,7 @@ class AzureRMStorageAccount(AzureRMModuleBase): try: poller = self.storage_client.storage_accounts.create(self.resource_group, self.name, parameters) self.get_poller_result(poller) - except AzureHttpError, e: + except AzureHttpError as e: self.log('Error creating storage account.') self.fail("Failed to create account: {0}".format(str(e))) # the poller doesn't actually return anything @@ -402,7 +402,7 @@ class AzureRMStorageAccount(AzureRMModuleBase): status = self.storage_client.storage_accounts.delete(self.resource_group, self.name) self.log("delete status: ") self.log(str(status)) - except AzureHttpError, e: + except AzureHttpError as e: self.fail("Failed to delete the account: {0}".format(str(e))) return True diff --git a/cloud/linode/linode.py b/cloud/linode/linode.py index 36f78d126e6..022dc231bf4 100644 --- a/cloud/linode/linode.py +++ b/cloud/linode/linode.py @@ -259,7 +259,7 @@ def linodeServers(module, api, state, name, plan, distribution, datacenter, lino api.linode_update(LinodeId=linode_id, Label='%s_%s' % (linode_id, name)) # Save server servers = api.linode_list(LinodeId=linode_id) - except Exception, e: + except Exception as e: module.fail_json(msg = '%s' % e.value[0]['ERRORMESSAGE']) if not disks: @@ -291,7 +291,7 @@ def linodeServers(module, api, state, name, plan, distribution, datacenter, lino Label='%s swap disk (lid: %s)' % (name, linode_id), Size=swap) jobs.append(res['JobID']) - except Exception, e: + except Exception as e: # TODO: destroy linode ? module.fail_json(msg = '%s' % e.value[0]['ERRORMESSAGE']) @@ -334,7 +334,7 @@ def linodeServers(module, api, state, name, plan, distribution, datacenter, lino api.linode_config_create(LinodeId=linode_id, KernelId=kernel_id, Disklist=disks_list, Label='%s config' % name) configs = api.linode_config_list(LinodeId=linode_id) - except Exception, e: + except Exception as e: module.fail_json(msg = '%s' % e.value[0]['ERRORMESSAGE']) # Start / Ensure servers are running @@ -395,7 +395,7 @@ def linodeServers(module, api, state, name, plan, distribution, datacenter, lino if server['STATUS'] != 2: try: res = api.linode_shutdown(LinodeId=linode_id) - except Exception, e: + except Exception as e: module.fail_json(msg = '%s' % e.value[0]['ERRORMESSAGE']) instance['status'] = 'Stopping' changed = True @@ -415,7 +415,7 @@ def linodeServers(module, api, state, name, plan, distribution, datacenter, lino instance = getInstanceDetails(api, server) try: res = api.linode_reboot(LinodeId=server['LINODEID']) - except Exception, e: + except Exception as e: module.fail_json(msg = '%s' % e.value[0]['ERRORMESSAGE']) instance['status'] = 'Restarting' changed = True @@ -426,7 +426,7 @@ def linodeServers(module, api, state, name, plan, distribution, datacenter, lino instance = getInstanceDetails(api, server) try: api.linode_delete(LinodeId=server['LINODEID'], skipChecks=True) - except Exception, e: + except Exception as e: module.fail_json(msg = '%s' % e.value[0]['ERRORMESSAGE']) instance['status'] = 'Deleting' changed = True @@ -481,14 +481,14 @@ def main(): if not api_key: try: api_key = os.environ['LINODE_API_KEY'] - except KeyError, e: + except KeyError as e: module.fail_json(msg = 'Unable to load %s' % e.message) # setup the auth try: api = linode_api.Api(api_key) api.test_echo() - except Exception, e: + except Exception as e: module.fail_json(msg = '%s' % e.value[0]['ERRORMESSAGE']) linodeServers(module, api, state, name, plan, distribution, datacenter, linode_id, diff --git a/windows/win_feature.py b/windows/win_feature.py index 3ba53d0553e..04226c609a8 100644 --- a/windows/win_feature.py +++ b/windows/win_feature.py @@ -77,7 +77,7 @@ author: - "Trond Hindenes (@trondhindenes)" ''' -EXAMPLES = ''' +EXAMPLES = r''' # This installs IIS. # The names of features available for install can be run by running the following Powershell Command: # PS C:\Users\Administrator> Import-Module ServerManager; Get-WindowsFeature @@ -99,6 +99,4 @@ ansible -m "win_feature" -a "name=NET-Framework-Core source=C:/Temp/iso/sources/ restart: yes include_sub_features: yes include_management_tools: yes - - ''' diff --git a/windows/win_get_url.py b/windows/win_get_url.py index f7c5819cb22..1492cb44f05 100644 --- a/windows/win_get_url.py +++ b/windows/win_get_url.py @@ -84,7 +84,7 @@ options: required: false ''' -EXAMPLES = ''' +EXAMPLES = r''' # Downloading a JPEG and saving it to a file with the ansible command. # Note the "dest" is quoted rather instead of escaping the backslashes $ ansible -i hosts -c winrm -m win_get_url -a "url=http://www.example.com/earthrise.jpg dest='C:\Users\Administrator\earthrise.jpg'" all