summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/tests
diff options
context:
space:
mode:
authorPavel Zhukov <pavel@zhukoff.net>2022-05-06 16:17:35 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-06-08 21:53:15 +0100
commitc6afc6d6ede401397419e067e8c229395a2afff0 (patch)
treec8701de277e86a595494b7d8b303f9eb5995f61a /bitbake/lib/bb/tests
parent53ed421226228f60a89a1868819b6c3ed6d45026 (diff)
downloadpoky-c6afc6d6ede401397419e067e8c229395a2afff0.tar.gz
bitbake: Add tests to cover BB_FETCH_PREMIRRORONLY functionality
Basic test to cover functionality of BB_FETCH_PREMIRRORONLY using local git repository. Local repository has been chosen to allow easy manipulation with the repo to simulate behaviour reported in [Yocto 13233] (Bitbake rev: 773e0815ba0c2183afcb169cda525b7625e60e42) Signed-off-by: Pavel Zhukov <pavel.zhukov@huawei.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/tests')
-rw-r--r--bitbake/lib/bb/tests/fetch.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index 1152e89c0d..a09c414ad8 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -2802,3 +2802,66 @@ class GitSharedTest(FetcherTest):
2802 fetcher.unpack(self.unpackdir) 2802 fetcher.unpack(self.unpackdir)
2803 alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates') 2803 alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates')
2804 self.assertFalse(os.path.exists(alt)) 2804 self.assertFalse(os.path.exists(alt))
2805
2806
2807class FetchPremirroronlyLocalTest(FetcherTest):
2808
2809 def git(self, cmd, cwd=None):
2810 if isinstance(cmd, str):
2811 cmd = 'git ' + cmd
2812 else:
2813 cmd = ['git'] + cmd
2814 if cwd is None:
2815 cwd = self.gitdir
2816 return bb.process.run(cmd, cwd=cwd)[0]
2817
2818 def setUp(self):
2819 super(FetchPremirroronlyLocalTest, self).setUp()
2820 self.mirrordir = os.path.join(self.tempdir, "mirrors")
2821 os.mkdir(self.mirrordir)
2822 self.reponame = "bitbake"
2823 self.gitdir = os.path.join(self.tempdir, "git", self.reponame)
2824 self.recipe_url = "git://git.fake.repo/bitbake"
2825 self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
2826 self.d.setVar("BB_NO_NETWORK", "1")
2827 self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
2828
2829 def make_git_repo(self):
2830 self.mirrorname = "git2_git.fake.repo.bitbake.tar.gz"
2831 recipeurl = "git:/git.fake.repo/bitbake"
2832 os.makedirs(self.gitdir)
2833 self.git("init", self.gitdir)
2834 for i in range(0):
2835 self.git_new_commit()
2836 bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir)
2837
2838 def git_new_commit(self):
2839 import random
2840 testfilename = "bibake-fetch.test"
2841 os.unlink(os.path.join(self.mirrordir, self.mirrorname))
2842 with open(os.path.join(self.gitdir, testfilename), "w") as testfile:
2843 testfile.write("Useless random data {}".format(random.random()))
2844 self.git("add {}".format(testfilename), self.gitdir)
2845 self.git("commit -a -m \"This random commit {}. I'm useless.\"".format(random.random()), self.gitdir)
2846 bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir)
2847 return self.git("rev-parse HEAD", self.gitdir).strip()
2848
2849 def test_mirror_commit_nonexistent(self):
2850 self.make_git_repo()
2851 self.d.setVar("SRCREV", "0"*40)
2852 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
2853 with self.assertRaises(bb.fetch2.NetworkAccess):
2854 fetcher.download()
2855
2856 def test_mirror_commit_exists(self):
2857 self.make_git_repo()
2858 self.d.setVar("SRCREV", self.git_new_commit())
2859 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
2860 fetcher.download()
2861 fetcher.unpack(self.unpackdir)
2862
2863 def test_mirror_tarball_nonexistent(self):
2864 self.d.setVar("SRCREV", "0"*40)
2865 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
2866 with self.assertRaises(bb.fetch2.NetworkAccess):
2867 fetcher.download()