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)
def test_should_return_tuples_of_svn_path_and_the_affected_file(self): service = SvnService(self.repo_url, None, None, path_to_config=get_svn_path_to_config()) expected_elements = [('host/berweb01', 'VARIABLES'), ('host/berweb01', 'VARIABLES/RPM_REQUIRES'), ('host/berweb01', 'symlinks'), ('host/berweb01', 'symlinks/link1.%symlink')] actual_elements = service.export('host/berweb01', 'target/tmp/test', 2) self.assertEqual(sorted(expected_elements), sorted(actual_elements))
def test_should_return_changed_paths(self): service = SvnService(self.repo_url, None, None, path_to_config=get_svn_path_to_config()) self.assertEqual(['typ/web/data/index.html'], service.get_changed_paths(2))
def test_should_return_by_change_set_affected_hosts(self): service = SvnService(self.repo_url, None, None, path_to_config=get_svn_path_to_config()) self.assertEqual(['berweb01', 'devweb00', 'devweb01', 'tuvweb01'], service.get_hosts(2))
def test_should_return_exactly_one_svn_log(self): service = SvnService(self.repo_url, None, None, path_to_config=get_svn_path_to_config()) logs = service.log('', 2, 5) self.assertEqual(1, len(logs))
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)
def test_should_return_tuples_of_svn_path_and_the_affected_file(self): service = SvnService(self.repo_url, None, None, path_to_config=get_svn_path_to_config()) self.assertEqual([('host/berweb01', 'VARIABLES'), ('host/berweb01', 'VARIABLES/RPM_REQUIRES'), ('host/berweb01', 'symlinks'), ('host/berweb01', 'symlinks/link1.%symlink')], service.export('host/berweb01', 'target/tmp/test', 2))
def test_should_not_include_files_outside_config_directory(self): mock_svn_service = Mock(SvnService) mock_svn_service.config_url = 'svn://url/for/configuration/repository' mock_svn_service.path_to_config = '/config' mock_svn_service.client = Mock() mock_info = Mock() mock_path_object_1 = Mock() mock_path_object_1.path = '/config/foo' mock_path_object_1.action = 'A' mock_path_object_2 = Mock() mock_path_object_2.path = '/XXXXXX/bar' mock_path_object_2.action = 'A' mock_path_object_3 = Mock() mock_path_object_3.path = '/XXX/foobar' mock_path_object_3.action = 'A' mock_info.changed_paths = [mock_path_object_1, mock_path_object_2, mock_path_object_3] mock_svn_service.get_logs_for_revision.return_value = [mock_info] actual = SvnService.get_changed_paths_with_action(mock_svn_service, '1980') self.assertEqual([('foo', 'A')], actual)
def test_should_return_list_with_tuples_including_one_tuple_which_has_a_delete_action( self): mock_svn_service = Mock(SvnService) mock_svn_service.config_url = 'svn://url/for/configuration/repository' mock_svn_service.path_to_config = '/config' mock_svn_service.client = Mock() mock_info = Mock() mock_path_object_1 = Mock() mock_path_object_1.path = '/config/' mock_path_object_1.action = 'A' mock_info.changed_paths = [mock_path_object_1] mock_path_object_2 = Mock() mock_path_object_2.path = '/config/spam.egg' mock_path_object_2.action = 'A' mock_path_object_3 = Mock() mock_path_object_3.path = '/config/foo.bar' mock_path_object_3.action = 'D' mock_info.changed_paths = [ mock_path_object_1, mock_path_object_2, mock_path_object_3 ] mock_svn_service.get_logs_for_revision.return_value = [mock_info] actual = SvnService.get_changed_paths_with_action( mock_svn_service, '1980') self.assertEqual([('', 'A'), ('spam.egg', 'A'), ('foo.bar', 'D')], actual)
def test_should_return_empty_list_empty_when_configuration_directory_has_been_created_in_commit(self): mock_svn_service = Mock(SvnService) mock_svn_service.get_changed_paths_with_action.return_value = [('', 'A')] actual = SvnService.get_deleted_paths(mock_svn_service, '1980') self.assertEqual([], actual)
def test_should_return_list_with_directory_name_and_path_to_file_when_a_file_has_been_added(self): mock_svn_service = Mock(SvnService) mock_svn_service.get_changed_paths_with_action.return_value = [('spam.egg', 'D')] actual = SvnService.get_deleted_paths(mock_svn_service, '1980') self.assertEqual(['spam.egg'], actual)
def test_should_only_return_list_with_directory_name_and_path_to_file_when_several_files_have_been_added_and_deleted(self): mock_svn_service = Mock(SvnService) mock_svn_service.get_changed_paths_with_action.return_value = [('', 'A'), ('example', 'D'), ('foo.bar', 'A'), ('spam.egg', 'D'), ('test/123', 'A')] actual = SvnService.get_deleted_paths(mock_svn_service, '1980') self.assertEqual(['example', 'spam.egg'], actual)
def create_svn_service_queue(self): svn_service = SvnService(base_url=self.repo_url, username=None, password=None, path_to_config=get_svn_path_to_config()) svn_service_queue = Queue() svn_service_queue.put(svn_service) return svn_service_queue
def test_should_raise_SvnServiceException_when_invalid_revision_is_given( self): service = SvnService(self.repo_url, None, None, path_to_config=get_svn_path_to_config()) self.assertRaises(SvnServiceException, service.get_changed_paths, 13)
def test_should_return_logs_for_revision(self): mock_svn_service = Mock(SvnService) mock_svn_service.base_url = 'svn://url/for/configuration/repository' mock_svn_service.path_to_config = '/config' mock_svn_service.client = Mock() mock_logs = Mock() mock_svn_service.client.log.return_value = mock_logs actual = SvnService.get_logs_for_revision(mock_svn_service, '1980') self.assertEqual(mock_logs, actual)
def test_should_return_list_with_empty_string_and_action_string_when_configuration_directory_has_been_created_in_commit(self): mock_svn_service = Mock(SvnService) mock_svn_service.config_url = 'svn://url/for/configuration/repository' mock_svn_service.path_to_config = '/config' mock_info = Mock() mock_path_object = Mock() mock_path_object.path = '/config/' mock_path_object.action = 'A' mock_info.changed_paths = [mock_path_object] mock_svn_service.get_logs_for_revision.return_value = [mock_info] actual = SvnService.get_changed_paths_with_action(mock_svn_service, '1980') self.assertEqual([('', 'A')], actual)
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_ensure_that_all_returned_host_names_are_ordinary_strings(self): mock_svn_service = Mock(SvnService) mock_svn_service.config_url = '/path to repository/config' mock_svn_service.client = Mock() item0 = Mock() item0.repos_path = "get_hosts removes the first element - so this will never show up" item1 = Mock() item1.repos_path = "bar" item2 = Mock() item2.repos_path = u"spam" mock_svn_service.client.list.return_value = [(item0,), (item1,), (item2,)] actual_host_names = SvnService.get_hosts(mock_svn_service, 123) self.assert_is_ordinary_string(actual_host_names[0]) self.assert_is_ordinary_string(actual_host_names[1])
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'))
def test_should_return_list_with_directory_name_and_action_for_path_to_file_when_a_file_has_been_added(self): mock_svn_service = Mock(SvnService) mock_svn_service.config_url = 'svn://url/for/configuration/repository' mock_svn_service.path_to_config = '/config' mock_svn_service.client = Mock() mock_info = Mock() mock_path_object_1 = Mock() mock_path_object_1.path = '/config/' mock_path_object_1.action = 'A' mock_info.changed_paths = [mock_path_object_1] mock_path_object_2 = Mock() mock_path_object_2.path = '/config/spam.egg' mock_path_object_2.action = 'A' mock_info.changed_paths = [mock_path_object_1, mock_path_object_2] mock_svn_service.get_logs_for_revision.return_value = [mock_info] actual = SvnService.get_changed_paths_with_action(mock_svn_service, '1980') self.assertEqual([('', 'A'), ('spam.egg', 'A')], actual)
def test_should_return_list_with_tuples_including_one_tuple_which_has_a_delete_action(self): mock_svn_service = Mock(SvnService) mock_svn_service.config_url = 'svn://url/for/configuration/repository' mock_svn_service.path_to_config = '/config' mock_svn_service.client = Mock() mock_info = Mock() mock_path_object_1 = Mock() mock_path_object_1.path = '/config/' mock_path_object_1.action = 'A' mock_info.changed_paths = [mock_path_object_1] mock_path_object_2 = Mock() mock_path_object_2.path = '/config/spam.egg' mock_path_object_2.action = 'A' mock_path_object_3 = Mock() mock_path_object_3.path = '/config/foo.bar' mock_path_object_3.action = 'D' mock_info.changed_paths = [mock_path_object_1, mock_path_object_2, mock_path_object_3] mock_svn_service.get_logs_for_revision.return_value = [mock_info] actual = SvnService.get_changed_paths_with_action(mock_svn_service, '1980') self.assertEqual([('', 'A'), ('spam.egg', 'A'), ('foo.bar', 'D')], actual)
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 _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)