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

Source Code for Module yakumo.smoketests.st50_server

  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 (Servers)""" 
 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  AZ_NAME = 'nova' 
 31   
 32   
33 -def main(c, key_pair=None, flavor=None, image=None, network=None, 34 availability_zone=None, **kwargs):
35 36 LOG.debug("key pair: %s", key_pair) 37 LOG.debug("flavor: %s", flavor) 38 LOG.debug("image: %s", image) 39 LOG.debug("network: %s", network) 40 LOG.debug("availability zone: %s", availability_zone) 41 42 LOG.info("Create Server #1") 43 name = get_random_str('server') 44 with c.server.create(name=name, 45 networks=[network], 46 image=image, 47 flavor=flavor, 48 availability_zone=availability_zone, 49 key_pair=key_pair) as s: 50 51 LOG.debug("list servers: %s", [_.name for _ in c.server.list()]) 52 53 LOG.debug("wait for created") 54 s.wait_for_finished() 55 test("Server #1 name is " + name, s.name == name) 56 test("Server #1 is active", s.status == 'ACTIVE') 57 test("Server #1 az is " + availability_zone.name, 58 s.availability_zone == availability_zone) 59 60 LOG.info("wait for guest OS booted") 61 for i in range(30): 62 time.sleep(10) 63 cl = s.get_console_log(lines=20) 64 if 'login:' in cl: 65 test("Guest OS is ready", True) 66 break 67 else: 68 test("Guest OS is ready", False) 69 70 LOG.info("Stop Server #1") 71 s.stop() 72 LOG.debug("wait for stopped") 73 s.wait_for_finished() 74 test("Server #1 is stopped", s.status == 'SHUTOFF') 75 76 LOG.info("Start Server #1") 77 s.start() 78 LOG.debug("wait for started") 79 s.wait_for_finished() 80 test("Server #1 is active", s.status == 'ACTIVE') 81 82 LOG.info("Force reboot Server #1") 83 s.reboot(force=True) 84 LOG.debug("wait for started") 85 s.wait_for_finished() 86 test("Server #1 is active", s.status == 'ACTIVE') 87 88 LOG.info("Suspend Server #1") 89 s.suspend() 90 LOG.debug("wait for suspended") 91 s.wait_for_finished() 92 test("Server #1 is suspended", s.status == 'SUSPENDED') 93 94 LOG.info("Resume Server #1") 95 s.resume() 96 LOG.debug("wait for resumed") 97 s.wait_for_finished() 98 test("Server #1 is active", s.status == 'ACTIVE') 99 100 LOG.info("Pause Server #1") 101 s.pause() 102 LOG.debug("wait for paused") 103 s.wait_for_finished() 104 test("Server #1 is paused", s.status == 'PAUSED') 105 106 LOG.info("Unpause Server #1") 107 s.unpause() 108 LOG.debug("wait for unpaused") 109 s.wait_for_finished() 110 test("Server is active", s.status == 'ACTIVE') 111 112 LOG.info("Lock Server #1") 113 s.lock() 114 LOG.debug("wait for locked") 115 s.wait_for_finished() 116 test("Server #1 is active", s.status == 'ACTIVE') 117 118 LOG.info("Stop Server #1 locked (will be failed)") 119 try: 120 s.stop() 121 s.wait_for_finished() 122 except: 123 pass 124 test("Server #1 is active", s.status == 'ACTIVE') 125 126 LOG.info("Unlock Server #1") 127 s.unlock() 128 LOG.debug("wait for unlocked") 129 s.wait_for_finished() 130 131 LOG.info("Stop Server #1 unlocked (will be succeeded)") 132 try: 133 s.stop() 134 s.wait_for_finished() 135 except: 136 pass 137 test("Server #1 is stopped", s.status == 'SHUTOFF') 138 139 LOG.info("Show Server #1 action: %s", 140 [_['action'] for _ in s.get_actions()]) 141 142 test("Server #1 is deleted", s not in c.server.list())
143 144 145 if __name__ == '__main__': 146 c = utils.get_client() 147 k = c.key_pair.find_one(name=KEY_PAIR_NAME) 148 f = c.flavor.find_one(name=FLAVOR_NAME) 149 i = c.image.find_one(name=IMAGE_NAME) 150 n = c.network.find_one(name=NETWORK_NAME) 151 az = c.availability_zone.get_empty(AZ_NAME) 152 153 LOG.debug("list servers: %s", [_.name for _ in c.server.list()]) 154 main(c, key_pair=k, flavor=f, image=i, network=n, availability_zone=az) 155 LOG.debug("list servers: %s", [_.name for _ in c.server.list()]) 156 157 show_test_summary() 158