Merge pull request #312 from SUSE/derived_container_source_locators

Derived container source locators
This commit is contained in:
Marcus Schäfer 2017-04-26 16:44:17 +02:00 committed by GitHub
commit 1b082f9fee
3 changed files with 50 additions and 14 deletions

View File

@ -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
@ -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])
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,15 +219,29 @@ class Uri(object):
)
return obs_distribution
def _suse_buildservice_path(self, name):
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.
"""
return self._local_path(
'/usr/src/packages/SOURCES/repos/' + name
)
bs_source_dir = '/usr/src/packages/SOURCES'
if self.repo_type == 'container':
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 = os.sep.join(
[bs_source_dir, 'repos', name]
)
return self._local_path(local_path)
def __del__(self):
for mount in reversed(self.mount_stack):

View File

@ -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):
"""

View File

@ -131,6 +131,16 @@ 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'
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')