tests/fetch: Add test for broken mirror tarball

Message ID 20220616161521.20906-1-pavel@zhukoff.net
State Accepted, archived
Commit c9aaca3dd2dfdf4a291d6e1f6263037e0f54b4b6
Headers show
Series tests/fetch: Add test for broken mirror tarball | expand

Commit Message

With PREMIRROR set and BB_NETWORK = "1" bitbake should not try to
fetch into non-initialized git directory if tarball is broken (or not in
gzip format)

[Yocto 14822]

Signed-off-by: Pavel Zhukov <pavel.zhukov@huawei.com>
---
 lib/bb/tests/fetch.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Luca Ceresoli June 20, 2022, 9:40 a.m. UTC | #1
Hi Pavel,

On Thu, 16 Jun 2022 18:15:22 +0200
"Pavel Zhukov" <pavel@zhukoff.net> wrote:

> With PREMIRROR set and BB_NETWORK = "1" bitbake should not try to

s/PREMIRROR/PREMIRRORS/
s/BB_NETWORK/BB_NO_NETWORK/

I fixed those when applying your patch for testing, thus no need to
resend just for these.

Patch

diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py
index 622c46a0..ee41bff4 100644
--- a/lib/bb/tests/fetch.py
+++ b/lib/bb/tests/fetch.py
@@ -2895,3 +2895,28 @@  class FetchPremirroronlyNetworkTest(FetcherTest):
         fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
         with self.assertRaises(bb.fetch2.NetworkAccess):
             fetcher.download()
+
+class FetchPremirroronlyBrokenTarball(FetcherTest):
+
+    def setUp(self):
+        super(FetchPremirroronlyBrokenTarball, self).setUp()
+        self.mirrordir = os.path.join(self.tempdir, "mirrors")
+        os.mkdir(self.mirrordir)
+        self.reponame = "bitbake"
+        self.gitdir = os.path.join(self.tempdir, "git", self.reponame)
+        self.recipe_url = "git://git.fake.repo/bitbake"
+        self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
+        self.d.setVar("BB_NO_NETWORK", "1")
+        self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
+        self.mirrorname = "git2_git.fake.repo.bitbake.tar.gz"
+        with open(os.path.join(self.mirrordir, self.mirrorname), 'w') as targz:
+            targz.write("This is not tar.gz file!")
+
+    def test_mirror_broken_download(self):
+        import sys
+        self.d.setVar("SRCREV", "0"*40)
+        fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
+        with self.assertRaises(bb.fetch2.FetchError):
+            fetcher.download()
+        stdout = sys.stdout.getvalue()
+        self.assertFalse(" not a git repository (or any parent up to mount point /)" in stdout)