Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-130362 / 24.10 / Add system.vendor.is_vendored endpoint #14117

Merged
merged 7 commits into from
Aug 1, 2024
8 changes: 8 additions & 0 deletions src/middlewared/middlewared/api/v25_04_0/vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ class UnvendorArgs(BaseModel):

class UnvendorResult(BaseModel):
result: None


class IsVendoredArgs(BaseModel):
pass


class IsVendoredResult(BaseModel):
result: bool
8 changes: 7 additions & 1 deletion src/middlewared/middlewared/plugins/system_vendor/vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
7 changes: 4 additions & 3 deletions tests/api2/test_system_vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading