Merge "port test_keypairs into nova v3 part2"
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index 9cb425a..e0a5376 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -268,6 +268,7 @@
cls.tenant_usages_client = cls.os.tenant_usages_v3_client
cls.volumes_client = cls.os.volumes_client
cls.certificates_client = cls.os.certificates_v3_client
+ cls.keypairs_client = cls.os.keypairs_v3_client
@classmethod
def create_image_from_server(cls, server_id, **kwargs):
diff --git a/tempest/api/compute/v3/keypairs/test_keypairs.py b/tempest/api/compute/v3/keypairs/test_keypairs.py
index b36595c..029633f 100644
--- a/tempest/api/compute/v3/keypairs/test_keypairs.py
+++ b/tempest/api/compute/v3/keypairs/test_keypairs.py
@@ -20,17 +20,17 @@
from tempest import test
-class KeyPairsTestJSON(base.BaseV2ComputeTest):
+class KeyPairsV3TestJSON(base.BaseV3ComputeTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(KeyPairsTestJSON, cls).setUpClass()
+ super(KeyPairsV3TestJSON, cls).setUpClass()
cls.client = cls.keypairs_client
def _delete_keypair(self, keypair_name):
resp, _ = self.client.delete_keypair(keypair_name)
- self.assertEqual(202, resp.status)
+ self.assertEqual(204, resp.status)
def _create_keypair(self, keypair_name, pub_key=None):
resp, body = self.client.create_keypair(keypair_name, pub_key)
@@ -49,7 +49,7 @@
# as the keypair dicts from list API doesn't have them.
keypair.pop('private_key')
keypair.pop('user_id')
- self.assertEqual(200, resp.status)
+ self.assertEqual(201, resp.status)
key_list.append(keypair)
# Fetch all keypairs and verify the list
# has all created keypairs
@@ -72,7 +72,7 @@
# Keypair should be created, verified and deleted
k_name = data_utils.rand_name('keypair-')
resp, keypair = self._create_keypair(k_name)
- self.assertEqual(200, resp.status)
+ self.assertEqual(201, resp.status)
private_key = keypair['private_key']
key_name = keypair['name']
self.assertEqual(key_name, k_name,
@@ -111,7 +111,7 @@
"XcPojYN56tI0OlrGqojbediJYD0rUsJu4weZpbn8vilb3JuDY+jws"
"snSA8wzBx3A/8y9Pp1B nova@ubuntu")
resp, keypair = self._create_keypair(k_name, pub_key)
- self.assertEqual(200, resp.status)
+ self.assertEqual(201, resp.status)
self.assertFalse('private_key' in keypair,
"Field private_key is not empty!")
key_name = keypair['name']
@@ -120,5 +120,5 @@
"to the requested name!")
-class KeyPairsTestXML(KeyPairsTestJSON):
+class KeyPairsV3TestXML(KeyPairsV3TestJSON):
_interface = 'xml'
diff --git a/tempest/api/compute/v3/keypairs/test_keypairs_negative.py b/tempest/api/compute/v3/keypairs/test_keypairs_negative.py
index 621487c..edc0c26 100644
--- a/tempest/api/compute/v3/keypairs/test_keypairs_negative.py
+++ b/tempest/api/compute/v3/keypairs/test_keypairs_negative.py
@@ -22,12 +22,12 @@
from tempest import test
-class KeyPairsNegativeTestJSON(base.BaseV2ComputeTest):
+class KeyPairsNegativeV3TestJSON(base.BaseV3ComputeTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(KeyPairsNegativeTestJSON, cls).setUpClass()
+ super(KeyPairsNegativeV3TestJSON, cls).setUpClass()
cls.client = cls.keypairs_client
def _create_keypair(self, keypair_name, pub_key=None):
@@ -70,12 +70,11 @@
# Keypairs with duplicate names should not be created
k_name = data_utils.rand_name('keypair-')
resp, _ = self.client.create_keypair(k_name)
- self.assertEqual(200, resp.status)
+ self.addCleanup(self.client.delete_keypair, k_name)
+ self.assertEqual(201, resp.status)
# Now try the same keyname to create another key
self.assertRaises(exceptions.Conflict, self._create_keypair,
k_name)
- resp, _ = self.client.delete_keypair(k_name)
- self.assertEqual(202, resp.status)
@test.attr(type=['negative', 'gate'])
def test_create_keypair_with_empty_name_string(self):
@@ -98,5 +97,5 @@
k_name)
-class KeyPairsNegativeTestXML(KeyPairsNegativeTestJSON):
+class KeyPairsNegativeV3TestXML(KeyPairsNegativeV3TestJSON):
_interface = 'xml'
diff --git a/tempest/clients.py b/tempest/clients.py
index 3333b9b..2983fa8 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -60,6 +60,8 @@
HypervisorV3ClientJSON
from tempest.services.compute.v3.json.interfaces_client import \
InterfacesV3ClientJSON
+from tempest.services.compute.v3.json.keypairs_client import \
+ KeyPairsV3ClientJSON
from tempest.services.compute.v3.json.servers_client import \
ServersV3ClientJSON
from tempest.services.compute.v3.json.services_client import \
@@ -76,6 +78,7 @@
HypervisorV3ClientXML
from tempest.services.compute.v3.xml.interfaces_client import \
InterfacesV3ClientXML
+from tempest.services.compute.v3.xml.keypairs_client import KeyPairsV3ClientXML
from tempest.services.compute.v3.xml.servers_client import ServersV3ClientXML
from tempest.services.compute.v3.xml.services_client import \
ServicesV3ClientXML
@@ -220,6 +223,7 @@
self.servers_v3_client = ServersV3ClientXML(*client_args)
self.limits_client = LimitsClientXML(*client_args)
self.images_client = ImagesClientXML(*client_args)
+ self.keypairs_v3_client = KeyPairsV3ClientXML(*client_args)
self.keypairs_client = KeyPairsClientXML(*client_args)
self.quotas_client = QuotasClientXML(*client_args)
self.flavors_client = FlavorsClientXML(*client_args)
@@ -275,6 +279,7 @@
self.servers_v3_client = ServersV3ClientJSON(*client_args)
self.limits_client = LimitsClientJSON(*client_args)
self.images_client = ImagesClientJSON(*client_args)
+ self.keypairs_v3_client = KeyPairsV3ClientJSON(*client_args)
self.keypairs_client = KeyPairsClientJSON(*client_args)
self.quotas_client = QuotasClientJSON(*client_args)
self.flavors_client = FlavorsClientJSON(*client_args)
diff --git a/tempest/services/compute/v3/json/keypairs_client.py b/tempest/services/compute/v3/json/keypairs_client.py
index 5e1900c..500aa0e 100644
--- a/tempest/services/compute/v3/json/keypairs_client.py
+++ b/tempest/services/compute/v3/json/keypairs_client.py
@@ -20,15 +20,15 @@
from tempest.common.rest_client import RestClient
-class KeyPairsClientJSON(RestClient):
+class KeyPairsV3ClientJSON(RestClient):
def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(KeyPairsClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ super(KeyPairsV3ClientJSON, self).__init__(config, username, password,
+ auth_url, tenant_name)
+ self.service = self.config.compute.catalog_v3_type
def list_keypairs(self):
- resp, body = self.get("os-keypairs")
+ resp, body = self.get("keypairs")
body = json.loads(body)
# Each returned keypair is embedded within an unnecessary 'keypair'
# element which is a deviation from other resources like floating-ips,
@@ -38,7 +38,7 @@
return resp, body['keypairs']
def get_keypair(self, key_name):
- resp, body = self.get("os-keypairs/%s" % str(key_name))
+ resp, body = self.get("keypairs/%s" % str(key_name))
body = json.loads(body)
return resp, body['keypair']
@@ -47,10 +47,10 @@
if pub_key:
post_body['keypair']['public_key'] = pub_key
post_body = json.dumps(post_body)
- resp, body = self.post("os-keypairs",
+ resp, body = self.post("keypairs",
headers=self.headers, body=post_body)
body = json.loads(body)
return resp, body['keypair']
def delete_keypair(self, key_name):
- return self.delete("os-keypairs/%s" % str(key_name))
+ return self.delete("keypairs/%s" % str(key_name))
diff --git a/tempest/services/compute/v3/xml/keypairs_client.py b/tempest/services/compute/v3/xml/keypairs_client.py
index 0157245..d87daff 100644
--- a/tempest/services/compute/v3/xml/keypairs_client.py
+++ b/tempest/services/compute/v3/xml/keypairs_client.py
@@ -24,21 +24,21 @@
from tempest.services.compute.xml.common import xml_to_json
-class KeyPairsClientXML(RestClientXML):
+class KeyPairsV3ClientXML(RestClientXML):
def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(KeyPairsClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ super(KeyPairsV3ClientXML, self).__init__(config, username, password,
+ auth_url, tenant_name)
+ self.service = self.config.compute.catalog_v3_type
def list_keypairs(self):
- resp, body = self.get("os-keypairs", self.headers)
+ resp, body = self.get("keypairs", self.headers)
node = etree.fromstring(body)
body = [{'keypair': xml_to_json(x)} for x in node.getchildren()]
return resp, body
def get_keypair(self, key_name):
- resp, body = self.get("os-keypairs/%s" % str(key_name), self.headers)
+ resp, body = self.get("keypairs/%s" % str(key_name), self.headers)
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -60,10 +60,10 @@
doc.append(keypair_element)
- resp, body = self.post("os-keypairs",
+ resp, body = self.post("keypairs",
headers=self.headers, body=str(doc))
body = xml_to_json(etree.fromstring(body))
return resp, body
def delete_keypair(self, key_name):
- return self.delete("os-keypairs/%s" % str(key_name))
+ return self.delete("keypairs/%s" % str(key_name))