<s> import time <EOL> from eucaops import Eucaops <EOL> from eucaops import EC2ops <EOL> from eutester . eutestcase import EutesterTestCase <EOL> import os <EOL> import random <EOL> class InstanceBasics ( EutesterTestCase ) : <EOL> def __init__ ( self , extra_args = None ) : <EOL> self . setuptestcase ( ) <EOL> self . setup_parser ( ) <EOL> if extra_args : <EOL> for arg in extra_args : <EOL> self . parser . add_argument ( arg ) <EOL> self . get_args ( ) <EOL> if self . args . region : <EOL> self . tester = EC2ops ( credpath = self . args . credpath , region = self . args . region ) <EOL> else : <EOL> self . tester = Eucaops ( credpath = self . args . credpath , config_file = self . args . config , password = self . args . password ) <EOL> self . tester . poll_count = <NUM_LIT> <EOL> self . group = self . tester . add_group ( group_name = "<STR_LIT>" + str ( time . time ( ) ) ) <EOL> self . tester . authorize_group_by_name ( group_name = self . group . name ) <EOL> self . tester . authorize_group_by_name ( group_name = self . group . name , port = - <NUM_LIT:1> , protocol = "<STR_LIT>" ) <EOL> self . keypair = self . tester . add_keypair ( "<STR_LIT>" + str ( time . time ( ) ) ) <EOL> self . keypath = '<STR_LIT>' % ( os . curdir , self . keypair . name ) <EOL> self . image = self . args . emi <EOL> if not self . image : <EOL> self . image = self . tester . get_emi ( root_device_type = "<STR_LIT>" ) <EOL> self . address = None <EOL> self . volume = None <EOL> self . snapshot = None <EOL> self . private_addressing = False <EOL> zones = self . tester . ec2 . get_all_zones ( ) <EOL> self . zone = random . choice ( zones ) . name <EOL> self . reservation = None <EOL> def clean_method ( self ) : <EOL> if self . reservation : <EOL> self . assertTrue ( self . tester . terminate_instances ( self . reservation ) , "<STR_LIT>" ) <EOL> self . tester . delete_group ( self . group ) <EOL> self . tester . delete_keypair ( self . keypair ) <EOL> os . remove ( self . keypath ) <EOL> def MyTest ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . reservation : <EOL> self . reservation = self . tester . run_instance ( self . image , keypair = self . keypair . name , group = self . group . name ) <EOL> for instance in self . reservation . instances : <EOL> self . assertTrue ( self . tester . wait_for_reservation ( self . reservation ) , '<STR_LIT>' ) <EOL> self . assertNotEqual ( instance . public_dns_name , instance . private_ip_address , '<STR_LIT>' ) <EOL> self . assertTrue ( self . tester . ping ( instance . public_dns_name ) , '<STR_LIT>' ) <EOL> self . assertFalse ( instance . found ( "<STR_LIT>" + instance . rootfs_device + "<STR_LIT:2>" , "<STR_LIT>" ) , '<STR_LIT>' + instance . rootfs_device + "<STR_LIT:2>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> testcase = InstanceBasics ( ) <EOL> list = testcase . args . tests or [ "<STR_LIT>" ] <EOL> unit_list = [ ] <EOL> for test in list : <EOL> unit_list . append ( testcase . create_testunit_by_name ( test ) ) <EOL> result = testcase . run_test_case_list ( unit_list , clean_on_exit = True ) <EOL> exit ( result ) </s>
