<s> import json <EOL> import os <EOL> import re <EOL> import subprocess <EOL> import sys <EOL> import tempfile <EOL> import time <EOL> import unittest <EOL> import yaml <EOL> import apiclient <EOL> import boto . ec2 <EOL> from flexmock import flexmock <EOL> import httplib2 <EOL> import oauth2client . client <EOL> import oauth2client . file <EOL> import oauth2client . tools <EOL> import SOAPpy <EOL> lib = os . path . dirname ( __file__ ) + os . sep + "<STR_LIT:..>" + os . sep + "<STR_LIT>" <EOL> sys . path . append ( lib ) <EOL> from agents . ec2_agent import EC2Agent <EOL> from agents . gce_agent import CredentialTypes <EOL> from agents . gce_agent import GCEAgent <EOL> from appscale_logger import AppScaleLogger <EOL> from appscale_tools import AppScaleTools <EOL> from custom_exceptions import AppScaleException <EOL> from local_state import LocalState <EOL> from parse_args import ParseArgs <EOL> class TestAppScaleTerminateInstances ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . keyname = "<STR_LIT>" <EOL> self . group = "<STR_LIT>" <EOL> self . function = "<STR_LIT>" <EOL> flexmock ( AppScaleLogger ) <EOL> AppScaleLogger . should_receive ( '<STR_LIT>' ) . and_return ( ) <EOL> AppScaleLogger . should_receive ( '<STR_LIT>' ) . and_return ( ) <EOL> flexmock ( time ) <EOL> time . should_receive ( '<STR_LIT>' ) . and_return ( ) <EOL> local_state = flexmock ( LocalState ) <EOL> local_state . should_receive ( '<STR_LIT>' ) . and_return ( "<STR_LIT>" ) <EOL> self . fake_temp_file = flexmock ( name = '<STR_LIT>' ) <EOL> self . fake_temp_file . should_receive ( '<STR_LIT>' ) . and_return ( '<STR_LIT>' ) <EOL> self . fake_temp_file . should_receive ( '<STR_LIT>' ) . and_return ( ) <EOL> self . fake_temp_file . should_receive ( '<STR_LIT>' ) . with_args ( <NUM_LIT:0> ) . and_return ( ) <EOL> flexmock ( tempfile ) <EOL> tempfile . should_receive ( '<STR_LIT>' ) . and_return ( self . fake_temp_file ) <EOL> self . success = flexmock ( name = '<STR_LIT:success>' , returncode = <NUM_LIT:0> ) <EOL> self . success . should_receive ( '<STR_LIT>' ) . and_return ( <NUM_LIT:0> ) <EOL> self . failed = flexmock ( name = '<STR_LIT>' , returncode = <NUM_LIT:1> ) <EOL> self . failed . should_receive ( '<STR_LIT>' ) . and_return ( <NUM_LIT:1> ) <EOL> for credential in EC2Agent . REQUIRED_EC2_CREDENTIALS : <EOL> os . environ [ credential ] = "<STR_LIT>" <EOL> def tearDown ( self ) : <EOL> for credential in EC2Agent . REQUIRED_EC2_CREDENTIALS : <EOL> os . environ [ credential ] = "<STR_LIT>" <EOL> def test_terminate_when_not_running ( self ) : <EOL> flexmock ( os . path ) <EOL> os . path . should_call ( '<STR_LIT>' ) <EOL> os . path . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_secret_key_location ( self . keyname ) ) . and_return ( False ) <EOL> argv = [ <EOL> "<STR_LIT>" , self . keyname , <EOL> "<STR_LIT>" <EOL> ] <EOL> options = ParseArgs ( argv , self . function ) . args <EOL> self . assertRaises ( AppScaleException , AppScaleTools . terminate_instances , <EOL> options ) <EOL> def test_terminate_in_virtual_cluster_and_succeeds ( self ) : <EOL> flexmock ( os . path ) <EOL> os . path . should_call ( '<STR_LIT>' ) <EOL> os . path . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_secret_key_location ( self . keyname ) ) . and_return ( True ) <EOL> builtins = flexmock ( sys . modules [ '<STR_LIT>' ] ) <EOL> builtins . should_call ( '<STR_LIT>' ) <EOL> fake_yaml_file = flexmock ( name = '<STR_LIT>' ) <EOL> fake_yaml_file . should_receive ( '<STR_LIT>' ) . and_return ( yaml . dump ( { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) ) <EOL> builtins . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_locations_yaml_location ( self . keyname ) , '<STR_LIT:r>' ) . and_return ( fake_yaml_file ) <EOL> os . path . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_locations_json_location ( self . keyname ) ) . and_return ( True ) <EOL> fake_json_file = flexmock ( name = '<STR_LIT>' ) <EOL> fake_json_file . should_receive ( '<STR_LIT>' ) . and_return ( json . dumps ( [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } <EOL> ] ) ) <EOL> builtins . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_locations_json_location ( self . keyname ) , '<STR_LIT:r>' ) . and_return ( fake_json_file ) <EOL> fake_secret_file = flexmock ( name = '<STR_LIT>' ) <EOL> fake_secret_file . should_receive ( '<STR_LIT>' ) . and_return ( '<STR_LIT>' ) <EOL> builtins . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_secret_key_location ( self . keyname ) , '<STR_LIT:r>' ) . and_return ( fake_secret_file ) <EOL> fake_appcontroller = flexmock ( name = '<STR_LIT>' ) <EOL> fake_appcontroller . should_receive ( '<STR_LIT>' ) . with_args ( '<STR_LIT>' ) . and_return ( json . dumps ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> flexmock ( SOAPpy ) <EOL> SOAPpy . should_receive ( '<STR_LIT>' ) . with_args ( '<STR_LIT>' ) . and_return ( fake_appcontroller ) <EOL> flexmock ( subprocess ) <EOL> subprocess . should_receive ( '<STR_LIT>' ) . with_args ( re . compile ( '<STR_LIT>' ) , <EOL> shell = True , stdout = self . fake_temp_file , stderr = subprocess . STDOUT ) . and_return ( self . failed ) . and_return ( self . success ) <EOL> flexmock ( subprocess ) <EOL> subprocess . should_receive ( '<STR_LIT>' ) . with_args ( re . compile ( '<STR_LIT>' ) , <EOL> shell = True , stdout = self . fake_temp_file , stderr = subprocess . STDOUT ) . and_return ( self . success ) <EOL> flexmock ( os ) <EOL> os . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_locations_yaml_location ( self . keyname ) ) . and_return ( ) <EOL> os . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_locations_json_location ( self . keyname ) ) . and_return ( ) <EOL> os . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_secret_key_location ( self . keyname ) ) . and_return ( ) <EOL> builtins . should_receive ( '<STR_LIT>' ) . and_return ( '<STR_LIT:yes>' ) <EOL> argv = [ <EOL> "<STR_LIT>" , self . keyname <EOL> ] <EOL> options = ParseArgs ( argv , self . function ) . args <EOL> AppScaleTools . terminate_instances ( options ) <EOL> def test_terminate_in_cloud_and_succeeds ( self ) : <EOL> flexmock ( os . path ) <EOL> os . path . should_call ( '<STR_LIT>' ) <EOL> os . path . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_secret_key_location ( self . keyname ) ) . and_return ( True ) <EOL> builtins = flexmock ( sys . modules [ '<STR_LIT>' ] ) <EOL> builtins . should_call ( '<STR_LIT>' ) <EOL> fake_yaml_file = flexmock ( name = '<STR_LIT>' ) <EOL> fake_yaml_file . should_receive ( '<STR_LIT>' ) . and_return ( yaml . dump ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . group , <EOL> } ) ) <EOL> builtins . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_locations_yaml_location ( self . keyname ) , '<STR_LIT:r>' ) . and_return ( fake_yaml_file ) <EOL> fake_json_file = flexmock ( name = '<STR_LIT>' ) <EOL> fake_json_file . should_receive ( '<STR_LIT>' ) . and_return ( json . dumps ( [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } <EOL> ] ) ) <EOL> builtins . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_locations_json_location ( self . keyname ) , '<STR_LIT:r>' ) . and_return ( fake_json_file ) <EOL> fake_secret_file = flexmock ( name = '<STR_LIT>' ) <EOL> fake_secret_file . should_receive ( '<STR_LIT>' ) . and_return ( '<STR_LIT>' ) <EOL> builtins . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_secret_key_location ( self . keyname ) , '<STR_LIT:r>' ) . and_return ( fake_secret_file ) <EOL> fake_ec2 = flexmock ( name = '<STR_LIT>' ) <EOL> fake_one_running = flexmock ( name = '<STR_LIT>' , key_name = self . keyname , state = '<STR_LIT>' , <EOL> id = '<STR_LIT>' , public_dns_name = '<STR_LIT>' , private_dns_name = '<STR_LIT>' ) <EOL> fake_two_running = flexmock ( name = '<STR_LIT>' , key_name = self . keyname , state = '<STR_LIT>' , <EOL> id = '<STR_LIT>' , public_dns_name = '<STR_LIT>' , private_dns_name = '<STR_LIT>' ) <EOL> fake_three_running = flexmock ( name = '<STR_LIT>' , key_name = '<STR_LIT>' , <EOL> state = '<STR_LIT>' , id = '<STR_LIT>' , public_dns_name = '<STR_LIT>' , <EOL> private_dns_name = '<STR_LIT>' ) <EOL> fake_reservation_running = flexmock ( name = '<STR_LIT>' , instances = [ fake_one_running , <EOL> fake_two_running , fake_three_running ] ) <EOL> fake_one_terminated = flexmock ( name = '<STR_LIT>' , key_name = self . keyname , state = '<STR_LIT>' , <EOL> id = '<STR_LIT>' , public_dns_name = '<STR_LIT>' , private_dns_name = '<STR_LIT>' ) <EOL> fake_two_terminated = flexmock ( name = '<STR_LIT>' , key_name = self . keyname , state = '<STR_LIT>' , <EOL> id = '<STR_LIT>' , public_dns_name = '<STR_LIT>' , private_dns_name = '<STR_LIT>' ) <EOL> fake_three_terminated = flexmock ( name = '<STR_LIT>' , key_name = '<STR_LIT>' , <EOL> state = '<STR_LIT>' , id = '<STR_LIT>' , public_dns_name = '<STR_LIT>' , <EOL> private_dns_name = '<STR_LIT>' ) <EOL> fake_reservation_terminated = flexmock ( name = '<STR_LIT>' , instances = [ fake_one_terminated , <EOL> fake_two_terminated , fake_three_terminated ] ) <EOL> fake_ec2 . should_receive ( '<STR_LIT>' ) . and_return ( fake_reservation_running ) . and_return ( fake_reservation_terminated ) <EOL> flexmock ( boto . ec2 ) <EOL> boto . ec2 . should_receive ( '<STR_LIT>' ) . and_return ( fake_ec2 ) <EOL> fake_ec2 . should_receive ( '<STR_LIT>' ) . with_args ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) . and_return ( [ fake_one_terminated , fake_two_terminated ] ) <EOL> fake_ec2 . should_receive ( '<STR_LIT>' ) . and_return ( ) <EOL> fake_ec2 . should_receive ( '<STR_LIT>' ) . and_return ( False ) . and_return ( True ) <EOL> flexmock ( os ) <EOL> os . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_locations_yaml_location ( self . keyname ) ) . and_return ( ) <EOL> os . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_locations_json_location ( self . keyname ) ) . and_return ( ) <EOL> os . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_secret_key_location ( self . keyname ) ) . and_return ( ) <EOL> builtins . should_receive ( '<STR_LIT>' ) . and_return ( '<STR_LIT:yes>' ) <EOL> argv = [ <EOL> "<STR_LIT>" , self . keyname <EOL> ] <EOL> options = ParseArgs ( argv , self . function ) . args <EOL> AppScaleTools . terminate_instances ( options ) <EOL> def test_terminate_in_gce_and_succeeds ( self ) : <EOL> flexmock ( os . path ) <EOL> os . path . should_call ( '<STR_LIT>' ) <EOL> os . path . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_locations_yaml_location ( self . keyname ) ) . and_return ( True ) <EOL> os . path . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_client_secrets_location ( self . keyname ) ) . and_return ( True ) <EOL> os . path . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_secret_key_location ( self . keyname ) ) . and_return ( True ) <EOL> project_id = "<STR_LIT>" <EOL> zone = '<STR_LIT>' <EOL> builtins = flexmock ( sys . modules [ '<STR_LIT>' ] ) <EOL> builtins . should_call ( '<STR_LIT>' ) <EOL> fake_yaml_file = flexmock ( name = '<STR_LIT>' ) <EOL> fake_yaml_file . should_receive ( '<STR_LIT>' ) . and_return ( yaml . dump ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . group , <EOL> '<STR_LIT>' : project_id , <EOL> '<STR_LIT>' : zone <EOL> } ) ) <EOL> builtins . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_locations_yaml_location ( self . keyname ) , '<STR_LIT:r>' ) . and_return ( fake_yaml_file ) <EOL> fake_json_file = flexmock ( name = '<STR_LIT>' ) <EOL> fake_json_file . should_receive ( '<STR_LIT>' ) . and_return ( json . dumps ( [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } <EOL> ] ) ) <EOL> builtins . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_locations_json_location ( self . keyname ) , '<STR_LIT:r>' ) . and_return ( fake_json_file ) <EOL> fake_secret_file = flexmock ( name = '<STR_LIT>' ) <EOL> fake_secret_file . should_receive ( '<STR_LIT>' ) . and_return ( '<STR_LIT>' ) <EOL> builtins . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_secret_key_location ( self . keyname ) , '<STR_LIT:r>' ) . and_return ( fake_secret_file ) <EOL> client_secrets = LocalState . get_client_secrets_location ( self . keyname ) <EOL> fake_flow = flexmock ( name = '<STR_LIT>' ) <EOL> flexmock ( oauth2client . client ) <EOL> oauth2client . client . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> client_secrets , scope = str ) . and_return ( fake_flow ) <EOL> fake_storage = flexmock ( name = '<STR_LIT>' ) <EOL> fake_storage . should_receive ( '<STR_LIT>' ) . and_return ( None ) <EOL> fake_flags = oauth2client . tools . argparser . parse_args ( args = [ ] ) <EOL> flexmock ( oauth2client . file ) <EOL> oauth2client . file . should_receive ( '<STR_LIT>' ) . with_args ( str ) . and_return ( <EOL> fake_storage ) <EOL> fake_credentials = flexmock ( name = '<STR_LIT>' ) <EOL> flexmock ( oauth2client . tools ) <EOL> oauth2client . tools . should_receive ( '<STR_LIT>' ) . with_args ( fake_flow , <EOL> fake_storage , fake_flags ) . and_return ( fake_credentials ) <EOL> fake_http = flexmock ( name = '<STR_LIT>' ) <EOL> fake_authorized_http = flexmock ( name = '<STR_LIT>' ) <EOL> flexmock ( httplib2 ) <EOL> httplib2 . should_receive ( '<STR_LIT>' ) . and_return ( fake_http ) <EOL> fake_credentials . should_receive ( '<STR_LIT>' ) . with_args ( fake_http ) . and_return ( fake_authorized_http ) <EOL> fake_gce = flexmock ( name = '<STR_LIT>' ) <EOL> instance_one_info = { <EOL> u'<STR_LIT:status>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:name>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : { u'<STR_LIT>' : u'<STR_LIT>' } , <EOL> u'<STR_LIT:image>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : [ { <EOL> u'<STR_LIT:index>' : <NUM_LIT:0> , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:type>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' <EOL> } ] , <EOL> u'<STR_LIT>' : False , <EOL> u'<STR_LIT>' : [ { <EOL> u'<STR_LIT>' : [ GCEAgent . GCE_SCOPE ] , <EOL> u'<STR_LIT:email>' : u'<STR_LIT>' <EOL> } ] , <EOL> u'<STR_LIT>' : { <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' <EOL> } , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:id>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : [ { <EOL> u'<STR_LIT>' : [ { <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:type>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:name>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' <EOL> } ] , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:name>' : u'<STR_LIT>' <EOL> } ] <EOL> } <EOL> instance_two_info = { <EOL> u'<STR_LIT:status>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:name>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : { u'<STR_LIT>' : u'<STR_LIT>' } , <EOL> u'<STR_LIT:image>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : [ { <EOL> u'<STR_LIT:index>' : <NUM_LIT:0> , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:type>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' <EOL> } ] , <EOL> u'<STR_LIT>' : False , <EOL> u'<STR_LIT>' : [ { <EOL> u'<STR_LIT>' : [ GCEAgent . GCE_SCOPE ] , <EOL> u'<STR_LIT:email>' : u'<STR_LIT>' <EOL> } ] , <EOL> u'<STR_LIT>' : { <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' <EOL> } , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:id>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : [ { <EOL> u'<STR_LIT>' : [ { <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:type>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:name>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' <EOL> } ] , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:name>' : u'<STR_LIT>' <EOL> } ] <EOL> } <EOL> list_instance_info = { <EOL> u'<STR_LIT>' : [ instance_one_info , instance_two_info ] , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:id>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' <EOL> } <EOL> fake_list_instance_request = flexmock ( name = '<STR_LIT>' ) <EOL> fake_list_instance_request . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> http = fake_authorized_http ) . and_return ( list_instance_info ) <EOL> fake_instances = flexmock ( name = '<STR_LIT>' ) <EOL> fake_instances . should_receive ( '<STR_LIT:list>' ) . with_args ( project = project_id , <EOL> filter = "<STR_LIT>" , zone = zone ) . and_return ( fake_list_instance_request ) <EOL> fake_gce . should_receive ( '<STR_LIT>' ) . and_return ( fake_instances ) <EOL> delete_instance = u'<STR_LIT>' <EOL> delete_instance_info_one = { <EOL> u'<STR_LIT:status>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:name>' : delete_instance , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : <NUM_LIT:0> , <EOL> u'<STR_LIT:id>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:user>' : u'<STR_LIT>' <EOL> } <EOL> delete_instance_info_two = { <EOL> u'<STR_LIT:status>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:name>' : delete_instance , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : <NUM_LIT:0> , <EOL> u'<STR_LIT:id>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:user>' : u'<STR_LIT>' <EOL> } <EOL> fake_delete_instance_request_one = flexmock ( name = '<STR_LIT>' ) <EOL> fake_delete_instance_request_one . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> http = fake_authorized_http ) . and_return ( delete_instance_info_one ) <EOL> fake_instances . should_receive ( '<STR_LIT>' ) . with_args ( project = project_id , <EOL> zone = zone , instance = '<STR_LIT>' ) . and_return ( <EOL> fake_delete_instance_request_one ) <EOL> fake_delete_instance_request_two = flexmock ( name = '<STR_LIT>' ) <EOL> fake_delete_instance_request_two . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> http = fake_authorized_http ) . and_return ( delete_instance_info_two ) <EOL> fake_instances . should_receive ( '<STR_LIT>' ) . with_args ( project = project_id , <EOL> zone = zone , instance = '<STR_LIT>' ) . and_return ( <EOL> fake_delete_instance_request_two ) <EOL> all_done = { <EOL> u'<STR_LIT:status>' : u'<STR_LIT>' <EOL> } <EOL> fake_instance_checker = flexmock ( name = '<STR_LIT>' ) <EOL> fake_instance_checker . should_receive ( '<STR_LIT>' ) . and_return ( all_done ) <EOL> fake_blocker = flexmock ( name = '<STR_LIT>' ) <EOL> fake_blocker . should_receive ( '<STR_LIT>' ) . with_args ( project = project_id , <EOL> operation = delete_instance , zone = zone ) . and_return ( <EOL> fake_instance_checker ) <EOL> fake_gce . should_receive ( '<STR_LIT>' ) . and_return ( fake_blocker ) <EOL> delete_firewall = u'<STR_LIT>' <EOL> fake_delete_firewall_info = { <EOL> u'<STR_LIT:status>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:name>' : delete_firewall , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : <NUM_LIT:0> , <EOL> u'<STR_LIT:id>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:user>' : u'<STR_LIT>' <EOL> } <EOL> fake_delete_firewall_request = flexmock ( name = '<STR_LIT>' ) <EOL> fake_delete_firewall_request . should_receive ( '<STR_LIT>' ) . and_return ( fake_delete_firewall_info ) <EOL> fake_firewalls = flexmock ( name = '<STR_LIT>' ) <EOL> fake_firewalls . should_receive ( '<STR_LIT>' ) . with_args ( project = project_id , <EOL> firewall = self . group ) . and_return ( fake_delete_firewall_request ) <EOL> fake_gce . should_receive ( '<STR_LIT>' ) . and_return ( fake_firewalls ) <EOL> fake_firewall_checker = flexmock ( name = '<STR_LIT>' ) <EOL> fake_firewall_checker . should_receive ( '<STR_LIT>' ) . and_return ( all_done ) <EOL> fake_blocker . should_receive ( '<STR_LIT>' ) . with_args ( project = project_id , <EOL> operation = delete_firewall ) . and_return ( fake_firewall_checker ) <EOL> fake_gce . should_receive ( '<STR_LIT>' ) . and_return ( fake_blocker ) <EOL> delete_network = u'<STR_LIT>' <EOL> fake_delete_network_info = { <EOL> u'<STR_LIT:status>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:name>' : delete_network , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : <NUM_LIT:0> , <EOL> u'<STR_LIT:id>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:user>' : u'<STR_LIT>' <EOL> } <EOL> fake_delete_network_request = flexmock ( name = '<STR_LIT>' ) <EOL> fake_delete_network_request . should_receive ( '<STR_LIT>' ) . and_return ( fake_delete_network_info ) <EOL> fake_networks = flexmock ( name = '<STR_LIT>' ) <EOL> fake_networks . should_receive ( '<STR_LIT>' ) . with_args ( project = project_id , <EOL> network = self . group ) . and_return ( fake_delete_network_request ) <EOL> fake_gce . should_receive ( '<STR_LIT>' ) . and_return ( fake_networks ) <EOL> fake_network_checker = flexmock ( name = '<STR_LIT>' ) <EOL> fake_network_checker . should_receive ( '<STR_LIT>' ) . and_return ( all_done ) <EOL> fake_blocker . should_receive ( '<STR_LIT>' ) . with_args ( project = project_id , <EOL> operation = delete_network ) . and_return ( fake_network_checker ) <EOL> flexmock ( apiclient . discovery ) <EOL> apiclient . discovery . should_receive ( '<STR_LIT>' ) . with_args ( '<STR_LIT>' , <EOL> GCEAgent . API_VERSION ) . and_return ( fake_gce ) <EOL> flexmock ( GCEAgent ) . should_receive ( '<STR_LIT>' ) . and_return ( CredentialTypes . OAUTH ) <EOL> flexmock ( os ) <EOL> os . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_locations_yaml_location ( self . keyname ) ) . and_return ( ) <EOL> os . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_locations_json_location ( self . keyname ) ) . and_return ( ) <EOL> os . should_receive ( '<STR_LIT>' ) . with_args ( <EOL> LocalState . get_secret_key_location ( self . keyname ) ) . and_return ( ) <EOL> argv = [ <EOL> "<STR_LIT>" , self . keyname , <EOL> "<STR_LIT>" <EOL> ] <EOL> options = ParseArgs ( argv , self . function ) . args <EOL> AppScaleTools . terminate_instances ( options ) </s>
