Package yakumo :: Package smoketests :: Module st56_key_pair
[hide private]
[frames] | no frames]

Source Code for Module yakumo.smoketests.st56_key_pair

 1  #!/usr/bin/env python 
 2  # 
 3  # Copyright 2014-2017 by Akira Yoshiyama <akirayoshiyama@gmail.com>. 
 4  # All Rights Reserved. 
 5  # 
 6  #    Licensed under the Apache License, Version 2.0 (the "License"); you may 
 7  #    not use this file except in compliance with the License. You may obtain 
 8  #    a copy of the License at 
 9  # 
10  #         http://www.apache.org/licenses/LICENSE-2.0 
11  # 
12  #    Unless required by applicable law or agreed to in writing, software 
13  #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
14  #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
15  #    License for the specific language governing permissions and limitations 
16  #    under the License. 
17  """Compute API Test (Key Pairs)""" 
18   
19   
20  import os 
21  import time 
22   
23  from yakumo.smoketest import * 
24  from yakumo import utils 
25   
26   
27  PUBLIC_KEY = os.environ.get('HOME', '') + "/.ssh/id_rsa.pub" 
28   
29   
30 -def main(c, **kwargs):
31 32 LOG.info("Create Key Pair #1") 33 name = get_random_str('keypair') 34 private_key_file = "/tmp/%s.pem" % name 35 with c.key_pair.create(name=name, private_key_file=private_key_file) as k1: 36 37 LOG.debug("list key pairs: %s", [_.name for _ in c.key_pair.list()]) 38 39 test("Key Pair #1: name is " + name, k1.name == name) 40 LOG.debug("public key: %s", k1.public_key) 41 LOG.debug("private key: %s", k1.private_key) 42 test("Key Pair #1: public key is provided", len(k1.public_key) > 0) 43 test("Key Pair #1: private key is provided", len(k1.private_key) > 0) 44 45 with open(private_key_file) as f: 46 private_key = f.read() 47 test("Key Pair #1: private key is saved", 48 private_key == k1.private_key) 49 50 test("Key Pair #1 is deleted", k1 not in c.key_pair.list()) 51 52 LOG.info("Create Key Pair #2") 53 name = get_random_str('keypair') 54 with open(PUBLIC_KEY) as f: 55 public_key = f.read() 56 public_key.strip() 57 58 with c.key_pair.create(name=name, public_key=public_key) as k2: 59 LOG.debug("list key pairs: %s", [_.name for _ in c.key_pair.list()]) 60 61 test("Key Pair #2: name is " + name, k2.name == name) 62 LOG.debug("public key: %s", k2.public_key) 63 LOG.debug("private key: %s", k2.private_key) 64 test("Key Pair #2: public key is the same", 65 k2.public_key == public_key) 66 test("Key Pair #2: private key is not provided", 67 k2.private_key is None) 68 69 test("Key Pair #2 is deleted", k2 not in c.key_pair.list())
70 71 72 if __name__ == '__main__': 73 c = utils.get_client() 74 75 LOG.debug("list key pairs: %s", [_.name for _ in c.key_pair.list()]) 76 main(c) 77 LOG.debug("list key pairs: %s", [_.name for _ in c.key_pair.list()]) 78 79 show_test_summary() 80