Skip to contentSkip to conversation

BZ#13039: updates to fetch2 and tests/fetch

PATCH In review Scott Weaver 4 participants 9 messages Sep 5, 2021 – Oct 15, 2021 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

cover BZ#13039: updates to fetch2 and tests/fetch

In this patch set, I address BZ#13039 and add fetcher tests specifically for downloadfilename use cases along with an update to the npm fetcher tests.

https://bugzilla.yoctoproject.org/show_bug.cgi?id=13039

Scott Weaver (3):
bitbake: fetch2: fix premirror URI when downloadfilename defined
bitbake: tests/fetch: add downloadfilename tests
bitbake: tests/fetch: add and fix npm tests

 bitbake/lib/bb/fetch2/__init__.py |  2 +-
 bitbake/lib/bb/tests/fetch.py     | 47 +++++++++++++++++++++++++++++--
 2 files changed, 46 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/3 bitbake: fetch2: fix premirror URI when downloadfilename defined

When downloadfilename is defined in a recipe's SRC_URI and PREMIRRORS is also defined using the same URI, the downloadfilename is appended to the mirror URI and it should not be.

[YOCTO #13039]

---
 bitbake/lib/bb/fetch2/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/fetch2/__init__.py +1 -1
index 914fa5c024..47a4943369 100644
@@ -466,7 +466,7 @@ def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None):
                     # Kill parameters, they make no sense for mirror tarballs
                     uri_decoded[5] = {}
                 elif ud.localpath and ud.method.supports_checksum(ud):
-                    basename = os.path.basename(ud.localpath)
+                    basename = os.path.basename(uri_decoded[loc])
                 if basename and not result_decoded[loc].endswith(basename):
                     result_decoded[loc] = os.path.join(result_decoded[loc], basename)
         else:
Signature · 1 line
2.25.1
#8 lore raw

PATCH 2/3 bitbake: tests/fetch: add downloadfilename tests

In reply to Scott Weaver

This adds three new tests which evaluate different use cases of the downloadfilename property.

bb.tests.fetch.FetcherNetworkTest:
- test_fetch_specify_downloadfilename
- test_fetch_premirror_specify_downloadfilename_regex_uri
- test_fetch_premirror_specify_downloadfilename_specific_uri

---
 bitbake/lib/bb/tests/fetch.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
bitbake/lib/bb/tests/fetch.py +21 -0
index 9291ce4a06..1735d0b071 100644
@@ -866,6 +866,27 @@ class FetcherNetworkTest(FetcherTest):
         fetcher.download()
         self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
 
+    @skipIfNoNetwork()
+    def test_fetch_specify_downloadfilename(self):
+        fetcher = bb.fetch.Fetch(["http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz;downloadfilename=bitbake-v1.0.0.tar.gz"], self.d)
+        fetcher.download()
+        self.assertEqual(os.path.getsize(self.dldir + "/bitbake-v1.0.0.tar.gz"), 57749)
+
+    @skipIfNoNetwork()
+    def test_fetch_premirror_specify_downloadfilename_regex_uri(self):
+        self.d.setVar("PREMIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake/")
+        fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz;downloadfilename=bitbake-v1.0.0.tar.gz"], self.d)
+        fetcher.download()
+        self.assertEqual(os.path.getsize(self.dldir + "/bitbake-v1.0.0.tar.gz"), 57749)
+
+    @skipIfNoNetwork()
+    # BZ13039
+    def test_fetch_premirror_specify_downloadfilename_specific_uri(self):
+        self.d.setVar("PREMIRRORS", "http://invalid.yoctoproject.org/releases/bitbake http://downloads.yoctoproject.org/releases/bitbake")
+        fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz;downloadfilename=bitbake-v1.0.0.tar.gz"], self.d)
+        fetcher.download()
+        self.assertEqual(os.path.getsize(self.dldir + "/bitbake-v1.0.0.tar.gz"), 57749)
+
     @skipIfNoNetwork()
     def gitfetcher(self, url1, url2):
         def checkrevision(self, fetcher):
Signature · 1 line
2.25.1
#9 lore raw

PATCH 3/3 bitbake: tests/fetch: add and fix npm tests

In reply to Scott Weaver

This adds one new test that verifies the use of a specific filename when defined in PREMIRRORS.

bb.tests.fetch.NPMTest:
- test_npm_premirrors_with_specified_filename

While testing bz#13039, it was found that test_npm_registry_alternate fails with ENOTFOUND. This was corrected by using npmjs's public mirror.

The change to fetch2 for bz#13039 highlighted an issue with the test_npm_premirrors test where the created file:// mirror was using the downloadfilename rather than the tarball that is defined by the npm url.

---
 bitbake/lib/bb/tests/fetch.py | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
bitbake/lib/bb/tests/fetch.py +24 -2
index 1735d0b071..242be36891 100644
@@ -2278,9 +2278,10 @@ class NPMTest(FetcherTest):
         fetcher.download()
         self.assertTrue(os.path.exists(ud.localpath))
         # Setup the mirror
+        pkgname = os.path.basename(ud.proxy.urls[0].split(';')[0])
         mirrordir = os.path.join(self.tempdir, 'mirror')
         bb.utils.mkdirhier(mirrordir)
-        os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
+        os.replace(ud.localpath, os.path.join(mirrordir, pkgname))
         self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s/\n' % mirrordir)
         self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
         # Fetch again
@@ -2288,6 +2289,27 @@ class NPMTest(FetcherTest):
         fetcher.download()
         self.assertTrue(os.path.exists(ud.localpath))
 
+    @skipIfNoNpm()
+    @skipIfNoNetwork()
+    def test_npm_premirrors_with_specified_filename(self):
+        url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
+        # Fetch once to get a tarball
+        fetcher = bb.fetch.Fetch([url], self.d)
+        ud = fetcher.ud[fetcher.urls[0]]
+        fetcher.download()
+        self.assertTrue(os.path.exists(ud.localpath))
+        # Setup the mirror
+        mirrordir = os.path.join(self.tempdir, 'mirror')
+        bb.utils.mkdirhier(mirrordir)
+        mirrorfilename = os.path.join(mirrordir, os.path.basename(ud.localpath))
+        os.replace(ud.localpath, mirrorfilename)
+        self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s\n' % mirrorfilename)
+        self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
+        # Fetch again
+        self.assertFalse(os.path.exists(ud.localpath))
+        fetcher.download()
+        self.assertTrue(os.path.exists(ud.localpath))
+
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_mirrors(self):
@@ -2350,7 +2372,7 @@ class NPMTest(FetcherTest):
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_registry_alternate(self):
-        url = 'npm://registry.freajs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
+        url = 'npm://skimdb.npmjs.com;package=@savoirfairelinux/node-server-example;version=1.0.0'
         fetcher = bb.fetch.Fetch([url], self.d)
         fetcher.download()
         fetcher.unpack(self.unpackdir)
Signature · 1 line
2.25.1
#2 lore raw

Re: [bitbake-devel][ 1/3] bitbake: fetch2: fix premirror URI when downloadfilename defined

In reply to Scott Weaver
Quoted 5 lines · Scott Weaver

When downloadfilename is defined in a recipe's SRC_URI and PREMIRRORS is also defined using the same URI, the downloadfilename is appended to the mirror URI and it should not be.

[YOCTO #13039]

As I commented in the bugzilla, I suppose it is an invalid bug.

It save the tarball with the name of the value of downloadfilename rather than the basename of the url. In this case, the name of tarball in the premirror downloads/ directory is uthash-2.0.2.tar.gz rather than 2.0.2.tar.gz if the premirror is created by run bitbake do_fetch. So when premirror is used, it checks uthash-2.0.2.tar.gz in the premirrors but not the original value '2.0.2.tar.gz'.

With this patch, it fails to fetch the tarball from premirrors. It could be reproduced by config:

BB_NO_NETWORK = "1"
BB_FETCH_PREMIRRORONLY = "1"

Regards,
Kai

Quoted 22 lines
---
  bitbake/lib/bb/fetch2/__init__.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/fetch2/__init__.py +1 -1
index 914fa5c024..47a4943369 100644
@@ -466,7 +466,7 @@ def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None):
                      # Kill parameters, they make no sense for mirror tarballs
                      uri_decoded[5] = {}
                  elif ud.localpath and ud.method.supports_checksum(ud):
-                    basename = os.path.basename(ud.localpath)
+                    basename = os.path.basename(uri_decoded[loc])
                  if basename and not result_decoded[loc].endswith(basename):
                      result_decoded[loc] = os.path.join(result_decoded[loc], basename)
          else:
Signature · 2 lines
Kai Kang
Wind River Linux
#3 lore raw

Re: [bitbake-devel][ 1/3] bitbake: fetch2: fix premirror URI when downloadfilename defined

Quoted 18 lines · Kai
Quoted 5 lines · Scott Weaver

When downloadfilename is defined in a recipe's SRC_URI and PREMIRRORS is also defined using the same URI, the downloadfilename is appended to the mirror URI and it should not be.

[YOCTO #13039]

As I commented in the bugzilla, I suppose it is an invalid bug.

It save the tarball with the name of the value of downloadfilename rather than the basename of the url.
In this case, the name of tarball in the premirror downloads/ directory is uthash-2.0.2.tar.gz rather than
2.0.2.tar.gz if the premirror is created by run bitbake do_fetch. So when premirror is used, it checks
uthash-2.0.2.tar.gz in the premirrors but not the original value '2.0.2.tar.gz'.

Quoted 8 lines

With this patch, it fails to fetch the tarball from premirrors. It could be reproduced by config:

BB_NO_NETWORK = "1"
BB_FETCH_PREMIRRORONLY = "1"

Regards,
Kai

Sorry, Kai. I didn't see your email until just now.
I'll look into it. IMO, I would treat this like a new/different bug than the one I addressed with this patch but regardless it is a related use case to this BZ.

I'll update the BZ after I've dug into this.

- Scott

Quoted 33 lines
Quoted 28 lines
---
  bitbake/lib/bb/fetch2/__init__.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/fetch2/__init__.py +1 -2
index 914fa5c024..47a4943369 100644
@@ -466,7 +466,7 @@ def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None):
                      # Kill parameters, they make no sense for mirror tarballs
                      uri_decoded[5] = {}
                  elif ud.localpath and ud.method.supports_checksum(ud):
-                    basename = os.path.basename(ud.localpath)
+                    basename = os.path.basename(uri_decoded[loc])
                  if basename and not result_decoded[loc].endswith(basename):
                      result_decoded[loc] = os.path.join(result_decoded[loc], basename)
          else:
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#12592): https://lists.openembedded.org/g/bitbake-devel/message/12592
Mute This Topic: https://lists.openembedded.org/mt/85401309/3616933
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 2 lines
Kai Kang
Wind River Linux
Signature · 1 line
  - Scott
#4 lore raw

Re: [bitbake-devel][ 1/3] bitbake: fetch2: fix premirror URI when downloadfilename defined

Hi Scott,

Quoted 44 lines · Scott Weaver
Quoted 18 lines · Kai
Quoted 5 lines · Scott Weaver

When downloadfilename is defined in a recipe's SRC_URI and PREMIRRORS is also defined using the same URI, the downloadfilename is appended to the mirror URI and it should not be.

[YOCTO #13039]

As I commented in the bugzilla, I suppose it is an invalid bug.

It save the tarball with the name of the value of downloadfilename rather than the basename of the url.
In this case, the name of tarball in the premirror downloads/ directory is uthash-2.0.2.tar.gz rather than
2.0.2.tar.gz if the premirror is created by run bitbake do_fetch. So when premirror is used, it checks
uthash-2.0.2.tar.gz in the premirrors but not the original value '2.0.2.tar.gz'.

Quoted 8 lines

With this patch, it fails to fetch the tarball from premirrors. It could be reproduced by config:

BB_NO_NETWORK = "1"
BB_FETCH_PREMIRRORONLY = "1"

Regards,
Kai

Sorry, Kai. I didn't see your email until just now.
I'll look into it. IMO, I would treat this like a new/different bug than the one I addressed with this patch but regardless it is a related use case to this BZ.

I'll update the BZ after I've dug into this.

- Scott

Quoted 6 lines
Quoted 6 lines
---
   bitbake/lib/bb/fetch2/__init__.py | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 10 lines
Quoted 10 lines

bitbake/lib/bb/fetch2/__init__.py def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None): · line 469

Quoted 10 lines
bitbake/lib/bb/fetch2/__init__.py +1 -1
index 914fa5c024..47a4943369 100644
@@ -466,7 +466,7 @@ def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None):
                       # Kill parameters, they make no sense for mirror tarballs
                       uri_decoded[5] = {}
                   elif ud.localpath and ud.method.supports_checksum(ud):
-                    basename = os.path.basename(ud.localpath)
+                    basename = os.path.basename(uri_decoded[loc])

Use meta-openembedded/meta-networking/recipes-connectivity/dhcp/dhcp-relay_4.4.2p1.bb as an example:

* Before the patch, basename is bind.tar.gz
* After the patch, basename is bind-9.11.32.tar.gz

The patch changes basename from bind-9.11.32.tar.gz to bind.tar.gz, but didn't remove downloadfilename=bind.tar.gz from the mirror URI. The commit message says:

"the downloadfilename is appended to the mirror URI and it should not be."

But the downloadfilename is still in the mirror URI after the patch.

And the patch has a side effect is that it makes PREMIRROR or MIRRORS harder to use, the saved filename in DL_DIR is bind.tar.gz, but the required name in the mirror is bind-9.11.32.tar.gz since bind.tar.gz doesn't work any more, which isn't as straightforward as before, people who uses DL_DIR as PREMIRRORS doesn't work any more.

BTW, leave downloadfilename in the mirror URI won't affect anything AFAIK.

// Robert

Quoted 22 lines
Quoted 11 lines
Quoted 6 lines
bitbake/lib/bb/fetch2/__init__.py +0 -0
                   if basename and not result_decoded[loc].endswith(basename):
                       result_decoded[loc] = os.path.join(result_decoded[loc], basename)
           else:
Signature · 2 lines
Kai Kang
Wind River Linux

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#12711): https://lists.openembedded.org/g/bitbake-devel/message/12711
Mute This Topic: https://lists.openembedded.org/mt/85401309/3616940
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#5 lore raw

Re: [bitbake-devel][ 1/3] bitbake: fetch2: fix premirror URI when downloadfilename defined

In reply to Scott Weaver

Hi Scott,

I think the key problem here is which tarball name to be used for premirror.
Previously, it's using 'downloadfilename'. So instead of holding 1.4.0.tar.gz on yocto's mirror, it holds freeDiameter-1.4.0.tar.gz. Now, with this patch, the basename of the URL (e.g. 1.4.0.tar.gz) is used.

This at least causes the regression that a local download/ directory could be serve as a premirror.

I've sent out a patch to restore the previous behavior, it should also solve yocto#13039. The title is: [bitbake-devel][PATCH] fetch2: fix downloadfilename issue with premirror

Could you please check if it works for you?

Regards,
Qi

Quoted 34 lines · Scott Weaver

When downloadfilename is defined in a recipe's SRC_URI and PREMIRRORS is also defined using the same URI, the downloadfilename is appended to the mirror URI and it should not be.

[YOCTO #13039]

---
  bitbake/lib/bb/fetch2/__init__.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/fetch2/__init__.py +1 -2
index 914fa5c024..47a4943369 100644
@@ -466,7 +466,7 @@ def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None):
                      # Kill parameters, they make no sense for mirror tarballs
                      uri_decoded[5] = {}
                  elif ud.localpath and ud.method.supports_checksum(ud):
-                    basename = os.path.basename(ud.localpath)
+                    basename = os.path.basename(uri_decoded[loc])
                  if basename and not result_decoded[loc].endswith(basename):
                      result_decoded[loc] = os.path.join(result_decoded[loc], basename)
          else:
 
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#12592): https://lists.openembedded.org/g/bitbake-devel/message/12592
Mute This Topic: https://lists.openembedded.org/mt/85401309/3618072
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#7 lore raw

Re: [bitbake-devel][ 1/3] bitbake: fetch2: fix premirror URI when downloadfilename defined

In reply to a message not in the archive
Quoted 7 lines · Chen Qi

Hi Scott,

I think the key problem here is which tarball name to be used for premirror.
Previously, it's using 'downloadfilename'. So instead of holding 1.4.0.tar.gz on yocto's mirror, it holds freeDiameter-1.4.0.tar.gz. Now, with this patch, the basename of the URL (e.g. 1.4.0.tar.gz) is used.

This at least causes the regression that a local download/ directory could be serve as a premirror.

Sorry, typo. Should be:

This at least causes the regression that a local download/ directory could not serve as a premirror.

Quoted 51 lines

I've sent out a patch to restore the previous behavior, it should also solve yocto#13039. The title is: [bitbake-devel][PATCH] fetch2: fix downloadfilename issue with premirror

Could you please check if it works for you?

Regards,
Qi

Quoted 22 lines · Scott Weaver

When downloadfilename is defined in a recipe's SRC_URI and PREMIRRORS is also defined using the same URI, the downloadfilename is appended to the mirror URI and it should not be.

[YOCTO #13039]

---
bitbake/lib/bb/fetch2/__init__.py
<https://urldefense.com/v3/__http://__init__.py__;%21%21AjveYdw8EvQ%21NcbTHox-6oqYMaVTv6H3RVVTYA06zLNBPvkC6ZLg3Y6PRXUmmAyBKwEPXzGAFvB8Gw$> | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/fetch2/__init__.py <https://urldefense.com/v3/__http://__init__.py__;%21%21AjveYdw8EvQ%21NcbTHox-6oqYMaVTv6H3RVVTYA06zLNBPvkC6ZLg3Y6PRXUmmAyBKwEPXzGAFvB8Gw$> renamed from bitbake/lib/bb/fetch2/__init__.py <https://urldefense.com/v3/__http://__init__.py__;%21%21AjveYdw8EvQ%21NcbTHox-6oqYMaVTv6H3RVVTYA06zLNBPvkC6ZLg3Y6PRXUmmAyBKwEPXzGAFvB8Gw$> +0 -1
index 914fa5c024..47a4943369 100644
--- a/bitbake/lib/bb/fetch2/__init__.py 

<https://urldefense.com/v3/__http://__init__.py__;%21%21AjveYdw8EvQ%21NcbTHox-6oqYMaVTv6H3RVVTYA06zLNBPvkC6ZLg3Y6PRXUmmAyBKwEPXzGAFvB8Gw$>
+++ b/bitbake/lib/bb/fetch2/__init__.py
<https://urldefense.com/v3/__http://__init__.py__;%21%21AjveYdw8EvQ%21NcbTHox-6oqYMaVTv6H3RVVTYA06zLNBPvkC6ZLg3Y6PRXUmmAyBKwEPXzGAFvB8Gw$>

bitbake/lib/bb/fetch2/__init__.py <https://urldefense.com/v3/__http://__init__.py__;%21%21AjveYdw8EvQ%21NcbTHox-6oqYMaVTv6H3RVVTYA06zLNBPvkC6ZLg3Y6PRXUmmAyBKwEPXzGAFvB8Gw$> def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None): · line 472

Quoted 8 lines
bitbake/lib/bb/fetch2/__init__.py <https://urldefense.com/v3/__http://__init__.py__;%21%21AjveYdw8EvQ%21NcbTHox-6oqYMaVTv6H3RVVTYA06zLNBPvkC6ZLg3Y6PRXUmmAyBKwEPXzGAFvB8Gw$> renamed from bitbake/lib/bb/fetch2/__init__.py <https://urldefense.com/v3/__http://__init__.py__;%21%21AjveYdw8EvQ%21NcbTHox-6oqYMaVTv6H3RVVTYA06zLNBPvkC6ZLg3Y6PRXUmmAyBKwEPXzGAFvB8Gw$> +1 -1
@@ -466,7 +466,7 @@ def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None):
                      # Kill parameters, they make no sense for mirror tarballs
                      uri_decoded[5] = {}
                  elif ud.localpath and ud.method.supports_checksum(ud):
-                    basename = os.path.basename(ud.localpath)
+                    basename = os.path.basename(uri_decoded[loc])
                  if basename and not result_decoded[loc].endswith(basename):
                      result_decoded[loc] = os.path.join(result_decoded[loc], basename)
          else:

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#12780): https://lists.openembedded.org/g/bitbake-devel/message/12780
Mute This Topic: https://lists.openembedded.org/mt/85401309/3618072
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-