Exemplo n.º 1
0
    def test_401_raises_unauthoirzed_exception(self):
        class MockRequester(object):
            def put(self, *args, **kwargs):
                return namedtuple("response", "status_code content")(401,
                                                                     "tururu")

        out = TestBufferConanOutput()
        uploader = Uploader(MockRequester(), out, verify=False)
        f = tempfile.mktemp()
        save(f, "some contents")
        with six.assertRaisesRegex(self, AuthenticationException, "tururu"):
            uploader.upload("fake_url", f)
Exemplo n.º 2
0
    def test_403_raises_forbidden_exception_if_token(self):
        class MockRequester(object):
            def put(self, *args, **kwargs):
                return namedtuple("response", "status_code content")(403,
                                                                     "tururu")

        out = TestBufferConanOutput()
        auth = namedtuple("auth", "token")("SOMETOKEN")
        uploader = Uploader(MockRequester(), out, verify=False)
        f = tempfile.mktemp()
        save(f, "some contents")
        with six.assertRaisesRegex(self, ForbiddenException, "tururu"):
            uploader.upload("fake_url", f, auth=auth)
Exemplo n.º 3
0
    def _upload_files(self, files, base_url, retry, retry_wait):
        t1 = time.time()
        failed = []
        uploader = Uploader(self.requester, self._output, self.verify_ssl)
        # Take advantage of filenames ordering, so that conan_package.tgz and conan_export.tgz
        # can be < conanfile, conaninfo, and sent always the last, so smaller files go first
        for filename in sorted(files, reverse=True):
            self._output.rewrite_line("Uploading %s" % filename)
            resource_url = "%s/%s" % (base_url, filename)
            try:
                response = uploader.upload(resource_url, files[filename], auth=self.auth,
                                           dedup=self._checksum_deploy, retry=retry,
                                           retry_wait=retry_wait,
                                           headers=self._put_headers)
                self._output.writeln("")
                if not response.ok:
                    self._output.error("\nError uploading file: %s, '%s'" % (filename,
                                                                             response.content))
                    failed.append(filename)
                else:
                    pass
            except Exception as exc:
                self._output.error("\nError uploading file: %s, '%s'" % (filename, exc))
                failed.append(filename)

        if failed:
            raise ConanException("Execute upload again to retry upload the failed files: %s"
                                 % ", ".join(failed))
        else:
            logger.debug("\nAll uploaded! Total time: %s\n" % str(time.time() - t1))
Exemplo n.º 4
0
    def upload_files(self, file_urls, files, output, retry, retry_wait):
        t1 = time.time()
        failed = []
        uploader = Uploader(self.requester, output, self.verify_ssl)
        # Take advantage of filenames ordering, so that conan_package.tgz and conan_export.tgz
        # can be < conanfile, conaninfo, and sent always the last, so smaller files go first
        for filename, resource_url in sorted(file_urls.items(), reverse=True):
            output.rewrite_line("Uploading %s" % filename)
            auth, dedup = self._file_server_capabilities(resource_url)
            try:
                response = uploader.upload(resource_url, files[filename], auth=auth, dedup=dedup,
                                           retry=retry, retry_wait=retry_wait, headers=self._put_headers)
                output.writeln("")
                if not response.ok:
                    output.error("\nError uploading file: %s, '%s'" % (filename, response.content))
                    failed.append(filename)
                else:
                    pass
            except Exception as exc:
                output.error("\nError uploading file: %s, '%s'" % (filename, exc))
                failed.append(filename)

        if failed:
            raise ConanException("Execute upload again to retry upload the failed files: %s"
                                 % ", ".join(failed))
        else:
            logger.debug("\nAll uploaded! Total time: %s\n" % str(time.time() - t1))
Exemplo n.º 5
0
    def upload_files(self, file_urls, files, output):
        t1 = time.time()
        failed = {}
        uploader = Uploader(self.requester, output, self.verify_ssl)
        # Take advantage of filenames ordering, so that conan_package.tgz and conan_export.tgz
        # can be < conanfile, conaninfo, and sent always the last, so smaller files go first
        for filename, resource_url in sorted(file_urls.items(), reverse=True):
            output.rewrite_line("Uploading %s" % filename)
            auth, dedup = self._file_server_capabilities(resource_url)
            response = uploader.upload(resource_url, files[filename], auth=auth, dedup=dedup)
            output.writeln("")
            if not response.ok:
                output.error("\nError uploading file: %s" % filename)
                logger.debug(response.content)
                failed[filename] = resource_url
            else:
                pass

        if failed:
            logger.debug(failed)
            output.warn("\nThe upload of some files has failed. "
                        "Execute upload again to retry upload the failed files.")
            raise ConanException("Upload failed!")
        else:
            logger.debug("\nAll uploaded! Total time: %s\n" % str(time.time() - t1))
Exemplo n.º 6
0
    def upload_files(self, file_urls, files, output):
        t1 = time.time()
        failed = {}
        uploader = Uploader(self.requester, output, self.VERIFY_SSL)
        # Take advantage of filenames ordering, so that conan_package.tgz and conan_export.tgz
        # can be < conanfile, conaninfo, and sent always the last, so smaller files go first
        for filename, resource_url in sorted(file_urls.items(), reverse=True):
            output.rewrite_line("Uploading %s" % filename)
            auth, dedup = self._file_server_capabilities(resource_url)
            response = uploader.upload(resource_url, files[filename], auth=auth, dedup=dedup)
            output.writeln("")
            if not response.ok:
                output.error("\nError uploading file: %s" % filename)
                logger.debug(response.content)
                failed[filename] = resource_url
            else:
                pass

        if failed:
            logger.debug(failed)
            output.warn("\nThe upload of some files has failed. "
                        "Execute upload again to retry upload the failed files.")
            raise ConanException("Upload failed!")
        else:
            logger.debug("\nAll uploaded! Total time: %s\n" % str(time.time() - t1))
Exemplo n.º 7
0
    def _upload_files(self, files, urls, retry, retry_wait):
        t1 = time.time()
        failed = []
        uploader = Uploader(self.requester, self._output, self.verify_ssl)
        # conan_package.tgz and conan_export.tgz are uploaded first to avoid uploading conaninfo.txt
        # or conanamanifest.txt with missing files due to a network failure
        for filename in sorted(files):
            self._output.rewrite_line("Uploading %s" % filename)
            resource_url = urls[filename]
            try:
                response = uploader.upload(resource_url,
                                           files[filename],
                                           auth=self.auth,
                                           dedup=self._checksum_deploy,
                                           retry=retry,
                                           retry_wait=retry_wait,
                                           headers=self._put_headers)
                self._output.writeln("")
                if not response.ok:
                    self._output.error("\nError uploading file: %s, '%s'" %
                                       (filename, response.content))
                    failed.append(filename)
                else:
                    pass
            except (AuthenticationException, ForbiddenException):
                raise
            except Exception as exc:
                self._output.error("\nError uploading file: %s, '%s'" %
                                   (filename, exc))
                failed.append(filename)

        if failed:
            raise ConanException(
                "Execute upload again to retry upload the failed files: %s" %
                ", ".join(failed))
        else:
            logger.debug("\nUPLOAD: All uploaded! Total time: %s\n" %
                         str(time.time() - t1))
Exemplo n.º 8
0
    def _upload_files(self, file_urls, files, output, retry, retry_wait):
        t1 = time.time()
        failed = []
        uploader = Uploader(self.requester, output, self.verify_ssl)
        # conan_package.tgz and conan_export.tgz are uploaded first to avoid uploading conaninfo.txt
        # or conanamanifest.txt with missing files due to a network failure
        for filename, resource_url in sorted(file_urls.items()):
            output.rewrite_line("Uploading %s" % filename)
            auth, dedup = self._file_server_capabilities(resource_url)
            try:
                response = uploader.upload(resource_url,
                                           files[filename],
                                           auth=auth,
                                           dedup=dedup,
                                           retry=retry,
                                           retry_wait=retry_wait,
                                           headers=self._put_headers)
                output.writeln("")
                if not response.ok:
                    output.error("\nError uploading file: %s, '%s'" %
                                 (filename, response.content))
                    failed.append(filename)
                else:
                    pass
            except Exception as exc:
                output.error("\nError uploading file: %s, '%s'" %
                             (filename, exc))
                failed.append(filename)

        if failed:
            raise ConanException(
                "Execute upload again to retry upload the failed files: %s" %
                ", ".join(failed))
        else:
            logger.debug("UPLOAD: \nAll uploaded! Total time: %s\n" %
                         str(time.time() - t1))