From 958fcf17ff1b49606631b93df1e45807f2e684c9 Mon Sep 17 00:00:00 2001 From: Logan Cary Date: Wed, 31 Jul 2024 21:07:55 -0400 Subject: [PATCH] NAS-130362 / 24.10 / Add `system.vendor.is_vendored` endpoint (#14117) * add `is_vendored` endpoint * set `is_vendored` to private * fix `IsVendoredResult` --- 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..b9900199bb850 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: bool diff --git a/src/middlewared/middlewared/plugins/system_vendor/vendor.py b/src/middlewared/middlewared/plugins/system_vendor/vendor.py index bca773e2db2dc..68912ae43ab97 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 @@ -37,3 +39,7 @@ def unvendor(self): self.logger.exception('Unexpected error attempting to remove %r', SENTINEL_FILE_PATH) self.middleware.call_sync('etc.generate', 'grub') + + @api_method(IsVendoredArgs, IsVendoredResult, private=True) + 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