コード例 #1
0
def patch_critical_objects(stdout='', stderr='', return_code=0, flags=FLAGS):
  with contextlib2.ExitStack() as stack:
    flags.gcloud_path = 'gcloud'
    flags.run_uri = _RUN_URI
    flags.data_search_paths = ''

    stack.enter_context(mock.patch(builtins.__name__ + '.open'))
    stack.enter_context(mock.patch(vm_util.__name__ + '.PrependTempDir'))
    stack.enter_context(mock.patch(vm_util.__name__ + '.NamedTemporaryFile'))
    stack.enter_context(
        mock.patch(
            util.__name__ + '.GetDefaultProject', return_value='fakeproject'))
    stack.enter_context(
        mock.patch(
            util.__name__ + '.GetDefaultUser', return_value='fakeuser'))
    stack.enter_context(
        mock.patch(
            gce_network.__name__ + '.GceFirewall.GetFirewall',
            return_value='fakefirewall'))
    stack.enter_context(
        mock.patch(
            gce_network.__name__ + '.GceNetwork.GetNetwork',
            return_value=gce_network.GceNetwork(
                gce_network.GceNetworkSpec('fakeproject'))))

    retval = (stdout, stderr, return_code)
    issue_command = stack.enter_context(
        mock.patch(vm_util.__name__ + '.IssueCommand', return_value=retval))
    yield issue_command
コード例 #2
0
 def network(self):
     spec = gce_network.GceNetworkSpec(project=FLAGS.project)
     network = gce_network.GceNetwork.GetNetworkFromNetworkSpec(spec)
     return network.network_resource.name