def test_should_move_directory_to_destination(self, mock_exists, mock_move, mock_rmtree):

        mock_exists.return_value = False

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(self.mock_config_rpm_maker, ['devweb01'])

        mock_move.assert_called_with('target/tmp/configviewer/hosts/devweb01.new-revision-54', 'target/tmp/configviewer/hosts/devweb01')
 def test_affected_hosts(self):
     config_rpm_maker = ConfigRpmMaker(None, None)
     self.assertEqual(set(['berweb01', 'devweb01', 'tuvweb02']), config_rpm_maker._get_affected_hosts(['typ/web', 'foo/bar'], ['berweb01', 'devweb01', 'tuvweb02']))
     self.assertEqual(set(['berweb01', 'devweb01', 'tuvweb02']), config_rpm_maker._get_affected_hosts(['foo/bar', 'all'], ['berweb01', 'devweb01', 'tuvweb02']))
     self.assertEqual(set(['berweb01', 'tuvweb02']), config_rpm_maker._get_affected_hosts(['loc/pro', 'loc/tuv'], ['berweb01', 'devweb01', 'tuvweb02']))
     self.assertEqual(set(['devweb01']), config_rpm_maker._get_affected_hosts(['foo/bar', 'loctyp/devweb'], ['berweb01', 'devweb01', 'tuvweb02']))
     self.assertEqual(set(['devweb01']), config_rpm_maker._get_affected_hosts(['foo/bar', 'host/devweb01'], ['berweb01', 'devweb01', 'tuvweb02']))
    def test_should_not_remove_directory_if_it_does_not_already_exist(self, mock_exists, mock_move, mock_rmtree):

        mock_exists.return_value = False

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(self.mock_config_rpm_maker, ['devweb01'])

        self.assert_mock_never_called(mock_rmtree)
    def test_should_create_working_directory_in_configured_temporary_directory(self, mock_makedirs, mock_mkdtemp, mock_exists):

        mock_config_rpm_maker = self.create_mock_config_rpm_maker()

        ConfigRpmMaker._prepare_work_dir(mock_config_rpm_maker)

        mock_mkdtemp.assert_called_with(prefix='yadt-config-rpm-maker.', suffix='.4852', dir='temporary directory')
    def test_should_not_do_anything_if_no_hosts_are_given(
            self, mock_move, mock_rmtree):

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(
            self.mock_config_rpm_maker, [])

        self.assert_mock_never_called(mock_move)
        self.assert_mock_never_called(mock_rmtree)
    def test_should_not_create_any_directory_when_all_directories_exist(self, mock_makedirs, mock_mkdtemp, mock_exists):

        mock_config_rpm_maker = self.create_mock_config_rpm_maker()
        mock_exists.return_value = True

        ConfigRpmMaker._prepare_work_dir(mock_config_rpm_maker)

        self.assert_mock_never_called(mock_makedirs)
    def test_should_not_remove_directory_if_it_does_not_already_exist(
            self, mock_exists, mock_move, mock_rmtree):

        mock_exists.return_value = False

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(
            self.mock_config_rpm_maker, ['devweb01'])

        self.assert_mock_never_called(mock_rmtree)
    def test_should_not_remove_directory_if_the_revision_of_the_file_in_the_directory_is_higher(self, mock_exists, mock_move, mock_rmtree):

        self.mock_config_rpm_maker._read_integer_from_file.return_value = 99

        mock_exists.return_value = True

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(self.mock_config_rpm_maker, ['devweb01'])

        self.assertTrue(call('target/tmp/configviewer/hosts/devweb01') not in mock_rmtree.call_args_list)
    def test_should_remove_temporary_directory_if_the_revision_of_the_file_in_the_directory_is_higher(self, mock_exists, mock_move, mock_rmtree):

        self.mock_config_rpm_maker._read_integer_from_file.return_value = 99

        mock_exists.return_value = True

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(self.mock_config_rpm_maker, ['devweb01'])

        mock_rmtree.assert_called_with('target/tmp/configviewer/hosts/devweb01.new-revision-54')
    def test_should_remove_directories_of_hosts_if_they_already_exist(self, mock_exists, mock_move, mock_rmtree):

        mock_exists.return_value = True
        self.mock_config_rpm_maker._read_integer_from_file.return_value = 42

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(self.mock_config_rpm_maker, ['devweb01', 'tuvweb01'])

        mock_rmtree.assert_any_call('target/tmp/configviewer/hosts/devweb01')
        mock_rmtree.assert_any_call('target/tmp/configviewer/hosts/tuvweb01')
    def test_should_not_create_any_directory_when_all_directories_exist(
            self, mock_makedirs, mock_mkdtemp, mock_exists):

        mock_config_rpm_maker = self.create_mock_config_rpm_maker()
        mock_exists.return_value = True

        ConfigRpmMaker._prepare_work_dir(mock_config_rpm_maker)

        self.assert_mock_never_called(mock_makedirs)
    def test_should_create_SOURCES_directory_when_it_does_not_exist(self, mock_makedirs, mock_mkdtemp, mock_exists):

        mock_config_rpm_maker = self.create_mock_config_rpm_maker()
        mock_exists.return_value = False
        mock_mkdtemp.return_value = 'working-directory'

        ConfigRpmMaker._prepare_work_dir(mock_config_rpm_maker)

        mock_makedirs.assert_any_call('working-directory/rpmbuild/SOURCES')
    def test_should_create_SOURCES_directory_when_it_does_not_exist(
            self, mock_makedirs, mock_mkdtemp, mock_exists):

        mock_config_rpm_maker = self.create_mock_config_rpm_maker()
        mock_exists.return_value = False
        mock_mkdtemp.return_value = 'working-directory'

        ConfigRpmMaker._prepare_work_dir(mock_config_rpm_maker)

        mock_makedirs.assert_any_call('working-directory/rpmbuild/SOURCES')
    def test_should_create_working_directory_in_configured_temporary_directory(
            self, mock_makedirs, mock_mkdtemp, mock_exists):

        mock_config_rpm_maker = self.create_mock_config_rpm_maker()

        ConfigRpmMaker._prepare_work_dir(mock_config_rpm_maker)

        mock_mkdtemp.assert_called_with(prefix='yadt-config-rpm-maker.',
                                        suffix='.4852',
                                        dir='temporary directory')
    def test_should_remove_directory_if_it_does_already_exist(self, mock_build_config_viewer_host_directory, mock_exists, mock_move, mock_rmtree):

        mock_build_config_viewer_host_directory.return_value = 'target/tmp/configviewer/hosts/devweb01'
        self.mock_config_rpm_maker._read_integer_from_file.return_value = 53

        mock_exists.return_value = True

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(self.mock_config_rpm_maker, ['devweb01'])

        mock_rmtree.assert_called_with('target/tmp/configviewer/hosts/devweb01')
    def test_should_not_remove_error_log_if_it_does_not_exist(self, mock_exists, mock_rmtree, mock_remove):

        mock_exists.return_value = False
        mock_config_rpm_maker = Mock(ConfigRpmMaker)
        mock_config_rpm_maker._keep_work_dir.return_value = False
        mock_config_rpm_maker.work_dir = '/path/to/working/directory'
        mock_config_rpm_maker.error_log_file = '/path/to/error.log'

        ConfigRpmMaker._clean_up_work_dir(mock_config_rpm_maker)

        self.assert_mock_never_called(mock_remove)
    def test_should_not_remove_anything_when_configuration_says_we_should_not_clean_up(self, mock_exists, mock_rmtree, mock_remove):

        mock_config_rpm_maker = Mock(ConfigRpmMaker)
        mock_config_rpm_maker._keep_work_dir.return_value = True
        mock_config_rpm_maker.work_dir = '/path/to/working/directory'

        ConfigRpmMaker._clean_up_work_dir(mock_config_rpm_maker)

        self.assert_mock_never_called(mock_exists)
        self.assert_mock_never_called(mock_rmtree)
        self.assert_mock_never_called(mock_remove)
    def test_should_remove_directories_of_hosts_if_they_already_exist(
            self, mock_exists, mock_move, mock_rmtree):

        mock_exists.return_value = True
        self.mock_config_rpm_maker._read_integer_from_file.return_value = 42

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(
            self.mock_config_rpm_maker, ['devweb01', 'tuvweb01'])

        mock_rmtree.assert_any_call('target/tmp/configviewer/hosts/devweb01')
        mock_rmtree.assert_any_call('target/tmp/configviewer/hosts/tuvweb01')
Ejemplo n.º 19
0
 def test_should_find_matching_hosts(self):
     config_rpm_maker = ConfigRpmMaker(None, None)
     self.assertEqual(['berweb01', 'devweb01'],
                      config_rpm_maker._find_matching_hosts(
                          All(), 'all/foo/bar', ['berweb01', 'devweb01']))
     self.assertEqual([],
                      config_rpm_maker._find_matching_hosts(
                          All(), 'foo/bar', ['berweb01', 'devweb01']))
     self.assertEqual(['berweb01', 'devweb01'],
                      config_rpm_maker._find_matching_hosts(
                          Typ(), 'typ/web', ['berweb01', 'devweb01']))
    def test_should_move_directory_to_destination(self, mock_exists, mock_move,
                                                  mock_rmtree):

        mock_exists.return_value = False

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(
            self.mock_config_rpm_maker, ['devweb01'])

        mock_move.assert_called_with(
            'target/tmp/configviewer/hosts/devweb01.new-revision-54',
            'target/tmp/configviewer/hosts/devweb01')
    def test_should_not_try_to_remove_working_directory_if_it_is_not_set(self, mock_exists, mock_rmtree, mock_remove):

        mock_exists.return_value = False
        mock_config_rpm_maker = Mock(ConfigRpmMaker)
        mock_config_rpm_maker._keep_work_dir.return_value = False
        mock_config_rpm_maker.work_dir = None
        mock_config_rpm_maker.error_log_file = None

        ConfigRpmMaker._clean_up_work_dir(mock_config_rpm_maker)

        self.assert_mock_never_called(mock_rmtree)
        self.assert_mock_never_called(mock_remove)
    def test_should_remove_temporary_directory_if_the_revision_of_the_file_in_the_directory_is_higher(
            self, mock_exists, mock_move, mock_rmtree):

        self.mock_config_rpm_maker._read_integer_from_file.return_value = 99

        mock_exists.return_value = True

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(
            self.mock_config_rpm_maker, ['devweb01'])

        mock_rmtree.assert_called_with(
            'target/tmp/configviewer/hosts/devweb01.new-revision-54')
    def test_should_not_remove_anything_when_configuration_says_we_should_not_clean_up(
            self, mock_exists, mock_rmtree, mock_remove):

        mock_config_rpm_maker = Mock(ConfigRpmMaker)
        mock_config_rpm_maker._keep_work_dir.return_value = True
        mock_config_rpm_maker.work_dir = '/path/to/working/directory'

        ConfigRpmMaker._clean_up_work_dir(mock_config_rpm_maker)

        self.assert_mock_never_called(mock_exists)
        self.assert_mock_never_called(mock_rmtree)
        self.assert_mock_never_called(mock_remove)
    def test_should_not_remove_error_log_if_it_does_not_exist(
            self, mock_exists, mock_rmtree, mock_remove):

        mock_exists.return_value = False
        mock_config_rpm_maker = Mock(ConfigRpmMaker)
        mock_config_rpm_maker._keep_work_dir.return_value = False
        mock_config_rpm_maker.work_dir = '/path/to/working/directory'
        mock_config_rpm_maker.error_log_file = '/path/to/error.log'

        ConfigRpmMaker._clean_up_work_dir(mock_config_rpm_maker)

        self.assert_mock_never_called(mock_remove)
    def test_should_add_fail_information_to_failed_host_queue(self):

        mock_config_rpm_maker = Mock(ConfigRpmMaker)
        mock_config_rpm_maker.failed_host_queue = Mock()
        mock_host_queue = Mock()
        mock_config_rpm_maker.host_queue = mock_host_queue

        ConfigRpmMaker._notify_that_host_failed(mock_config_rpm_maker,
                                                'devabc123', 'Stacktrace')

        mock_config_rpm_maker.failed_host_queue.put.assert_called_with(
            ('devabc123', 'Stacktrace'))
    def test_should_remove_error_log_if_it_exists(self, mock_exists, mock_rmtree, mock_remove):

        mock_exists.return_value = True
        mock_config_rpm_maker = Mock(ConfigRpmMaker)
        mock_config_rpm_maker._keep_work_dir.return_value = False
        mock_config_rpm_maker.work_dir = '/path/to/working/directory'
        mock_config_rpm_maker.error_log_file = '/path/to/error.log'

        ConfigRpmMaker._clean_up_work_dir(mock_config_rpm_maker)

        mock_exists.assert_any_call('/path/to/error.log')
        mock_remove.assert_called_with('/path/to/error.log')
    def test_should_not_remove_directory_if_the_revision_of_the_file_in_the_directory_is_higher(
            self, mock_exists, mock_move, mock_rmtree):

        self.mock_config_rpm_maker._read_integer_from_file.return_value = 99

        mock_exists.return_value = True

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(
            self.mock_config_rpm_maker, ['devweb01'])

        self.assertTrue(
            call('target/tmp/configviewer/hosts/devweb01') not in
            mock_rmtree.call_args_list)
    def test_should_not_try_to_remove_working_directory_if_it_is_not_set(
            self, mock_exists, mock_rmtree, mock_remove):

        mock_exists.return_value = False
        mock_config_rpm_maker = Mock(ConfigRpmMaker)
        mock_config_rpm_maker._keep_work_dir.return_value = False
        mock_config_rpm_maker.work_dir = None
        mock_config_rpm_maker.error_log_file = None

        ConfigRpmMaker._clean_up_work_dir(mock_config_rpm_maker)

        self.assert_mock_never_called(mock_rmtree)
        self.assert_mock_never_called(mock_remove)
    def test_should_remove_error_log_if_it_exists(self, mock_exists,
                                                  mock_rmtree, mock_remove):

        mock_exists.return_value = True
        mock_config_rpm_maker = Mock(ConfigRpmMaker)
        mock_config_rpm_maker._keep_work_dir.return_value = False
        mock_config_rpm_maker.work_dir = '/path/to/working/directory'
        mock_config_rpm_maker.error_log_file = '/path/to/error.log'

        ConfigRpmMaker._clean_up_work_dir(mock_config_rpm_maker)

        mock_exists.assert_any_call('/path/to/error.log')
        mock_remove.assert_called_with('/path/to/error.log')
    def test_should_remove_directory_if_it_does_already_exist(
            self, mock_build_config_viewer_host_directory, mock_exists,
            mock_move, mock_rmtree):

        mock_build_config_viewer_host_directory.return_value = 'target/tmp/configviewer/hosts/devweb01'
        self.mock_config_rpm_maker._read_integer_from_file.return_value = 53

        mock_exists.return_value = True

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(
            self.mock_config_rpm_maker, ['devweb01'])

        mock_rmtree.assert_called_with(
            'target/tmp/configviewer/hosts/devweb01')
    def test_should_remove_directories_of_hosts_if_they_already_exist_and_should_leave_them_if_they_have_a_higher_revision(
            self, mock_exists, mock_move, mock_rmtree):
        def read_integer_from_file_side_effect(path):
            if path.endswith('devweb01.rev'):
                return 99
            elif path.endswith('tuvweb01.rev'):
                raise Exception(
                    'This should not happen since the exists side effect returns False'
                )
            elif path.endswith('berweb01.rev'):
                return 42
            else:
                raise Exception("Unknown path %s" % path)

        self.mock_config_rpm_maker._read_integer_from_file.side_effect = read_integer_from_file_side_effect

        def exists_side_effect(path):
            if path.endswith('devweb01'):
                return True
            elif path.endswith('tuvweb01'):
                return False
            elif path.endswith('berweb01'):
                return True
            else:
                raise Exception("Unknown path %s" % path)

        mock_exists.side_effect = exists_side_effect

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(
            self.mock_config_rpm_maker, ['devweb01', 'tuvweb01', 'berweb01'])

        mock_rmtree.assert_any_call(
            'target/tmp/configviewer/hosts/devweb01.new-revision-54')
        self.assertTrue(
            call('target/tmp/configviewer/hosts/devweb01.new-revision-54',
                 'target/tmp/configviewer/hosts/devweb01') not in
            mock_move.call_args_list)

        self.assertTrue(
            call('target/tmp/configviewer/hosts/tuvweb01') not in
            mock_rmtree.call_args_list)
        mock_move.assert_any_call(
            'target/tmp/configviewer/hosts/tuvweb01.new-revision-54',
            'target/tmp/configviewer/hosts/tuvweb01')

        mock_rmtree.assert_any_call('target/tmp/configviewer/hosts/berweb01')
        mock_move.assert_any_call(
            'target/tmp/configviewer/hosts/berweb01.new-revision-54',
            'target/tmp/configviewer/hosts/berweb01')
Ejemplo n.º 32
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)
Ejemplo n.º 33
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 test_should_clear_hosts_queue_when_maximum_of_failed_hosts_reached(
            self, mock_config):

        mock_config.return_value = 3
        mock_config_rpm_maker = Mock(ConfigRpmMaker)
        fake_queue = Queue()
        fake_queue.put(('hostname1', 'stacktrace1'))
        fake_queue.put(('hostname2', 'stacktrace2'))
        mock_config_rpm_maker.failed_host_queue = fake_queue
        mock_config_rpm_maker.host_queue = Mock()

        ConfigRpmMaker._notify_that_host_failed(mock_config_rpm_maker,
                                                'devabc123', 'Stacktrace')

        mock_config_rpm_maker.host_queue.queue.clear.assert_called_with()
        mock_config.assert_called_with()
    def test_should_not_clear_hosts_queue_when_failed_hosts_under_maximum(
            self, mock_config):

        mock_config.return_value = 100
        mock_config_rpm_maker = Mock(ConfigRpmMaker)
        fake_queue = Queue()
        fake_queue.put(('hostname1', 'stacktrace1'))
        fake_queue.put(('hostname2', 'stacktrace2'))
        fake_queue.put(('hostname3', 'stacktrace3'))
        mock_config_rpm_maker.failed_host_queue = fake_queue
        mock_config_rpm_maker.host_queue = Mock()

        ConfigRpmMaker._notify_that_host_failed(mock_config_rpm_maker,
                                                'devabc123', 'Stacktrace')

        self.assert_mock_never_called(
            mock_config_rpm_maker.host_queue.queue.clear)
        mock_config.assert_called_with()
Ejemplo n.º 36
0
def building_configuration_rpms_and_clean_host_directories(
        repository, revision):
    """ This function will start the process of building configuration rpms
        for the given configuration repository and the revision. """

    path_to_config = get_svn_path_to_config()
    svn_service = SvnService(base_url=repository,
                             path_to_config=path_to_config)
    svn_service.log_change_set_meta_information(revision)
    ConfigRpmMaker(revision=revision, svn_service=svn_service).build()
    clean_up_deleted_hosts_data(svn_service, revision)
Ejemplo n.º 37
0
 def test_should_identify_affected_hosts(self):
     config_rpm_maker = ConfigRpmMaker(None, None)
     self.assertEqual(set(['berweb01', 'devweb01', 'tuvweb02']), config_rpm_maker._get_affected_hosts(['typ/web', 'foo/bar'], ['berweb01', 'devweb01', 'tuvweb02']))
     self.assertEqual(set(['berweb01', 'devweb01', 'tuvweb02']), config_rpm_maker._get_affected_hosts(['foo/bar', 'all'], ['berweb01', 'devweb01', 'tuvweb02']))
     self.assertEqual(set(['berweb01', 'tuvweb02']), config_rpm_maker._get_affected_hosts(['loc/pro', 'loc/tuv'], ['berweb01', 'devweb01', 'tuvweb02']))
     self.assertEqual(set(['devweb01']), config_rpm_maker._get_affected_hosts(['foo/bar', 'loctyp/devweb'], ['berweb01', 'devweb01', 'tuvweb02']))
     self.assertEqual(set(['devweb01']), config_rpm_maker._get_affected_hosts(['foo/bar', 'host/devweb01'], ['berweb01', 'devweb01', 'tuvweb02']))
    def test_should_remove_directories_of_hosts_if_they_already_exist_and_should_leave_them_if_they_have_a_higher_revision(self, mock_exists, mock_move, mock_rmtree):

        def read_integer_from_file_side_effect(path):
            if path.endswith('devweb01.rev'):
                return 99
            elif path.endswith('tuvweb01.rev'):
                raise Exception('This should not happen since the exists side effect returns False')
            elif path.endswith('berweb01.rev'):
                return 42
            else:
                raise Exception("Unknown path %s" % path)

        self.mock_config_rpm_maker._read_integer_from_file.side_effect = read_integer_from_file_side_effect

        def exists_side_effect(path):
            if path.endswith('devweb01'):
                return True
            elif path.endswith('tuvweb01'):
                return False
            elif path.endswith('berweb01'):
                return True
            else:
                raise Exception("Unknown path %s" % path)

        mock_exists.side_effect = exists_side_effect

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(self.mock_config_rpm_maker, ['devweb01', 'tuvweb01', 'berweb01'])

        mock_rmtree.assert_any_call('target/tmp/configviewer/hosts/devweb01.new-revision-54')
        self.assertTrue(call('target/tmp/configviewer/hosts/devweb01.new-revision-54', 'target/tmp/configviewer/hosts/devweb01') not in mock_move.call_args_list)

        self.assertTrue(call('target/tmp/configviewer/hosts/tuvweb01') not in mock_rmtree.call_args_list)
        mock_move.assert_any_call('target/tmp/configviewer/hosts/tuvweb01.new-revision-54', 'target/tmp/configviewer/hosts/tuvweb01')

        mock_rmtree.assert_any_call('target/tmp/configviewer/hosts/berweb01')
        mock_move.assert_any_call('target/tmp/configviewer/hosts/berweb01.new-revision-54', 'target/tmp/configviewer/hosts/berweb01')
    def test_should_not_delete_host_directory_when_a_file_has_been_deleted_in_repository_host_directory(
            self):

        svn_service = SvnService(base_url=self.repo_url,
                                 path_to_config=get_svn_path_to_config())
        ConfigRpmMaker('1', svn_service).build()

        if call('svn delete -q -m "deleting hostspecific file devweb01" %s/config/host/devweb01/host_specific_file'
                % self.repo_url,
                shell=True):
            raise IntegrationTestException('Could not delete test data.')

        clean_up_deleted_hosts_data(svn_service, '3')

        self.assert_path_exists(build_config_viewer_host_directory('berweb01'))
        self.assert_path_exists(build_config_viewer_host_directory('tuvweb01'))
        self.assert_path_exists(build_config_viewer_host_directory('devweb01'))
    def test_should_delete_config_viewer_host_directories_when_directories_have_been_deleted_in_repository(
            self):

        svn_service = SvnService(base_url=self.repo_url,
                                 path_to_config=get_svn_path_to_config())
        ConfigRpmMaker('1', svn_service).build()

        if call('svn delete -q -m "deleting host tuvweb01 and devweb01" {0}/config/host/devweb01 {0}/config/host/tuvweb01'
                .format(self.repo_url),
                shell=True):
            raise IntegrationTestException('Could not delete test data.')

        clean_up_deleted_hosts_data(svn_service, '3')

        self.assert_path_exists(build_config_viewer_host_directory('berweb01'))
        self.assert_path_does_not_exist(
            build_config_viewer_host_directory('devweb01'))
        self.assert_path_does_not_exist(
            build_config_viewer_host_directory('tuvweb01'))
Ejemplo n.º 41
0
    def _given_config_rpm_maker(self):
        svn_service = SvnService(base_url=self.repo_url, path_to_config=get_svn_path_to_config())

        return ConfigRpmMaker('2', svn_service)
Ejemplo n.º 42
0
 def test_should_raise_CouldNotBuildSomeRpmsException(self):
     self.assertRaises(CouldNotBuildSomeRpmsException, ConfigRpmMaker(None, None)._build_hosts, ['devabc123'])
 def test_find_matching_hosts(self):
     config_rpm_maker = ConfigRpmMaker(None, None)
     self.assertEqual(['berweb01', 'devweb01'], config_rpm_maker._find_matching_hosts(All(), 'all/foo/bar', ['berweb01', 'devweb01']))
     self.assertEqual([], config_rpm_maker._find_matching_hosts(All(), 'foo/bar', ['berweb01', 'devweb01']))
     self.assertEqual(['berweb01', 'devweb01'], config_rpm_maker._find_matching_hosts(Typ(), 'typ/web', ['berweb01', 'devweb01']))
    def test_should_create_files_for_hosts(self):

        configuration.set_property(is_no_clean_up_enabled, True)
        svn_service = SvnService(base_url=self.repo_url,
                                 path_to_config=get_svn_path_to_config())

        ConfigRpmMaker('2', svn_service).build()

        self.assert_config_viewer_file(
            'berweb01', 'berweb01.overlaying', """host/berweb01:/VARIABLES
loctyp/berweb:/VARIABLES/OVERRIDE
loc/pro:/VARIABLES/RPM_PROVIDES
host/berweb01:/VARIABLES/RPM_REQUIRES
loctyp/berweb:/VARIABLES/VAR_IN_VAR
typ/web:/data
typ/web:/data/file-with-special-character
typ/web:/data/index.html
typ/web:/data/other.html
loctyp/berweb:/files
all:/files/binary.zip
all:/files/file_from_all
loc/ber:/files/file_from_ber
loc/pro:/files/file_from_pro
loctyp/berweb:/files/override
host/berweb01:/symlinks
host/berweb01:/symlinks/link1.%symlink
loctyp/berweb:/vars
all:/vars/override
loctyp/berweb:/vars/var_in_var
""")

        self.assert_config_viewer_file(
            'berweb01', 'berweb01.variables',
            """<!DOCTYPE html><html><head><title>berweb01.variables</title></head><body><pre>                                 ALIASES :
                                     ALL : all
                                    FQDN : .+
                                    HOST : berweb01
                                  HOSTNR : 01
           INSTALL_PROTECTION_DEPENDENCY : hostname-<strong title="HOST">berweb01</strong>
                                      IP : .+
                                     LOC : ber
                                  LOCTYP : berweb
                                OVERRIDE : berweb
                                REVISION : 2
                                RPM_NAME : berweb01
                            RPM_PROVIDES : pro-prov2, all-prov2, all-prov, pro-prov, typ-web-provides, all-prov3
                            RPM_REQUIRES : ber-req2, pro-req, all-req, ber-req, ty-web-requirement, all-req2, host-spec-requirement
                  RPM_REQUIRES_NON_REPOS : ber-req2, pro-req, all-req, ber-req, ty-web-requirement, all-req2, host-spec-requirement
                      RPM_REQUIRES_REPOS :
                            SHORT_HOSTNR : 1
                                     TYP : web
                              VAR_IN_VAR : <strong title="LOC">ber</strong><strong title="TYP">web</strong><strong title="OVERRIDE">berweb</strong>
</pre></body></html>""")

        self.assert_host_files_are_there('berweb01')
        self.assert_config_viewer_file('berweb01',
                                       join('files', 'file_from_ber'), "")
        self.assert_config_viewer_file('berweb01',
                                       join('files', 'file_from_pro'), "")
        self.assert_config_viewer_file(
            'berweb01', join('files', 'override'),
            "<!DOCTYPE html><html><head><title>override</title></head><body><pre>berweb</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'berweb01', join('VARIABLES', 'LOC'),
            "<!DOCTYPE html><html><head><title>LOC</title></head><body><pre>ber</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'berweb01', join('VARIABLES', 'LOCTYP'),
            "<!DOCTYPE html><html><head><title>LOCTYP</title></head><body><pre>berweb</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'berweb01', join('VARIABLES', 'OVERRIDE'),
            "<!DOCTYPE html><html><head><title>OVERRIDE</title></head><body><pre>berweb</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'berweb01', join('VARIABLES', 'RPM_PROVIDES'),
            "<!DOCTYPE html><html><head><title>RPM_PROVIDES</title></head><body><pre>pro-prov2, all-prov2, all-prov, pro-prov, typ-web-provides, all-prov3</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'berweb01', join('VARIABLES', 'RPM_REQUIRES'),
            "<!DOCTYPE html><html><head><title>RPM_REQUIRES</title></head><body><pre>ber-req2, pro-req, all-req, ber-req, ty-web-requirement, all-req2, host-spec-requirement</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'berweb01', join('VARIABLES', 'RPM_REQUIRES_NON_REPOS'),
            "<!DOCTYPE html><html><head><title>RPM_REQUIRES_NON_REPOS</title></head><body><pre>ber-req2, pro-req, all-req, ber-req, ty-web-requirement, all-req2, host-spec-requirement</pre></body></html>"
        )
        self.assert_config_viewer_file('berweb01',
                                       join('VARIABLES', 'RPM_REQUIRES_REPOS'),
                                       "")
        self.assert_config_viewer_file(
            'berweb01', join('VARIABLES', 'VAR_IN_VAR'),
            '''<!DOCTYPE html><html><head><title>VAR_IN_VAR</title></head><body><pre><strong title="LOC">ber</strong><strong title="TYP">web</strong><strong title="OVERRIDE">berweb</strong></pre></body></html>'''
        )
        self.assert_config_viewer_file(
            'berweb01', join('vars', 'override'),
            '''<!DOCTYPE html><html><head><title>override</title></head><body><pre><strong title="OVERRIDE">berweb</strong></pre></body></html>'''
        )
        self.assert_config_viewer_file(
            'berweb01', join('vars', 'var_in_var'),
            '''<!DOCTYPE html><html><head><title>var_in_var</title></head><body><pre><strong title="VAR_IN_VAR">berwebberweb</strong></pre></body></html>'''
        )

        self.assert_host_files_are_there('devweb01')
        self.assert_config_viewer_file(
            'devweb01', join('files', 'override'),
            "<!DOCTYPE html><html><head><title>override</title></head><body><pre>all</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'devweb01', join('VARIABLES', 'LOC'),
            "<!DOCTYPE html><html><head><title>LOC</title></head><body><pre>dev</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'devweb01', join('VARIABLES', 'LOCTYP'),
            "<!DOCTYPE html><html><head><title>LOCTYP</title></head><body><pre>devweb</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'devweb01', join('VARIABLES', 'OVERRIDE'),
            "<!DOCTYPE html><html><head><title>OVERRIDE</title></head><body><pre>all</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'devweb01', join('VARIABLES', 'RPM_PROVIDES'),
            "<!DOCTYPE html><html><head><title>RPM_PROVIDES</title></head><body><pre>typ-web-provides, all-prov, all-prov2, all-prov3</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'devweb01', join('VARIABLES', 'RPM_REQUIRES'),
            "<!DOCTYPE html><html><head><title>RPM_REQUIRES</title></head><body><pre>all-req2, all-req, ty-web-requirement</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'devweb01', join('VARIABLES', 'RPM_REQUIRES_NON_REPOS'),
            "<!DOCTYPE html><html><head><title>RPM_REQUIRES_NON_REPOS</title></head><body><pre>all-req2, all-req, ty-web-requirement</pre></body></html>"
        )
        self.assert_config_viewer_file('devweb01',
                                       join('VARIABLES', 'RPM_REQUIRES_REPOS'),
                                       "")
        self.assert_config_viewer_file(
            'devweb01', join('vars', 'override'),
            '''<!DOCTYPE html><html><head><title>override</title></head><body><pre><strong title="OVERRIDE">all</strong></pre></body></html>'''
        )

        self.assert_config_viewer_file(
            'devweb01', 'devweb01.overlaying', """host/devweb01:/VARIABLES
host/devweb01:/VARIABLES/DUMMY_VAR1
all:/VARIABLES/OVERRIDE
typ/web:/VARIABLES/RPM_PROVIDES
typ/web:/VARIABLES/RPM_REQUIRES
typ/web:/data
typ/web:/data/file-with-special-character
typ/web:/data/index.html
typ/web:/data/other.html
all:/files
all:/files/binary.zip
all:/files/file_from_all
all:/files/override
host/devweb01:/host_specific_file
all:/vars
all:/vars/override
""")

        self.assert_config_viewer_file(
            'devweb01', 'devweb01.variables',
            """<!DOCTYPE html><html><head><title>devweb01.variables</title></head><body><pre>                                 ALIASES :
                                     ALL : all
                              DUMMY_VAR1 :
                                    FQDN : .+
                                    HOST : devweb01
                                  HOSTNR : 01
           INSTALL_PROTECTION_DEPENDENCY : hostname-<strong title="HOST">devweb01</strong>
                                      IP : .+
                                     LOC : dev
                                  LOCTYP : devweb
                                OVERRIDE : all
                                REVISION : 2
                                RPM_NAME : devweb01
                            RPM_PROVIDES : typ-web-provides, all-prov, all-prov2, all-prov3
                            RPM_REQUIRES : all-req2, all-req, ty-web-requirement
                  RPM_REQUIRES_NON_REPOS : all-req2, all-req, ty-web-requirement
                      RPM_REQUIRES_REPOS :
                            SHORT_HOSTNR : 1
                                     TYP : web
</pre></body></html>""")

        self.assert_host_files_are_there('tuvweb01')

        self.assert_config_viewer_file_exactly(
            'tuvweb01', 'tuvweb01.overlaying', """host/tuvweb01:/VARIABLES
host/tuvweb01:/VARIABLES/DUMMY_VAR2
all:/VARIABLES/OVERRIDE
typ/web:/VARIABLES/RPM_PROVIDES
typ/web:/VARIABLES/RPM_REQUIRES
typ/web:/data
typ/web:/data/file-with-special-character
typ/web:/data/index.html
typ/web:/data/other.html
all:/files
all:/files/binary.zip
all:/files/file_from_all
all:/files/override
all:/vars
all:/vars/override
""")

        self.assert_config_viewer_file(
            'tuvweb01', 'tuvweb01.variables',
            """<!DOCTYPE html><html><head><title>tuvweb01.variables</title></head><body><pre>                                 ALIASES :
                                     ALL : all
                              DUMMY_VAR2 :
                                    FQDN : .+
                                    HOST : tuvweb01
                                  HOSTNR : 01
           INSTALL_PROTECTION_DEPENDENCY : hostname-<strong title="HOST">tuvweb01</strong>
                                      IP : .+
                                     LOC : tuv
                                  LOCTYP : tuvweb
                                OVERRIDE : all
                                REVISION : 2
                                RPM_NAME : tuvweb01
                            RPM_PROVIDES : typ-web-provides, all-prov, all-prov2, all-prov3
                            RPM_REQUIRES : all-req2, all-req, ty-web-requirement
                  RPM_REQUIRES_NON_REPOS : all-req2, all-req, ty-web-requirement
                      RPM_REQUIRES_REPOS :
                            SHORT_HOSTNR : 1
                                     TYP : web
</pre></body></html>""")

        self.assert_config_viewer_file(
            'tuvweb01', join('files', 'override'),
            "<!DOCTYPE html><html><head><title>override</title></head><body><pre>all</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'tuvweb01', join('VARIABLES', 'LOC'),
            "<!DOCTYPE html><html><head><title>LOC</title></head><body><pre>tuv</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'tuvweb01', join('VARIABLES', 'LOCTYP'),
            "<!DOCTYPE html><html><head><title>LOCTYP</title></head><body><pre>tuvweb</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'tuvweb01', join('VARIABLES', 'OVERRIDE'),
            "<!DOCTYPE html><html><head><title>OVERRIDE</title></head><body><pre>all</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'tuvweb01', join('VARIABLES', 'RPM_PROVIDES'),
            "<!DOCTYPE html><html><head><title>RPM_PROVIDES</title></head><body><pre>typ-web-provides, all-prov, all-prov2, all-prov3</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'tuvweb01', join('VARIABLES', 'RPM_REQUIRES'),
            "<!DOCTYPE html><html><head><title>RPM_REQUIRES</title></head><body><pre>all-req2, all-req, ty-web-requirement</pre></body></html>"
        )
        self.assert_config_viewer_file(
            'tuvweb01', join('VARIABLES', 'RPM_REQUIRES_NON_REPOS'),
            "<!DOCTYPE html><html><head><title>RPM_REQUIRES_NON_REPOS</title></head><body><pre>all-req2, all-req, ty-web-requirement</pre></body></html>"
        )
        self.assert_config_viewer_file('tuvweb01',
                                       join('VARIABLES', 'RPM_REQUIRES_REPOS'),
                                       "")
        self.assert_config_viewer_file(
            'tuvweb01', join('vars', 'override'),
            '''<!DOCTYPE html><html><head><title>override</title></head><body><pre><strong title="OVERRIDE">all</strong></pre></body></html>'''
        )
    def setUp(self):

        self.mock_svn_service = Mock()
        self.config_rpm_maker = ConfigRpmMaker('123', self.mock_svn_service)
    def test_should_not_do_anything_if_no_hosts_are_given(self, mock_move, mock_rmtree):

        ConfigRpmMaker._move_configviewer_dirs_to_final_destination(self.mock_config_rpm_maker, [])

        self.assert_mock_never_called(mock_move)
        self.assert_mock_never_called(mock_rmtree)