def test_method_forwarding_windows(self, *unused_mocks):
    # Test that the correct calls are being forwarded to the subprocess module
    # and that the shell=True flag is added when we are on Windows.
    processes.force_shell = True

    processes.call(['subprocess', 'call'], shell=False, other_arg=True)
    processes.subprocess.call.assert_called_once_with(
        ['subprocess', 'call'],
        shell=True,
        other_arg=True)

    processes.check_call(
        ['subprocess', 'check_call'],
        shell=False,
        other_arg=True)
    processes.subprocess.check_call.assert_called_once_with(
        ['subprocess', 'check_call'],
        shell=True,
        other_arg=True)

    processes.check_output(
        ['subprocess', 'check_output'],
        shell=False,
        other_arg=True)
    processes.subprocess.check_output.assert_called_once_with(
        ['subprocess', 'check_output'],
        shell=True,
        other_arg=True)

    processes.Popen(['subprocess', 'Popen'], shell=False, other_arg=True)
    processes.subprocess.Popen.assert_called_once_with(
        ['subprocess', 'Popen'],
        shell=True,
        other_arg=True)
Пример #2
0
 def _refresh(self, http_request):
     """Gets an access token using the gcloud client."""
     try:
         gcloud_process = processes.Popen(
             ['gcloud', 'auth', 'print-access-token'],
             stdout=processes.PIPE)
     except OSError as exn:
         logging.error('The gcloud tool was not found.', exc_info=True)
         raise AuthenticationException('The gcloud tool was not found: %s' %
                                       exn)
     output, _ = gcloud_process.communicate()
     self.access_token = output.strip()
Пример #3
0
def _gcs_file_copy(from_path, to_path, encoding=''):
  """Copy a local file to a GCS location with retries for transient errors."""
  if not encoding:
    command_args = ['gsutil', '-m', '-q', 'cp', from_path, to_path]
  else:
    encoding = 'Content-Type:' + encoding
    command_args = ['gsutil', '-m', '-q', '-h', encoding, 'cp', from_path,
                    to_path]
  logging.info('Executing command: %s', command_args)
  popen = processes.Popen(command_args, stdout=processes.PIPE,
                          stderr=processes.PIPE)
  stdoutdata, stderrdata = popen.communicate()
  if popen.returncode != 0:
    raise ValueError(
        'Failed to copy GCS file from %s to %s (stdout=%s, stderr=%s).' % (
            from_path, to_path, stdoutdata, stderrdata))