fetch2/git.py: fix a corner case in try_premirror
PATCH 1/3 fetch2/git.py: fix a corner case in try_premirror
From: Chen Qi <[email protected]>
For gitsm recipes, it's possible that some URL is used more than once. e.g.,
A -> B:rev1 (B is a submodule of A)
A -> C (C is a submodule of A)
C -> B:rev2 (B is a submodule of C)
A anc C are both using B as submodules, but on different revs. Now if we have:
B:rev1 -> D
B:rev2 -> E
Then, the mirror will not be fully used.
Say we have all repo mirrors for A, B, C, D, E, then in theory it's not necessary to reach out to any network for downloading. But it's not the case. After downloading B(rev1) and its submodule D from mirrors, the fetch process continues to download C, thus B(rev2) and E. Now it finds that B needs an update because its submodule E needs an update. Of course this is true because E is not downloaded yet. Now the problem comes to whether to use mirror or not. The git.py defines try_premirror to return 'False' when the ud.clonedir exists. As B has been cloned, the ud.clonedir exists and try_mirror returns False, resulting in not using mirror and going to upstream directly.
We can see that the mirrors are not fully used. This is usually not problem, as the cost is only some network download. But in case the following two settings are there, we get errors.BB_NO_NETWORK = "0"BB_ALLOWED_NETWORKS = "*.some.allowed.domain"
In such case, the gitsm recipe A will fail to fetch. Note that all contents that A needs are in mirrors and now it's failing to fetch. This is unexpected.
Note that the different revs of the same repo in gitsm recipe is not the only way to reveal this problem. For example, there might be a recipe call B that uses B:rev3. Check the protobuf and grpc recipes as an example.
For now, we can use the following steps to reproduce this issue. To be clear, the grpc recipe in meta-oe is now 1.60.0.
1. Add in local.conf:
DL_DIR = "${TOPDIR}/downloads-premirror"
bitbake grpc -c fetch
2. Comment out the DL_DIR setting in local.conf and add the following lines:
PREMIRRORS:append = " \
git://.*/.* git://${TOPDIR}/downloads-premirror/git2/MIRRORNAME;protocol=file \n \
gitsm://.*/.* gitsm://${TOPDIR}/downloads-premirror/git2/MIRRORNAME;protocol=file \n \ "
3. Set BB_NO_NETWORK = "1" and then 'bitbake grpc -c fetch'.
This command succeeds and this shows that the premirror holds everything we need.
4. Add the following lines and then 'bitbake grpc -c fetch'. BB_NO_NETWORK = "0"
BB_ALLOWED_NETWORKS = "*.some.domain"
After step 4, the error message is as below:
ERROR: grpc-1.60.0-r0 do_fetch: The URL: 'gitsm://github.com/protocolbuffers/protobuf.git;protocol=https;name=third_party/protobuf;subpath=third_party/protobuf;nobranch=1;lfs=True;bareclone=1;nobranch=1' is not trusted and cannot be used
This patch fixes this problem by handling this corner case, that is, if the URL is not trusted from the settings of BB_NO_NETWORK and BB_ALLOWED_NETWORKS, then we should try premirrors because trying to reach upstream is destined to fail.
--- bitbake/lib/bb/fetch2/git.py | 6 ++++++ 1 file changed, 6 insertions(+)
bitbake/lib/bb/fetch2/git.py +6 -0
@@ -87,6 +87,7 @@ from contextlib import contextmanager from bb.fetch2 import FetchMethod from bb.fetch2 import runfetchcmd from bb.fetch2 import logger +from bb.fetch2 import trusted_network sha1_re = re.compile(r'^[0-9a-f]{40}$')
@@ -355,6 +356,11 @@ class Git(FetchMethod): # is not possible if bb.utils.to_boolean(d.getVar("BB_FETCH_PREMIRRORONLY")): return True + # If the url is not in trusted network, that is, BB_NO_NETWORK is set to 0 + # and BB_ALLOWED_NETWORKS does not contain the host that ud.url uses, then + # we need to try premirrors first as using upstream is destined to fail. + if not trusted_network(d, ud.url): + return True if os.path.exists(ud.clonedir): return False return True
Signature · 1 line
2.42.0
PATCH 2/3 tests/fetch.py: add test case for using premirror in restricted network
From: Chen Qi <[email protected]>
We had issue when BB_ALLOWED_NETWORKS is set and `bitbake grpc-native -c fetch' failed even with all contents available in PREMIRRORS.
Add a test case to ensure no regression in the future.
--- bitbake/lib/bb/tests/fetch.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
bitbake/lib/bb/tests/fetch.py +19 -0
@@ -1107,6 +1107,25 @@ class FetcherNetworkTest(FetcherTest): if os.path.exists(os.path.join(repo_path, 'bitbake-gitsm-test1')): self.assertTrue(os.path.exists(os.path.join(repo_path, 'bitbake-gitsm-test1', 'bitbake')), msg='submodule of submodule missing') + @skipIfNoNetwork() + def test_git_submodule_restricted_network_premirrors(self): + # this test is to ensure that premirrors will be tried in restricted network + # that is, BB_ALLOWED_NETWORKS does not contain the domain the url uses + url = "gitsm://github.com/grpc/grpc.git;protocol=https;name=grpc;branch=v1.60.x;rev=0ef13a7555dbaadd4633399242524129eef5e231" + # create a download directory to be used as premirror later + tempdir = tempfile.mkdtemp(prefix="bitbake-fetch-") + dl_premirror = os.path.join(tempdir, "download-premirror") + os.mkdir(dl_premirror) + self.d.setVar("DL_DIR", dl_premirror) + fetcher = bb.fetch.Fetch([url], self.d) + fetcher.download() + # now use the premirror in restricted network + self.d.setVar("DL_DIR", self.dldir) + self.d.setVar("PREMIRRORS", "gitsm://.*/.* gitsm://%s/git2/MIRRORNAME;protocol=file" % dl_premirror) + self.d.setVar("BB_ALLOWED_NETWORKS", "*.some.domain") + fetcher = bb.fetch.Fetch([url], self.d) + fetcher.download() + @skipIfNoNetwork() def test_git_submodule_dbus_broker(self): # The following external repositories have show failures in fetch and unpack operations
Signature · 1 line
2.42.0
PATCH 3/3 fetch2/git.py: add comment in try_premirrors
In reply to [email protected]From: Chen Qi <[email protected]>
The purpose of ensuring 'incremental fetch' is not easy to see from the codes. So add comments to explain this.
--- bitbake/lib/bb/fetch2/git.py | 5 +++++ 1 file changed, 5 insertions(+)
bitbake/lib/bb/fetch2/git.py +5 -0
@@ -361,6 +361,11 @@ class Git(FetchMethod): # we need to try premirrors first as using upstream is destined to fail. if not trusted_network(d, ud.url): return True + # the following check is to ensure incremental fetch in downloads, this is + # because the premirror might be old and does not contain the new rev required, + # and this will cause a total removal and new clone. So if we can reach to + # network, we prefer upstream over premirror, though the premirror might contain + # the new rev. if os.path.exists(ud.clonedir): return False return True
Signature · 1 line
2.42.0
Re: [bitbake-devel][PATCH 3/3] fetch2/git.py: add comment in try_premirrors
This reminds me of a case while using a kirkstone branch, where a git submodule was the same repo but a different branch as the parent module, and the fetcher was not able to complete even without mirrors.
It was a go project where vendor modules were kept in a branch whose name was vendor/ prefixed to the branch of the main project. This allowed the module dependencies to be regulated (and not fetched during compile) while still being associated with the project branch without tainting the project branch or history - but it meant that the fetcher would hang.
Would these changes address that?
Sam
Quoted 46 lines · Chen Qi via lists.openembedded.org
From: Chen Qi <[email protected]>
The purpose of ensuring 'incremental fetch' is not easy to see from the codes. So add comments to explain this.
Signed-off-by Chen Qi <[email protected]>--- bitbake/lib/bb/fetch2/git.py | 5 +++++ 1 file changed, 5 insertions(+)bitbake/lib/bb/fetch2/git.py +0
-0@@ -361,6 +361,11 @@ class Git(FetchMethod): # we need to try premirrors first as using upstream is destinedto fail.
if nottrusted_network(d, ud.url):
return True
+ # the following check is to ensure incremental fetch in
downloads, this is
+ # because the premirror might be old and does not contain the new
rev required,
+ # and this will cause a total removal and new clone. So if we can
reach to
+ # network, we prefer upstream over premirror, though the
premirror might contain
+ # the new rev.
ifos.path.exists(ud.clonedir):
return False
return True
--
2.42.0-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#15818):
https://lists.openembedded.org/g/bitbake-devel/message/15818
Mute This Topic: https://lists.openembedded.org/mt/104090273/7497305
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [bitbake-devel][PATCH 3/3] fetch2/git.py: add comment in try_premirrors
Quoted 1 line · Sam Liddicott
This reminds me of a case while using a kirkstone branch, where a git submodule was the same repo but a different branch as the parent module, and the fetcher was not able to complete even without mirrors.
I think the problem you encountered is a different one. If you have a reliable way to reproduce the issue (try poky master first), then you can file a bug in yocto bugzilla.
P.S.
1. Some projects delete branches and I once encountered this. Did you manually check that all revs are still available in upstream for those submodules.
2. You can try using meta-virtualization/scripts/oe-go-mod-autogen.py when you work with go mod recipes, though your recipe's repo seems to handle go modules in a custom way and you may not need this.
Regards,
Qi
Quoted 66 lines
It was a go project where vendor modules were kept in a branch whose name was vendor/ prefixed to the branch of the main project. This allowed the module dependencies to be regulated (and not fetched during compile) while still being associated with the project branch without tainting the project branch or history - but it meant that the fetcher would hang.
Would these changes address that?
Sam
On Thu, 1 Feb 2024 at 03:31, Chen Qi via lists.openembedded.org <https://urldefense.com/v3/__http://lists.openembedded.org__;!!AjveYdw8EvQ!abkk4w1KDkQAv1NfDTy93YpSD4d1825gTUGc4LYGxrQWW5b6Y-UppkBFI7S3Mz0xK7iiZAcAe6eDotE$> <[email protected]> wrote:
From: Chen Qi <[email protected]> The purpose of ensuring 'incremental fetch' is not easy to see from the codes. So add comments to explain this. Signed-off-by: Chen Qi <[email protected]> --- bitbake/lib/bb/fetch2/git.py <https://urldefense.com/v3/__http://git.py__;!!AjveYdw8EvQ!abkk4w1KDkQAv1NfDTy93YpSD4d1825gTUGc4LYGxrQWW5b6Y-UppkBFI7S3Mz0xK7iiZAcAPZ807pk$> | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bitbake/lib/bb/fetch2/git.py <https://urldefense.com/v3/__http://git.py__;!!AjveYdw8EvQ!abkk4w1KDkQAv1NfDTy93YpSD4d1825gTUGc4LYGxrQWW5b6Y-UppkBFI7S3Mz0xK7iiZAcAPZ807pk$> b/bitbake/lib/bb/fetch2/git.py <https://urldefense.com/v3/__http://git.py__;!!AjveYdw8EvQ!abkk4w1KDkQAv1NfDTy93YpSD4d1825gTUGc4LYGxrQWW5b6Y-UppkBFI7S3Mz0xK7iiZAcAPZ807pk$> index 322a9366da..fa8c597ea2 100644 --- a/bitbake/lib/bb/fetch2/git.py <https://urldefense.com/v3/__http://git.py__;!!AjveYdw8EvQ!abkk4w1KDkQAv1NfDTy93YpSD4d1825gTUGc4LYGxrQWW5b6Y-UppkBFI7S3Mz0xK7iiZAcAPZ807pk$> +++ b/bitbake/lib/bb/fetch2/git.py <https://urldefense.com/v3/__http://git.py__;!!AjveYdw8EvQ!abkk4w1KDkQAv1NfDTy93YpSD4d1825gTUGc4LYGxrQWW5b6Y-UppkBFI7S3Mz0xK7iiZAcAPZ807pk$> @@ -361,6 +361,11 @@ class Git(FetchMethod): # we need to try premirrors first as using upstream is destined to fail. if not trusted_network(d, ud.url): return True + # the following check is to ensure incremental fetch in downloads, this is + # because the premirror might be old and does not contain the new rev required, + # and this will cause a total removal and new clone. So if we can reach to + # network, we prefer upstream over premirror, though the premirror might contain + # the new rev. if os.path.exists(ud.clonedir): return False return True -- 2.42.0 -=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#15818): https://lists.openembedded.org/g/bitbake-devel/message/15818 <https://urldefense.com/v3/__https://lists.openembedded.org/g/bitbake-devel/message/15818__;!!AjveYdw8EvQ!abkk4w1KDkQAv1NfDTy93YpSD4d1825gTUGc4LYGxrQWW5b6Y-UppkBFI7S3Mz0xK7iiZAcA8nSAEcE$> Mute This Topic: https://lists.openembedded.org/mt/104090273/7497305 <https://urldefense.com/v3/__https://lists.openembedded.org/mt/104090273/7497305__;!!AjveYdw8EvQ!abkk4w1KDkQAv1NfDTy93YpSD4d1825gTUGc4LYGxrQWW5b6Y-UppkBFI7S3Mz0xK7iiZAcAWxGg7kI$> Group Owner: [email protected] <mailto:bitbake-devel%[email protected]> Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub <https://urldefense.com/v3/__https://lists.openembedded.org/g/bitbake-devel/unsub__;!!AjveYdw8EvQ!abkk4w1KDkQAv1NfDTy93YpSD4d1825gTUGc4LYGxrQWW5b6Y-UppkBFI7S3Mz0xK7iiZAcAMfW6SJU$> [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
ping
Quoted 96 lines · Chen Qi via lists.openembedded.org
From: Chen Qi <[email protected]>
For gitsm recipes, it's possible that some URL is used more than once. e.g.,
A -> B:rev1 (B is a submodule of A)
A -> C (C is a submodule of A)
C -> B:rev2 (B is a submodule of C)
A anc C are both using B as submodules, but on different revs. Now if we have:
B:rev1 -> D
B:rev2 -> E
Then, the mirror will not be fully used.
Say we have all repo mirrors for A, B, C, D, E, then in theory it's not necessary to reach out to any network for downloading. But it's not the case. After downloading B(rev1) and its submodule D from mirrors, the fetch process continues to download C, thus B(rev2) and E. Now it finds that B needs an update because its submodule E needs an update. Of course this is true because E is not downloaded yet. Now the problem comes to whether to use mirror or not. Thegit.pydefinestry_premirrorto return 'False' when the ud.clonedir exists. As B has been cloned, the ud.clonedir exists andtry_mirrorreturns False, resulting in not using mirror and going to upstream directly.We can see that the mirrors are not fully used. This is usually not problem, as the cost is only some network download. But in case the following two settings are there, we get errors.
BB_NO_NETWORK= "0"BB_ALLOWED_NETWORKS= "*.some.allowed.domain"
In such case, the gitsm recipe A will fail to fetch. Note that all contents that A needs are in mirrors and now it's failing to fetch. This is unexpected.Note that the different revs of the same repo in gitsm recipe is not the only way to reveal this problem. For example, there might be a recipe call B that uses B:rev3. Check the protobuf and grpc recipes as an example.
For now, we can use the following steps to reproduce this issue. To be clear, the grpc recipe in meta-oe is now 1.60.0.
1. Add in local.conf:
DL_DIR= "${TOPDIR}/downloads-premirror"
bitbake grpc -c fetch
2. Comment out theDL_DIRsetting in local.conf and add the following lines:PREMIRRORS:append = " \ git://.*/.* git://${TOPDIR}/downloads-premirror/git2/MIRRORNAME;protocol=file \n \ gitsm://.*/.* gitsm://${TOPDIR}/downloads-premirror/git2/MIRRORNAME;protocol=file \n \ "3. Set
BB_NO_NETWORK= "1" and then 'bitbake grpc -c fetch'.
This command succeeds and this shows that the premirror holds everything we need.
4. Add the following lines and then 'bitbake grpc -c fetch'.BB_NO_NETWORK= "0"
BB_ALLOWED_NETWORKS= "*.some.domain"After step 4, the error message is as below:
ERROR: grpc-1.60.0-r0do_fetch: The URL: 'gitsm://github.com/protocolbuffers/protobuf.git;protocol=https;name=third_party/protobuf;subpath=third_party/protobuf;nobranch=1;lfs=True;bareclone=1;nobranch=1' is not trusted and cannot be usedThis patch fixes this problem by handling this corner case, that is, if the URL is not trusted from the settings of
BB_NO_NETWORKandBB_ALLOWED_NETWORKS, then we should try premirrors because trying to reach upstream is destined to fail.Signed-off-by Chen Qi <[email protected]>--- bitbake/lib/bb/fetch2/git.py | 6 ++++++ 1 file changed, 6 insertions(+)bitbake/lib/bb/fetch2/git.py +6
-1@@ -87,6 +87,7 @@ from contextlib import contextmanager from bb.fetch2 import FetchMethod from bb.fetch2 import runfetchcmd from bb.fetch2 import logger +from bb.fetch2 import trusted_network sha1_re = re.compile(r'^[0-9a-f]{40}$')@@ -355,6 +356,11 @@ class Git(FetchMethod): # is not possible if bb.utils.to_boolean(d.getVar("BB_FETCH_PREMIRRORONLY")): return True + # If the url is not in trusted network, that is, BB_NO_NETWORK is set to 0 + # and BB_ALLOWED_NETWORKS does not contain the host that ud.url uses, then + # we need to try premirrors first as using upstream is destined to fail. + if not trusted_network(d, ud.url): + return True if os.path.exists(ud.clonedir): return False return True -=-=-=-=-=-=-=-=-=-=-=-Links: You receive all messages sent to this group.
View/Reply Online (#15817): https://lists.openembedded.org/g/bitbake-devel/message/15817
Mute This Topic: https://lists.openembedded.org/mt/104090271/7304865
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-