Ejemplo n.º 1
0
    def testCopy(self):
        gs_path = 'gs://bucket/some/path'
        local_path = '/some/local/path'
        http_path = 'http://host.domain/some/path'

        result = 'TheResult'

        self.mox.StubOutWithMock(gslib, 'Copy')
        self.mox.StubOutWithMock(filelib, 'Copy')
        self.mox.StubOutWithMock(urilib, 'URLRetrieve')

        # Set up the test replay script.
        # Run 1, two local files.
        filelib.Copy(local_path, local_path + '.1').AndReturn(result)
        # Run 2, local and GS.
        gslib.Copy(local_path, gs_path).AndReturn(result)
        # Run 4, GS and GS
        gslib.Copy(gs_path, gs_path + '.1').AndReturn(result)
        # Run 7, HTTP and local
        urilib.URLRetrieve(http_path, local_path).AndReturn(result)
        # Run 8, local and HTTP
        self.mox.ReplayAll()

        # Run the test verification.
        self.assertEquals(result, urilib.Copy(local_path, local_path + '.1'))
        self.assertEquals(result, urilib.Copy(local_path, gs_path))
        self.assertEquals(result, urilib.Copy(gs_path, gs_path + '.1'))
        self.assertEquals(result, urilib.Copy(http_path, local_path))
        self.assertRaises(urilib.NotSupportedBetweenTypes, urilib.Copy,
                          local_path, http_path)
        self.mox.VerifyAll()
Ejemplo n.º 2
0
  def testCopy(self):
    gs_path = 'gs://bucket/some/path'
    local_path = '/some/local/path'
    http_path = 'http://host.domain/some/path'

    gs_mock = self.PatchObject(gs.GSContext, 'Copy')
    file_mock = self.PatchObject(filelib, 'Copy')
    urlretrieve_mock = self.PatchObject(urilib, 'URLRetrieve')

    # Set up the test replay script.
    # Run 1, two local files.
    urilib.Copy(local_path, local_path + '.1')
    file_mock.assert_called_once_with(local_path, local_path + '.1')
    file_mock.reset_mock()

    # Run 2, local and GS.
    urilib.Copy(local_path, gs_path)
    gs_mock.assert_called_once_with(local_path, gs_path)
    gs_mock.reset_mock()

    # Run 4, GS and GS
    urilib.Copy(gs_path, gs_path + '.1')
    gs_mock.assert_called_once_with(gs_path, gs_path + '.1')
    gs_mock.reset_mock()

    # Run 7, HTTP and local
    urilib.Copy(http_path, local_path)
    urlretrieve_mock.assert_called_once_with(http_path, local_path)
    urlretrieve_mock.reset_mock()

    # Run 8, local and HTTP
    self.assertRaises(urilib.NotSupportedBetweenTypes, urilib.Copy,
                      local_path, http_path)
Ejemplo n.º 3
0
    def _UploadResults(self):
        """Copy the payload generation results to the specified destination."""

        logging.info('Uploading payload to %s.', self.payload.uri)

        # Deliver the payload to the final location.
        if self.signer:
            urilib.Copy(self.signed_payload_file, self.payload.uri)
        else:
            urilib.Copy(self.payload_file, self.payload.uri)

        # Upload payload related artifacts.
        urilib.Copy(self.log_file, self._LogsUri(self.payload.uri))
        urilib.Copy(self.description_file, self._JsonUri(self.payload.uri))
Ejemplo n.º 4
0
  def testUploadResults(self):
    """Test the overall payload generation process via mox."""
    gen_sign = self._GetStdGenerator(work_dir='/work', sign=True)
    gen_nosign = self._GetStdGenerator(work_dir='/work', sign=False)

    # Set up stubs.
    self.mox.StubOutWithMock(urilib, 'Copy')
    self.mox.StubOutWithMock(urilib, 'ListFiles')

    # Record signed calls.
    urilib.Copy('/work/delta.bin.signed',
                'gs://full_old_foo/boo')
    urilib.Copy('/work/delta.bin.signed.metadata-signature',
                'gs://full_old_foo/boo.metadata-signature')
    urilib.Copy('/work/delta.log',
                'gs://full_old_foo/boo.log')
    urilib.Copy('/work/delta.json',
                'gs://full_old_foo/boo.json')

    # Record unsigned calls.
    urilib.Copy('/work/delta.bin',
                'gs://full_old_foo/boo')
    urilib.Copy('/work/delta.log',
                'gs://full_old_foo/boo.log')
    urilib.Copy('/work/delta.json',
                'gs://full_old_foo/boo.json')

    # Run the test.
    self.mox.ReplayAll()
    gen_sign._UploadResults()
    gen_nosign._UploadResults()
Ejemplo n.º 5
0
def _DefaultFetchFunc(uri, cache_file):
    """The default fetch function.

  This simply downloads the uri into the cache file using urilib

  Args:
    uri: The URI to download.
    cache_file: The path to put the downloaded file in.
  """
    urilib.Copy(uri, cache_file)