def create_test_project(develproject, testproject): repo_metadata = """ <project name="%(testproject)s"> <title>Autogenerated CI project</title> <description/> <link project="%(develproject)s"/> <person userid="opensuseapibmw" role="maintainer"/> <publish> <enable repository="standard"/> </publish> <repository name="standard" rebuild="direct" block="local" linkedbuild="localdep"> <path project="%(develproject)s" repository="SLE_12_SP3"/> <arch>x86_64</arch> </repository> </project> """ % {'testproject': testproject, 'develproject': develproject} with tempfile.NamedTemporaryFile() as meta: meta.write(repo_metadata) meta.flush() print("Creating test project %s linked to devel project %s" % (testproject, develproject)) sh.osc('-A', 'https://api.suse.de', 'api', '-T', meta.name, '/source/%s/_meta' % testproject) return testproject
def wait_for_package(self, package): """ Wait for a particular package to complete building """ print("Waiting for %s to build" % package.name) # cd into the checked out package with cd(os.path.join(self.obs_test_project_name, package.name)): while 'unknown' in sh.osc('results'): print("Waiting for build to be scheduled") time.sleep(3) print("Waiting for build results") for attempt in range(3): results = sh.osc('results', '--watch') print("Build results: %s" % results) if 'broken' in results: # Sometimes results --watch ends too soon, give it a few # retries before actually failing print("Sleeping for 10s before rechecking") time.sleep(10) continue else: break if 'succeeded' not in results: print("Package build failed.") return False return True
def _create_test_project(self): repo_metadata = """ <project name="%(obs_test_project_name)s"> <title>Autogenerated CI project</title> <description> %(obs_project_description)s </description> <link project="%(obs_linked_project)s"/> <person userid="opensuseapibmw" role="maintainer"/> <publish> <enable repository="standard"/> </publish> <repository name="standard" rebuild="direct" block="local" linkedbuild="localdep"> <path project="%(obs_linked_project)s" repository="%(obs_repository)s"/> <arch>x86_64</arch> </repository> </project> """ % { 'obs_test_project_name': self.obs_test_project_name, 'obs_linked_project': self.obs_linked_project, 'obs_repository': self.obs_repository, 'obs_project_description': self.obs_project_description } with tempfile.NamedTemporaryFile() as meta: meta.write(repo_metadata) meta.flush() print("Creating test project %s linked to project %s" % (self.obs_test_project_name, self.obs_linked_project)) sh.osc('-A', 'https://api.suse.de', 'api', '-T', meta.name, '/source/%s/_meta' % self.obs_test_project_name) sh.osc('-A', 'https://api.suse.de', 'deleterequest', self.obs_test_project_name, '--accept-in-hours', 720, '-m', 'Auto delete after 30 days.')
def osc_mkpac(workdir, packagename): olddir = os.getcwd() try: os.chdir(workdir) sh.osc('mkpac', packagename) finally: os.chdir(olddir)
def _create_test_project(self): repo_metadata = """ <project name="%(obs_test_project_name)s"> <title>Autogenerated CI project</title> <description/> <link project="%(obs_linked_project)s"/> <person userid="opensuseapibmw" role="maintainer"/> <publish> <enable repository="standard"/> </publish> <repository name="standard" rebuild="direct" block="local" linkedbuild="localdep"> <path project="%(obs_linked_project)s" repository="%(obs_repository)s"/> <arch>x86_64</arch> </repository> </project> """ % { 'obs_test_project_name': self.obs_test_project_name, 'obs_linked_project': self.obs_linked_project, 'obs_repository': self.obs_repository } with tempfile.NamedTemporaryFile() as meta: meta.write(repo_metadata) meta.flush() print("Creating test project %s linked to project %s" % (self.obs_test_project_name, self.obs_linked_project)) sh.osc('-A', 'https://api.suse.de', 'api', '-T', meta.name, '/source/%s/_meta' % self.obs_test_project_name)
def upload_meta(project, build_repository, linkproject): projectlink = '' if linkproject: projectlink = '<link project="%s"/>\n' % linkproject description = '' if linkproject: if 'ZUUL_UUID' in os.environ: description = """ This project tests the following Zuul Change IDs: %(ZUUL_CHANGE_IDS)s\n Branch used: %(ZUUL_BRANCH)s\n Project used: %(ZUUL_PROJECT)s """ % (os.environ) templ = """ <project name="%(project)s"> <title>Autogenerated CI project</title> <description> %(description)s </description> <url> %(url)s </url> %(projectlink)s <person userid="%(user)s" role="maintainer"/> <publish> <disable/> </publish> %(build_repository)s </project>""" % ({'project': project, 'user': get_osc_user(), 'description': description, 'url': os.environ.get('BUILD_URL'), 'projectlink': projectlink, 'build_repository': build_repository}) with tempfile.NamedTemporaryFile() as meta: meta.write(templ) meta.flush() print('Updating meta for ', project) # work around build service bug that forgets the publish flag # https://github.com/openSUSE/open-build-service/issues/7126 for success_counter in range(2): # work around build service bug that triggers a database deadlock for fail_counter in range(1, 5): try: sh.osc('api', '-T', meta.name, '/source/%s/_meta' % project) break except sh.ErrorReturnCode_1: # Sleep a bit and try again. This has not been scientifically # proven to be the correct sleep factor, but it seems to work time.sleep(2) continue # wait for the source service to catch up with creation if success_counter == 0: # Sleep a bit and try again. This has not been scientifically # proven to be the correct sleep factor, but it seems to work time.sleep(3)
def create_package(pypi_name, version, url, git_url): obs_name = 'python-%s-source' % pypi_name try: create_package_(pypi_name, version, url, git_url) except: print('exception, deleting: ', obs_name) sh.rm('-rf', obs_name) sh.osc('rm', obs_name)
def osc_commit_all(workdir, packagename): olddir = os.getcwd() try: os.chdir(os.path.join(workdir, packagename)) sh.osc('addremove') sh.osc('commit', '--noservice', '-n') finally: os.chdir(olddir)
def wait_for_build(): print("Waiting for build to be scheduled") while 'unknown' in sh.osc('results'): time.sleep(3) print("Waiting for build results") results = sh.osc('results', '--watch') if 'succeeded' not in results: print("Build results: %s" % results) print("Package build failed.") sys.exit(1)
def create_new_build_project(workdir, project, linkproject): sh.mkdir('-p', workdir) olddir = os.getcwd() try: os.chdir(workdir) if linkproject: upload_meta_enable_repository(project, linkproject) sh.osc('init', project) finally: os.chdir(olddir)
def spec_is_modified(pkgoutdir, project, pkgname): specname = pkgname + ".spec" cached_spec = os.path.join(pkgoutdir, '.osc', specname) cleanup = False if not os.path.exists(cached_spec): cleanup = True sh.osc('api', '/source/%s/%s/%s.spec' % ( project, pkgname, pkgname), _out=cached_spec) r = sh.cmp( '-s', os.path.join(pkgoutdir, specname), cached_spec, _ok_code=[0, 1]) if cleanup: os.remove(cached_spec) return r.exit_code == 1
def upload_meta(project, build_repository, linkproject): projectlink = '' if linkproject: projectlink = '<link project="%s"/>\n' % linkproject description = '' if linkproject: if 'ZUUL_UUID' in os.environ: description = """ This project tests the following Zuul Change IDs: %(ZUUL_CHANGE_IDS)s\n Branch used: %(ZUUL_BRANCH)s\n Project used: %(ZUUL_PROJECT)s """ % (os.environ) templ = """ <project name="%(project)s"> <title>Autogenerated CI project</title> <description> %(description)s </description> %(projectlink)s <person userid="%(user)s" role="maintainer"/> <publish> <disable/> </publish> %(build_repository)s </project>""" % ({ 'project': project, 'user': get_osc_user(), 'description': description, 'projectlink': projectlink, 'build_repository': build_repository }) with tempfile.NamedTemporaryFile(delete=False) as meta: meta.write(templ) print('Updating meta for ', project) meta.close() # work around build service bug that triggers a database deadlock for fail_counter in range(1, 5): try: sh.osc('api', '-T', meta.name, '/source/%s/_meta' % project) break except sh.ErrorReturnCode_1: # Sleep a bit and try again. This has not been scientifically # proven to be the correct sleep factor, but it seems to work time.sleep(2) continue os.unlink(meta.name)
def upload_meta(project, build_repository, linkproject): projectlink = '' if linkproject: projectlink = '<link project="%s"/>\n' % linkproject description = '' if linkproject: if 'ZUUL_UUID' in os.environ: description = """ This project tests the following Zuul Change IDs: %(ZUUL_CHANGE_IDS)s\n Branch used: %(ZUUL_BRANCH)s\n Project used: %(ZUUL_PROJECT)s """ % (os.environ) templ = """ <project name="%(project)s"> <title>Autogenerated CI project</title> <description> %(description)s </description> %(projectlink)s <person userid="%(user)s" role="maintainer"/> <publish> <disable/> </publish> %(build_repository)s </project>""" % ({'project': project, 'user': get_osc_user(), 'description': description, 'projectlink': projectlink, 'build_repository': build_repository}) with tempfile.NamedTemporaryFile(delete=False) as meta: meta.write(templ) print('Updating meta for ', project) meta.close() # work around build service bug that triggers a database deadlock for fail_counter in range(1, 5): try: sh.osc('api', '-T', meta.name, '/source/%s/_meta' % project) break except sh.ErrorReturnCode_1: # Sleep a bit and try again. This has not been scientifically # proven to be the correct sleep factor, but it seems to work time.sleep(2) continue os.unlink(meta.name)
def create_project(worktree, project, linkproject): workdir = os.path.join(os.getcwd(), 'out') sh.rm('-rf', workdir) create_new_build_project(workdir, project, linkproject) try: existing_pkgs = [ x.strip() for x in sh.osc('ls', '-e', project, _iter=True) ] except Exception: existing_pkgs = [] alive_pkgs = set() worktree_pattern = os.path.join(worktree, 'openstack', '*', '*.spec.j2') for spectemplate in sorted(glob.glob(worktree_pattern)): pkgname = pymodule2pkg(spectemplate) alive_pkgs.add(pkgname) print(pkgname) sys.stdout.flush() pkgoutdir = os.path.join(workdir, pkgname) osc_mkpac(workdir, pkgname) copy_extra_sources(os.path.dirname(spectemplate), pkgoutdir) generate_pkgspec(pkgoutdir, spectemplate, pkgname) if pkgname in existing_pkgs: if spec_is_modified(pkgoutdir, project, pkgname): osc_detachbranch(workdir, project, pkgname) print("Committing update to %s" % pkgname) osc_commit_all(workdir, pkgname) else: print("Adding new pkg %s" % pkgname) osc_commit_all(workdir, pkgname) if not alive_pkgs: print("Worktree does not contain any packages?") sys.exit(1) # remove no longer alive pkgs for i in existing_pkgs: if not linkproject and i not in alive_pkgs: print("Removing outdated ", i) sh.osc('rdelete', '-m', 'x', project, i)
def create_project(worktree, project, linkproject): workdir = os.path.join(os.getcwd(), 'out') sh.rm('-rf', workdir) create_new_build_project(workdir, project, linkproject) try: existing_pkgs = [x.strip() for x in sh.osc('ls', '-e', project, _iter=True)] except: existing_pkgs = [] alive_pkgs = set() worktree_pattern = os.path.join(worktree, 'openstack', '*', '*.spec.j2') for spectemplate in sorted(glob.glob(worktree_pattern)): pkgname = pymodule2pkg(spectemplate) alive_pkgs.add(pkgname) print(pkgname) sys.stdout.flush() pkgoutdir = os.path.join(workdir, pkgname) osc_mkpac(workdir, pkgname) copy_extra_sources(os.path.dirname(spectemplate), pkgoutdir) generate_pkgspec( pkgoutdir, os.path.join(worktree, 'global-requirements.txt'), spectemplate, pkgname) if pkgname in existing_pkgs: if spec_is_modified(pkgoutdir, project, pkgname): osc_detachbranch(workdir, project, pkgname) print("Committing update to %s" % pkgname) osc_commit_all(workdir, pkgname) else: print("Adding new pkg %s" % pkgname) osc_commit_all(workdir, pkgname) # remove no longer alive pkgs for i in existing_pkgs: if not linkproject and i not in alive_pkgs: print("Removing outdated ", i) sh.osc('rdelete', '-m', 'x', project, i)
def osc_detachbranch(workdir, project, pkgname): olddir = os.getcwd() try: os.chdir(os.path.join(workdir)) sh.osc('detachbranch', project, pkgname) os.mkdir(pkgname + '.b') for f in glob.glob(os.path.join(pkgname, '*')): os.rename(f, os.path.join(pkgname + '.b', os.path.basename(f))) sh.rm('-rf', pkgname) sh.osc('co', pkgname) for f in glob.glob(os.path.join(pkgname + '.b', '*')): dst = os.path.basename(f) try: os.unlink(os.path.join(pkgname, dst)) except OSError: pass os.rename(f, os.path.join(pkgname, dst)) os.rmdir(pkgname + '.b') finally: os.chdir(olddir)
def wait_for_build(change, testproject): package_name = project_map()[change.project] print("Waiting for %s to build" % package_name) with cd('%s/%s' % (testproject, package_name)): while 'unknown' in sh.osc('results'): print("Waiting for build to be scheduled") time.sleep(3) print("Waiting for build results") for attempt in range(3): results = sh.osc('results', '--watch') print("Build results: %s" % results) if 'broken' in results: # Sometimes results --watch ends too soon, give it a few # retries before actually failing print("Sleeping for 10s before rechecking") time.sleep(10) continue else: break if 'succeeded' not in results: print("Package build failed.") sys.exit(1)
def osc_commit_all(workdir, packagename): olddir = os.getcwd() try: os.chdir(os.path.join(workdir, packagename)) sh.osc('addremove') for o in sh.osc('service', 'localrun', 'source_validator'): if o.startswith('###ASK'): sh.osc('rm', o.strip().split()[1]) sh.osc('commit', '--noservice', '-n') finally: os.chdir(olddir)
def _create_test_project(self): repo_metadata = """ <project name="%(obs_test_project_name)s"> <title>Autogenerated CI project</title> <description> %(obs_project_description)s </description> <link project="%(obs_linked_project)s"/> <person userid="opensuseapibmw" role="maintainer"/> <publish> <enable repository="standard"/> </publish> <repository name="standard" rebuild="direct" block="local" linkedbuild="localdep"> <path project="%(obs_linked_project)s" repository="%(obs_repository)s"/> <arch>x86_64</arch> </repository> </project> """ % { 'obs_test_project_name': self.obs_test_project_name, 'obs_linked_project': self.obs_linked_project, 'obs_repository': self.obs_repository, 'obs_project_description': self.obs_project_description } with tempfile.NamedTemporaryFile(mode='w+') as meta: meta.write(repo_metadata) meta.flush() print("Creating test project %s linked to project %s" % (self.obs_test_project_name, self.obs_linked_project)) sh.osc('-A', 'https://api.suse.de', 'api', '-T', meta.name, '/source/%s/_meta' % self.obs_test_project_name) # The '--all' parameter is required starting with v0.164.0 osc_version = int(sh.osc('--version').strip().split('.')[1]) sh.osc('-A', 'https://api.suse.de', 'deleterequest', self.obs_test_project_name, '--accept-in-hours', 720, '-m', 'Auto delete after 30 days.', '--all' if osc_version > 163 else '')
def wrapped_f(project, osc_filename=None, package=None, osc_data=None): if osc_data: return find_func(project, osc_data) osc_data = sh.osc('-A', 'https://api.suse.de', 'cat', project.obs_linked_project, package.name, osc_filename) osc_data_item = find_func(project, str(osc_data)) if not osc_data_item: raise ValueError( "Could not find a %s in " "https://build.suse.de/package/view_file/%s/%s/%s" % (description, project.obs_linked_project, package.name, osc_filename)) return osc_data_item
def wrapped_f(project, osc_filename=None, package=None, osc_data=None): if osc_data: return find_func(project, osc_data) osc_data = sh.osc( '-A', 'https://api.suse.de', 'cat', project.obs_linked_project, package.name, osc_filename) osc_data_item = find_func(project, str(osc_data)) if not osc_data_item: raise ValueError( "Could not find a %s in " "https://build.suse.de/package/view_file/%s/%s/%s" % (description, project.obs_linked_project, package.name, osc_filename)) return osc_data_item
def add_test_package(self, package): """ Create a package in the OBS Project - Copy the given package into the OBS Project - Update the service file to use the local git checkout of the package source - Grab the local source - Commit the package to be built into the project """ print("Creating test package %s" % package.name) # Clean up any checkouts from previous builds cleanup_path(os.path.join(self.obs_test_project_name, package.name)) # Copy the package from the upstream project into our teste project sh.osc('-A', 'https://api.suse.de', 'copypac', '--keep-link', self.obs_linked_project, package.name, self.obs_test_project_name) # Checkout the package from obs sh.osc('-A', 'https://api.suse.de', 'checkout', self.obs_test_project_name, package.name) # cd into the checked out package with cd(os.path.join(self.obs_test_project_name, package.name)): with open('_service', 'r+') as service_file: # Update the service file to use the git state in our workspace service_def = service_file.read() service_def = re.sub( r'<param name="url">.*</param>', '<param name="url">%s</param>' % package.source_dir, service_def) service_def = re.sub( r'<param name="revision">.*</param>', '<param name="revision">%s</param>' % package.test_branch, service_def) service_file.seek(0) service_file.write(service_def) service_file.truncate() # Run the osc service and commit the changes to OBS sh.osc('rm', glob.glob('%s*.obscpio' % package.name)) sh.osc('service', 'disabledrun') sh.osc('add', glob.glob('%s*.obscpio' % package.name)) sh.osc( 'commit', '-m', 'Testing gerrit changes applied to %s' % package.applied_change_numbers()) self.packages.add(package)
def create_package_(pypi_name, version, url, git_url): obs_name = 'python-%s-source' % pypi_name #if os.path.isdir(obs_name): # print('skipping', obs_name, git_url) # return args = { 'pypi_name': pypi_name, 'obs_name': obs_name, 'version': version, 'url': url, 'git_url': git_url } print(obs_name, version, git_url) sh.osc('mkpac', obs_name, _ok_code=[0, 1]) # FIXME rsa can only sdist on python2 # FIXME thrift has entrypoint at lib/py/setup.py # FIXME ovs has entrypoint at python/setup.py template = Template(open('create-packages-from-pip.spec.j2').read()) content = template.render(args) open('{0}/{0}.spec'.format(obs_name), 'w').write(content) sh.osc('add', '{0}/{0}.spec'.format(obs_name)) template = Template(open('create-packages-from-pip.changes.j2').read()) content = template.render(args) open('{0}/{0}.changes'.format(obs_name), 'w').write(content) sh.osc('add', '{0}/{0}.changes'.format(obs_name)) git_dir = '{0}/{1}'.format(obs_name, pypi_name) if not os.path.isdir(git_dir): sh.git('-C', obs_name, 'clone', git_url, pypi_name) git_version = version special_version = { 'flask_oslolog': { '0.1': 'master' }, 'openstack.nose_plugin': { '0.11': 'a1037419eff17e7a8c788e6d3051c00151154c31' }, 'enum-compat': { None: '0.0.2' }, 'uWSGI': { None: '2.0.18' }, 'rtslib-fb': { '2.1.69': 'v2.1.fb69' }, 'certifi': { '2019.6.16': '2019.06.16' }, 'requests-aws': { '0.1.8': '2181a74fcffc591dcc310346973475ae3a514f01' }, 'XStatic-angular-ui-router': { '0.3.1.2': 'd9b95b7ca2ad9ee603cf9457a364d780f680b8d5' }, # FIXME make a reimport from original hg or reconstruct from pypi as the below is not quite right 'Tempita': { '0.5.2': 'f9ac35a24fb2b9215663cbd7a7b4b6e26c0eacf7' }, # FIXME reverse from pypi tar as git repo doesn't have the newer tag nor versions in history 'gnocchiclient': { '7.0.5': '7.0.4' }, 'frozendict': { '1.2': '7566f29882ea42d10e46d0915f817c6c15b6de7d' }, 'beautifulsoup4': { '4.7.1': '0c1053d9ae093ea7db74c24ee29f430cc6fcae88' }, 'python-3parclient': { '4.2.9': '23200ddcbb41334c92df33eeaf5174eb79982d1a' }, 'XStatic-Hogan': { '2.0.0.2': '9e39977f6a6744810b08fa0323147e9f31dbd363' }, 'sphinxcontrib-serializinghtml': { '1.1.3': '422d9a5fbf748faa18d425d2e07167ece56fa245' }, 'snowballstemmer': { '1.9.0': '69ea0d05cdb5aeb073015912cf8e1d18e1d645a4' }, 'XStatic-JQuery-Migrate': { '1.2.1.1': '989b3b31106727542dd83810c3b952f90d8cdb8f' }, 'google-auth-httplib2': { '0.0.3': '73ca3ddd2a340128eb3a4109a8e7130fc1a07aef' }, 'XStatic-JQuery.quicksearch': { '2.0.3.1': 'f5221c8c30507340846d97d6db41a782e7c63316' }, } if pypi_name in special_version and version in special_version[ pypi_name]: git_version = special_version[pypi_name][version] version_formats = { '{0}', 'v{0}', 'version-{0}', 'release-{0}', 'release_{0}', 'release_v{0}', '{1}-{0}', 'underscore-for-dash', 'rel_underscore-for-dash', } for version_format in version_formats: test_version = version_format.format(git_version, pypi_name) if version_format is 'underscore-for-dash': test_version = re.sub('[.]', '_', git_version) elif version_format is 'rel_underscore-for-dash': test_version = 'rel_' + re.sub('[.]', '_', git_version) status = sh.git('-C', git_dir, 'rev-parse', test_version, _ok_code=[0, 128]) if 0 == status.exit_code: git_version = test_version break sh.git('-C', git_dir, 'checkout', '-b', version, git_version) # osc add for the git repo needs to run with cwd in the package, it doesn't work with cwd in the project sh.osc('add', pypi_name, _cwd=obs_name, _in='y\n')
def freeze_project(project): """Generate a _frozenlink file for the project""" result = sh.osc('api', '-X', 'POST', '/source/%s?cmd=freezelink' % project) if '<status code="ok" />' not in result: print('WARNING: freeze the project fails: %s' % result)
def add_test_package(self, package): """ Create a package in the OBS Project - Copy the given package into the OBS Project - Update the service file to use the local git checkout of the package source - Grab the local source - Commit the package to be built into the project """ if self.is_current(package): print( "Skipping %s as the inherited package is the same." % package.name) return print("Creating test package %s" % package.name) package.prep_workspace() # Clean up any checkouts from previous builds cleanup_path(os.path.join(self.obs_test_project_name, package.name)) # Copy the package from the upstream project into our teste project sh.osc('-A', 'https://api.suse.de', 'copypac', '--keep-link', self.obs_linked_project, package.name, self.obs_test_project_name) # Checkout the package from obs sh.osc('-A', 'https://api.suse.de', 'checkout', self.obs_test_project_name, package.name) # cd into the checked out package with cd(os.path.join(self.obs_test_project_name, package.name)): with open('_service', 'r+') as service_file: # Update the service file to use the git state in our workspace service_def = service_file.read() obsinfo_basename = self._get_obsinfo_basename( osc_data=service_def) service_def = re.sub( r'<param name="url">.*</param>', '<param name="url">%s</param>' % package.source_dir, service_def) service_def = re.sub( r'<param name="revision">.*</param>', '<param name="revision">%s</param>' % package.test_branch, service_def) service_file.seek(0) service_file.write(service_def) service_file.truncate() # Run the osc service and commit the changes to OBS sh.osc('rm', glob.glob('%s*.obscpio' % obsinfo_basename)) env = os.environ.copy() # TODO use proper api, once available from: # https://github.com/openSUSE/obs-service-tar_scm/issues/258 # Workaround to make obs_scm work with a local path. # Otherwise it only works with remote URLs. env['TAR_SCM_TESTMODE'] = '1' sh.osc('service', 'disabledrun', _env=env) sh.osc('add', glob.glob('%s*.obscpio' % obsinfo_basename)) sh.osc('commit', '-m', 'Testing gerrit changes applied to %s' % package.applied_change_numbers()) self.packages.add(package)
def create_test_package(change, develproject, testproject): package_name = project_map()[change.project] print("Creating test package %s" % package_name) sh.osc('-A', 'https://api.suse.de', 'copypac', '--keep-link', develproject, package_name, testproject) sh.osc('-A', 'https://api.suse.de', 'checkout', testproject, package_name) source_dir = '%s/source/%s.git' % (os.getcwd(), change.project) with cd('%s/%s' % (testproject, package_name)): with open('_service', 'r+') as service_file: service_def = service_file.read() service_def = re.sub(r'<param name="url">.*</param>', '<param name="url">%s</param>' % source_dir, service_def) service_def = re.sub(r'<param name="revision">.*</param>', '<param name="revision">test-merge</param>', service_def) service_file.seek(0) service_file.write(service_def) service_file.truncate() sh.osc('rm', glob.glob('%s*.obscpio' % package_name)) sh.osc('service', 'disabledrun') sh.osc('add', glob.glob('%s*.obscpio' % package_name)) sh.osc('commit', '-m', 'Testing change %s' % change.id) wait_for_build()
def add_test_package(self, package): """ Create a package in the OBS Project - Copy the given package into the OBS Project - Update the service file to use the local git checkout of the package source - Grab the local source - Commit the package to be built into the project """ if self.is_current(package): print("Skipping %s as the inherited package is the same." % package.name) return print("Creating test package %s" % package.name) package.prep_workspace() # Clean up any checkouts from previous builds cleanup_path(os.path.join(self.obs_test_project_name, package.name)) # Copy the package from the upstream project into our teste project sh.osc('-A', 'https://api.suse.de', 'copypac', '--keep-link', self.obs_linked_project, package.name, self.obs_test_project_name) # Checkout the package from obs sh.osc('-A', 'https://api.suse.de', 'checkout', self.obs_test_project_name, package.name) # cd into the checked out package with cd(os.path.join(self.obs_test_project_name, package.name)): with open('_service', 'r+') as service_file: # Update the service file to use the git state in our workspace service_def = service_file.read() obsinfo_basename = self._get_obsinfo_basename( osc_data=service_def) service_def = re.sub( r'<param name="url">.*</param>', '<param name="url">%s</param>' % package.source_dir, service_def) service_def = re.sub( r'<param name="revision">.*</param>', '<param name="revision">%s</param>' % package.test_branch, service_def) service_file.seek(0) service_file.write(service_def) service_file.truncate() # Run the osc service and commit the changes to OBS sh.osc('rm', glob.glob('%s*.obscpio' % obsinfo_basename)) env = os.environ.copy() # TODO use proper api, once available from: # https://github.com/openSUSE/obs-service-tar_scm/issues/258 # Workaround to make obs_scm work with a local path. # Otherwise it only works with remote URLs. env['TAR_SCM_TESTMODE'] = '1' sh.osc('service', 'disabledrun', _env=env) sh.osc('add', glob.glob('%s*.obscpio' % obsinfo_basename)) sh.osc( 'commit', '-m', 'Testing gerrit changes applied to %s' % package.applied_change_numbers()) self.packages.add(package)