blob: 44da88cfb31a2cc3159d6775f0425e15c695f86c [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
PrernaDembla6b79aff2018-01-11 18:28:03 +053023 def _delete_keypair(self, keypair_name, client=None, **params):
24 if not client:
25 client = self.keypairs_client
26 client.delete_keypair(keypair_name, **params)
Marc Koderer78e5a8b2015-08-03 15:04:53 +020027
zhufl5bcd7ee2017-01-13 17:47:14 +080028 def create_keypair(self, keypair_name=None,
29 pub_key=None, keypair_type=None,
PrernaDembla6b79aff2018-01-11 18:28:03 +053030 user_id=None, client=None):
31 if not client:
32 client = self.keypairs_client
zhufl5bcd7ee2017-01-13 17:47:14 +080033 if keypair_name is None:
34 keypair_name = data_utils.rand_name(
35 self.__class__.__name__ + '-keypair')
Marc Koderer78e5a8b2015-08-03 15:04:53 +020036 kwargs = {'name': keypair_name}
Ghanshyam4541bd12016-02-29 13:46:39 +090037 delete_params = {}
Marc Koderer78e5a8b2015-08-03 15:04:53 +020038 if pub_key:
39 kwargs.update({'public_key': pub_key})
ghanshyama1f87132015-11-13 14:49:27 +090040 if keypair_type:
41 kwargs.update({'type': keypair_type})
Ghanshyam4541bd12016-02-29 13:46:39 +090042 if user_id:
43 kwargs.update({'user_id': user_id})
44 delete_params['user_id'] = user_id
PrernaDembla6b79aff2018-01-11 18:28:03 +053045 body = client.create_keypair(**kwargs)['keypair']
46 self.addCleanup(self._delete_keypair, keypair_name,
47 client, **delete_params)
Marc Koderer78e5a8b2015-08-03 15:04:53 +020048 return body