Updated the EC2 metadata controller so that it returns the correct value

for instance-type metadata.
This commit is contained in:
Dan Prince 2011-08-09 16:00:54 -04:00
parent 5afb04d2fb
commit c81febc28a
2 changed files with 16 additions and 5 deletions

View File

@ -299,7 +299,7 @@ class CloudController(object):
'hostname': hostname,
'instance-action': 'none',
'instance-id': ec2_id,
'instance-type': instance_ref['instance_type'],
'instance-type': instance_ref['instance_type'].name,
'local-hostname': hostname,
'local-ipv4': address,
'placement': {'availability-zone': availability_zone},

View File

@ -107,14 +107,18 @@ class AddressTests(base.UserSmokeTestCase):
class SecurityGroupTests(base.UserSmokeTestCase):
def __public_instance_is_accessible(self):
id_url = "latest/meta-data/instance-id"
def __get_metadata_item(self, category):
id_url = "latest/meta-data/%s" % category
options = "-f -s --max-time 1"
command = "curl %s %s/%s" % (options, self.data['public_ip'], id_url)
status, output = commands.getstatusoutput(command)
instance_id = output.strip()
value = output.strip()
if status > 0:
return False
return value
def __public_instance_is_accessible(self):
instance_id = self.__get_metadata_item('instance-id')
if not instance_id:
return False
if instance_id != self.data['instance'].id:
@ -166,7 +170,14 @@ class SecurityGroupTests(base.UserSmokeTestCase):
finally:
result = self.conn.disassociate_address(self.data['public_ip'])
def test_005_can_revoke_security_group_ingress(self):
def test_005_validate_metadata(self):
instance = self.data['instance']
self.assertTrue(instance.instance_type,
self.__get_metadata_item("instance-type"))
#FIXME(dprince): validate more metadata here
def test_006_can_revoke_security_group_ingress(self):
self.assertTrue(self.conn.revoke_security_group(TEST_GROUP,
ip_protocol='tcp',
from_port=80,