From 687bc3a53bc1e2537ca4189e4b8d12cef6404ae8 Mon Sep 17 00:00:00 2001 From: Logan Cary Date: Tue, 23 Jul 2024 13:08:04 -0400 Subject: [PATCH 1/3] add `is_vendored` endpoint --- src/middlewared/middlewared/api/v25_04_0/vendor.py | 8 ++++++++ .../middlewared/plugins/system_vendor/vendor.py | 8 +++++++- tests/api2/test_system_vendor.py | 7 ++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/middlewared/middlewared/api/v25_04_0/vendor.py b/src/middlewared/middlewared/api/v25_04_0/vendor.py index 62a83a5a4295a..c5ae3a0985b79 100644 --- a/src/middlewared/middlewared/api/v25_04_0/vendor.py +++ b/src/middlewared/middlewared/api/v25_04_0/vendor.py @@ -15,3 +15,11 @@ class UnvendorArgs(BaseModel): class UnvendorResult(BaseModel): result: None + + +class IsVendoredArgs(BaseModel): + pass + + +class IsVendoredResult(BaseModel): + result: None diff --git a/src/middlewared/middlewared/plugins/system_vendor/vendor.py b/src/middlewared/middlewared/plugins/system_vendor/vendor.py index 81324e41a7b49..730cde984abec 100644 --- a/src/middlewared/middlewared/plugins/system_vendor/vendor.py +++ b/src/middlewared/middlewared/plugins/system_vendor/vendor.py @@ -2,7 +2,9 @@ import os from middlewared.api import api_method -from middlewared.api.current import VendorNameArgs, VendorNameResult, UnvendorArgs, UnvendorResult +from middlewared.api.current import ( + VendorNameArgs, VendorNameResult, UnvendorArgs, UnvendorResult, IsVendoredArgs, IsVendoredResult +) from middlewared.service import Service @@ -35,3 +37,7 @@ def unvendor(self): pass except Exception: self.logger.exception('Unexpected error attempting to remove %r', SENTINEL_FILE_PATH) + + @api_method(IsVendoredArgs, IsVendoredResult) + def is_vendored(self): + return os.path.isfile(SENTINEL_FILE_PATH) diff --git a/tests/api2/test_system_vendor.py b/tests/api2/test_system_vendor.py index 83581088db24b..2d8c87759da11 100644 --- a/tests/api2/test_system_vendor.py +++ b/tests/api2/test_system_vendor.py @@ -4,11 +4,12 @@ SENTINEL_FILE_PATH = "/data/.vendor" -def test_name_is_none(): - # /data/.vendor should not exist +def test_no_vendor_file(): file_exists = ssh(f"test -e {SENTINEL_FILE_PATH}", check=False, complete_response=True)["result"] assert not file_exists + assert not call("system.vendor.is_vendored") + - # system.vendor.name should successfully return None +def test_name_is_none(): vendor_name = call("system.vendor.name") assert vendor_name is None From 58e53afd13f31ea1df7f89419dbd78efc23dd405 Mon Sep 17 00:00:00 2001 From: Logan Cary Date: Thu, 25 Jul 2024 12:48:42 -0400 Subject: [PATCH 2/3] set `is_vendored` to private --- src/middlewared/middlewared/plugins/system_vendor/vendor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/middlewared/middlewared/plugins/system_vendor/vendor.py b/src/middlewared/middlewared/plugins/system_vendor/vendor.py index 0d12c2ec23d38..68912ae43ab97 100644 --- a/src/middlewared/middlewared/plugins/system_vendor/vendor.py +++ b/src/middlewared/middlewared/plugins/system_vendor/vendor.py @@ -40,6 +40,6 @@ def unvendor(self): self.middleware.call_sync('etc.generate', 'grub') - @api_method(IsVendoredArgs, IsVendoredResult) + @api_method(IsVendoredArgs, IsVendoredResult, private=True) def is_vendored(self): return os.path.isfile(SENTINEL_FILE_PATH) From 9c69620e99c225866e44a3749ff44f066ceefe24 Mon Sep 17 00:00:00 2001 From: Logan Cary Date: Wed, 31 Jul 2024 13:39:01 -0400 Subject: [PATCH 3/3] fix `IsVendoredResult` --- src/middlewared/middlewared/api/v25_04_0/vendor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/middlewared/middlewared/api/v25_04_0/vendor.py b/src/middlewared/middlewared/api/v25_04_0/vendor.py index c5ae3a0985b79..b9900199bb850 100644 --- a/src/middlewared/middlewared/api/v25_04_0/vendor.py +++ b/src/middlewared/middlewared/api/v25_04_0/vendor.py @@ -22,4 +22,4 @@ class IsVendoredArgs(BaseModel): class IsVendoredResult(BaseModel): - result: None + result: bool