public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/
Date: Sun, 21 Feb 2021 08:33:33 +0000 (UTC)	[thread overview]
Message-ID: <1613896379.d84cfb857bcb29c5710710b119dee634bbd4d1a4.zmedico@gentoo> (raw)

commit:     d84cfb857bcb29c5710710b119dee634bbd4d1a4
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 21 08:19:06 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Feb 21 08:32:59 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=d84cfb85

testEbuildFetch: refactor to test multiple layout preferences

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/tests/ebuild/test_fetch.py | 115 ++++++++++++++++++++++++---------
 1 file changed, 83 insertions(+), 32 deletions(-)

diff --git a/lib/portage/tests/ebuild/test_fetch.py b/lib/portage/tests/ebuild/test_fetch.py
index 5b67dc519..c5ea8253b 100644
--- a/lib/portage/tests/ebuild/test_fetch.py
+++ b/lib/portage/tests/ebuild/test_fetch.py
@@ -1,4 +1,4 @@
-# Copyright 2019-2020 Gentoo Authors
+# Copyright 2019-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import functools
@@ -50,23 +50,10 @@ class EbuildFetchTestCase(TestCase):
 
 		loop = SchedulerInterface(global_event_loop())
 
-		def run_async(func, *args, **kwargs):
-			with ForkExecutor(loop=loop) as executor:
-				return loop.run_until_complete(loop.run_in_executor(executor,
-					functools.partial(func, *args, **kwargs)))
-
 		scheme = 'http'
 		host = '127.0.0.1'
 		content = {}
 
-		content['/distfiles/layout.conf'] = b'[structure]\n0=flat\n'
-
-		for k, v in distfiles.items():
-			# mirror path
-			content['/distfiles/{}'.format(k)] = v
-			# upstream path
-			content['/distfiles/{}.txt'.format(k)] = v
-
 		with AsyncHTTPServer(host, content, loop) as server:
 			ebuilds_subst = {}
 			for cpv, metadata in ebuilds.items():
@@ -86,22 +73,86 @@ class EbuildFetchTestCase(TestCase):
 
 			playground = ResolverPlayground(ebuilds=ebuilds_subst, distfiles=distfiles, user_config=user_config_subst)
 			ro_distdir = tempfile.mkdtemp()
-			eubin = os.path.join(playground.eprefix, "usr", "bin")
 			try:
-				fetchcommand = portage.util.shlex_split(playground.settings['FETCHCOMMAND'])
-				fetch_bin = portage.process.find_binary(fetchcommand[0])
-				if fetch_bin is None:
-					self.skipTest('FETCHCOMMAND not found: {}'.format(playground.settings['FETCHCOMMAND']))
-				os.symlink(fetch_bin, os.path.join(eubin, os.path.basename(fetch_bin)))
-				resumecommand = portage.util.shlex_split(playground.settings['RESUMECOMMAND'])
-				resume_bin = portage.process.find_binary(resumecommand[0])
-				if resume_bin is None:
-					self.skipTest('RESUMECOMMAND not found: {}'.format(playground.settings['RESUMECOMMAND']))
-				if resume_bin != fetch_bin:
-					os.symlink(resume_bin, os.path.join(eubin, os.path.basename(resume_bin)))
-				root_config = playground.trees[playground.eroot]['root_config']
-				portdb = root_config.trees["porttree"].dbapi
+				self._testEbuildFetch(loop, scheme, host, distfiles, ebuilds, content, server, playground, ro_distdir)
+			finally:
+				shutil.rmtree(ro_distdir)
+				playground.cleanup()
+
+	def _testEbuildFetch(
+		self,
+		loop,
+		scheme,
+		host,
+		distfiles,
+		ebuilds,
+		content,
+		server,
+		playground,
+		ro_distdir,
+	):
+		mirror_layouts = (
+			(
+				"[structure]",
+				"0=filename-hash BLAKE2B 8",
+				"1=flat",
+			),
+			(
+				"[structure]",
+				"1=filename-hash BLAKE2B 8",
+				"0=flat",
+			),
+		)
+
+		fetchcommand = portage.util.shlex_split(playground.settings["FETCHCOMMAND"])
+		fetch_bin = portage.process.find_binary(fetchcommand[0])
+		if fetch_bin is None:
+			self.skipTest(
+				"FETCHCOMMAND not found: {}".format(playground.settings["FETCHCOMMAND"])
+			)
+		eubin = os.path.join(playground.eprefix, "usr", "bin")
+		os.symlink(fetch_bin, os.path.join(eubin, os.path.basename(fetch_bin)))
+		resumecommand = portage.util.shlex_split(playground.settings["RESUMECOMMAND"])
+		resume_bin = portage.process.find_binary(resumecommand[0])
+		if resume_bin is None:
+			self.skipTest(
+				"RESUMECOMMAND not found: {}".format(
+					playground.settings["RESUMECOMMAND"]
+				)
+			)
+		if resume_bin != fetch_bin:
+			os.symlink(resume_bin, os.path.join(eubin, os.path.basename(resume_bin)))
+		root_config = playground.trees[playground.eroot]["root_config"]
+		portdb = root_config.trees["porttree"].dbapi
+
+		def run_async(func, *args, **kwargs):
+			with ForkExecutor(loop=loop) as executor:
+				return loop.run_until_complete(
+					loop.run_in_executor(
+						executor, functools.partial(func, *args, **kwargs)
+					)
+				)
+
+		for layout_lines in mirror_layouts:
 				settings = config(clone=playground.settings)
+				layout_data = "".join("{}\n".format(line) for line in layout_lines)
+				mirror_conf = MirrorLayoutConfig()
+				mirror_conf.read_from_file(io.StringIO(layout_data))
+				layouts = mirror_conf.get_all_layouts()
+				content["/distfiles/layout.conf"] = layout_data.encode("utf8")
+
+				for k, v in distfiles.items():
+					# mirror path
+					for layout in layouts:
+						content["/distfiles/" + layout.get_path(k)] = v
+					# upstream path
+					content["/distfiles/{}.txt".format(k)] = v
+
+				for filename in os.listdir(settings["DISTDIR"]):
+					try:
+						os.unlink(os.path.join(settings["DISTDIR"], filename))
+					except OSError:
+						pass
 
 				# Demonstrate that fetch preserves a stale file in DISTDIR when no digests are given.
 				foo_uri = {'foo': ('{scheme}://{host}:{port}/distfiles/foo'.format(scheme=scheme, host=host, port=server.server_port),)}
@@ -172,7 +223,10 @@ class EbuildFetchTestCase(TestCase):
 					filter(None, [PORTAGE_PYM_PATH] + os.environ.get('PYTHONPATH', '').split(':')))
 
 				for k in distfiles:
-					os.unlink(os.path.join(settings['DISTDIR'], k))
+					try:
+						os.unlink(os.path.join(settings['DISTDIR'], k))
+					except OSError:
+						pass
 
 				proc = loop.run_until_complete(asyncio.create_subprocess_exec(*emirrordist_cmd, env=env))
 				self.assertEqual(loop.run_until_complete(proc.wait()), 0)
@@ -354,9 +408,6 @@ class EbuildFetchTestCase(TestCase):
 						os.chmod(settings['DISTDIR'], orig_distdir_mode)
 						settings.features.remove('skiprocheck')
 						settings.features.add('distlocks')
-			finally:
-				shutil.rmtree(ro_distdir)
-				playground.cleanup()
 
 	def test_flat_layout(self):
 		self.assertTrue(FlatLayout.verify_args(('flat',)))


             reply	other threads:[~2021-02-21  8:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-21  8:33 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-12-31  0:01 [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/ Zac Medico
2023-12-05  6:11 Zac Medico
2023-10-30  5:09 Zac Medico
2021-05-24  6:20 Zac Medico
2020-08-03 23:28 Zac Medico
2020-07-19 21:55 Zac Medico
2020-03-22  1:12 Zac Medico
2019-10-19 23:15 Zac Medico
2019-10-19  5:29 Zac Medico
2019-10-19  1:38 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1613896379.d84cfb857bcb29c5710710b119dee634bbd4d1a4.zmedico@gentoo \
    --to=zmedico@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox