summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorMauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com>2012-09-10 09:14:40 -0400
committerMauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com>2012-09-18 20:49:59 -0400
commit894ea491ddaee1530f429165c5819cecd5167c77 (patch)
tree3e47423d5192fb6a40a1b71f6153e852ea82f624 /nova
parent0ffff7c490d54f9b932df4b2dcd62158242dae2a (diff)
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
Diffstat (limited to 'nova')
-rw-r--r--nova/tests/integrated/api_samples/os-keypairs/keypairs-get-resp.json.tpl11
-rw-r--r--nova/tests/integrated/api_samples/os-keypairs/keypairs-get-resp.xml.tpl9
-rw-r--r--nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-req.json.tpl6
-rw-r--r--nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-req.xml.tpl4
-rw-r--r--nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-resp.json.tpl8
-rw-r--r--nova/tests/integrated/api_samples/os-keypairs/keypairs-import-post-resp.xml.tpl7
-rw-r--r--nova/tests/integrated/api_samples/os-keypairs/keypairs-post-req.json.tpl5
-rw-r--r--nova/tests/integrated/api_samples/os-keypairs/keypairs-post-req.xml.tpl3
-rw-r--r--nova/tests/integrated/api_samples/os-keypairs/keypairs-post-resp.json.tpl9
-rw-r--r--nova/tests/integrated/api_samples/os-keypairs/keypairs-post-resp.xml.tpl9
-rw-r--r--nova/tests/integrated/test_api_samples.py58
11 files changed, 129 insertions, 0 deletions
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 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<keypairs>
+ <keypair>
+ <public_key>%(public_key)s
+</public_key>
+ <name>%(keypair_name)s</name>
+ <fingerprint>%(fingerprint)s</fingerprint>
+ </keypair>
+</keypairs>
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>%(keypair_name)s</name>
+ <public_key>%(public_key)s</public_key>
+</keypair>
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 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<keypair>
+ <public_key>%(public_key)s</public_key>
+ <user_id>fake</user_id>
+ <name>%(keypair_name)s</name>
+ <fingerprint>%(fingerprint)s</fingerprint>
+</keypair>
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>%(keypair_name)s</name>
+</keypair>
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 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<keypair>
+ <public_key>%(public_key)s
+</public_key>
+ <private_key>%(private_key)s</private_key>
+ <user_id>fake</user_id>
+ <name>%(keypair_name)s</name>
+ <fingerprint>%(fingerprint)s</fingerprint>
+</keypair>
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'