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

Source Code for Module yakumo.smoketests.st51_boot_from_volume

  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 (Booting from Volume)""" 
 18   
 19   
 20  import time 
 21   
 22  from yakumo.smoketest import * 
 23  from yakumo import utils 
 24   
 25   
 26  KEY_PAIR_NAME = 'key1' 
 27  FLAVOR_NAME = 'm1.small' 
 28  IMAGE_NAME = 'cirros' 
 29  NETWORK_NAME = 'private' 
 30   
 31   
32 -def main(c, key_pair=None, flavor=None, image=None, network=None, **kwargs):
33 34 LOG.debug("key pair: %s", key_pair) 35 LOG.debug("flavor: %s", flavor) 36 LOG.debug("image: %s", image) 37 LOG.debug("network: %s", network) 38 39 LOG.debug("list volumes: %s", [_.name for _ in c.volume.list()]) 40 LOG.debug("list servers: %s", [_.name for _ in c.server.list()]) 41 42 LOG.info("Create Volume #1") 43 name = get_random_str('volume') 44 with c.volume.create(name=name, source=image, size=1) as v: 45 46 LOG.debug("list volumes: %s", [_.name for _ in c.volume.list()]) 47 48 test("Volume #1 is created", v is not None) 49 50 LOG.debug("wait for created") 51 v.wait_for_finished() 52 53 test("Volume #1 name is " + name, v.name == name) 54 test("Volume #1 is available", v.status == 'available') 55 test("Volume #1 source is the image", v.source_image == image) 56 57 LOG.info("Create Server #1 with Volume #1") 58 name = get_random_str('server') 59 with c.server.create(name=name, 60 networks=[network], 61 disks=[{'source': v}], 62 flavor=flavor, 63 key_pair=key_pair) as s: 64 65 LOG.debug("list servers: %s", [_.name for _ in c.server.list()]) 66 67 LOG.debug("wait for created") 68 s.wait_for_finished() 69 test("Server #1 name is " + name, s.name == name) 70 test("Server #1 is active", s.status == 'ACTIVE') 71 v.reload() 72 test("Volume #1 is in-use", v.status == 'in-use') 73 74 LOG.info("wait for guest OS booted") 75 for i in range(30): 76 time.sleep(10) 77 cl = s.get_console_log(lines=20) 78 if 'login:' in cl: 79 test("Guest OS is ready", True) 80 break 81 else: 82 test("Guest OS is ready", False) 83 84 LOG.info("Stop Server #1") 85 s.stop() 86 LOG.debug("wait for stopped") 87 s.wait_for_finished() 88 test("Server #1 is stopped", s.status == 'SHUTOFF') 89 90 LOG.info("Start Server #1") 91 s.start() 92 LOG.debug("wait for started") 93 s.wait_for_finished() 94 test("Server #1 is active", s.status == 'ACTIVE') 95 96 test("Server #1 is deleted", s not in c.server.list()) 97 98 v.reload() 99 test("Volume #1 is available", v.status == 'available') 100 101 test("Volume #1 is deleted", v not in c.volume.list())
102 103 104 if __name__ == '__main__': 105 c = utils.get_client() 106 k = c.key_pair.find_one(name=KEY_PAIR_NAME) 107 f = c.flavor.find_one(name=FLAVOR_NAME) 108 i = c.image.find_one(name=IMAGE_NAME) 109 n = c.network.find_one(name=NETWORK_NAME) 110 111 LOG.debug("list volumes: %s", [_.name for _ in c.volume.list()]) 112 LOG.debug("list servers: %s", [_.name for _ in c.server.list()]) 113 main(c, key_pair=k, flavor=f, image=i, network=n) 114 LOG.debug("list volumes: %s", [_.name for _ in c.volume.list()]) 115 LOG.debug("list servers: %s", [_.name for _ in c.server.list()]) 116 117 show_test_summary() 118