diff options
Diffstat (limited to 'bitbake/lib/bb/tests/fetch.py')
| -rw-r--r-- | bitbake/lib/bb/tests/fetch.py | 182 |
1 files changed, 86 insertions, 96 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index a56d7daa3b..4bcff543fc 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py | |||
| @@ -251,8 +251,23 @@ class URITest(unittest.TestCase): | |||
| 251 | self.assertEqual(uri.params, {}) | 251 | self.assertEqual(uri.params, {}) |
| 252 | self.assertEqual(str(uri), (str(uri).split(";"))[0]) | 252 | self.assertEqual(str(uri), (str(uri).split(";"))[0]) |
| 253 | 253 | ||
| 254 | class FetcherTest(unittest.TestCase): | ||
| 255 | |||
| 256 | def setUp(self): | ||
| 257 | self.d = bb.data.init() | ||
| 258 | self.tempdir = tempfile.mkdtemp() | ||
| 259 | self.dldir = os.path.join(self.tempdir, "download") | ||
| 260 | os.mkdir(self.dldir) | ||
| 261 | self.d.setVar("DL_DIR", self.dldir) | ||
| 262 | self.unpackdir = os.path.join(self.tempdir, "unpacked") | ||
| 263 | os.mkdir(self.unpackdir) | ||
| 264 | persistdir = os.path.join(self.tempdir, "persistdata") | ||
| 265 | self.d.setVar("PERSISTENT_DIR", persistdir) | ||
| 254 | 266 | ||
| 255 | class FetcherUriTest(unittest.TestCase): | 267 | def tearDown(self): |
| 268 | bb.utils.prunedir(self.tempdir) | ||
| 269 | |||
| 270 | class MirrorUriTest(FetcherTest): | ||
| 256 | 271 | ||
| 257 | replaceuris = { | 272 | replaceuris = { |
| 258 | ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "http://somewhere.org/somedir/") | 273 | ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "http://somewhere.org/somedir/") |
| @@ -315,102 +330,77 @@ class FetcherUriTest(unittest.TestCase): | |||
| 315 | uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d) | 330 | uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d) |
| 316 | self.assertEqual(uris, ['file:///someotherpath/downloads/bitbake-1.0.tar.gz']) | 331 | self.assertEqual(uris, ['file:///someotherpath/downloads/bitbake-1.0.tar.gz']) |
| 317 | 332 | ||
| 318 | class FetcherTest(unittest.TestCase): | 333 | class FetcherNetworkTest(FetcherTest): |
| 319 | 334 | ||
| 320 | def setUp(self): | 335 | if os.environ.get("BB_SKIP_NETTESTS") == "yes": |
| 321 | self.d = bb.data.init() | 336 | print("Unset BB_SKIP_NETTESTS to run network tests") |
| 322 | self.tempdir = tempfile.mkdtemp() | 337 | else: |
| 323 | self.dldir = os.path.join(self.tempdir, "download") | 338 | def test_fetch(self): |
| 324 | os.mkdir(self.dldir) | 339 | fetcher = bb.fetch.Fetch(["http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d) |
| 325 | self.d.setVar("DL_DIR", self.dldir) | 340 | fetcher.download() |
| 326 | self.unpackdir = os.path.join(self.tempdir, "unpacked") | 341 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) |
| 327 | os.mkdir(self.unpackdir) | 342 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.1.tar.gz"), 57892) |
| 328 | persistdir = os.path.join(self.tempdir, "persistdata") | 343 | self.d.setVar("BB_NO_NETWORK", "1") |
| 329 | self.d.setVar("PERSISTENT_DIR", persistdir) | 344 | fetcher = bb.fetch.Fetch(["http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d) |
| 330 | 345 | fetcher.download() | |
| 331 | def tearDown(self): | ||
| 332 | bb.utils.prunedir(self.tempdir) | ||
| 333 | |||
| 334 | @unittest.skipIf(os.environ.get("BB_SKIP_NETTESTS") == "yes", | ||
| 335 | "Unset BB_SKIP_NETTESTS to run network tests") | ||
| 336 | def test_fetch(self): | ||
| 337 | fetcher = bb.fetch.Fetch(["http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d) | ||
| 338 | fetcher.download() | ||
| 339 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) | ||
| 340 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.1.tar.gz"), 57892) | ||
| 341 | self.d.setVar("BB_NO_NETWORK", "1") | ||
| 342 | fetcher = bb.fetch.Fetch(["http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d) | ||
| 343 | fetcher.download() | ||
| 344 | fetcher.unpack(self.unpackdir) | ||
| 345 | self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.0/")), 9) | ||
| 346 | self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.1/")), 9) | ||
| 347 | |||
| 348 | @unittest.skipIf(os.environ.get("BB_SKIP_NETTESTS") == "yes", | ||
| 349 | "Unset BB_SKIP_NETTESTS to run network tests") | ||
| 350 | def test_fetch_mirror(self): | ||
| 351 | self.d.setVar("MIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake") | ||
| 352 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d) | ||
| 353 | fetcher.download() | ||
| 354 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) | ||
| 355 | |||
| 356 | @unittest.skipIf(os.environ.get("BB_SKIP_NETTESTS") == "yes", | ||
| 357 | "Unset BB_SKIP_NETTESTS to run network tests") | ||
| 358 | def test_fetch_premirror(self): | ||
| 359 | self.d.setVar("PREMIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake") | ||
| 360 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d) | ||
| 361 | fetcher.download() | ||
| 362 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) | ||
| 363 | |||
| 364 | def gitfetcher(self, url1, url2): | ||
| 365 | def checkrevision(self, fetcher): | ||
| 366 | fetcher.unpack(self.unpackdir) | 346 | fetcher.unpack(self.unpackdir) |
| 367 | revision = bb.process.run("git rev-parse HEAD", shell=True, cwd=self.unpackdir + "/git")[0].strip() | 347 | self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.0/")), 9) |
| 368 | self.assertEqual(revision, "270a05b0b4ba0959fe0624d2a4885d7b70426da5") | 348 | self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.1/")), 9) |
| 369 | 349 | ||
| 370 | self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1") | 350 | def test_fetch_mirror(self): |
| 371 | self.d.setVar("SRCREV", "270a05b0b4ba0959fe0624d2a4885d7b70426da5") | 351 | self.d.setVar("MIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake") |
| 372 | fetcher = bb.fetch.Fetch([url1], self.d) | 352 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d) |
| 373 | fetcher.download() | 353 | fetcher.download() |
| 374 | checkrevision(self, fetcher) | 354 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) |
| 375 | # Wipe out the dldir clone and the unpacked source, turn off the network and check mirror tarball works | 355 | |
| 376 | bb.utils.prunedir(self.dldir + "/git2/") | 356 | def test_fetch_premirror(self): |
| 377 | bb.utils.prunedir(self.unpackdir) | 357 | self.d.setVar("PREMIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake") |
| 378 | self.d.setVar("BB_NO_NETWORK", "1") | 358 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d) |
| 379 | fetcher = bb.fetch.Fetch([url2], self.d) | 359 | fetcher.download() |
| 380 | fetcher.download() | 360 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) |
| 381 | checkrevision(self, fetcher) | 361 | |
| 382 | 362 | def gitfetcher(self, url1, url2): | |
| 383 | @unittest.skipIf(os.environ.get("BB_SKIP_NETTESTS") == "yes", | 363 | def checkrevision(self, fetcher): |
| 384 | "Unset BB_SKIP_NETTESTS to run network tests") | 364 | fetcher.unpack(self.unpackdir) |
| 385 | def test_gitfetch(self): | 365 | revision = bb.process.run("git rev-parse HEAD", shell=True, cwd=self.unpackdir + "/git")[0].strip() |
| 386 | url1 = url2 = "git://git.openembedded.org/bitbake" | 366 | self.assertEqual(revision, "270a05b0b4ba0959fe0624d2a4885d7b70426da5") |
| 387 | self.gitfetcher(url1, url2) | 367 | |
| 388 | 368 | self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1") | |
| 389 | @unittest.skipIf(os.environ.get("BB_SKIP_NETTESTS") == "yes", | 369 | self.d.setVar("SRCREV", "270a05b0b4ba0959fe0624d2a4885d7b70426da5") |
| 390 | "Unset BB_SKIP_NETTESTS to run network tests") | 370 | fetcher = bb.fetch.Fetch([url1], self.d) |
| 391 | def test_gitfetch_premirror(self): | 371 | fetcher.download() |
| 392 | url1 = "git://git.openembedded.org/bitbake" | 372 | checkrevision(self, fetcher) |
| 393 | url2 = "git://someserver.org/bitbake" | 373 | # Wipe out the dldir clone and the unpacked source, turn off the network and check mirror tarball works |
| 394 | self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n") | 374 | bb.utils.prunedir(self.dldir + "/git2/") |
| 395 | self.gitfetcher(url1, url2) | 375 | bb.utils.prunedir(self.unpackdir) |
| 396 | 376 | self.d.setVar("BB_NO_NETWORK", "1") | |
| 397 | @unittest.skipIf(os.environ.get("BB_SKIP_NETTESTS") == "yes", | 377 | fetcher = bb.fetch.Fetch([url2], self.d) |
| 398 | "Unset BB_SKIP_NETTESTS to run network tests") | 378 | fetcher.download() |
| 399 | def test_gitfetch_premirror2(self): | 379 | checkrevision(self, fetcher) |
| 400 | url1 = url2 = "git://someserver.org/bitbake" | 380 | |
| 401 | self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n") | 381 | def test_gitfetch(self): |
| 402 | self.gitfetcher(url1, url2) | 382 | url1 = url2 = "git://git.openembedded.org/bitbake" |
| 403 | 383 | self.gitfetcher(url1, url2) | |
| 404 | @unittest.skipIf(os.environ.get("BB_SKIP_NETTESTS") == "yes", | 384 | |
| 405 | "Unset BB_SKIP_NETTESTS to run network tests") | 385 | def test_gitfetch_premirror(self): |
| 406 | def test_gitfetch_premirror3(self): | 386 | url1 = "git://git.openembedded.org/bitbake" |
| 407 | realurl = "git://git.openembedded.org/bitbake" | 387 | url2 = "git://someserver.org/bitbake" |
| 408 | dummyurl = "git://someserver.org/bitbake" | 388 | self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n") |
| 409 | self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git") | 389 | self.gitfetcher(url1, url2) |
| 410 | os.chdir(self.tempdir) | 390 | |
| 411 | bb.process.run("git clone %s %s 2> /dev/null" % (realurl, self.sourcedir), shell=True) | 391 | def test_gitfetch_premirror2(self): |
| 412 | self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file \n" % (dummyurl, self.sourcedir)) | 392 | url1 = url2 = "git://someserver.org/bitbake" |
| 413 | self.gitfetcher(dummyurl, dummyurl) | 393 | self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n") |
| 394 | self.gitfetcher(url1, url2) | ||
| 395 | |||
| 396 | def test_gitfetch_premirror3(self): | ||
| 397 | realurl = "git://git.openembedded.org/bitbake" | ||
| 398 | dummyurl = "git://someserver.org/bitbake" | ||
| 399 | self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git") | ||
| 400 | os.chdir(self.tempdir) | ||
| 401 | bb.process.run("git clone %s %s 2> /dev/null" % (realurl, self.sourcedir), shell=True) | ||
| 402 | self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file \n" % (dummyurl, self.sourcedir)) | ||
| 403 | self.gitfetcher(dummyurl, dummyurl) | ||
| 414 | 404 | ||
| 415 | class URLHandle(unittest.TestCase): | 405 | class URLHandle(unittest.TestCase): |
| 416 | 406 | ||
