diff options
Diffstat (limited to 'bitbake/lib/bb/tests/fetch.py')
-rw-r--r-- | bitbake/lib/bb/tests/fetch.py | 122 |
1 files changed, 111 insertions, 11 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index c77725190f..0091723601 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py | |||
@@ -20,6 +20,7 @@ import tarfile | |||
20 | from bb.fetch2 import URI | 20 | from bb.fetch2 import URI |
21 | from bb.fetch2 import FetchMethod | 21 | from bb.fetch2 import FetchMethod |
22 | import bb | 22 | import bb |
23 | import bb.utils | ||
23 | from bb.tests.support.httpserver import HTTPService | 24 | from bb.tests.support.httpserver import HTTPService |
24 | 25 | ||
25 | def skipIfNoNetwork(): | 26 | def skipIfNoNetwork(): |
@@ -27,6 +28,18 @@ def skipIfNoNetwork(): | |||
27 | return unittest.skip("network test") | 28 | return unittest.skip("network test") |
28 | return lambda f: f | 29 | return lambda f: f |
29 | 30 | ||
31 | |||
32 | @contextlib.contextmanager | ||
33 | def hide_directory(directory): | ||
34 | """Hide the given directory and restore it after the context is left""" | ||
35 | temp_name = directory + ".bak" | ||
36 | os.rename(directory, temp_name) | ||
37 | try: | ||
38 | yield | ||
39 | finally: | ||
40 | os.rename(temp_name, directory) | ||
41 | |||
42 | |||
30 | class TestTimeout(Exception): | 43 | class TestTimeout(Exception): |
31 | # Indicate to pytest that this is not a test suite | 44 | # Indicate to pytest that this is not a test suite |
32 | __test__ = False | 45 | __test__ = False |
@@ -2325,25 +2338,112 @@ class GitLfsTest(FetcherTest): | |||
2325 | return unpacked_lfs_file | 2338 | return unpacked_lfs_file |
2326 | 2339 | ||
2327 | @skipIfNoGitLFS() | 2340 | @skipIfNoGitLFS() |
2341 | def test_gitsm_lfs(self): | ||
2342 | """Test that the gitsm fetcher caches objects stored via LFS""" | ||
2343 | self.git(["lfs", "install", "--local"], cwd=self.srcdir) | ||
2344 | |||
2345 | def fetch_and_verify(revision, filename, content): | ||
2346 | self.d.setVar('SRCREV', revision) | ||
2347 | fetcher, ud = self.fetch() | ||
2348 | |||
2349 | with hide_directory(submoduledir), hide_directory(self.srcdir): | ||
2350 | workdir = self.d.getVar('WORKDIR') | ||
2351 | fetcher.unpack(workdir) | ||
2352 | |||
2353 | with open(os.path.join(workdir, "git", filename)) as f: | ||
2354 | self.assertEqual(f.read(), content) | ||
2355 | |||
2356 | # Create the git repository that will later be used as a submodule | ||
2357 | submoduledir = self.tempdir + "/submodule" | ||
2358 | bb.utils.mkdirhier(submoduledir) | ||
2359 | self.git_init(submoduledir) | ||
2360 | self.git(["lfs", "install", "--local"], cwd=submoduledir) | ||
2361 | self.commit_file('.gitattributes', '*.mp3 filter=lfs -text', cwd=submoduledir) | ||
2362 | |||
2363 | submodule_commit_1 = self.commit_file("a.mp3", "submodule version 1", cwd=submoduledir) | ||
2364 | _ = self.commit_file("a.mp3", "submodule version 2", cwd=submoduledir) | ||
2365 | |||
2366 | # Add the submodule to the repository at its current HEAD revision | ||
2367 | self.git(["-c", "protocol.file.allow=always", "submodule", "add", submoduledir, "submodule"], | ||
2368 | cwd=self.srcdir) | ||
2369 | base_commit_1 = self.commit() | ||
2370 | |||
2371 | # Let the submodule point at a different revision | ||
2372 | self.git(["checkout", submodule_commit_1], self.srcdir + "/submodule") | ||
2373 | self.git(["add", "submodule"], cwd=self.srcdir) | ||
2374 | base_commit_2 = self.commit() | ||
2375 | |||
2376 | # Add a LFS file to the repository | ||
2377 | base_commit_3 = self.commit_file("a.mp3", "version 1") | ||
2378 | # Update the added LFS file | ||
2379 | base_commit_4 = self.commit_file("a.mp3", "version 2") | ||
2380 | |||
2381 | self.d.setVar('SRC_URI', "gitsm://%s;protocol=file;lfs=1;branch=master" % self.srcdir) | ||
2382 | |||
2383 | # Verify that LFS objects referenced from submodules are fetched and checked out | ||
2384 | fetch_and_verify(base_commit_1, "submodule/a.mp3", "submodule version 2") | ||
2385 | # Verify that the repository inside the download cache of a submodile is extended with any | ||
2386 | # additional LFS objects needed when checking out a different revision. | ||
2387 | fetch_and_verify(base_commit_2, "submodule/a.mp3", "submodule version 1") | ||
2388 | # Verify that LFS objects referenced from the base repository are fetched and checked out | ||
2389 | fetch_and_verify(base_commit_3, "a.mp3", "version 1") | ||
2390 | # Verify that the cached repository is extended with any additional LFS objects required | ||
2391 | # when checking out a different revision. | ||
2392 | fetch_and_verify(base_commit_4, "a.mp3", "version 2") | ||
2393 | |||
2394 | @skipIfNoGitLFS() | ||
2395 | def test_gitsm_lfs_disabled(self): | ||
2396 | """Test that the gitsm fetcher does not use LFS when explicitly disabled""" | ||
2397 | self.git(["lfs", "install", "--local"], cwd=self.srcdir) | ||
2398 | |||
2399 | def fetch_and_verify(revision, filename, content): | ||
2400 | self.d.setVar('SRCREV', revision) | ||
2401 | fetcher, ud = self.fetch() | ||
2402 | |||
2403 | with hide_directory(submoduledir), hide_directory(self.srcdir): | ||
2404 | workdir = self.d.getVar('WORKDIR') | ||
2405 | fetcher.unpack(workdir) | ||
2406 | |||
2407 | with open(os.path.join(workdir, "git", filename)) as f: | ||
2408 | # Assume that LFS did not perform smudging when the expected content is | ||
2409 | # missing. | ||
2410 | self.assertNotEqual(f.read(), content) | ||
2411 | |||
2412 | # Create the git repository that will later be used as a submodule | ||
2413 | submoduledir = self.tempdir + "/submodule" | ||
2414 | bb.utils.mkdirhier(submoduledir) | ||
2415 | self.git_init(submoduledir) | ||
2416 | self.git(["lfs", "install", "--local"], cwd=submoduledir) | ||
2417 | self.commit_file('.gitattributes', '*.mp3 filter=lfs -text', cwd=submoduledir) | ||
2418 | |||
2419 | submodule_commit_1 = self.commit_file("a.mp3", "submodule version 1", cwd=submoduledir) | ||
2420 | |||
2421 | # Add the submodule to the repository at its current HEAD revision | ||
2422 | self.git(["-c", "protocol.file.allow=always", "submodule", "add", submoduledir, "submodule"], | ||
2423 | cwd=self.srcdir) | ||
2424 | base_commit_1 = self.commit() | ||
2425 | |||
2426 | # Add a LFS file to the repository | ||
2427 | base_commit_2 = self.commit_file("a.mp3", "version 1") | ||
2428 | |||
2429 | self.d.setVar('SRC_URI', "gitsm://%s;protocol=file;lfs=1;branch=master;lfs=0" % self.srcdir) | ||
2430 | |||
2431 | # Verify that LFS objects referenced from submodules are not fetched nor checked out | ||
2432 | fetch_and_verify(base_commit_1, "submodule/a.mp3", "submodule version 1") | ||
2433 | # Verify that the LFS objects referenced from the base repository are not fetched nor | ||
2434 | # checked out | ||
2435 | fetch_and_verify(base_commit_2, "a.mp3", "version 1") | ||
2436 | |||
2437 | @skipIfNoGitLFS() | ||
2328 | def test_fetch_lfs_on_srcrev_change(self): | 2438 | def test_fetch_lfs_on_srcrev_change(self): |
2329 | """Test if fetch downloads missing LFS objects when a different revision within an existing repository is requested""" | 2439 | """Test if fetch downloads missing LFS objects when a different revision within an existing repository is requested""" |
2330 | self.git(["lfs", "install", "--local"], cwd=self.srcdir) | 2440 | self.git(["lfs", "install", "--local"], cwd=self.srcdir) |
2331 | 2441 | ||
2332 | @contextlib.contextmanager | ||
2333 | def hide_upstream_repository(): | ||
2334 | """Hide the upstream repository to make sure that git lfs cannot pull from it""" | ||
2335 | temp_name = self.srcdir + ".bak" | ||
2336 | os.rename(self.srcdir, temp_name) | ||
2337 | try: | ||
2338 | yield | ||
2339 | finally: | ||
2340 | os.rename(temp_name, self.srcdir) | ||
2341 | |||
2342 | def fetch_and_verify(revision, filename, content): | 2442 | def fetch_and_verify(revision, filename, content): |
2343 | self.d.setVar('SRCREV', revision) | 2443 | self.d.setVar('SRCREV', revision) |
2344 | fetcher, ud = self.fetch() | 2444 | fetcher, ud = self.fetch() |
2345 | 2445 | ||
2346 | with hide_upstream_repository(): | 2446 | with hide_directory(self.srcdir): |
2347 | workdir = self.d.getVar('WORKDIR') | 2447 | workdir = self.d.getVar('WORKDIR') |
2348 | fetcher.unpack(workdir) | 2448 | fetcher.unpack(workdir) |
2349 | 2449 | ||