From cd8ec243ad8edb3b572e622c54363826c51500b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Sch=C3=A4fer?= Date: Tue, 25 Apr 2017 15:25:04 +0200 Subject: [PATCH 1/3] Use urlparse to detect uri scheme The source location postfix can contain several different formats e.g :/, or :// or even just :, python's urlparse is able to cope with all that which allows to work with the url scheme base name and thus makes handling this code more robust --- kiwi/xml_state.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/kiwi/xml_state.py b/kiwi/xml_state.py index 313b02c8..9cf69c1f 100644 --- a/kiwi/xml_state.py +++ b/kiwi/xml_state.py @@ -19,6 +19,7 @@ import re import copy import platform from collections import namedtuple +from six.moves.urllib.parse import urlparse # project from . import xml_parse @@ -1129,30 +1130,32 @@ class XMLState(object): def translate_obs_to_ibs_repositories(self): """ - Change obs:// repotype to ibs:// type + Change obs repotype to ibs type This will result in pointing to build.suse.de instead of build.opensuse.org """ for repository in self.get_repository_sections(): source_path = repository.get_source() - if 'obs://' in source_path.get_path(): + source_uri = urlparse(source_path.get_path()) + if source_uri.scheme == 'obs': source_path.set_path( - source_path.get_path().replace('obs://', 'ibs://') + source_path.get_path().replace('obs:', 'ibs:') ) def translate_obs_to_suse_repositories(self): """ - Change obs:// repotype to suse:// type + Change obs: repotype to suse: type This will result in a local repo path suitable for a buildservice worker instance """ for repository in self.get_repository_sections(): source_path = repository.get_source() - if 'obs://' in source_path.get_path(): + source_uri = urlparse(source_path.get_path()) + if source_uri.scheme == 'obs': source_path.set_path( - source_path.get_path().replace('obs://', 'suse://') + source_path.get_path().replace('obs:', 'suse:') ) def set_repository(self, repo_source, repo_type, repo_alias, repo_prio): @@ -1504,7 +1507,7 @@ class XMLState(object): """ derived_image = self.build_type.get_derived_from() if derived_image: - return Uri(derived_image) + return Uri(derived_image, repo_type='container') def _used_profiles(self, profiles=None): """ From f58d96ea6c3260d9b6334ef8151030ab786300cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Sch=C3=A4fer?= Date: Tue, 25 Apr 2017 15:28:38 +0200 Subject: [PATCH 2/3] Implement obs source on derived_from The following reference to a derived container: obs:/project/repo/container#tag Will be translated into the following buildservice local path: /usr/src/packages/SOURCES/containers/project/repo/container#tag --- kiwi/system/uri.py | 20 ++++++++++++++------ test/unit/system_uri_test.py | 5 +++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/kiwi/system/uri.py b/kiwi/system/uri.py index 996aebe1..3f1a6e9f 100644 --- a/kiwi/system/uri.py +++ b/kiwi/system/uri.py @@ -46,7 +46,7 @@ class Uri(object): URI, repository location, file * :attr:`repo_type` - repository type name, rpm-dir, rpm-md, yast2 + repository type name, rpm-dir, rpm-md, yast2, container * :attr:`mount_stack` list of mounted locations @@ -111,7 +111,7 @@ class Uri(object): return self._iso_mount_path(uri.path) elif uri.scheme == 'suse': return self._suse_buildservice_path( - ''.join([uri.netloc, uri.path]) + ''.join([uri.netloc, uri.path]), uri.fragment ) elif uri.scheme == 'http' or uri.scheme == 'https' or uri.scheme == 'ftp': return ''.join([uri.scheme, '://', uri.netloc, uri.path]) @@ -210,15 +210,23 @@ class Uri(object): ) return obs_distribution - def _suse_buildservice_path(self, name): + def _suse_buildservice_path(self, name, fragment=None): """ Special to openSUSE buildservice. If the buildservice builds the image it arranges the repos for each build in a special environment, the so called build worker. """ - return self._local_path( - '/usr/src/packages/SOURCES/repos/' + name - ) + if self.repo_type == 'container': + local_path = ''.join( + ['/usr/src/packages/SOURCES/containers/', name] + ) + if fragment: + local_path = ''.join([local_path, '#', fragment]) + else: + local_path = ''.join( + ['/usr/src/packages/SOURCES/repos/', name] + ) + return self._local_path(local_path) def __del__(self): for mount in reversed(self.mount_stack): diff --git a/test/unit/system_uri_test.py b/test/unit/system_uri_test.py index 520f885c..c78aa8de 100644 --- a/test/unit/system_uri_test.py +++ b/test/unit/system_uri_test.py @@ -131,6 +131,11 @@ class TestUri(object): assert uri.translate() == \ '/usr/src/packages/SOURCES/repos/openSUSE:13.2/standard' + def test_translate_suse_buildservice_container_path(self): + uri = Uri('suse://project/repo/container#latest', 'container') + assert uri.translate() == \ + '/usr/src/packages/SOURCES/containers/project/repo/container#latest' + @patch('kiwi.system.uri.MountManager') @patch('kiwi.system.uri.mkdtemp') @patch('kiwi.system.uri.Path.wipe') From 9487a189ed3a7a1cd8b91abd7daed18a8e78b0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Sch=C3=A4fer?= Date: Tue, 25 Apr 2017 17:41:01 +0200 Subject: [PATCH 3/3] Implement obsrepositories source on derived_from The following reference to a derived container: obsrepositories:/container#latest Will be translated into the following buildservice local path: /usr/src/packages/SOURCES/containers/_obsrepositories/container#latest --- kiwi/system/uri.py | 31 +++++++++++++++++++++++-------- test/unit/system_uri_test.py | 5 +++++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/kiwi/system/uri.py b/kiwi/system/uri.py index 3f1a6e9f..b9b95cbc 100644 --- a/kiwi/system/uri.py +++ b/kiwi/system/uri.py @@ -73,7 +73,8 @@ class Uri(object): 'iso': True, 'dir': True, 'file': True, - 'suse': True + 'suse': True, + 'obsrepositories': True } def translate(self): @@ -99,6 +100,12 @@ class Uri(object): return self._obs_project( ''.join([uri.netloc, uri.path]) ) + elif uri.scheme == 'obsrepositories': + return self._suse_buildservice_path( + name=''.join([uri.netloc, uri.path]), + fragment=uri.fragment, + urischeme=uri.scheme + ) elif uri.scheme == 'ibs': return self._ibs_project( ''.join([uri.netloc, uri.path]) @@ -111,7 +118,9 @@ class Uri(object): return self._iso_mount_path(uri.path) elif uri.scheme == 'suse': return self._suse_buildservice_path( - ''.join([uri.netloc, uri.path]), uri.fragment + name=''.join([uri.netloc, uri.path]), + fragment=uri.fragment, + urischeme=uri.scheme ) elif uri.scheme == 'http' or uri.scheme == 'https' or uri.scheme == 'ftp': return ''.join([uri.scheme, '://', uri.netloc, uri.path]) @@ -210,21 +219,27 @@ class Uri(object): ) return obs_distribution - def _suse_buildservice_path(self, name, fragment=None): + def _suse_buildservice_path(self, name, urischeme, fragment=None): """ Special to openSUSE buildservice. If the buildservice builds the image it arranges the repos for each build in a special environment, the so called build worker. """ + bs_source_dir = '/usr/src/packages/SOURCES' if self.repo_type == 'container': - local_path = ''.join( - ['/usr/src/packages/SOURCES/containers/', name] - ) + if urischeme == 'obsrepositories': + local_path = os.sep.join( + [bs_source_dir, 'containers/_obsrepositories', name] + ) + else: + local_path = os.sep.join( + [bs_source_dir, 'containers', name] + ) if fragment: local_path = ''.join([local_path, '#', fragment]) else: - local_path = ''.join( - ['/usr/src/packages/SOURCES/repos/', name] + local_path = os.sep.join( + [bs_source_dir, 'repos', name] ) return self._local_path(local_path) diff --git a/test/unit/system_uri_test.py b/test/unit/system_uri_test.py index c78aa8de..7f9eef9f 100644 --- a/test/unit/system_uri_test.py +++ b/test/unit/system_uri_test.py @@ -136,6 +136,11 @@ class TestUri(object): assert uri.translate() == \ '/usr/src/packages/SOURCES/containers/project/repo/container#latest' + def test_translate_buildservice_obsrepositories_container_path(self): + uri = Uri('obsrepositories:/container#latest', 'container') + assert uri.translate() == \ + '/usr/src/packages/SOURCES/containers/_obsrepositories/container#latest' + @patch('kiwi.system.uri.MountManager') @patch('kiwi.system.uri.mkdtemp') @patch('kiwi.system.uri.Path.wipe')