From c1f224954e511cb76c2571449ed3a7c1c9d72a8f Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Sun, 29 Dec 2013 08:59:07 -0500 Subject: [PATCH] Cleanup some style --- moto/autoscaling/models.py | 2 ++ moto/core/responses.py | 8 +++++++- moto/dynamodb/models.py | 6 +++--- moto/ec2/models.py | 14 +++++++------- moto/ec2/responses/instances.py | 8 ++++++-- moto/emr/models.py | 4 ++-- moto/route53/models.py | 2 +- 7 files changed, 28 insertions(+), 16 deletions(-) diff --git a/moto/autoscaling/models.py b/moto/autoscaling/models.py index a367ba297..a9447974b 100644 --- a/moto/autoscaling/models.py +++ b/moto/autoscaling/models.py @@ -83,6 +83,8 @@ class FakeAutoScalingGroup(object): self.launch_config = autoscaling_backend.launch_configurations[launch_config_name] self.launch_config_name = launch_config_name self.vpc_zone_identifier = vpc_zone_identifier + self.health_check_period = health_check_period + self.health_check_type = health_check_type self.set_desired_capacity(desired_capacity) diff --git a/moto/core/responses.py b/moto/core/responses.py index b71ad0d6e..a47cf531c 100644 --- a/moto/core/responses.py +++ b/moto/core/responses.py @@ -75,7 +75,13 @@ def metadata_response(request, full_url, headers): Expiration=tomorrow.strftime("%Y-%m-%dT%H:%M:%SZ") ) - path = parsed_url.path.lstrip("/latest/meta-data/") + path = parsed_url.path + + meta_data_prefix = "/latest/meta-data/" + # Strip prefix if it is there + if path.startswith(meta_data_prefix): + path = path[len(meta_data_prefix):] + if path == '': result = 'iam' elif path == 'iam': diff --git a/moto/dynamodb/models.py b/moto/dynamodb/models.py index 198b6dc38..67f5152d6 100644 --- a/moto/dynamodb/models.py +++ b/moto/dynamodb/models.py @@ -3,10 +3,10 @@ import datetime import json try: - from collections import OrderedDict + from collections import OrderedDict except ImportError: - # python 2.6 or earlier, use backport - from ordereddict import OrderedDict + # python 2.6 or earlier, use backport + from ordereddict import OrderedDict from moto.core import BaseBackend diff --git a/moto/ec2/models.py b/moto/ec2/models.py index a8e29bf2d..4e05ceda8 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -36,23 +36,23 @@ class Instance(BotoInstance): self._state = InstanceState("running", 16) self.user_data = user_data - def start(self): + def start(self, *args, **kwargs): self._state.name = "running" self._state.code = 16 - def stop(self): + def stop(self, *args, **kwargs): self._state.name = "stopped" self._state.code = 80 - def terminate(self): + def terminate(self, *args, **kwargs): self._state.name = "terminated" self._state.code = 48 - def reboot(self): + def reboot(self, *args, **kwargs): self._state.name = "running" self._state.code = 16 - def get_tags(self): + def get_tags(self, *args, **kwargs): tags = ec2_backend.describe_tags(self.id) return tags @@ -562,7 +562,7 @@ class SpotRequestBackend(object): instance_type, placement, kernel_id, ramdisk_id, monitoring_enabled, subnet_id): requests = [] - for index in range(count): + for _ in range(count): spot_request_id = random_spot_request_id() request = SpotInstanceRequest( spot_request_id, price, image_id, type, valid_from, valid_until, @@ -584,7 +584,7 @@ class SpotRequestBackend(object): return requests -class ElasticAddress(): +class ElasticAddress(object): def __init__(self, domain): self.public_ip = random_ip() self.allocation_id = random_eip_allocation_id() if domain == "vpc" else None diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index 85b2b4874..cc2c002bf 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -68,12 +68,16 @@ class InstanceResponse(BaseResponse): return template.render(instance=instance, attribute=attribute, value=value) def modify_instance_attribute(self): + attribute_key = None for key, value in self.querystring.iteritems(): if '.Value' in key: + attribute_key = key break - value = self.querystring.get(key)[0] - normalized_attribute = camelcase_to_underscores(key.split(".")[0]) + if not attribute_key: + return + value = self.querystring.get(attribute_key)[0] + normalized_attribute = camelcase_to_underscores(attribute_key.split(".")[0]) instance_ids = instance_ids_from_querystring(self.querystring) instance_id = instance_ids[0] ec2_backend.modify_instance_attribute(instance_id, normalized_attribute, value) diff --git a/moto/emr/models.py b/moto/emr/models.py index 5dca3f62e..6c2045622 100644 --- a/moto/emr/models.py +++ b/moto/emr/models.py @@ -100,7 +100,7 @@ class FakeJobFlow(object): def master_instance_type(self): groups = self.instance_groups if groups: - groups[0].type + return groups[0].type else: return self.initial_master_instance_type @@ -108,7 +108,7 @@ class FakeJobFlow(object): def slave_instance_type(self): groups = self.instance_groups if groups: - groups[0].type + return groups[0].type else: return self.initial_slave_instance_type diff --git a/moto/route53/models.py b/moto/route53/models.py index d901996fa..1b2067504 100644 --- a/moto/route53/models.py +++ b/moto/route53/models.py @@ -2,7 +2,7 @@ from moto.core import BaseBackend from moto.core.utils import get_random_hex -class FakeZone: +class FakeZone(object): def __init__(self, name, id): self.name = name