From e5965b2aa4ad6de841bc1e844aa2ef2198a93663 Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Sat, 10 Sep 2022 21:39:40 +0200 Subject: [PATCH] build: cleanup KDIR_TMP after each build Clean the KDIR_TMP folder after each build since it stores every image ever created. Also run isort and black. Signed-off-by: Paul Spooren --- asu/build.py | 26 ++++++++++++++++-- tests/test_api.py | 21 ++++++++++++++ ...sttarget-testsubtarget.Linux-x86_64.tar.xz | Bin 2348 -> 2475 bytes .../Makefile | 3 ++ .../pseudo_kernel_build_dir/tmp/fake_trash | 0 .../testtarget/testsubtarget/sha256sums | 2 +- .../testtarget/testsubtarget/sha256sums.sig | 2 +- 7 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64/pseudo_kernel_build_dir/tmp/fake_trash diff --git a/asu/build.py b/asu/build.py index 96c44681..0cedee8b 100644 --- a/asu/build.py +++ b/asu/build.py @@ -9,8 +9,12 @@ import requests from rq import get_current_job -from .common import (fingerprint_pubkey_usign, get_file_hash, - get_packages_hash, verify_usign) +from .common import ( + fingerprint_pubkey_usign, + get_file_hash, + get_packages_hash, + verify_usign, +) log = logging.getLogger("rq.worker") log.setLevel(logging.DEBUG) @@ -338,6 +342,24 @@ def download_file(filename: str, dest: str = None): if "is too big" in image_build.stderr: report_error("Selected packages exceed device storage") + kernel_build_dir_run = subprocess.run( + ["make", "val.KERNEL_BUILD_DIR"], + text=True, + cwd=cache_workdir, + capture_output=True, + ) + + if kernel_build_dir_run.returncode: + report_error("Couldn't determine KERNEL_BUILD_DIR") + + kernel_build_dir_tmp = Path(kernel_build_dir_run.stdout.strip()) / "tmp" + + if kernel_build_dir_tmp.exists(): + log.info("Removing KDIR_TMP at %s", kernel_build_dir_tmp) + rmtree(kernel_build_dir_tmp) + else: + log.warning("KDIR_TMP missing at %s", kernel_build_dir_tmp) + json_file = Path(req["store_path"] / bin_dir / "profiles.json") if not json_file.is_file(): diff --git a/tests/test_api.py b/tests/test_api.py index ea191313..2f8c0b89 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -518,3 +518,24 @@ def test_api_build_package_to_replace(client, upstream): ) assert response.status == "200 OK" assert response.json.get("request_hash") == "8dd81d51057d322b46aa3739ccf4a8a6" + + +def test_api_build_cleanup(app, upstream): + client = app.test_client() + response = client.post( + "/api/v1/build", + json=dict( + version="TESTVERSION", + target="testtarget/testsubtarget", + profile="testprofile", + packages=["test1", "test2"], + filesystem="ext4", + ), + ) + assert response.status == "200 OK" + assert not ( + app.config["CACHE_PATH"] + / "cache/TESTVERSION/testtarget/testsubtarget" + / "pseudo_kernel_build_dir/tmp/" + / "fake_trash" + ).exists() diff --git a/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64.tar.xz b/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64.tar.xz index 3277025ac771160994f08d450b68cda3768ac779..254ae6452288c4423e1f39e1a0d41478569811c3 100644 GIT binary patch literal 2475 zcmV;c2~_qUiwFP;>>OhN1MOSskK4Ev&)4X$5C-{>bVG-iM0$V%&F0t*x|?h>vp|8O zFer+&wPQ=FjyX{5|K3N+hdi;z_DpxS*_s%{65o&SJs$5MsT8Hjuc`)RGc`6zn@v+w zp~lorqpGoK{A1lF-P_=YEN`#TwTwqGfAwVFf-x3R6#Cz|`^A)Zzw;6j&afacj|B^X z$RqY7jP{oBfYR2`H&CUmO?4LzVAkG2pZ8<=`<0a9{_|g%vZ%ABs4`Ozbdhfz9T<<8 z^Ih{#v7i`76o;5$O!$)!KgIwY=l{O*@8>)l@0PK1{zdHOpMcdzI3i&Gks$Oq|Bq4L zeERtQ!*`?e*Pp+8cRu?3>C^f9v(dZ1pY!);f4&JeQqTVO^Xs$kJ^lCA{#YJb9$^1J zstaSYso5!Gm;J|tEaHC*Z(#p1!Q^QFk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I=))kp39xW%jv5s5%DykgWf>`8i#gk2|&n#=wQ(?<^)b-p)|EiTsk4cMf3 zpLy2R&Y0rE-_Ee-nb~gc!qRP#a1jO};U{Xb!wzyIKvv8R6j_e9QroIba4u zE6w9*>9*r2hO+Wu&yTBSO#M--kRvd^^-Msgs?bpS9?s1GGmD!6kqia1+ z%bBLVe6_e8jo+>qH>9r5bk@g3)4a+vyMTVHiv;?~@&@+DUd3@x_G)cGync-av86Zc zbWON}L2D9>mKyLeT6XvyZS@BAcc8BZw#9?@-`gtrfZu=gm(oo)Z}#Ze`}?niZpMEq zs7#)C{C^@vxl9X*wPaZ`b{Q6ojwNv9g50pC(Qk$9a}XqLY+i9slu8 z8H7KaillOs6K6F@!Zyhg2Z~@5kdBjtgCSC5o~Gl}N@A2&T&2ozqa?AIflhHpovR;t zxl}MiAhsqj{DcF!+1MB>giF$~c8W+xvLrE5F>Ms()Do~KWzHz#w7R3-8@r|7Ti|#u S&*iy1`SKrv&l#ZrHUIzw7s`VG diff --git a/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64/Makefile b/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64/Makefile index 3cd7d9e1..625d4f9e 100644 --- a/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64/Makefile +++ b/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64/Makefile @@ -9,3 +9,6 @@ manifest: info: @cat ./openwrt-testtarget-testsubtarget-testprofile.info + +val.KERNEL_BUILD_DIR: + @echo "$$(pwd)/pseudo_kernel_build_dir/" diff --git a/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64/pseudo_kernel_build_dir/tmp/fake_trash b/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64/pseudo_kernel_build_dir/tmp/fake_trash new file mode 100644 index 00000000..e69de29b diff --git a/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums b/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums index b9edb4d8..35fe96fb 100644 --- a/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums +++ b/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums @@ -1 +1 @@ -f7a57262cde30d84db51d6db5b1eee16f5c0525e67f01dcbe10a9693e3c88fde *openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64.tar.xz +4e645577d934129a65d0f79cf55d90e1199f5ab90ab27803cefae8badc868599 *openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64.tar.xz diff --git a/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums.sig b/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums.sig index 9edfbf77..6999e851 100644 --- a/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums.sig +++ b/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums.sig @@ -1,2 +1,2 @@ untrusted comment: verify with testkey.pub -RWRqylWEtrAZQ/BrgCkjQaOak7bVi7CWfwKbK/rKK39w4e0l7jL+D23xAZZXS3Qb/x6jwulK3lbuCU61etNGaLE2KxWfk1hY4QM= +RWRqylWEtrAZQwwqVGXn0U/Q3nnrboIdIVK2aW7Q8JMN3pmCzHa8o5MppWUqMhxh/h2Dc/3WUjVtWgvfDGrR0tJJ/Wauy9r7QwM=