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

Source Code for Module yakumo.smoketests.st22_image_metadata_nova

 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  """Image API Test (Image Metadata)""" 
18   
19   
20  import hashlib 
21  import os 
22  import tempfile 
23   
24  from yakumo.smoketest import * 
25  from yakumo import utils 
26   
27   
28 -def main(c):
29 30 SOURCE_IMAGE = './images/cirros-0.3.5-x86_64-disk.img' 31 32 LOG.info("Create an image") 33 34 name = get_random_str('image') 35 metadata = {'foo': 'bar', 'foo2': 'bar2'} 36 with c.image.create(name=name, 37 file=SOURCE_IMAGE, 38 container_format='bare', 39 disk_format='qcow2', 40 tags=['tag1'], 41 **metadata) as i: 42 LOG.debug("wait for created") 43 i.wait_for_finished() 44 45 test("Image name", i.name == name) 46 test("Image is active", i.status == 'active') 47 48 LOG.info("Update image metadata via nova API") 49 ni = c.nova.image.find_one(name=name) 50 test("Image name", ni.name == name) 51 52 LOG.debug("Initial metadata: %s", ni.metadata) 53 test("Metadata has %s" % metadata, ni.metadata == metadata) 54 55 m = {'foo2': 'bar4', 'foo3': 'bar3'} 56 LOG.debug("Set metadata : %s", m) 57 metadata.update(m) 58 ni.set_metadata(**m) 59 LOG.debug("Updated metadata: %s", ni.metadata) 60 test("Metadata has %s" % metadata, ni.metadata == metadata) 61 62 m = ['foo', 'foo2'] 63 LOG.debug("Unset metadata : %s", m) 64 for key in m: 65 metadata.pop(key) 66 ni.unset_metadata(*m) 67 LOG.debug("Updated metadata: %s", ni.metadata) 68 test("Metadata has %s" % metadata, ni.metadata == metadata)
69 70 71 if __name__ == '__main__': 72 c = utils.get_client() 73 74 LOG.debug("list images: %s", [_.name for _ in c.image.list()]) 75 main(c) 76 LOG.debug("list images: %s", [_.name for _ in c.image.list()]) 77 78 show_test_summary() 79