ec2: Prevent list_sizes to fail without pricing
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/8fbbe4b8 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/8fbbe4b8 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/8fbbe4b8 Branch: refs/heads/trunk Commit: 8fbbe4b8e28ae660f5f613922c9f84bdb7ab9efb Parents: bd7a397 Author: Quentin Pradet <quent...@apache.org> Authored: Thu Oct 12 07:55:42 2017 +0400 Committer: Quentin Pradet <quent...@apache.org> Committed: Fri Oct 13 08:56:12 2017 +0400 ---------------------------------------------------------------------- libcloud/compute/drivers/ec2.py | 7 +++++-- libcloud/test/compute/test_ec2.py | 7 ++++--- 2 files changed, 9 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/8fbbe4b8/libcloud/compute/drivers/ec2.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py index a5bcf27..dd62097 100644 --- a/libcloud/compute/drivers/ec2.py +++ b/libcloud/compute/drivers/ec2.py @@ -3568,8 +3568,11 @@ class BaseEC2NodeDriver(NodeDriver): for instance_type in available_types: attributes = INSTANCE_TYPES[instance_type] attributes = copy.deepcopy(attributes) - price = self._get_size_price(size_id=instance_type) - attributes.update({'price': price}) + try: + price = self._get_size_price(size_id=instance_type) + attributes['price'] = price + except KeyError: + attributes['price'] = None # pricing not available sizes.append(NodeSize(driver=self, **attributes)) return sizes http://git-wip-us.apache.org/repos/asf/libcloud/blob/8fbbe4b8/libcloud/test/compute/test_ec2.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py index 2e015ac..a36e650 100644 --- a/libcloud/test/compute/test_ec2.py +++ b/libcloud/test/compute/test_ec2.py @@ -75,11 +75,12 @@ class BaseEC2Tests(LibcloudTestCase): unsupported_regions = list() for region in VALID_EC2_REGIONS: - if region in ['cn-north-1']: - continue # pricing not available + no_pricing = region in ['cn-north-1'] driver = EC2NodeDriver(*EC2_PARAMS, **{'region': region}) try: - driver.list_sizes() + sizes = driver.list_sizes() + if no_pricing: + self.assertTrue(all([s.price is None for s in sizes])) except: unsupported_regions.append(region)