Beispiel #1
0
    def test_should_raise_CouldNotUploadRpmsException(self):
        rpm_upload_command_before_test = get_rpm_upload_command()
        configuration.set_property(get_rpm_upload_command, "foobar")

        self.assertRaises(CouldNotUploadRpmsException, ConfigRpmMaker(None, None)._upload_rpms, [''])

        configuration.set_property(get_rpm_upload_command, rpm_upload_command_before_test)
Beispiel #2
0
    def _upload_rpms(self, rpms):
        rpm_upload_cmd = get_rpm_upload_command()
        chunk_size = self._get_chunk_size(rpms)

        if rpm_upload_cmd:
            LOGGER.info("Uploading %s rpm(s).", len(rpms))
            LOGGER.debug(
                'Uploading rpm(s) using command "%s" and chunk_size "%s"',
                rpm_upload_cmd, chunk_size)

            pos = 0
            while pos < len(rpms):
                rpm_chunk = rpms[pos:pos + chunk_size]
                cmd = '%s %s' % (rpm_upload_cmd, ' '.join(rpm_chunk))
                process = subprocess.Popen(cmd,
                                           shell=True,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE)
                stdout, stderr = process.communicate()
                if process.returncode:
                    error_message = 'Rpm upload failed with exit code %s. Executed command "%s"\n' % (
                        process.returncode, cmd)
                    if stdout:
                        error_message += 'stdout: "%s"\n' % stdout.strip()
                    if stderr:
                        error_message += 'stderr: "%s"\n' % stderr.strip()
                    raise CouldNotUploadRpmsException(error_message)
                pos += chunk_size
        else:
            LOGGER.info(
                "Rpms will not be uploaded since no upload command has been configured."
            )
Beispiel #3
0
    def test_should_perform_chunked_uploads(self):
        old_config = get_rpm_upload_command()
        target_file = os.path.abspath(
            os.path.join(get_temporary_directory(), 'upload.txt'))
        if os.path.exists(target_file):
            os.remove(target_file)
        cmd_file = os.path.abspath(
            os.path.join(get_temporary_directory(), 'upload.sh'))
        with open(cmd_file, 'w') as f:
            f.write(
                '#!/bin/bash\ndest=$1 ; shift ; echo "${#@} $@" >> "$dest"')

        os.chmod(cmd_file, 0755)
        cmd = '%s %s' % (cmd_file, target_file)
        configuration.set_property(get_rpm_upload_command, cmd)
        try:
            ConfigRpmMaker(None, None)._upload_rpms(['a' for x in range(25)])
        finally:
            configuration.set_property(get_rpm_upload_command, old_config)

        self.assertTrue(os.path.exists(target_file))
        with open(target_file) as f:
            self.assertEqual(
                f.read(),
                '10 a a a a a a a a a a\n10 a a a a a a a a a a\n5 a a a a a\n'
            )
    def _upload_rpms(self, rpms):
        rpm_upload_cmd = get_rpm_upload_command()
        chunk_size = self._get_chunk_size(rpms)

        if rpm_upload_cmd:
            LOGGER.info("Uploading %s rpm(s).", len(rpms))
            LOGGER.debug('Uploading rpm(s) using command "%s" and chunk_size "%s"', rpm_upload_cmd, chunk_size)

            pos = 0
            while pos < len(rpms):
                rpm_chunk = rpms[pos : pos + chunk_size]
                cmd = "%s %s" % (rpm_upload_cmd, " ".join(rpm_chunk))
                process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                stdout, stderr = process.communicate()
                if process.returncode:
                    error_message = 'Rpm upload failed with exit code %s. Executed command "%s"\n' % (
                        process.returncode,
                        cmd,
                    )
                    if stdout:
                        error_message += 'stdout: "%s"\n' % stdout.strip()
                    if stderr:
                        error_message += 'stderr: "%s"\n' % stderr.strip()
                    raise CouldNotUploadRpmsException(error_message)
                pos += chunk_size
        else:
            LOGGER.info("Rpms will not be uploaded since no upload command has been configured.")
    def test_should_raise_CouldNotUploadRpmsException(self):
        rpm_upload_command_before_test = get_rpm_upload_command()
        configuration.set_property(get_rpm_upload_command, "foobar")

        self.assertRaises(CouldNotUploadRpmsException, ConfigRpmMaker(None, None)._upload_rpms, [''])

        configuration.set_property(get_rpm_upload_command, rpm_upload_command_before_test)
    def test_should_perform_chunked_uploads(self):
        old_config = get_rpm_upload_command()
        target_file = os.path.abspath(os.path.join(get_temporary_directory(), 'upload.txt'))
        if os.path.exists(target_file):
            os.remove(target_file)
        cmd_file = os.path.abspath(os.path.join(get_temporary_directory(), 'upload.sh'))
        with open(cmd_file, 'w') as f:
            f.write('#!/bin/bash\ndest=$1 ; shift ; echo "${#@} $@" >> "$dest"')

        os.chmod(cmd_file, 0755)
        cmd = '%s %s' % (cmd_file, target_file)
        configuration.set_property(get_rpm_upload_command, cmd)
        try:
            ConfigRpmMaker(None, None)._upload_rpms(['a' for x in range(25)])
        finally:
            configuration.set_property(get_rpm_upload_command, old_config)

        self.assertTrue(os.path.exists(target_file))
        with open(target_file) as f:
            self.assertEqual(f.read(), '10 a a a a a a a a a a\n10 a a a a a a a a a a\n5 a a a a a\n')