Skip to content

Commit

Permalink
NAS-130362 / 24.10 / Add system.vendor.is_vendored endpoint (#14117)
Browse files Browse the repository at this point in the history
* add `is_vendored` endpoint

* set `is_vendored` to private

* fix `IsVendoredResult`
  • Loading branch information
creatorcary authored Aug 1, 2024
1 parent b510924 commit 958fcf1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
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

0 comments on commit 958fcf1

Please sign in to comment.