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

Source Code for Module yakumo.smoketests.st60_container_admin

 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  """Container API Test (Container Metadata)""" 
18   
19   
20  import sys 
21   
22  from yakumo.smoketest import * 
23  from yakumo import utils 
24   
25   
26  QUOTA_BYTES = 10 * 1024 ** 3  # 10GB 
27  QUOTA_COUNT = 10 
28   
29   
30 -def main(c):
31 if not c._session.has_endpoint('object-store'): 32 return 33 34 LOG.info("Create an container") 35 36 name = get_random_str('container') 37 metadata = {'foo': 'bar', 'foo2': 'bar2'} 38 with c.container.create(name=name, 39 quota_bytes=QUOTA_BYTES, 40 quota_count=QUOTA_COUNT, 41 metadata=metadata) as co: 42 43 test("Container #1: name is " + name, co.name == name) 44 test("Container #1: quota bytes is %s" % QUOTA_BYTES, 45 co.quota_bytes == QUOTA_BYTES) 46 test("Container #1: quota count is %s" % QUOTA_COUNT, 47 co.quota_count == QUOTA_COUNT) 48 49 LOG.info("Double quotas") 50 co.update(quota_bytes=(QUOTA_BYTES * 2), quota_count=(QUOTA_COUNT * 2)) 51 test("Container #1: quota bytes is %s" % (QUOTA_BYTES * 2), 52 co.quota_bytes == QUOTA_BYTES * 2) 53 test("Container #1: quota count is %s" % (QUOTA_COUNT * 2), 54 co.quota_count == QUOTA_COUNT * 2) 55 56 LOG.info("Update metadata") 57 LOG.debug("Initial metadata: %s", co.metadata) 58 test("Metadata has %s" % metadata, co.metadata == metadata) 59 60 m = {'foo2': 'bar4', 'foo3': 'bar3'} 61 LOG.debug("Set metadata : %s", m) 62 metadata.update(m) 63 co.set_metadata(**m) 64 LOG.debug("Updated metadata: %s", co.metadata) 65 test("Metadata has %s" % metadata, co.metadata == metadata) 66 67 m = ['foo', 'foo2'] 68 LOG.debug("Unset metadata : %s", m) 69 for key in m: 70 metadata.pop(key) 71 co.unset_metadata(*m) 72 LOG.debug("Updated metadata: %s", co.metadata) 73 test("Metadata has %s" % metadata, co.metadata == metadata)
74 75 76 if __name__ == '__main__': 77 c = utils.get_client() 78 if not c._session.has_endpoint('object-store'): 79 sys.exit(0) 80 81 LOG.debug("list containers: %s", [_.name for _ in c.container.list()]) 82 main(c) 83 LOG.debug("list containers: %s", [_.name for _ in c.container.list()]) 84 85 show_test_summary() 86