예제 #1
0
    def test_should_log_message_as_info_if_return_code_is_zero(
            self, mock_logger, mock_exit):

        exit_program('Success.', 0)

        mock_logger.info.assert_called_with('Success.')
        self.assertEqual(0, mock_logger.error.call_count)
    def test_should_not_log_elapsed_time_when_we_did_not_start_to_measure_the_time(self, mock_logger, mock_exit, mock_time):

        mock_time.return_value = 1

        exit_program('Success.', 0)

        self.assertEqual(1, len(mock_logger.info.call_args_list))
    def test_should_round_elapsed_time_down_to_two_decimals_after_dot(self, mock_logger, mock_exit, mock_time, mock_get_timestamp_from_start):

        mock_get_timestamp_from_start.return_value = 0
        mock_time.return_value = 0.555555555555

        exit_program('Success.', 0)

        mock_logger.info.assert_any_call('Elapsed time: 0.56s')
    def test_should_log_elapsed_time(self, mock_logger, mock_exit, mock_time, mock_get_timestamp_from_start):

        mock_get_timestamp_from_start.return_value = 0
        mock_time.return_value = 1

        exit_program('Success.', 0)

        mock_logger.info.assert_any_call('Elapsed time: 1.0s')
예제 #5
0
    def test_should_not_log_elapsed_time_when_we_did_not_start_to_measure_the_time(
            self, mock_logger, mock_exit, mock_time):

        mock_time.return_value = 1

        exit_program('Success.', 0)

        self.assertEqual(1, len(mock_logger.info.call_args_list))
예제 #6
0
    def test_should_log_elapsed_time(self, mock_logger, mock_exit, mock_time,
                                     mock_get_timestamp_from_start):

        mock_get_timestamp_from_start.return_value = 0
        mock_time.return_value = 1

        exit_program('Success.', 0)

        mock_logger.info.assert_any_call('Elapsed time: 1.0s')
예제 #7
0
    def test_should_round_elapsed_time_down_to_two_decimals_after_dot(
            self, mock_logger, mock_exit, mock_time,
            mock_get_timestamp_from_start):

        mock_get_timestamp_from_start.return_value = 0
        mock_time.return_value = 0.555555555555

        exit_program('Success.', 0)

        mock_logger.info.assert_any_call('Elapsed time: 0.56s')
def ensure_valid_revision(revision):
    """ Ensures that the given argument is a valid revision (a string of digits)
        and exits the program if not.

        returns: the given revision """

    if not revision.isdigit():
        exit_program('Given revision "%s" is not an integer.' % revision,
                     return_code=RETURN_CODE_REVISION_IS_NOT_AN_INTEGER)

    LOGGER.debug('Accepting "%s" as a valid subversion revision.', revision)
    return revision
def ensure_valid_revision(revision):
    """ Ensures that the given argument is a valid revision (a string of digits)
        and exits the program if not.

        returns: the given revision """

    if not revision.isdigit():
        exit_program('Given revision "%s" is not an integer.' % revision,
                     return_code=RETURN_CODE_REVISION_IS_NOT_AN_INTEGER)

    LOGGER.debug('Accepting "%s" as a valid subversion revision.', revision)
    return revision
예제 #10
0
def main():
    """ This function will be called by the command line interface. """

    LOGGER.setLevel(DEBUG)

    try:
        arguments = parse_arguments(argv[1:], version='yadt-config-rpm-maker %s' % __version__)

        initialize_logging_to_console(arguments)
        repository_url, revision = extract_repository_url_and_revision_from_arguments(arguments)
        initialize_logging_to_syslog(arguments, revision)
        initialize_configuration(arguments)

        start_measuring_time()
        log_additional_information()
        building_configuration_rpms_and_clean_host_directories(repository_url, revision)

    except ConfigurationException as e:
        log_exception_message(e)
        return exit_program('Configuration error!', return_code=RETURN_CODE_CONFIGURATION_ERROR)

    except BaseConfigRpmMakerException as e:
        log_exception_message(e)
        return exit_program('An exception occurred!', return_code=RETURN_CODE_EXCEPTION_OCCURRED)

    except Exception:
        stack_trace = traceback.format_exc(5)
        for line in stack_trace.split('\n'):
            LOGGER.error(line)
        return exit_program('An unknown exception occurred!', return_code=RETURN_CODE_UNKNOWN_EXCEPTION_OCCURRED)

    except KeyboardInterrupt:
        return exit_program('Execution interrupted by user!', return_code=RETURN_CODE_EXECUTION_INTERRUPTED_BY_USER)

    exit_program(MESSAGE_SUCCESS, return_code=RETURN_CODE_SUCCESS)
def ensure_valid_repository_url(repository_url):
    """ Ensures that the given url is a valid repository url

        returns: the given repository_url """

    parsed_url = urlparse(repository_url)
    scheme = parsed_url.scheme

    if scheme in VALID_REPOSITORY_URL_SCHEMES:
        LOGGER.debug('Accepting "%s" as a valid repository url.', repository_url)
        return repository_url

    if scheme == '':
        file_uri = 'file://%s' % parsed_url.path
        LOGGER.debug('Accepting "%s" as a valid repository url.', file_uri)
        return file_uri

    return exit_program('Given repository url "%s" is invalid.' % repository_url,
                        return_code=RETURN_CODE_REPOSITORY_URL_INVALID)
def ensure_valid_repository_url(repository_url):
    """ Ensures that the given url is a valid repository url

        returns: the given repository_url """

    parsed_url = urlparse(repository_url)
    scheme = parsed_url.scheme

    if scheme in VALID_REPOSITORY_URL_SCHEMES:
        LOGGER.debug('Accepting "%s" as a valid repository url.',
                     repository_url)
        return repository_url

    if scheme is '':
        file_uri = 'file://%s' % parsed_url.path
        LOGGER.debug('Accepting "%s" as a valid repository url.', file_uri)
        return file_uri

    return exit_program('Given repository url "%s" is invalid.' %
                        repository_url,
                        return_code=RETURN_CODE_REPOSITORY_URL_INVALID)
예제 #13
0
def main():
    """ This function will be called by the command line interface. """

    LOGGER.setLevel(DEBUG)

    try:
        arguments = parse_arguments(argv[1:],
                                    version='yadt-config-rpm-maker %s' %
                                    __version__)

        initialize_logging_to_console(arguments)
        repository_url, revision = extract_repository_url_and_revision_from_arguments(
            arguments)
        initialize_logging_to_syslog(arguments, revision)
        initialize_configuration(arguments)

        start_measuring_time()
        log_additional_information()
        building_configuration_rpms_and_clean_host_directories(
            repository_url, revision)

    except ConfigurationException as e:
        log_exception_message(e)
        return exit_program('Configuration error!',
                            return_code=RETURN_CODE_CONFIGURATION_ERROR)

    except BaseConfigRpmMakerException as e:
        log_exception_message(e)
        return exit_program('An exception occurred!',
                            return_code=RETURN_CODE_EXCEPTION_OCCURRED)

    except Exception:
        stack_trace = traceback.format_exc(5)
        for line in stack_trace.split('\n'):
            LOGGER.error(line)
        return exit_program('An unknown exception occurred!',
                            return_code=RETURN_CODE_UNKNOWN_EXCEPTION_OCCURRED)

    except KeyboardInterrupt:
        return exit_program(
            'Execution interrupted by user!',
            return_code=RETURN_CODE_EXECUTION_INTERRUPTED_BY_USER)

    exit_program(MESSAGE_SUCCESS, return_code=RETURN_CODE_SUCCESS)
예제 #14
0
    def test_should_exit_with_given_return_code(self, mock_exit, mock_logger):

        exit_program('Some message.', 123)

        mock_exit.assert_called_once_with(123)
예제 #15
0
    def test_should_log_message_as_error_if_return_code_is_not_zero(self, mock_logger, mock_exit):

        exit_program('Failed.', 1)

        mock_logger.error.assert_called_with('Failed.')
예제 #16
0
    def test_should_exit_with_given_return_code(self, mock_exit, mock_logger):

        exit_program('Some message.', 123)

        mock_exit.assert_called_once_with(123)
예제 #17
0
    def test_should_log_message_as_error_if_return_code_is_not_zero(
            self, mock_logger, mock_exit):

        exit_program('Failed.', 1)

        mock_logger.error.assert_called_with('Failed.')
예제 #18
0
    def test_should_log_message_as_info_if_return_code_is_zero(self, mock_logger, mock_exit):

        exit_program('Success.', 0)

        mock_logger.info.assert_called_with('Success.')
        self.assertEqual(0, mock_logger.error.call_count)