<s> from __future__ import print_function <EOL> import argparse <EOL> import datetime <EOL> import logging <EOL> import os <EOL> import random <EOL> import sys <EOL> import threading <EOL> import time <EOL> import unittest <EOL> import pyrax <EOL> import pyrax . exceptions as exc <EOL> import pyrax . utils as utils <EOL> class SmokeTester ( object ) : <EOL> def __init__ ( self , context , region , logname = None , nolog = False , <EOL> clean = False ) : <EOL> self . context = context <EOL> self . region = region <EOL> self . clean = clean <EOL> self . failures = [ ] <EOL> self . cleanup_items = [ ] <EOL> self . smoke_server = None <EOL> self . smoke_volume = None <EOL> self . smoke_snapshot = None <EOL> logname = "<STR_LIT>" % ( logname or "<STR_LIT>" , self . region ) <EOL> self . log = logging . getLogger ( logname ) <EOL> if nolog : <EOL> handler = logging . NullHandler ( ) <EOL> else : <EOL> handler = logging . FileHandler ( filename = logname , mode = "<STR_LIT:w>" , <EOL> encoding = "<STR_LIT:utf-8>" ) <EOL> formatter = logging . Formatter ( "<STR_LIT>" ) <EOL> handler . setFormatter ( formatter ) <EOL> self . log . addHandler ( handler ) <EOL> self . log . setLevel ( logging . DEBUG ) <EOL> self . cs = self . context . get_client ( "<STR_LIT>" , self . region ) <EOL> self . cf = self . context . get_client ( "<STR_LIT>" , self . region ) <EOL> self . cbs = self . context . get_client ( "<STR_LIT>" , self . region ) <EOL> self . cdb = self . context . get_client ( "<STR_LIT>" , self . region ) <EOL> self . clb = self . context . get_client ( "<STR_LIT>" , self . region ) <EOL> self . dns = self . context . get_client ( "<STR_LIT>" , self . region ) <EOL> self . cnw = self . context . get_client ( "<STR_LIT>" , self . region ) <EOL> self . cmn = self . context . get_client ( "<STR_LIT>" , self . region ) <EOL> self . au = self . context . get_client ( "<STR_LIT>" , self . region ) <EOL> self . pq = self . context . get_client ( "<STR_LIT>" , self . region ) <EOL> self . services = ( { "<STR_LIT>" : self . cs , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : self . cf , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : self . cbs , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : self . cdb , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : self . clb , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : self . dns , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : self . cnw , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : self . cmn , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : self . au , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : self . pq , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> ) <EOL> def logit ( self , * args , ** kwargs ) : <EOL> txtargs = [ "<STR_LIT:%s>" % arg for arg in args ] <EOL> msg = "<STR_LIT:U+0020>" . join ( txtargs ) <EOL> print ( "<STR_LIT>" % ( self . region , msg ) , ** kwargs ) <EOL> self . log . debug ( msg ) <EOL> def check_services ( self ) : <EOL> for service in self . services : <EOL> self . logit ( "<STR_LIT>" , service [ "<STR_LIT:name>" ] , end = '<STR_LIT:U+0020>' ) <EOL> if service [ "<STR_LIT>" ] : <EOL> self . logit ( "<STR_LIT>" ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" % service [ "<STR_LIT:name>" ] ) <EOL> def run_clean ( self ) : <EOL> def cleanup_smoke ( svc , list_method = None , * list_params ) : <EOL> list_method = list_method or "<STR_LIT:list>" <EOL> mthd = getattr ( svc , list_method ) <EOL> try : <EOL> svcname = svc . name <EOL> except AttributeError : <EOL> svcname = "<STR_LIT:%s>" % svc <EOL> try : <EOL> ents = [ ent for ent in mthd ( * list_params ) <EOL> if ent . name . startswith ( "<STR_LIT>" ) ] <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" , svcname ) <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> return <EOL> if ents : <EOL> try : <EOL> ent . delete ( ) <EOL> self . logit ( "<STR_LIT>" , svcname , "<STR_LIT>" , ent . id ) <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" , svcname , "<STR_LIT>" , ent . id ) <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" , <EOL> self . region , "<STR_LIT>" , svcname ) <EOL> cleanup_smoke ( self . cnw ) <EOL> cleanup_smoke ( self . cs ) <EOL> cleanup_smoke ( self . cdb ) <EOL> cleanup_smoke ( self . cf , "<STR_LIT>" , "<STR_LIT>" ) <EOL> cleanup_smoke ( self . cf ) <EOL> cleanup_smoke ( self . clb ) <EOL> cleanup_smoke ( self . dns , "<STR_LIT>" , "<STR_LIT>" ) <EOL> cleanup_smoke ( self . dns ) <EOL> cleanup_smoke ( self . cmn , "<STR_LIT>" , "<STR_LIT>" ) <EOL> cleanup_smoke ( self . cmn , "<STR_LIT>" ) <EOL> cleanup_smoke ( self . cmn , "<STR_LIT>" ) <EOL> cleanup_smoke ( self . cmn , "<STR_LIT>" ) <EOL> cleanup_smoke ( self . cmn , "<STR_LIT>" , "<STR_LIT>" ) <EOL> cleanup_smoke ( self . cbs ) <EOL> return <EOL> def run_tests ( self ) : <EOL> if self . clean : <EOL> return self . run_clean ( ) <EOL> if self . cs : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . cs_list_flavors ( ) <EOL> self . cs_list_images ( ) <EOL> self . cs_create_server ( ) <EOL> self . cs_reboot_server ( ) <EOL> self . cs_list_servers ( ) <EOL> if self . cnw : <EOL> self . logit ( "<STR_LIT>" ) <EOL> try : <EOL> self . cnw_create_network ( ) <EOL> self . cnw_list_networks ( ) <EOL> except exc . NotFound : <EOL> self . logit ( "<STR_LIT>" ) <EOL> except exc . NetworkCountExceeded : <EOL> self . logit ( "<STR_LIT>" ) <EOL> if self . cdb : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . cdb_list_flavors ( ) <EOL> self . cdb_create_instance ( ) <EOL> self . cdb_create_db ( ) <EOL> self . cdb_create_user ( ) <EOL> if self . cf : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . cf_create_container ( ) <EOL> self . cf_list_containers ( ) <EOL> self . cf_make_container_public ( ) <EOL> self . cf_make_container_private ( ) <EOL> self . cf_upload_file ( ) <EOL> if self . clb : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . lb_list ( ) <EOL> self . lb_create ( ) <EOL> if self . dns : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . dns_list ( ) <EOL> self . dns_create_domain ( ) <EOL> self . dns_create_record ( ) <EOL> if self . cmn : <EOL> if not self . smoke_server : <EOL> self . logit ( "<STR_LIT>" ) <EOL> return <EOL> self . cmn_create_entity ( ) <EOL> self . cmn_list_check_types ( ) <EOL> self . cmn_list_monitoring_zones ( ) <EOL> self . cmn_create_check ( ) <EOL> self . cmn_create_notification ( ) <EOL> self . cmn_create_notification_plan ( ) <EOL> self . cmn_create_alarm ( ) <EOL> if self . cbs : <EOL> self . cbs_list_volumes ( ) <EOL> self . cbs_list_types ( ) <EOL> self . cbs_list_snapshots ( ) <EOL> self . cbs_create_volume ( ) <EOL> self . cbs_attach_to_instance ( ) <EOL> self . cbs_detach_from_instance ( ) <EOL> self . cbs_create_snapshot ( ) <EOL> self . cbs_delete_snapshot ( ) <EOL> def cs_list_flavors ( self ) : <EOL> self . logit ( "<STR_LIT>" , end = '<STR_LIT:U+0020>' ) <EOL> self . cs_flavors = self . cs . list_flavors ( ) <EOL> if self . cs_flavors : <EOL> self . logit ( ) <EOL> for flavor in self . cs_flavors : <EOL> self . logit ( "<STR_LIT>" , flavor ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> self . logit ( ) <EOL> def cs_list_images ( self ) : <EOL> self . logit ( "<STR_LIT>" , end = '<STR_LIT:U+0020>' ) <EOL> self . cs_images = self . cs . list_base_images ( ) <EOL> if self . cs_images : <EOL> for image in self . cs_images : <EOL> self . logit ( "<STR_LIT>" , image ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cnw_create_network ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> new_network_name = "<STR_LIT>" <EOL> new_network_cidr = "<STR_LIT>" <EOL> self . logit ( "<STR_LIT>" , end = '<STR_LIT:U+0020>' ) <EOL> self . logit ( "<STR_LIT>" , self . cnw ) <EOL> self . smoke_network = self . cnw . create ( new_network_name , <EOL> cidr = new_network_cidr ) <EOL> self . cleanup_items . append ( self . smoke_network ) <EOL> if self . smoke_network : <EOL> self . logit ( "<STR_LIT>" ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cnw_list_networks ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> try : <EOL> networks = self . cnw . list ( ) <EOL> except exc . NotFound : <EOL> self . logit ( "<STR_LIT>" ) <EOL> return <EOL> for network in networks : <EOL> self . logit ( "<STR_LIT>" % ( network . id , network . name , <EOL> network . cidr ) ) <EOL> if not networks : <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def log_wait ( self , obj , att = "<STR_LIT:status>" , desired = None , verbose_atts = None ) : <EOL> start = time . time ( ) <EOL> self . logit ( "<STR_LIT>" , obj . name , obj ) <EOL> if not desired : <EOL> desired = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ret = utils . wait_until ( obj , "<STR_LIT:status>" , desired = desired , interval = <NUM_LIT:10> , <EOL> verbose = True , verbose_atts = "<STR_LIT>" ) <EOL> end = time . time ( ) <EOL> duration = str ( datetime . timedelta ( seconds = ( end - start ) ) ) <EOL> self . logit ( "<STR_LIT>" , obj . name , obj ) <EOL> self . logit ( "<STR_LIT>" % duration ) <EOL> return ret <EOL> def cs_create_server ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> img = [ img for img in self . cs_images <EOL> if "<STR_LIT>" in img . name ] [ <NUM_LIT:0> ] <EOL> flavor = self . cs_flavors [ <NUM_LIT:0> ] <EOL> self . smoke_server = self . cs . servers . create ( "<STR_LIT>" , <EOL> img . id , flavor . id ) <EOL> self . cleanup_items . append ( self . smoke_server ) <EOL> self . smoke_server = self . log_wait ( self . smoke_server ) <EOL> if self . smoke_server . status == "<STR_LIT>" : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> def cs_reboot_server ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . smoke_server . reboot ( ) <EOL> self . smoke_server = self . log_wait ( self . smoke_server ) <EOL> if self . smoke_server . status == "<STR_LIT>" : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> def cs_list_servers ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> servers = self . cs . servers . list ( ) <EOL> if not servers : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> else : <EOL> for server in servers : <EOL> self . logit ( "<STR_LIT>" , server . id , server . name ) <EOL> def cdb_list_flavors ( self ) : <EOL> self . logit ( "<STR_LIT>" , end = '<STR_LIT:U+0020>' ) <EOL> try : <EOL> self . cdb_flavors = self . cdb . list_flavors ( ) <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> self . cdb_flavors = None <EOL> if self . cdb_flavors : <EOL> for flavor in self . cdb_flavors : <EOL> self . logit ( "<STR_LIT>" , flavor ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cdb_create_instance ( self ) : <EOL> if not self . cdb_flavors : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . smoke_instance = None <EOL> return <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . smoke_instance = self . cdb . create ( "<STR_LIT>" , <EOL> flavor = self . cdb_flavors [ <NUM_LIT:0> ] , volume = <NUM_LIT:1> ) <EOL> self . cleanup_items . append ( self . smoke_instance ) <EOL> self . smoke_instance = self . log_wait ( self . smoke_instance ) <EOL> if self . smoke_instance . status == "<STR_LIT>" : <EOL> self . logit ( "<STR_LIT>" ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cdb_create_db ( self ) : <EOL> if not self . smoke_instance : <EOL> self . logit ( "<STR_LIT>" ) <EOL> return <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . smoke_db = self . smoke_instance . create_database ( "<STR_LIT>" ) <EOL> self . cleanup_items . append ( self . smoke_db ) <EOL> dbs = self . smoke_instance . list_databases ( ) <EOL> if self . smoke_db in dbs : <EOL> self . logit ( "<STR_LIT>" ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cdb_create_user ( self ) : <EOL> if not self . smoke_instance : <EOL> self . logit ( "<STR_LIT>" ) <EOL> return <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . smoke_user = self . smoke_instance . create_user ( "<STR_LIT>" , <EOL> "<STR_LIT>" , database_names = [ self . smoke_db ] ) <EOL> self . cleanup_items . append ( self . smoke_user ) <EOL> users = self . smoke_instance . list_users ( ) <EOL> if self . smoke_user in users : <EOL> self . logit ( "<STR_LIT>" ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cf_create_container ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . smoke_cont = self . cf . create_container ( "<STR_LIT>" ) <EOL> self . cleanup_items . append ( self . smoke_cont ) <EOL> if self . smoke_cont : <EOL> self . logit ( "<STR_LIT>" ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cf_list_containers ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> conts = self . cf . get_all_containers ( ) <EOL> if conts : <EOL> for cont in conts : <EOL> try : <EOL> nm = cont . name <EOL> num = cont . object_count <EOL> size = cont . total_bytes <EOL> self . logit ( "<STR_LIT>" % ( nm , num , size ) ) <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cf_make_container_public ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . smoke_cont . make_public ( ) <EOL> uri = self . smoke_cont . cdn_uri <EOL> if uri : <EOL> self . logit ( "<STR_LIT>" ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cf_make_container_private ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> try : <EOL> self . smoke_cont . make_private ( ) <EOL> self . logit ( "<STR_LIT>" ) <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cf_upload_file ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> cont = self . smoke_cont <EOL> text = utils . random_ascii ( <NUM_LIT> ) <EOL> obj = cont . store_object ( "<STR_LIT>" , text ) <EOL> self . cleanup_items . insert ( <NUM_LIT:0> , obj ) <EOL> all_objs = cont . get_object_names ( ) <EOL> if obj . name in all_objs : <EOL> self . logit ( "<STR_LIT>" ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def lb_list ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> lbs = self . clb . list ( ) <EOL> if not lbs : <EOL> self . logit ( "<STR_LIT>" ) <EOL> else : <EOL> for lb in lbs : <EOL> self . logit ( "<STR_LIT>" , lb . name ) <EOL> def lb_create ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> node = self . clb . Node ( address = "<STR_LIT>" , port = <NUM_LIT> , condition = "<STR_LIT>" ) <EOL> vip = self . clb . VirtualIP ( type = "<STR_LIT>" ) <EOL> lb = self . clb . create ( "<STR_LIT>" , port = <NUM_LIT> , protocol = "<STR_LIT>" , <EOL> nodes = [ node ] , virtual_ips = [ vip ] ) <EOL> self . cleanup_items . append ( lb ) <EOL> lb = self . log_wait ( lb ) <EOL> if lb : <EOL> self . logit ( "<STR_LIT>" ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def dns_list ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> doms = self . dns . list ( ) <EOL> if not doms : <EOL> self . logit ( "<STR_LIT>" ) <EOL> else : <EOL> for dns in doms : <EOL> self . logit ( "<STR_LIT>" , dns . name ) <EOL> def dns_create_domain ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> domain_name = "<STR_LIT>" <EOL> try : <EOL> dom = self . dns . create ( name = domain_name , <EOL> emailAddress = "<STR_LIT>" , ttl = <NUM_LIT> , <EOL> comment = "<STR_LIT>" ) <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . cleanup_items . append ( dom ) <EOL> except exc . DomainCreationFailed as e : <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def dns_create_record ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> domain_name = "<STR_LIT>" <EOL> try : <EOL> dom = self . dns . find ( name = domain_name ) <EOL> except exc . NotFound : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> return <EOL> a_rec = { "<STR_LIT:type>" : "<STR_LIT:A>" , <EOL> "<STR_LIT:name>" : domain_name , <EOL> "<STR_LIT:data>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> } <EOL> try : <EOL> recs = dom . add_records ( a_rec ) <EOL> self . logit ( "<STR_LIT>" ) <EOL> except exc . DomainRecordAdditionFailed as e : <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cmn_list_check_types ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> cts = self . cmn . list_check_types ( ) <EOL> for ct in cts : <EOL> self . logit ( "<STR_LIT>" , ct . id , ct . type ) <EOL> def cmn_list_monitoring_zones ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> zones = self . cmn . list_monitoring_zones ( ) <EOL> for zone in zones : <EOL> self . logit ( "<STR_LIT>" , zone . id , zone . name ) <EOL> def cmn_create_entity ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> srv = self . smoke_server <EOL> ip = srv . networks [ "<STR_LIT>" ] [ <NUM_LIT:0> ] <EOL> try : <EOL> self . smoke_entity = self . cmn . create_entity ( name = "<STR_LIT>" , <EOL> ip_addresses = { "<STR_LIT>" : ip } ) <EOL> self . cleanup_items . append ( self . smoke_entity ) <EOL> self . logit ( "<STR_LIT>" ) <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> self . smoke_entity = None <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cmn_create_check ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> ent = self . smoke_entity <EOL> alias = ent . ip_addresses . keys ( ) [ <NUM_LIT:0> ] <EOL> try : <EOL> self . smoke_check = self . cmn . create_check ( ent , <EOL> label = "<STR_LIT>" , check_type = "<STR_LIT>" , <EOL> details = { "<STR_LIT:count>" : <NUM_LIT:5> } , monitoring_zones_poll = [ "<STR_LIT>" ] , <EOL> period = <NUM_LIT> , timeout = <NUM_LIT:20> , target_alias = alias ) <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . cleanup_items . append ( self . smoke_check ) <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> self . smoke_check = None <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cmn_create_notification ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> email = "<STR_LIT>" <EOL> try : <EOL> self . smoke_notification = self . cmn . create_notification ( "<STR_LIT:email>" , <EOL> label = "<STR_LIT>" , details = { "<STR_LIT:address>" : email } ) <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . cleanup_items . append ( self . smoke_notification ) <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> self . smoke_notification = None <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cmn_create_notification_plan ( self ) : <EOL> if not self . smoke_notification : <EOL> self . logit ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return <EOL> self . logit ( "<STR_LIT>" ) <EOL> try : <EOL> self . smoke_notification_plan = self . cmn . create_notification_plan ( <EOL> label = "<STR_LIT>" , ok_state = self . smoke_notification ) <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . cleanup_items . append ( self . smoke_notification_plan ) <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> self . smoke_notification_plan = None <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cmn_create_alarm ( self ) : <EOL> if not self . smoke_notification_plan : <EOL> self . logit ( "<STR_LIT>" ) <EOL> return <EOL> self . logit ( "<STR_LIT>" ) <EOL> try : <EOL> self . smoke_alarm = self . cmn . create_alarm ( self . smoke_entity , <EOL> self . smoke_check , self . smoke_notification_plan , <EOL> label = "<STR_LIT>" ) <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . cleanup_items . append ( self . smoke_alarm ) <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> def cbs_list_volumes ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> vols = self . cbs . list ( ) <EOL> for vol in vols : <EOL> self . logit ( "<STR_LIT>" , vol . name , "<STR_LIT>" % vol . volume_type , "<STR_LIT>" , <EOL> vol . size ) <EOL> def cbs_list_types ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> typs = self . cbs . list_types ( ) <EOL> for typ in typs : <EOL> self . logit ( "<STR_LIT>" , typ . name ) <EOL> def cbs_list_snapshots ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> snaps = self . cbs . list_snapshots ( ) <EOL> for snap in snaps : <EOL> self . logit ( "<STR_LIT>" , snap . name , "<STR_LIT>" % snap . status , "<STR_LIT>" , <EOL> snap . size ) <EOL> def cbs_create_volume ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> typ = random . choice ( self . cbs . list_types ( ) ) <EOL> self . smoke_volume = self . cbs . create ( "<STR_LIT>" , size = <NUM_LIT:100> , <EOL> volume_type = "<STR_LIT>" , description = "<STR_LIT>" ) <EOL> self . cleanup_items . append ( self . smoke_volume ) <EOL> self . smoke_volume = self . log_wait ( self . smoke_volume , <EOL> desired = [ "<STR_LIT>" , "<STR_LIT:error>" ] ) <EOL> if self . smoke_volume . status == "<STR_LIT>" : <EOL> self . logit ( "<STR_LIT>" ) <EOL> self . failures . append ( "<STR_LIT>" ) <EOL> else : <EOL> self . logit ( "<STR_LIT>" ) <EOL> def cbs_attach_to_instance ( self ) : <EOL> if not self . smoke_server : <EOL> self . logit ( "<STR_LIT>" ) <EOL> return <EOL> self . logit ( "<STR_LIT>" ) <EOL> try : <EOL> self . smoke_volume . attach_to_instance ( self . smoke_server , "<STR_LIT>" ) <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> return <EOL> self . smoke_volume = self . log_wait ( self . smoke_volume , <EOL> desired = [ "<STR_LIT>" , "<STR_LIT:error>" ] ) <EOL> self . logit ( "<STR_LIT>" ) <EOL> def cbs_detach_from_instance ( self ) : <EOL> if not self . smoke_server : <EOL> self . logit ( "<STR_LIT>" ) <EOL> return <EOL> self . logit ( "<STR_LIT>" ) <EOL> try : <EOL> self . smoke_volume . detach ( ) <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> return <EOL> self . smoke_volume = self . log_wait ( self . smoke_volume , <EOL> desired = [ "<STR_LIT>" , "<STR_LIT:error>" ] ) <EOL> self . logit ( "<STR_LIT>" ) <EOL> def cbs_create_snapshot ( self ) : <EOL> if not self . smoke_volume : <EOL> self . logit ( "<STR_LIT>" ) <EOL> return <EOL> self . logit ( "<STR_LIT>" ) <EOL> try : <EOL> self . smoke_snapshot = self . cbs . create_snapshot ( self . smoke_volume , <EOL> name = "<STR_LIT>" ) <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> return <EOL> self . smoke_snapshot = self . log_wait ( self . smoke_snapshot , <EOL> desired = [ "<STR_LIT>" , "<STR_LIT:error>" ] ) <EOL> self . logit ( "<STR_LIT>" ) <EOL> def cbs_delete_snapshot ( self ) : <EOL> if not self . smoke_snapshot : <EOL> self . logit ( "<STR_LIT>" ) <EOL> return <EOL> self . logit ( "<STR_LIT>" ) <EOL> try : <EOL> self . cbs . delete_snapshot ( self . smoke_snapshot ) <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" , e ) <EOL> return <EOL> snap_id = self . smoke_snapshot . id <EOL> self . logit ( "<STR_LIT>" ) <EOL> while True : <EOL> try : <EOL> snap = self . cbs . get_snapshot ( snap_id ) <EOL> except exc . NotFound : <EOL> break <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> self . logit ( "<STR_LIT>" ) <EOL> def cleanup ( self ) : <EOL> self . logit ( "<STR_LIT>" ) <EOL> for item in self . cleanup_items : <EOL> try : <EOL> item . delete ( ) <EOL> self . logit ( "<STR_LIT>" , end = '<STR_LIT:U+0020>' ) <EOL> try : <EOL> self . logit ( item . name ) <EOL> except AttributeError : <EOL> self . logit ( item ) <EOL> except exc . NotFound : <EOL> pass <EOL> except Exception as e : <EOL> self . logit ( "<STR_LIT>" % ( item , e ) ) <EOL> class TestThread ( threading . Thread ) : <EOL> def __init__ ( self , context , region , logname , nolog , clean ) : <EOL> self . context = context <EOL> self . region = region <EOL> self . clean = clean <EOL> self . tester = SmokeTester ( context , region , logname , nolog , clean ) <EOL> threading . Thread . __init__ ( self ) <EOL> def run ( self ) : <EOL> print ( ) <EOL> print ( "<STR_LIT:=>" * <NUM_LIT> ) <EOL> if self . clean : <EOL> print ( "<STR_LIT>" % self . region ) <EOL> else : <EOL> print ( "<STR_LIT>" % self . region ) <EOL> print ( "<STR_LIT:=>" * <NUM_LIT> ) <EOL> try : <EOL> self . tester . run_tests ( ) <EOL> finally : <EOL> self . tester . cleanup ( ) <EOL> print ( ) <EOL> print ( "<STR_LIT:=>" * <NUM_LIT> ) <EOL> if self . tester . failures : <EOL> print ( "<STR_LIT>" ) <EOL> for failure in self . tester . failures : <EOL> print ( "<STR_LIT>" , failure ) <EOL> else : <EOL> print ( self . region , "<STR_LIT>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> parser = argparse . ArgumentParser ( description = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT>" , <EOL> help = """<STR_LIT>""" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , help = """<STR_LIT>""" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , help = """<STR_LIT>""" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = """<STR_LIT>""" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT:-c>" , action = "<STR_LIT:store_true>" , help = """<STR_LIT>""" ) <EOL> args = parser . parse_args ( ) <EOL> env = args . env <EOL> regions = args . regions <EOL> logname = args . logname or "<STR_LIT>" <EOL> nolog = args . no_log <EOL> clean = args . clean <EOL> start = time . time ( ) <EOL> context = pyrax . create_context ( env = env ) <EOL> print ( "<STR_LIT>" , end = "<STR_LIT:U+0020>" ) <EOL> try : <EOL> context . keyring_auth ( ) <EOL> print ( "<STR_LIT>" ) <EOL> except Exception as e : <EOL> print ( "<STR_LIT>" , e ) <EOL> exit ( ) <EOL> if not regions : <EOL> regions = context . regions <EOL> test_threads = [ ] <EOL> for region in regions : <EOL> try : <EOL> test = TestThread ( context , region , logname , nolog , clean ) <EOL> except exc . NoSuchClient : <EOL> print ( "<STR_LIT>" % region ) <EOL> continue <EOL> test_threads . append ( test ) <EOL> test . start ( ) <EOL> for test_thread in test_threads : <EOL> test_thread . join ( ) <EOL> end = time . time ( ) <EOL> print ( ) <EOL> print ( "<STR_LIT>" % ( end - start ) ) <EOL> print ( ) </s>
