本文整理汇总了Python中subprocess.should_receive函数的典型用法代码示例。如果您正苦于以下问题:Python should_receive函数的具体用法?Python should_receive怎么用?Python should_receive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了should_receive函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testTailWithIndexInBounds
def testTailWithIndexInBounds(self):
# calling 'appscale tail 1 *' should tail from the second node
# (nodes[1]). If there are two nodes in this deployment,
# we should tail from it successfully
appscale = AppScale()
contents = { 'keyname' : 'boo' }
yaml_dumped_contents = yaml.dump(contents)
one = {
'public_ip' : 'blarg'
}
two = {
'public_ip' : 'blarg2'
}
nodes = {'node_info': [one, two]}
nodes_contents = json.dumps(nodes)
mock = self.addMockForAppScalefile(appscale, yaml_dumped_contents)
(mock.should_receive('open')
.with_args(appscale.get_locations_json_file('boo'))
.and_return(flexmock(read=lambda: nodes_contents)))
flexmock(subprocess)
subprocess.should_receive('call').with_args(["ssh", "-o",
"StrictHostkeyChecking=no", "-i", appscale.get_key_location('boo'),
"[email protected]", "tail -F /var/log/appscale/c*"]).and_return().once()
appscale.tail(1, "c*")
示例2: test_appscale_with_ips_layout_flag_but_no_copy_id
def test_appscale_with_ips_layout_flag_but_no_copy_id(self):
# assume that we have ssh-keygen but not ssh-copy-id
flexmock(subprocess)
subprocess.should_receive('Popen').with_args(re.compile('hash ssh-keygen'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
flexmock(subprocess)
subprocess.should_receive('Popen').with_args(re.compile('hash ssh-copy-id'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.failed)
# don't use a 192.168.X.Y IP here, since sometimes we set our virtual
# machines to boot with those addresses (and that can mess up our tests).
ips_layout = yaml.safe_load("""
master : public1
database: public1
zookeeper: public2
appengine: public3
""")
argv = [
"--ips_layout", base64.b64encode(yaml.dump(ips_layout)),
"--keyname", self.keyname
]
options = ParseArgs(argv, self.function).args
self.assertRaises(BadConfigurationException, AppScaleTools.add_keypair,
options)
示例3: test_start_head_node_in_cloud_but_ami_not_appscale
def test_start_head_node_in_cloud_but_ami_not_appscale(self):
# mock out our attempts to find /etc/appscale and presume it doesn't exist
subprocess.should_receive('Popen').with_args(re.compile('/etc/appscale'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.failed)
self.assertRaises(AppScaleException, RemoteHelper.start_head_node,
self.options, self.node_layout)
示例4: test_appscale_in_two_node_virt_deployment
def test_appscale_in_two_node_virt_deployment(self):
# pretend that the place we're going to put logs into doesn't exist
flexmock(os.path)
os.path.should_call('exists') # set the fall-through
os.path.should_receive('exists').with_args('/tmp/foobaz').and_return(False)
# and mock out the mkdir operation
flexmock(os)
os.should_receive('mkdir').with_args('/tmp/foobaz').and_return()
# next, mock out finding the login ip address
os.path.should_receive('exists').with_args(
LocalState.get_locations_json_location(self.keyname)).and_return(True)
fake_nodes_json = flexmock(name="fake_nodes_json")
fake_nodes_json.should_receive('read').and_return(json.dumps([{
"public_ip" : "public1",
"private_ip" : "private1",
"jobs" : ["shadow", "login"]
}]))
builtins = flexmock(sys.modules['__builtin__'])
builtins.should_call('open')
builtins.should_receive('open').with_args(
LocalState.get_locations_json_location(self.keyname), 'r') \
.and_return(fake_nodes_json)
# mock out writing the secret key to ~/.appscale, as well as reading it
# later
secret_key_location = LocalState.get_secret_key_location(self.keyname)
fake_secret = flexmock(name="fake_secret")
fake_secret.should_receive('read').and_return('the secret')
builtins.should_receive('open').with_args(secret_key_location, 'r') \
.and_return(fake_secret)
# and slip in a fake appcontroller to report on the two IP addrs
fake_appcontroller = flexmock(name='fake_appcontroller')
fake_appcontroller.should_receive('get_all_public_ips').with_args(
'the secret').and_return(json.dumps(['public1', 'public2']))
flexmock(SOAPpy)
SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \
.and_return(fake_appcontroller)
# fake the creation of the log directories locally
os.should_receive('mkdir').with_args('/tmp/foobaz/public1').and_return()
os.should_receive('mkdir').with_args('/tmp/foobaz/public2').and_return()
# finally, fake the copying of the log files
flexmock(subprocess)
subprocess.should_receive('Popen').with_args(re.compile('/var/log/appscale'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
argv = [
"--keyname", self.keyname,
"--location", "/tmp/foobaz"
]
options = ParseArgs(argv, self.function).args
AppScaleTools.gather_logs(options)
示例5: test_copy_deployment_credentials_in_cloud
def test_copy_deployment_credentials_in_cloud(self):
# mock out the scp'ing to public1 and assume they succeed
subprocess.should_receive('Popen').with_args(re.compile('secret.key'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
subprocess.should_receive('Popen').with_args(re.compile('ssh.key'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
# mock out generating the private key
flexmock(M2Crypto.RSA)
fake_rsa_key = flexmock(name='fake_rsa_key')
fake_rsa_key.should_receive('save_key').with_args(
LocalState.get_private_key_location('bookey'), None)
M2Crypto.RSA.should_receive('gen_key').and_return(fake_rsa_key)
flexmock(M2Crypto.EVP)
fake_pkey = flexmock(name='fake_pkey')
fake_pkey.should_receive('assign_rsa').with_args(fake_rsa_key).and_return()
M2Crypto.EVP.should_receive('PKey').and_return(fake_pkey)
# and mock out generating the certificate
flexmock(M2Crypto.X509)
fake_cert = flexmock(name='fake_x509')
fake_cert.should_receive('set_pubkey').with_args(fake_pkey).and_return()
fake_cert.should_receive('set_subject')
fake_cert.should_receive('set_issuer_name')
fake_cert.should_receive('set_not_before')
fake_cert.should_receive('set_not_after')
fake_cert.should_receive('sign').with_args(fake_pkey, md="sha256")
fake_cert.should_receive('save_pem').with_args(
LocalState.get_certificate_location('bookey'))
M2Crypto.X509.should_receive('X509').and_return(fake_cert)
# next, mock out copying the private key and certificate
subprocess.should_receive('Popen').with_args(re.compile('mycert.pem'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
subprocess.should_receive('Popen').with_args(re.compile('mykey.pem'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
subprocess.should_receive('Popen').with_args(re.compile('mkdir -p'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
options = flexmock(name='options', keyname='bookey', infrastructure='ec2',
verbose=True)
RemoteHelper.copy_deployment_credentials('public1', options)
示例6: test_start_remote_appcontroller
def test_start_remote_appcontroller(self):
# mock out removing the old json file
subprocess.should_receive('Popen').with_args(re.compile('rm -rf'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
# assume we started god on public1 fine
subprocess.should_receive('Popen').with_args(re.compile('god &'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
# also assume that we scp'ed over the god config file fine
subprocess.should_receive('Popen').with_args(re.compile('appcontroller'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
# and assume we started the AppController on public1 fine
subprocess.should_receive('Popen').with_args(re.compile('god load'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
# finally, assume the appcontroller comes up after a few tries
# assume that ssh comes up on the third attempt
fake_socket = flexmock(name='fake_socket')
fake_socket.should_receive('connect').with_args(('public1',
AppControllerClient.PORT)).and_raise(Exception) \
.and_raise(Exception).and_return(None)
socket.should_receive('socket').and_return(fake_socket)
RemoteHelper.start_remote_appcontroller('public1', 'bookey', False)
示例7: test_rsync_files_from_dir_that_does_exist
def test_rsync_files_from_dir_that_does_exist(self):
# if the user specifies that we should copy from a directory that does
# exist, and has all the right directories in it, we should succeed
flexmock(os.path)
os.path.should_receive('exists').with_args(re.compile(
'/tmp/booscale-local/')).and_return(True)
# assume the rsyncs succeed
subprocess.should_receive('Popen').with_args(re.compile('rsync'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
RemoteHelper.rsync_files('public1', 'booscale', '/tmp/booscale-local',
False)
示例8: test_copy_local_metadata
def test_copy_local_metadata(self):
# mock out the copying of the two files
subprocess.should_receive('Popen').with_args(re.compile(
'locations-bookey.[yaml|json]'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
# and mock out copying the secret file
subprocess.should_receive('Popen').with_args(re.compile(
'bookey.secret'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
RemoteHelper.copy_local_metadata('public1', 'bookey', False)
示例9: test_start_head_node_in_cloud_but_using_unsupported_database
def test_start_head_node_in_cloud_but_using_unsupported_database(self):
# mock out our attempts to find /etc/appscale and presume it does exist
subprocess.should_receive('Popen').with_args(re.compile('/etc/appscale'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
# mock out our attempts to find /etc/appscale/version and presume it does
# exist
subprocess.should_receive('Popen').with_args(re.compile(
'/etc/appscale/{0}'.format(APPSCALE_VERSION)),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
# finally, put in a mock indicating that the database the user wants
# isn't supported
subprocess.should_receive('Popen').with_args(re.compile(
'/etc/appscale/{0}/{1}'.format(APPSCALE_VERSION, 'cassandra')),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.failed)
self.assertRaises(AppScaleException, RemoteHelper.start_head_node,
self.options, self.node_layout)
示例10: test_upload_app_successfully
def test_upload_app_successfully(self):
# add in mocks so that there is an app.yaml, but with no appid set
flexmock(os.path)
os.path.should_call('exists')
app_yaml_location = AppEngineHelper.get_app_yaml_location(self.app_dir)
os.path.should_receive('exists').with_args(app_yaml_location) \
.and_return(True)
# mock out reading the app.yaml file
builtins = flexmock(sys.modules['__builtin__'])
builtins.should_call('open') # set the fall-through
fake_app_yaml = flexmock(name="fake_app_yaml")
fake_app_yaml.should_receive('read').and_return(yaml.dump({
'application' : 'baz',
'runtime' : 'python27'
}))
builtins.should_receive('open').with_args(app_yaml_location, 'r') \
.and_return(fake_app_yaml)
# Mock out service host and port
app_data = {'owner' : '[email protected]',
'hosts' : {'192.168.1.1' : { 'http' : 8080, 'https' : 4380 }}}
app_stats_data = {'apps': {'baz': {'http': 8080, 'language': 'python27',
'total_reqs': 'no_change', 'appservers': 1, 'https': 4380, 'reqs_enqueued': None}}}
# mock out the SOAP call to the AppController and assume it succeeded
fake_appcontroller = flexmock(name='fake_appcontroller')
fake_appcontroller.should_receive('status').with_args('the secret') \
.and_return('Database is at public1')
fake_appcontroller.should_receive('done_uploading').with_args('baz',
'/opt/appscale/apps/baz.tar.gz', 'the secret').and_return()
fake_appcontroller.should_receive('update').with_args(['baz'],
'the secret').and_return()
fake_appcontroller.should_receive('is_app_running').with_args('baz',
'the secret').and_return(False).and_return(True)
fake_appcontroller.should_receive('does_user_exist').with_args(
'[email protected]', 'the secret').and_return('true')
fake_appcontroller.should_receive('does_user_exist').with_args(
'[email protected]', 'the secret').and_return('true')
fake_appcontroller.should_receive('does_app_exist').with_args(
'baz', 'the secret').and_return(json.dumps(app_data))
fake_appcontroller.should_receive('get_app_data').with_args(
'baz', 'the secret').and_return(json.dumps(app_data))
fake_appcontroller.should_receive('get_all_stats').with_args(
'the secret').and_return(json.dumps(app_stats_data))
fake_appcontroller.should_receive('reserve_app_id').with_args(
'[email protected]','baz','python27','the secret').and_return("true")
flexmock(SOAPpy)
SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \
.and_return(fake_appcontroller)
# mock out reading the locations.json file, and slip in our own json
os.path.should_receive('exists').with_args(
LocalState.get_locations_json_location(self.keyname)).and_return(True)
fake_nodes_json = flexmock(name="fake_nodes_json")
fake_nodes_json.should_receive('read').and_return(
json.dumps({"node_info": [{
"public_ip": "public1",
"private_ip": "private1",
"jobs": ["shadow", "login"]
}]}))
builtins.should_receive('open').with_args(
LocalState.get_locations_json_location(self.keyname), 'r') \
.and_return(fake_nodes_json)
# mock out reading the secret key from ~/.appscale
secret_key_location = LocalState.get_secret_key_location(self.keyname)
fake_secret = flexmock(name="fake_secret")
fake_secret.should_receive('read').and_return('the secret')
builtins.should_receive('open').with_args(secret_key_location, 'r') \
.and_return(fake_secret)
# mock out asking the user for the admin on the new app, and slip in an
# answer for them
builtins.should_receive('raw_input').and_return("[email protected]")
flexmock(getpass)
getpass.should_receive('getpass').and_return('aaaaaa')
# mock out making the remote app directory
flexmock(subprocess)
subprocess.should_receive('Popen').with_args(re.compile('mkdir -p'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
# and mock out tarring and copying the app
subprocess.should_receive('Popen').with_args(re.compile('tar -czhf'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
subprocess.should_receive('Popen').with_args(re.compile(
'/tmp/appscale-app-baz.tar.gz'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
# as well as removing the tar'ed app once we're done copying it
flexmock(os)
os.should_receive('remove').with_args('/tmp/appscale-app-baz-1234.tar.gz') \
.and_return()
#.........这里部分代码省略.........
示例11: test_terminate_in_virtual_cluster_and_succeeds
def test_terminate_in_virtual_cluster_and_succeeds(self):
# let's say that there is a locations.yaml file, which means appscale is
# running, so we should terminate the services on each box
flexmock(os.path)
os.path.should_call('exists') # set up the fall-through
os.path.should_receive('exists').with_args(
LocalState.get_locations_yaml_location(self.keyname)).and_return(True)
# mock out reading the locations.yaml file, and pretend that we're on
# a virtualized cluster
builtins = flexmock(sys.modules['__builtin__'])
builtins.should_call('open')
fake_yaml_file = flexmock(name='fake_file')
fake_yaml_file.should_receive('read').and_return(yaml.dump({
'infrastructure' : 'xen'
}))
builtins.should_receive('open').with_args(
LocalState.get_locations_yaml_location(self.keyname), 'r') \
.and_return(fake_yaml_file)
# mock out reading the json file, and pretend that we're running in a
# two node deployment
os.path.should_receive('exists').with_args(
LocalState.get_locations_json_location(self.keyname)).and_return(True)
fake_json_file = flexmock(name='fake_file')
fake_json_file.should_receive('read').and_return(json.dumps([
{
'public_ip' : 'public1',
'jobs' : ['shadow']
},
{
'public_ip' : 'public2',
'jobs' : ['appengine']
}
]))
builtins.should_receive('open').with_args(
LocalState.get_locations_json_location(self.keyname), 'r') \
.and_return(fake_json_file)
# and slip in a fake secret file
fake_secret_file = flexmock(name='fake_file')
fake_secret_file.should_receive('read').and_return('the secret')
builtins.should_receive('open').with_args(
LocalState.get_secret_key_location(self.keyname), 'r') \
.and_return(fake_secret_file)
# mock out talking to the appcontroller, and assume that it tells us there
# there are still two machines in this deployment
fake_appcontroller = flexmock(name='fake_appcontroller')
fake_appcontroller.should_receive('get_all_public_ips').with_args('the secret') \
.and_return(json.dumps(['public1', 'public2']))
flexmock(SOAPpy)
SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \
.and_return(fake_appcontroller)
# and mock out the ssh call to kill the remote appcontroller, assuming that
# it fails the first time and passes the second
flexmock(subprocess)
subprocess.should_receive('Popen').with_args(re.compile('controller stop'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.failed).and_return(self.success)
# next, mock out our checks to see how the stopping process is going and
# assume that it has stopped
flexmock(subprocess)
subprocess.should_receive('Popen').with_args(re.compile('ps x'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
# finally, mock out removing the yaml file, json file, and secret key from
# this machine
flexmock(os)
os.should_receive('remove').with_args(
LocalState.get_locations_yaml_location(self.keyname)).and_return()
os.should_receive('remove').with_args(
LocalState.get_locations_json_location(self.keyname)).and_return()
os.should_receive('remove').with_args(
LocalState.get_secret_key_location(self.keyname)).and_return()
argv = [
"--keyname", self.keyname
]
options = ParseArgs(argv, self.function).args
AppScaleTools.terminate_instances(options)
示例12: test_terminate_in_virtual_cluster_and_succeeds
def test_terminate_in_virtual_cluster_and_succeeds(self):
# let's say that there is a locations.yaml file, which means appscale is
# running, so we should terminate the services on each box
flexmock(os.path)
os.path.should_call("exists") # set up the fall-through
os.path.should_receive("exists").with_args(LocalState.get_secret_key_location(self.keyname)).and_return(True)
# mock out reading the locations.yaml file, and pretend that we're on
# a virtualized cluster
builtins = flexmock(sys.modules["__builtin__"])
builtins.should_call("open")
fake_yaml_file = flexmock(name="fake_file")
fake_yaml_file.should_receive("read").and_return(yaml.dump({"infrastructure": "xen"}))
builtins.should_receive("open").with_args(LocalState.get_locations_yaml_location(self.keyname), "r").and_return(
fake_yaml_file
)
# mock out reading the json file, and pretend that we're running in a
# two node deployment
os.path.should_receive("exists").with_args(LocalState.get_locations_json_location(self.keyname)).and_return(
True
)
fake_json_file = flexmock(name="fake_file")
fake_json_file.should_receive("read").and_return(
json.dumps([{"public_ip": "public1", "jobs": ["shadow"]}, {"public_ip": "public2", "jobs": ["appengine"]}])
)
builtins.should_receive("open").with_args(LocalState.get_locations_json_location(self.keyname), "r").and_return(
fake_json_file
)
# and slip in a fake secret file
fake_secret_file = flexmock(name="fake_file")
fake_secret_file.should_receive("read").and_return("the secret")
builtins.should_receive("open").with_args(LocalState.get_secret_key_location(self.keyname), "r").and_return(
fake_secret_file
)
# mock out talking to the appcontroller, and assume that it tells us there
# there are still two machines in this deployment
fake_appcontroller = flexmock(name="fake_appcontroller")
fake_appcontroller.should_receive("get_all_public_ips").with_args("the secret").and_return(
json.dumps(["public1", "public2"])
)
flexmock(SOAPpy)
SOAPpy.should_receive("SOAPProxy").with_args("https://public1:17443").and_return(fake_appcontroller)
# and mock out the ssh call to kill the remote appcontroller, assuming that
# it fails the first time and passes the second
flexmock(subprocess)
subprocess.should_receive("Popen").with_args(
re.compile("controller stop"), shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT
).and_return(self.failed).and_return(self.success)
# next, mock out our checks to see how the stopping process is going and
# assume that it has stopped
flexmock(subprocess)
subprocess.should_receive("Popen").with_args(
re.compile("ps x"), shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT
).and_return(self.success)
# finally, mock out removing the yaml file, json file, and secret key from
# this machine
flexmock(os)
os.should_receive("remove").with_args(LocalState.get_locations_yaml_location(self.keyname)).and_return()
os.should_receive("remove").with_args(LocalState.get_locations_json_location(self.keyname)).and_return()
os.should_receive("remove").with_args(LocalState.get_secret_key_location(self.keyname)).and_return()
# also mock out asking the user for confirmation on shutting down
# their cloud
builtins.should_receive("raw_input").and_return("yes")
argv = ["--keyname", self.keyname]
options = ParseArgs(argv, self.function).args
AppScaleTools.terminate_instances(options)
示例13: test_add_nodes_in_virt_deployment
def test_add_nodes_in_virt_deployment(self):
# don't use a 192.168.X.Y IP here, since sometimes we set our virtual
# machines to boot with those addresses (and that can mess up our tests).
ips_yaml = """
database: 1.2.3.4
zookeeper: 1.2.3.4
appengine: 1.2.3.4
"""
# mock out reading the yaml file, and slip in our own
fake_yaml_file = flexmock(name='fake_yaml')
fake_yaml_file.should_receive('read').and_return(ips_yaml)
builtins = flexmock(sys.modules['__builtin__'])
builtins.should_call('open') # set the fall-through
builtins.should_receive('open').with_args('/tmp/boo.yaml', 'r') \
.and_return(fake_yaml_file)
# and pretend we're on a virtualized cluster
locations_yaml = yaml.dump({
"infrastructure" : "xen"
})
fake_locations_yaml_file = flexmock(name='fake_yaml')
fake_locations_yaml_file.should_receive('read').and_return(locations_yaml)
builtins.should_receive('open').with_args(
LocalState.get_locations_yaml_location(self.keyname), 'r') \
.and_return(fake_locations_yaml_file)
# say that the ssh key works
flexmock(subprocess)
subprocess.should_receive('Popen').with_args(re.compile('ssh'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT,
stdin=self.fake_input_file) \
.and_return(self.success)
# mock out reading the locations.json file, and slip in our own json
flexmock(os.path)
os.path.should_call('exists') # set the fall-through
os.path.should_receive('exists').with_args(
LocalState.get_locations_json_location(self.keyname)).and_return(True)
fake_nodes_json = flexmock(name="fake_nodes_json")
fake_nodes_json.should_receive('read').and_return(json.dumps([{
"public_ip" : "public1",
"private_ip" : "private1",
"jobs" : ["shadow", "login"]
}]))
builtins.should_receive('open').with_args(
LocalState.get_locations_json_location(self.keyname), 'r') \
.and_return(fake_nodes_json)
# mock out writing the secret key to ~/.appscale, as well as reading it
# later
secret_key_location = LocalState.get_secret_key_location(self.keyname)
fake_secret = flexmock(name="fake_secret")
fake_secret.should_receive('read').and_return('the secret')
builtins.should_receive('open').with_args(secret_key_location, 'r') \
.and_return(fake_secret)
# mock out the SOAP call to the AppController and assume it succeeded
json_node_info = json.dumps(yaml.safe_load(ips_yaml))
fake_appcontroller = flexmock(name='fake_appcontroller')
fake_appcontroller.should_receive('start_roles_on_nodes') \
.with_args(json_node_info, 'the secret').and_return('OK')
flexmock(SOAPpy)
SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \
.and_return(fake_appcontroller)
argv = [
"--ips", "/tmp/boo.yaml",
"--keyname", self.keyname
]
options = ParseArgs(argv, self.function).args
AppScaleTools.add_instances(options)
示例14: test_appscale_in_two_node_virt_deployment
def test_appscale_in_two_node_virt_deployment(self):
# pretend that the place we're going to put logs into doesn't exist
flexmock(os.path)
os.path.should_call('exists') # set the fall-through
os.path.should_receive('exists').with_args('/tmp/foobaz').and_return(False)
# and mock out the mkdir operation
flexmock(os)
os.should_receive('mkdir').with_args('/tmp/foobaz').and_return()
# next, mock out finding the login ip address
os.path.should_receive('exists').with_args(
LocalState.get_locations_json_location(self.keyname)).and_return(True)
fake_nodes_json = flexmock(name="fake_nodes_json")
nodes_info = {
"node_info": [
{
"public_ip": "public1",
"private_ip": "private1",
"roles": ["load_balancer", "taskqueue_master", "zookeeper",
"db_master", "taskqueue", "shadow"]
}, {
"public_ip": "public2",
"private_ip": "private2",
"roles": ["memcache", "appengine", "zookeeper"]
}, {
"public_ip": "public3",
"private_ip": "private3",
"roles": ["memcache", "appengine"]
},
]
}
fake_nodes_json.should_receive('read').and_return(json.dumps(nodes_info))
builtins = flexmock(sys.modules['__builtin__'])
builtins.should_call('open')
builtins.should_receive('open').with_args(
LocalState.get_locations_json_location(self.keyname), 'r') \
.and_return(fake_nodes_json)
# mock out writing the secret key to ~/.appscale, as well as reading it
# later
secret_key_location = LocalState.get_secret_key_location(self.keyname)
fake_secret = flexmock(name="fake_secret")
fake_secret.should_receive('read').and_return('the secret')
builtins.should_receive('open').with_args(secret_key_location, 'r') \
.and_return(fake_secret)
# and slip in a fake appcontroller to report on the two IP addrs
fake_appcontroller = flexmock(name='fake_appcontroller')
fake_appcontroller.should_receive('get_all_public_ips').with_args(
'the secret').and_return(json.dumps(['public1', 'public2', 'public3']))
fake_appcontroller.should_receive('get_role_info').with_args(
'the secret').and_return(json.dumps(nodes_info['node_info']))
flexmock(SOAPpy)
SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \
.and_return(fake_appcontroller)
# fake the creation of the log directories locally
flexmock(utils)
utils.should_receive('mkdir').with_args('/tmp/foobaz/symlinks/private-ips')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public1')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public1/cassandra')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public1/rabbitmq')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public2')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public2/cassandra')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public2/rabbitmq')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public3')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public3/cassandra')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public3/rabbitmq')
utils.should_receive('mkdir').with_args('/tmp/foobaz/symlinks/load_balancer')
utils.should_receive('mkdir').with_args(
'/tmp/foobaz/symlinks/taskqueue_master')
utils.should_receive('mkdir').with_args('/tmp/foobaz/symlinks/zookeeper')
utils.should_receive('mkdir').with_args('/tmp/foobaz/symlinks/db_master')
utils.should_receive('mkdir').with_args('/tmp/foobaz/symlinks/taskqueue')
utils.should_receive('mkdir').with_args('/tmp/foobaz/symlinks/shadow')
utils.should_receive('mkdir').with_args('/tmp/foobaz/symlinks/memcache')
utils.should_receive('mkdir').with_args('/tmp/foobaz/symlinks/appengine')
# fake creation of symlink to for friendly navigation
links_mapping = {
'../../public1': [
'/tmp/foobaz/symlinks/private-ips/private1',
'/tmp/foobaz/symlinks/load_balancer/public1',
'/tmp/foobaz/symlinks/taskqueue_master/public1',
'/tmp/foobaz/symlinks/zookeeper/public1',
'/tmp/foobaz/symlinks/db_master/public1',
'/tmp/foobaz/symlinks/taskqueue/public1',
'/tmp/foobaz/symlinks/shadow/public1',
],
'../../public2': [
'/tmp/foobaz/symlinks/private-ips/private2',
'/tmp/foobaz/symlinks/zookeeper/public2',
'/tmp/foobaz/symlinks/appengine/public2',
'/tmp/foobaz/symlinks/memcache/public2',
],
'../../public3': [
'/tmp/foobaz/symlinks/private-ips/private3',
'/tmp/foobaz/symlinks/appengine/public3',
#.........这里部分代码省略.........
示例15: test_upload_app_successfully
def test_upload_app_successfully(self):
# add in mocks so that there is an app.yaml, but with no appid set
flexmock(os.path)
os.path.should_call('exists')
app_yaml_location = AppEngineHelper.get_app_yaml_location(self.app_dir)
os.path.should_receive('exists').with_args(app_yaml_location) \
.and_return(True)
# mock out reading the app.yaml file
builtins = flexmock(sys.modules['__builtin__'])
builtins.should_call('open') # set the fall-through
fake_app_yaml = flexmock(name="fake_app_yaml")
fake_app_yaml.should_receive('read').and_return(yaml.dump({
'application' : 'baz',
'runtime' : 'python'
}))
builtins.should_receive('open').with_args(app_yaml_location, 'r') \
.and_return(fake_app_yaml)
# mock out the SOAP call to the AppController and assume it succeeded
fake_appcontroller = flexmock(name='fake_appcontroller')
fake_appcontroller.should_receive('status').with_args('the secret') \
.and_return('Database is at public1')
fake_appcontroller.should_receive('done_uploading').with_args('baz',
'/var/apps/baz/app/baz.tar.gz', 'the secret').and_return()
fake_appcontroller.should_receive('update').with_args(['baz'],
'the secret').and_return()
fake_appcontroller.should_receive('is_app_running').with_args('baz',
'the secret').and_return(False).and_return(True)
flexmock(SOAPpy)
SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \
.and_return(fake_appcontroller)
# mock out reading the locations.json file, and slip in our own json
os.path.should_receive('exists').with_args(
LocalState.get_locations_json_location(self.keyname)).and_return(True)
fake_nodes_json = flexmock(name="fake_nodes_json")
fake_nodes_json.should_receive('read').and_return(json.dumps([{
"public_ip" : "public1",
"private_ip" : "private1",
"jobs" : ["shadow", "login"]
}]))
builtins.should_receive('open').with_args(
LocalState.get_locations_json_location(self.keyname), 'r') \
.and_return(fake_nodes_json)
# mock out reading the secret key from ~/.appscale
secret_key_location = LocalState.get_secret_key_location(self.keyname)
fake_secret = flexmock(name="fake_secret")
fake_secret.should_receive('read').and_return('the secret')
builtins.should_receive('open').with_args(secret_key_location, 'r') \
.and_return(fake_secret)
# mock out calls to the UserAppServer and presume that calls to create new
# users succeed
app_data = """
num_hosts:1
num_ports:1
hosts:public1
ports: 8080
"""
fake_userappserver = flexmock(name='fake_userappserver')
fake_userappserver.should_receive('does_user_exist').with_args(
'[email protected]', 'the secret').and_return('false')
fake_userappserver.should_receive('commit_new_user').with_args(
'[email protected]', str, 'xmpp_user', 'the secret').and_return('true')
fake_userappserver.should_receive('commit_new_user').with_args(
'[email protected]', str, 'xmpp_user', 'the secret').and_return('true')
fake_userappserver.should_receive('get_app_data').with_args(
'baz', 'the secret').and_return('\n\nnum_ports:0\n') \
.and_return(app_data).and_return(app_data).and_return(app_data)
fake_userappserver.should_receive('commit_new_app').with_args(
'baz', '[email protected]', 'python', 'the secret').and_return('true')
SOAPpy.should_receive('SOAPProxy').with_args('https://public1:4343') \
.and_return(fake_userappserver)
# mock out asking the user for the admin on the new app, and slip in an
# answer for them
builtins.should_receive('raw_input').and_return("[email protected]")
flexmock(getpass)
getpass.should_receive('getpass').and_return('aaaaaa')
# mock out making the remote app directory
flexmock(subprocess)
subprocess.should_receive('Popen').with_args(re.compile('mkdir -p'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
# and mock out tarring and copying the app
subprocess.should_receive('Popen').with_args(re.compile('tar -czf'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
subprocess.should_receive('Popen').with_args(re.compile(
'/tmp/appscale-app-baz.tar.gz'),
shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
.and_return(self.success)
#.........这里部分代码省略.........