implement test for create_key_pair
This commit is contained in:
parent
65beb30054
commit
ddfe478479
@ -19,6 +19,7 @@ from .utils import (
|
|||||||
random_eip_association_id,
|
random_eip_association_id,
|
||||||
random_eip_allocation_id,
|
random_eip_allocation_id,
|
||||||
random_ip,
|
random_ip,
|
||||||
|
random_key_pair,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -163,25 +164,26 @@ class InstanceBackend(object):
|
|||||||
|
|
||||||
class KeyPairBackend(object):
|
class KeyPairBackend(object):
|
||||||
|
|
||||||
class KeyPair(object):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.keypairs = defaultdict(dict)
|
self.keypairs = defaultdict(dict)
|
||||||
super(KeyPairBackend, self).__init__()
|
super(KeyPairBackend, self).__init__()
|
||||||
|
|
||||||
def create_key_pair(self, name):
|
def create_key_pair(self, name):
|
||||||
self.keypairs[name] = self.KeyPair()
|
self.keypairs[name] = keypair = random_key_pair()
|
||||||
return name
|
keypair['name'] = name
|
||||||
|
return keypair
|
||||||
|
|
||||||
def delete_key_pair(self, name):
|
def delete_key_pair(self, name):
|
||||||
return self.keypairs.pop(name)
|
keypair = self.keypairs.pop(name)
|
||||||
|
keypair['name'] = name
|
||||||
|
return keypair
|
||||||
|
|
||||||
def describe_key_pairs(self, filter_names=None):
|
def describe_key_pairs(self, filter_names=None):
|
||||||
results = []
|
results = []
|
||||||
for name, keypair in self.keypairs.iteritems():
|
for name, keypair in self.keypairs.iteritems():
|
||||||
if not filter_names or name in filter_names:
|
if not filter_names or name in filter_names:
|
||||||
results.append({name: keypair})
|
keypair['name'] = name
|
||||||
|
results.append(keypair)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,9 @@ from moto.ec2.models import ec2_backend
|
|||||||
class KeyPairs(BaseResponse):
|
class KeyPairs(BaseResponse):
|
||||||
|
|
||||||
def create_key_pair(self):
|
def create_key_pair(self):
|
||||||
raise NotImplementedError('KeyPairs.create_key_pair is not yet implemented')
|
name = self.querystring.get('KeyName')[0]
|
||||||
|
template = Template(CREATE_KEY_PAIR_RESPONSE)
|
||||||
|
return template.render(**ec2_backend.create_key_pair(name))
|
||||||
|
|
||||||
def delete_key_pair(self):
|
def delete_key_pair(self):
|
||||||
raise NotImplementedError('KeyPairs.delete_key_pair is not yet implemented')
|
raise NotImplementedError('KeyPairs.delete_key_pair is not yet implemented')
|
||||||
@ -24,3 +26,13 @@ DESCRIBE_KEY_PAIRS_RESPONSE = """<DescribeKeyPairsResponse xmlns="http://ec2.ama
|
|||||||
<keySet>
|
<keySet>
|
||||||
</keySet>
|
</keySet>
|
||||||
</DescribeKeyPairsResponse>"""
|
</DescribeKeyPairsResponse>"""
|
||||||
|
|
||||||
|
|
||||||
|
CREATE_KEY_PAIR_RESPONSE = """<CreateKeyPairResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
|
||||||
|
<keyName>{{ name }}</keyName>
|
||||||
|
<keyFingerprint>
|
||||||
|
{{ fingerprint }}
|
||||||
|
</keyFingerprint>
|
||||||
|
<keyMaterial>{{ material }}
|
||||||
|
</keyMaterial>
|
||||||
|
</CreateKeyPairResponse>"""
|
||||||
|
@ -144,3 +144,27 @@ def filter_reservations(reservations, filter_dict):
|
|||||||
reservation.instances = new_instances
|
reservation.instances = new_instances
|
||||||
result.append(reservation)
|
result.append(reservation)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
# not really random
|
||||||
|
def random_key_pair():
|
||||||
|
return {
|
||||||
|
'fingerprint': ('1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:'
|
||||||
|
'7d:b8:ca:9f:f5:f1:6f'),
|
||||||
|
'material': """---- BEGIN RSA PRIVATE KEY ----
|
||||||
|
MIICiTCCAfICCQD6m7oRw0uXOjANBgkqhkiG9w0BAQUFADCBiDELMAkGA1UEBhMC
|
||||||
|
VVMxCzAJBgNVBAgTAldBMRAwDgYDVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6
|
||||||
|
b24xFDASBgNVBAsTC0lBTSBDb25zb2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAd
|
||||||
|
BgkqhkiG9w0BCQEWEG5vb25lQGFtYXpvbi5jb20wHhcNMTEwNDI1MjA0NTIxWhcN
|
||||||
|
MTIwNDI0MjA0NTIxWjCBiDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAldBMRAwDgYD
|
||||||
|
VQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6b24xFDASBgNVBAsTC0lBTSBDb25z
|
||||||
|
b2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAdBgkqhkiG9w0BCQEWEG5vb25lQGFt
|
||||||
|
YXpvbi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMaK0dn+a4GmWIWJ
|
||||||
|
21uUSfwfEvySWtC2XADZ4nB+BLYgVIk60CpiwsZ3G93vUEIO3IyNoH/f0wYK8m9T
|
||||||
|
rDHudUZg3qX4waLG5M43q7Wgc/MbQITxOUSQv7c7ugFFDzQGBzZswY6786m86gpE
|
||||||
|
Ibb3OhjZnzcvQAaRHhdlQWIMm2nrAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAtCu4
|
||||||
|
nUhVVxYUntneD9+h8Mg9q6q+auNKyExzyLwaxlAoo7TJHidbtS4J5iNmZgXL0Fkb
|
||||||
|
FFBjvSfpJIlJ00zbhNYS5f6GuoEDmFJl0ZxBHjJnyp378OD8uTs7fLvjx79LjSTb
|
||||||
|
NYiytVbZPQUQ5Yaxu2jXnimvw3rrszlaEXAMPLE
|
||||||
|
-----END RSA PRIVATE KEY-----"""
|
||||||
|
}
|
||||||
|
@ -14,4 +14,4 @@ def test_key_pairs_empty():
|
|||||||
def test_key_pairs_create():
|
def test_key_pairs_create():
|
||||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||||
kp = conn.create_key_pair('foo')
|
kp = conn.create_key_pair('foo')
|
||||||
assert kp.material.startswith('-----BEGIN RSA PRIVATE KEY-----')
|
assert kp.material.startswith('---- BEGIN RSA PRIVATE KEY ----')
|
||||||
|
Loading…
Reference in New Issue
Block a user