blob: 005181064fc5065a142c8a5751e248d3a251bb0d [file] [log] [blame]
Marc Koderer78e5a8b2015-08-03 15:04:53 +02001# Copyright 2015 Deutsche Telekom AG
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from tempest.api.compute import base
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080017from tempest.lib.common.utils import data_utils
Marc Koderer78e5a8b2015-08-03 15:04:53 +020018
19
Ken'ichi Ohmichi02a8ccd2015-11-05 06:05:29 +000020class BaseKeypairTest(base.BaseV2ComputeTest):
Marc Koderer78e5a8b2015-08-03 15:04:53 +020021 """Base test case class for all keypair API tests."""
22
Marc Koderer78e5a8b2015-08-03 15:04:53 +020023 @classmethod
24 def setup_clients(cls):
25 super(BaseKeypairTest, cls).setup_clients()
26 cls.client = cls.keypairs_client
27
Ghanshyam4541bd12016-02-29 13:46:39 +090028 def _delete_keypair(self, keypair_name, **params):
29 self.client.delete_keypair(keypair_name, **params)
Marc Koderer78e5a8b2015-08-03 15:04:53 +020030
zhufl5bcd7ee2017-01-13 17:47:14 +080031 def create_keypair(self, keypair_name=None,
32 pub_key=None, keypair_type=None,
33 user_id=None):
34 if keypair_name is None:
35 keypair_name = data_utils.rand_name(
36 self.__class__.__name__ + '-keypair')
Marc Koderer78e5a8b2015-08-03 15:04:53 +020037 kwargs = {'name': keypair_name}
Ghanshyam4541bd12016-02-29 13:46:39 +090038 delete_params = {}
Marc Koderer78e5a8b2015-08-03 15:04:53 +020039 if pub_key:
40 kwargs.update({'public_key': pub_key})
ghanshyama1f87132015-11-13 14:49:27 +090041 if keypair_type:
42 kwargs.update({'type': keypair_type})
Ghanshyam4541bd12016-02-29 13:46:39 +090043 if user_id:
44 kwargs.update({'user_id': user_id})
45 delete_params['user_id'] = user_id
ghanshyamdee01f22015-08-17 11:41:47 +090046 body = self.client.create_keypair(**kwargs)['keypair']
Ghanshyam4541bd12016-02-29 13:46:39 +090047 self.addCleanup(self._delete_keypair, keypair_name, **delete_params)
Marc Koderer78e5a8b2015-08-03 15:04:53 +020048 return body