diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/cloud_tests/platforms/azurecloud/instance.py | 7 | ||||
| -rw-r--r-- | tests/cloud_tests/platforms/azurecloud/platform.py | 23 | ||||
| -rw-r--r-- | tests/cloud_tests/platforms/ec2/instance.py | 4 | ||||
| -rw-r--r-- | tests/cloud_tests/platforms/ec2/platform.py | 18 | ||||
| -rw-r--r-- | tests/cloud_tests/platforms/lxd/instance.py | 3 | ||||
| -rw-r--r-- | tests/cloud_tests/platforms/platforms.py | 6 | ||||
| -rw-r--r-- | tests/cloud_tests/testcases/__init__.py | 6 | 
7 files changed, 42 insertions, 25 deletions
| diff --git a/tests/cloud_tests/platforms/azurecloud/instance.py b/tests/cloud_tests/platforms/azurecloud/instance.py index a136cf0d..eedbaae8 100644 --- a/tests/cloud_tests/platforms/azurecloud/instance.py +++ b/tests/cloud_tests/platforms/azurecloud/instance.py @@ -134,9 +134,10 @@ class AzureCloudInstance(Instance):                                   self.vm_name, vm_params)              LOG.debug('creating instance %s from image_id=%s', self.vm_name,                        self.image_id) -        except CloudError: -            raise RuntimeError('failed creating instance:\n{}'.format( -                traceback.format_exc())) +        except CloudError as e: +            raise RuntimeError( +                'failed creating instance:\n{}'.format(traceback.format_exc()) +            ) from e          if wait:              self.instance.wait() diff --git a/tests/cloud_tests/platforms/azurecloud/platform.py b/tests/cloud_tests/platforms/azurecloud/platform.py index cb62a74b..a664f612 100644 --- a/tests/cloud_tests/platforms/azurecloud/platform.py +++ b/tests/cloud_tests/platforms/azurecloud/platform.py @@ -59,9 +59,12 @@ class AzureCloudPlatform(Platform):              self.vnet = self._create_vnet()              self.subnet = self._create_subnet()              self.nic = self._create_nic() -        except CloudError: -            raise RuntimeError('failed creating a resource:\n{}'.format( -                traceback.format_exc())) +        except CloudError as e: +            raise RuntimeError( +                'failed creating a resource:\n{}'.format( +                    traceback.format_exc() +                ) +            ) from e      def create_instance(self, properties, config, features,                          image_id, user_data=None): @@ -105,8 +108,10 @@ class AzureCloudPlatform(Platform):              if image_id.find('__') > 0:                  image_id = image_id.split('__')[1]                  LOG.debug('image_id shortened to %s', image_id) -        except KeyError: -            raise RuntimeError('no images found for %s' % img_conf['release']) +        except KeyError as e: +            raise RuntimeError( +                'no images found for %s' % img_conf['release'] +            ) from e          return AzureCloudImage(self, img_conf, image_id) @@ -140,9 +145,11 @@ class AzureCloudPlatform(Platform):                  secret=azure_creds['clientSecret'],                  tenant=azure_creds['tenantId'])              return credentials, subscription_id -        except KeyError: -            raise RuntimeError('Please configure Azure service principal' -                               ' credentials in %s' % cred_file) +        except KeyError as e: +            raise RuntimeError( +                'Please configure Azure service principal' +                ' credentials in %s' % cred_file +            ) from e      def _create_resource_group(self):          """Create resource group""" diff --git a/tests/cloud_tests/platforms/ec2/instance.py b/tests/cloud_tests/platforms/ec2/instance.py index ab6037b1..d2e84047 100644 --- a/tests/cloud_tests/platforms/ec2/instance.py +++ b/tests/cloud_tests/platforms/ec2/instance.py @@ -49,11 +49,11 @@ class EC2Instance(Instance):              # OutputBytes comes from platform._decode_console_output_as_bytes              response = self.instance.console_output()              return response['OutputBytes'] -        except KeyError: +        except KeyError as e:              if 'Output' in response:                  msg = ("'OutputBytes' did not exist in console_output() but "                         "'Output' did: %s..." % response['Output'][0:128]) -                raise util.PlatformError('console_log', msg) +                raise util.PlatformError('console_log', msg) from e              return ('No Console Output [%s]' % self.instance).encode()      def destroy(self): diff --git a/tests/cloud_tests/platforms/ec2/platform.py b/tests/cloud_tests/platforms/ec2/platform.py index 7a3d0fe0..b61a2ffb 100644 --- a/tests/cloud_tests/platforms/ec2/platform.py +++ b/tests/cloud_tests/platforms/ec2/platform.py @@ -35,12 +35,14 @@ class EC2Platform(Platform):              self.ec2_resource = b3session.resource('ec2')              self.ec2_region = b3session.region_name              self.key_name = self._upload_public_key(config) -        except botocore.exceptions.NoRegionError: +        except botocore.exceptions.NoRegionError as e:              raise RuntimeError( -                'Please configure default region in $HOME/.aws/config') -        except botocore.exceptions.NoCredentialsError: +                'Please configure default region in $HOME/.aws/config' +            ) from e +        except botocore.exceptions.NoCredentialsError as e:              raise RuntimeError( -                'Please configure ec2 credentials in $HOME/.aws/credentials') +                'Please configure ec2 credentials in $HOME/.aws/credentials' +            ) from e          self.vpc = self._create_vpc()          self.internet_gateway = self._create_internet_gateway() @@ -125,8 +127,10 @@ class EC2Platform(Platform):          try:              image_ami = image['id'] -        except KeyError: -            raise RuntimeError('No images found for %s!' % img_conf['release']) +        except KeyError as e: +            raise RuntimeError( +                'No images found for %s!' % img_conf['release'] +            ) from e          LOG.debug('found image: %s', image_ami)          image = EC2Image(self, img_conf, image_ami) @@ -195,7 +199,7 @@ class EC2Platform(Platform):                  CidrBlock=self.ipv4_cidr,                  AmazonProvidedIpv6CidrBlock=True)          except botocore.exceptions.ClientError as e: -            raise RuntimeError(e) +            raise RuntimeError(e) from e          vpc.wait_until_available()          self._tag_resource(vpc) diff --git a/tests/cloud_tests/platforms/lxd/instance.py b/tests/cloud_tests/platforms/lxd/instance.py index b27b9848..2b973a08 100644 --- a/tests/cloud_tests/platforms/lxd/instance.py +++ b/tests/cloud_tests/platforms/lxd/instance.py @@ -175,7 +175,8 @@ class LXDInstance(Instance):              raise PlatformError(                  "console log",                  "Console log failed [%d]: stdout=%s stderr=%s" % ( -                    e.exit_code, e.stdout, e.stderr)) +                    e.exit_code, e.stdout, e.stderr) +            ) from e      def reboot(self, wait=True):          """Reboot instance.""" diff --git a/tests/cloud_tests/platforms/platforms.py b/tests/cloud_tests/platforms/platforms.py index 58f65e52..ac3b6563 100644 --- a/tests/cloud_tests/platforms/platforms.py +++ b/tests/cloud_tests/platforms/platforms.py @@ -74,8 +74,10 @@ class Platform(object):          try:              return tmirror.json_entries[0] -        except IndexError: -            raise RuntimeError('no images found with filter: %s' % img_filter) +        except IndexError as e: +            raise RuntimeError( +                'no images found with filter: %s' % img_filter +            ) from e  class FilterMirror(mirrors.BasicMirrorWriter): diff --git a/tests/cloud_tests/testcases/__init__.py b/tests/cloud_tests/testcases/__init__.py index e8c371ca..bb9785d3 100644 --- a/tests/cloud_tests/testcases/__init__.py +++ b/tests/cloud_tests/testcases/__init__.py @@ -21,8 +21,10 @@ def discover_test(test_name):          config.name_sanitize(test_name))      try:          testmod = importlib.import_module(testmod_name) -    except NameError: -        raise ValueError('no test verifier found at: {}'.format(testmod_name)) +    except NameError as e: +        raise ValueError( +            'no test verifier found at: {}'.format(testmod_name) +        ) from e      found = [mod for name, mod in inspect.getmembers(testmod)               if (inspect.isclass(mod) | 
