Package yakumo :: Package cmd :: Module run_tests
[hide private]
[frames] | no frames]

Source Code for Module yakumo.cmd.run_tests

  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   
 18  from contextlib import contextmanager 
 19  import copy 
 20  import os 
 21   
 22  from yakumo import Client 
 23  from yakumo.smoketest import * 
 24  from yakumo import utils 
 25   
 26  from yakumo.smoketests import * 
 27   
 28   
 29  CIDR1 = os.environ.get('CIDR1', '192.168.35.0/24') 
 30  CIDR2 = os.environ.get('CIDR2', '192.168.36.0/24') 
 31  GATEWAY_IP1 = os.environ.get('GATEWAY_IP1', '192.168.35.254') 
 32  GATEWAY_IP2 = os.environ.get('GATEWAY_IP2', '192.168.36.254') 
 33   
 34  IMAGE = os.environ.get('IMAGE', 'images/cirros-0.3.5-x86_64-disk.img') 
 35  CONTAINER_FORMAT = os.environ.get('CONTAINER_FORMAT', 'bare') 
 36  DISK_FORMAT = os.environ.get('DISK_FORMAT', 'qcow2') 
 37  FLAVOR = os.environ.get('FLAVOR', 'm1.tiny') 
 38  AZ = os.environ.get('AZ', 'nova') 
 39  ROLE = os.environ.get('ROLE', '_member_') 
 40   
 41   
42 -def run_tenant_tests(c, c2):
43 44 for t in SWIFT_TESTS + GLANCE_TESTS + NEUTRON_TESTS + CINDER_TESTS: 45 try: 46 LOG.info("%s: Started", t.__doc__) 47 if t.__name__.endswith('admin'): 48 t.main(c) 49 else: 50 t.main(c2) 51 LOG.info("%s: Finished successfully", t.__doc__) 52 except Exception as e: 53 LOG.exception("%s: Error occured: %s", t.__doc__, e) 54 55 with c2.network.create(name=get_random_str('network'), 56 is_shared=False) as n1, \ 57 c2.network.create(name=get_random_str('network'), 58 is_shared=False) as n2: 59 60 with c2.subnet.create(name=get_random_str('subnet'), 61 network=n1, 62 ip_version=4, 63 cidr=CIDR1, 64 gateway_ip=GATEWAY_IP1, 65 is_dhcp_enabled=True) as sn1, \ 66 c2.subnet.create(name=get_random_str('subnet'), 67 network=n2, 68 ip_version=4, 69 cidr=CIDR2, 70 gateway_ip=GATEWAY_IP2, 71 is_dhcp_enabled=True) as sn2: 72 73 with c2.router.create(name=get_random_str('router')) as r1, \ 74 c2.router.create(name=get_random_str('router')) as r2, \ 75 c2.key_pair.create(name=get_random_str('keypair')) as k, \ 76 c2.image.create(name=get_random_str('image'), 77 file=IMAGE, 78 container_format=CONTAINER_FORMAT, 79 disk_format=DISK_FORMAT) as i: 80 81 r1.add_interface(subnet=sn1) 82 r2.add_interface(subnet=sn2) 83 84 f = c2.flavor.find_one(name=FLAVOR) 85 az = c2.availability_zone.get_empty(AZ) 86 87 for t in NOVA_TESTS: 88 try: 89 LOG.info("%s: Started", t.__doc__) 90 if t.__name__.endswith('admin'): 91 t.main( 92 c, image=i, flavor=f, key_pair=k, 93 network=n1, network2=n2, 94 availability_zone=az) 95 else: 96 t.main( 97 c2, image=i, flavor=f, key_pair=k, 98 network=n1, network2=n2, 99 availability_zone=az) 100 LOG.info("%s: Finished successfully", t.__doc__) 101 except Exception as e: 102 LOG.exception("%s: Error occured: %s", 103 t.__doc__, e) 104 105 r1.remove_interface(subnet=sn1) 106 r2.remove_interface(subnet=sn2) 107 108 test("Router #1 is deleted", r1 not in c2.router.list()) 109 test("Router #2 is deleted", r2 not in c2.router.list()) 110 test("Key Pair #1 is deleted", k not in c2.key_pair.list()) 111 test("Image #1 is deleted", i not in c2.image.list()) 112 113 test("Subnet #1 is deleted", sn1 not in c2.subnet.list()) 114 test("Subnet #2 is deleted", sn2 not in c2.subnet.list()) 115 116 test("Network #1 is deleted", n1 not in c2.network.list()) 117 test("Network #2 is deleted", n2 not in c2.network.list())
118 119
120 -def run_tests(c):
121 122 for t in KEYSTONE_TESTS: 123 try: 124 LOG.info("%s: Started", t.__doc__) 125 t.main(c) 126 LOG.info("%s: Finished successfully", t.__doc__) 127 except Exception as e: 128 LOG.exception("%s: Error occured: %s", t.__doc__, e) 129 130 project_name = get_random_str('test') 131 user_name = get_random_str('test') 132 password = get_random_str('pass') 133 134 config = copy.copy(c._session.config) 135 config['auth']['project_name'] = project_name 136 config['auth']['username'] = user_name 137 config['auth']['password'] = password 138 r = c.role.find_one(name=ROLE) 139 140 if config['identity_api_version'] == '2.0': 141 with c.project.create(name=project_name, 142 description='test project', 143 is_enabled=True) as p: 144 with c.user.create(name=user_name, 145 username='test user', 146 password=password, 147 project=p, 148 is_enabled=True) as u: 149 p.grant_roles(users=u, roles=r) 150 c2 = Client(**config) 151 run_tenant_tests(c, c2) 152 153 test("User #1 is deleted", u not in c.user.list()) 154 test("Project #1 is deleted", p not in c.project.list()) 155 156 elif config['identity_api_version'] == '3': 157 d = c.domain.find_one(name=config['auth']['project_domain_name']) 158 with c.project.create(name=project_name, 159 description='test project', 160 domain=d, 161 is_enabled=True) as p: 162 with c.user.create(name=user_name, 163 password=password, 164 domain=d, 165 is_enabled=True) as u: 166 p.grant_roles(users=u, roles=r) 167 c2 = Client(**config) 168 run_tenant_tests(c, c2) 169 170 test("User #1 is deleted", u not in c.user.list()) 171 test("Project #1 is deleted", p not in c.project.list())
172 173
174 -def main():
175 c = utils.get_client() 176 177 LOG.debug("list networks: %s", [_.name for _ in c.network.list()]) 178 LOG.debug("list subnets: %s", [_.name for _ in c.subnet.list()]) 179 LOG.debug("list routers: %s", [_.name for _ in c.router.list()]) 180 LOG.debug("list servers: %s", [_.name for _ in c.server.list()]) 181 LOG.debug("list key pairs: %s", [_.name for _ in c.key_pair.list()]) 182 LOG.debug("list images: %s", [_.name for _ in c.image.list()]) 183 run_tests(c) 184 LOG.debug("list networks: %s", [_.name for _ in c.network.list()]) 185 LOG.debug("list subnets: %s", [_.name for _ in c.subnet.list()]) 186 LOG.debug("list routers: %s", [_.name for _ in c.router.list()]) 187 LOG.debug("list servers: %s", [_.name for _ in c.server.list()]) 188 LOG.debug("list key pairs: %s", [_.name for _ in c.key_pair.list()]) 189 LOG.debug("list images: %s", [_.name for _ in c.image.list()]) 190 show_test_summary()
191 192 if __name__ == '__main__': 193 main() 194