From 894ea491ddaee1530f429165c5819cecd5167c77 Mon Sep 17 00:00:00 2001 From: "Mauro S. M. Rodrigues" Date: Mon, 10 Sep 2012 09:14:40 -0400 Subject: Add Keypairs extension to API samples test. NOTE: This include two samples of post request: One to create the keypair and another to import from a public key Change-Id: I754fd5998cf8be46a96e69e3459c91d4f767575e --- .../os-keypairs/keypairs-get-resp.json.tpl | 11 ++++ .../os-keypairs/keypairs-get-resp.xml.tpl | 9 ++++ .../os-keypairs/keypairs-import-post-req.json.tpl | 6 +++ .../os-keypairs/keypairs-import-post-req.xml.tpl | 4 ++ .../os-keypairs/keypairs-import-post-resp.json.tpl | 8 +++ .../os-keypairs/keypairs-import-post-resp.xml.tpl | 7 +++ .../os-keypairs/keypairs-post-req.json.tpl | 5 ++ .../os-keypairs/keypairs-post-req.xml.tpl | 3 ++ .../os-keypairs/keypairs-post-resp.json.tpl | 9 ++++ .../os-keypairs/keypairs-post-resp.xml.tpl | 9 ++++ nova/tests/integrated/test_api_samples.py | 58 ++++++++++++++++++++++ 11 files changed, 129 insertions(+) create mode 100644 nova/tests/integrated/api_samples/os-keypairs/keypairs-get-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-keypairs/keypairs-get-resp.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-req.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-req.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-resp.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-keypairs/keypairs-post-req.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-keypairs/keypairs-post-req.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-keypairs/keypairs-post-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-keypairs/keypairs-post-resp.xml.tpl (limited to 'nova') diff --git a/nova/tests/integrated/api_samples/os-keypairs/keypairs-get-resp.json.tpl b/nova/tests/integrated/api_samples/os-keypairs/keypairs-get-resp.json.tpl new file mode 100644 index 000000000..29ba63c00 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-keypairs/keypairs-get-resp.json.tpl @@ -0,0 +1,11 @@ +{ + "keypairs": [ + { + "keypair": { + "fingerprint": "%(fingerprint)s", + "name": "%(keypair_name)s", + "public_key": "%(public_key)s" + } + } + ] +} diff --git a/nova/tests/integrated/api_samples/os-keypairs/keypairs-get-resp.xml.tpl b/nova/tests/integrated/api_samples/os-keypairs/keypairs-get-resp.xml.tpl new file mode 100644 index 000000000..493bfa316 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-keypairs/keypairs-get-resp.xml.tpl @@ -0,0 +1,9 @@ + + + + %(public_key)s + + %(keypair_name)s + %(fingerprint)s + + diff --git a/nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-req.json.tpl b/nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-req.json.tpl new file mode 100644 index 000000000..2301fa05b --- /dev/null +++ b/nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-req.json.tpl @@ -0,0 +1,6 @@ +{ + "keypair": { + "name": "%(keypair_name)s", + "public_key": "%(public_key)s" + } +} diff --git a/nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-req.xml.tpl b/nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-req.xml.tpl new file mode 100644 index 000000000..0516de303 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-req.xml.tpl @@ -0,0 +1,4 @@ + + %(keypair_name)s + %(public_key)s + diff --git a/nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-resp.json.tpl b/nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-resp.json.tpl new file mode 100644 index 000000000..ca7192d5d --- /dev/null +++ b/nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-resp.json.tpl @@ -0,0 +1,8 @@ +{ + "keypair": { + "fingerprint": "%(fingerprint)s", + "name": "%(keypair_name)s", + "public_key": "%(public_key)s", + "user_id": "fake" + } +} diff --git a/nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-resp.xml.tpl b/nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-resp.xml.tpl new file mode 100644 index 000000000..ed2543c10 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-resp.xml.tpl @@ -0,0 +1,7 @@ + + + %(public_key)s + fake + %(keypair_name)s + %(fingerprint)s + diff --git a/nova/tests/integrated/api_samples/os-keypairs/keypairs-post-req.json.tpl b/nova/tests/integrated/api_samples/os-keypairs/keypairs-post-req.json.tpl new file mode 100644 index 000000000..68e2f0348 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-keypairs/keypairs-post-req.json.tpl @@ -0,0 +1,5 @@ +{ + "keypair": { + "name": "%(keypair_name)s" + } +} diff --git a/nova/tests/integrated/api_samples/os-keypairs/keypairs-post-req.xml.tpl b/nova/tests/integrated/api_samples/os-keypairs/keypairs-post-req.xml.tpl new file mode 100644 index 000000000..e14935d31 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-keypairs/keypairs-post-req.xml.tpl @@ -0,0 +1,3 @@ + + %(keypair_name)s + diff --git a/nova/tests/integrated/api_samples/os-keypairs/keypairs-post-resp.json.tpl b/nova/tests/integrated/api_samples/os-keypairs/keypairs-post-resp.json.tpl new file mode 100644 index 000000000..aace6f5cc --- /dev/null +++ b/nova/tests/integrated/api_samples/os-keypairs/keypairs-post-resp.json.tpl @@ -0,0 +1,9 @@ +{ + "keypair": { + "fingerprint": "%(fingerprint)s", + "name": "%(keypair_name)s", + "private_key": "%(private_key)s", + "public_key": "%(public_key)s", + "user_id": "fake" + } +} diff --git a/nova/tests/integrated/api_samples/os-keypairs/keypairs-post-resp.xml.tpl b/nova/tests/integrated/api_samples/os-keypairs/keypairs-post-resp.xml.tpl new file mode 100644 index 000000000..4f041e0c9 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-keypairs/keypairs-post-resp.xml.tpl @@ -0,0 +1,9 @@ + + + %(public_key)s + + %(private_key)s + fake + %(keypair_name)s + %(fingerprint)s + diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index 487048c92..a1304c55a 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -210,6 +210,16 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase): '-[0-9a-f]{4}-[0-9a-f]{12})', 'uuid': '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}' '-[0-9a-f]{4}-[0-9a-f]{12}', + 'private_key': '-----BEGIN RSA PRIVATE KEY-----' + '[a-zA-Z0-9\n/+=]*' + '-----END RSA PRIVATE KEY-----', + 'public_key': 'ssh-rsa[ a-zA-Z0-9/+=]*' + 'Generated by Nova', + 'fingerprint': '([0-9a-f]{2}:){15}[0-9a-f]{2}', +# '[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:' +# '[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:' +# '[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:' +# '[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}', 'host': self._get_host(), 'glance_host': self._get_glance_host(), 'compute_host': self.compute.host, @@ -859,3 +869,51 @@ class FloatingIpsJsonTest(ApiSampleTestBase): class FloatingIpsXmlTest(FloatingIpsJsonTest): ctype = 'xml' + + +class KeyPairsSampleJsonTest(ApiSampleTestBase): + extension_name = "nova.api.openstack.compute.contrib.keypairs.Keypairs" + + def test_keypairs_post(self, public_key=None): + """Get api sample of key pairs post request""" + key_name = 'keypair-' + str(uuid.uuid4()) + response = self._do_post('os-keypairs', 'keypairs-post-req', + {'keypair_name': key_name}) + subs = self._get_regexes() + subs['keypair_name'] = '(%s)' % key_name + self.assertEqual(response.status, 200) + self._verify_response('keypairs-post-resp', subs, response) + # NOTE(maurosr): return the key_name is necessary cause the + # verification returns the label of the last compared information in + # the response, not necessarily the key name. + return key_name + + def test_keypairs_import_key_post(self): + """Get api sample of key pairs post to import user's key""" + key_name = 'keypair-' + str(uuid.uuid4()) + subs = { + 'keypair_name': key_name, + 'public_key': "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGg" + "B4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0l" + "RE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv" + "9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYc" + "pSxsIbECHw== Generated by Nova" + } + response = self._do_post('os-keypairs', 'keypairs-import-post-req', + subs) + subs = self._get_regexes() + subs['keypair_name'] = '(%s)' % key_name + self.assertEqual(response.status, 200) + self._verify_response('keypairs-import-post-resp', subs, response) + + def test_keypairs_get(self): + """Get api sample of key pairs get request""" + key_name = self.test_keypairs_post() + response = self._do_get('os-keypairs') + subs = self._get_regexes() + subs['keypair_name'] = '(%s)' % key_name + return self._verify_response('keypairs-get-resp', subs, response) + + +class KeyPairsSampleXmlTest(KeyPairsSampleJsonTest): + ctype = 'xml' -- cgit