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

Source Code for Module yakumo.smoketests.st41_upload_to_image

 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  """Block Storage API Test (Upload volumes to Glance)""" 
18   
19   
20  from yakumo.smoketest import * 
21  from yakumo import utils 
22   
23   
24  IMAGE_NAME = 'cirros' 
25   
26   
27 -def main(c, image=None):
28 29 LOG.debug("image: %s", image) 30 31 LOG.info("Create Volume #1") 32 name = get_random_str('volume') 33 with c.volume.create(name=name, 34 description="volume 1", 35 source=image, 36 size=1) as v1: 37 38 test("Volume #1 is created", v1 is not None) 39 40 LOG.debug("wait for created") 41 v1.wait_for_finished() 42 43 test("Volume #1 name is " + name, v1.name == name) 44 test("Volume #1 is available", v1.status == 'available') 45 test("Volume #1 source is the image", v1.source_image == image) 46 47 LOG.info("Create Image #1 from Volume #1") 48 name = get_random_str('image') 49 with v1.upload(name=name, disk_format="raw") as i: 50 51 LOG.debug("list image: %s", [_.name for _ in c.image.list()]) 52 53 test("Image #1 is created", i is not None) 54 55 LOG.debug("wait for created") 56 i.wait_for_finished() 57 58 LOG.debug("image status: %s", i.status) 59 test("Image #1 name is " + name, i.name == name) 60 test("Image #1 is active", i.status == 'active') 61 62 LOG.info("Create Volume #2 from Image #1") 63 name = get_random_str('volume') 64 with c.volume.create(name=name, 65 description="volume 2", 66 source=i, 67 size=1) as v2: 68 69 test("Volume #2 is created", v2 is not None) 70 71 LOG.debug("wait for created") 72 v2.wait_for_finished() 73 74 test("Volume #2 name is " + name, v2.name == name) 75 test("Volume #2 is available", v2.status == 'available') 76 test("Volume #2 source is Image #1", v2.source_image == i) 77 78 test("Volume #2 is deleted", v2 not in c.volume.list()) 79 80 test("Image #1 is deleted", i not in c.image.list()) 81 82 test("Volume #1 is deleted", v1 not in c.volume.list())
83 84 85 if __name__ == '__main__': 86 c = utils.get_client() 87 i = c.image.find_one(name=IMAGE_NAME) 88 89 LOG.debug("list volumes: %s", [_.name for _ in c.volume.list()]) 90 LOG.debug("list image: %s", [_.name for _ in c.image.list()]) 91 main(c, image=i) 92 LOG.debug("list volumes: %s", [_.name for _ in c.volume.list()]) 93 LOG.debug("list image: %s", [_.name for _ in c.image.list()]) 94 95 show_test_summary() 96