

def test_add_nodes_in_virt_deployment(self):
    ips_yaml = '\ndatabase: 1.2.3.4\nzookeeper: 1.2.3.4\nappengine: 1.2.3.4\n    '
    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')
    builtins.should_receive('open').with_args('/tmp/boo.yaml', 'r').and_return(fake_yaml_file)
    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)
    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)
    flexmock(os.path)
    os.path.should_call('exists')
    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)
    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)
    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)

dataset/ETHPy150Open AppScale/appscale-tools/test/test_appscale_add_instances.py TestAppScaleAddInstances.test_add_nodes_in_virt_deployment/original