From 775fcbaf7b0cec5670814d783f843a46c8cbfa8f Mon Sep 17 00:00:00 2001 From: Aiden Baker Date: Tue, 23 Jul 2024 11:30:46 -0400 Subject: [PATCH 1/6] Prevent new tickets --- src/middlewared/middlewared/plugins/support.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/middlewared/middlewared/plugins/support.py b/src/middlewared/middlewared/plugins/support.py index c8a7735bc514f..9323af8a5fb0f 100644 --- a/src/middlewared/middlewared/plugins/support.py +++ b/src/middlewared/middlewared/plugins/support.py @@ -224,6 +224,9 @@ async def new_ticket(self, job, data): For SCALE Enterprise `token` and `type` attributes are not required. """ + if await self.middleware.call('system.vendor.name'): + raise CallError('Support is not available for this product', errno.EINVAL) + await self.middleware.call('network.general.will_perform_activity', 'support') job.set_progress(1, 'Gathering data') From e4c1c80a3c04df49b64e7a29f7674cfcbaf2d831 Mon Sep 17 00:00:00 2001 From: Aiden Baker Date: Tue, 23 Jul 2024 12:02:59 -0400 Subject: [PATCH 2/6] Show support unavailable Also paradigm update --- src/freenas/usr/local/bin/truenas-grub.py | 6 +++--- src/middlewared/middlewared/plugins/support.py | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/freenas/usr/local/bin/truenas-grub.py b/src/freenas/usr/local/bin/truenas-grub.py index 842bc414ae369..d321553ea1d78 100755 --- a/src/freenas/usr/local/bin/truenas-grub.py +++ b/src/freenas/usr/local/bin/truenas-grub.py @@ -16,12 +16,12 @@ def get_serial_ports(): advanced = query_config_table("system_advanced", prefix="adv_") kernel_extra_options = advanced.get("kernel_extra_options") or "" - # check for /data/.vendor + vendor = "TrueNAS Scale" try: with open("/data/.vendor", "r") as f: vendor = json.loads(f.read()).get("name", "TrueNAS Scale") - except FileNotFoundError: - vendor = "TrueNAS Scale" + except Exception: + pass # We need to allow tpm in grub as sedutil-cli requires it # `zfsforce=1` is needed because FreeBSD bootloader imports boot pool with hostid=0 while SCALE releases up to diff --git a/src/middlewared/middlewared/plugins/support.py b/src/middlewared/middlewared/plugins/support.py index 9323af8a5fb0f..e5739d4869bd4 100644 --- a/src/middlewared/middlewared/plugins/support.py +++ b/src/middlewared/middlewared/plugins/support.py @@ -108,6 +108,9 @@ async def is_available(self): Returns whether Proactive Support is available for this product type and current license. """ + if await self.middleware.call('system.vendor.name'): + return False + if not await self.middleware.call('system.is_enterprise'): return False From b46ceddcda0aa02a1cbbb5559958cbb50d56fe31 Mon Sep 17 00:00:00 2001 From: Aiden Baker Date: Wed, 24 Jul 2024 08:26:19 -0400 Subject: [PATCH 3/6] use vendor enum --- src/freenas/usr/local/bin/truenas-grub.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/freenas/usr/local/bin/truenas-grub.py b/src/freenas/usr/local/bin/truenas-grub.py index d321553ea1d78..75fe89a7c91f8 100755 --- a/src/freenas/usr/local/bin/truenas-grub.py +++ b/src/freenas/usr/local/bin/truenas-grub.py @@ -6,6 +6,7 @@ from middlewared.utils.serial import serial_port_choices from middlewared.utils.db import query_config_table +from middlewared.utils.vendor import Vendors def get_serial_ports(): @@ -16,10 +17,10 @@ def get_serial_ports(): advanced = query_config_table("system_advanced", prefix="adv_") kernel_extra_options = advanced.get("kernel_extra_options") or "" - vendor = "TrueNAS Scale" + vendor = Vendors.TRUENAS_SCALE try: with open("/data/.vendor", "r") as f: - vendor = json.loads(f.read()).get("name", "TrueNAS Scale") + vendor = json.loads(f.read()).get("name", Vendors.TRUENAS_SCALE) except Exception: pass From b7b1e0a3867632b61a1c0cf4f5357eef2de696a2 Mon Sep 17 00:00:00 2001 From: Aiden Baker Date: Wed, 24 Jul 2024 09:12:34 -0400 Subject: [PATCH 4/6] Suggested changes --- src/freenas/usr/local/bin/truenas-grub.py | 6 +++++- src/middlewared/middlewared/plugins/support.py | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/freenas/usr/local/bin/truenas-grub.py b/src/freenas/usr/local/bin/truenas-grub.py index 75fe89a7c91f8..88403a022f1a9 100755 --- a/src/freenas/usr/local/bin/truenas-grub.py +++ b/src/freenas/usr/local/bin/truenas-grub.py @@ -3,11 +3,13 @@ import psutil import os import json +import logging from middlewared.utils.serial import serial_port_choices from middlewared.utils.db import query_config_table from middlewared.utils.vendor import Vendors +logger = logging.getLogger(__name__) def get_serial_ports(): return {e['start']: e['name'].replace('uart', 'ttyS') for e in serial_port_choices()} @@ -21,8 +23,10 @@ def get_serial_ports(): try: with open("/data/.vendor", "r") as f: vendor = json.loads(f.read()).get("name", Vendors.TRUENAS_SCALE) - except Exception: + except FileNotFoundError: pass + except Exception: + logger.error("Failed to parse /data/.vendor", exc_info=True) # We need to allow tpm in grub as sedutil-cli requires it # `zfsforce=1` is needed because FreeBSD bootloader imports boot pool with hostid=0 while SCALE releases up to diff --git a/src/middlewared/middlewared/plugins/support.py b/src/middlewared/middlewared/plugins/support.py index e5739d4869bd4..e27e92ab173ac 100644 --- a/src/middlewared/middlewared/plugins/support.py +++ b/src/middlewared/middlewared/plugins/support.py @@ -227,8 +227,9 @@ async def new_ticket(self, job, data): For SCALE Enterprise `token` and `type` attributes are not required. """ - if await self.middleware.call('system.vendor.name'): - raise CallError('Support is not available for this product', errno.EINVAL) + vendor = await self.middleware.call('system.vendor.name') + if vendor: + raise CallError(f'Support is not available for this product ({vendor})', errno.EINVAL) await self.middleware.call('network.general.will_perform_activity', 'support') From bc80432879f2bd820fac0d5c89b7c2ff753c959b Mon Sep 17 00:00:00 2001 From: Aiden Baker Date: Wed, 24 Jul 2024 14:18:52 -0400 Subject: [PATCH 5/6] Initial commit --- tests/api2/test_pool_replace_disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/api2/test_pool_replace_disk.py b/tests/api2/test_pool_replace_disk.py index 1347194d48dc2..b3bafbac3282e 100644 --- a/tests/api2/test_pool_replace_disk.py +++ b/tests/api2/test_pool_replace_disk.py @@ -34,7 +34,7 @@ def test_pool_replace_disk(topology, i): }, job=True) # Sometimes the VM is slow so look 5 times with 1 second in between - for _ in range(5): + for _ in range(10): pool = call("pool.get_instance", pool["id"]) if len(disks(pool["topology"])) == count: break From e3437c3cd035f9ce95a05b328ab0507f9db8775a Mon Sep 17 00:00:00 2001 From: Aiden Baker Date: Thu, 25 Jul 2024 08:57:36 -0400 Subject: [PATCH 6/6] Updated comment --- tests/api2/test_pool_replace_disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/api2/test_pool_replace_disk.py b/tests/api2/test_pool_replace_disk.py index b3bafbac3282e..a2c933403c8ef 100644 --- a/tests/api2/test_pool_replace_disk.py +++ b/tests/api2/test_pool_replace_disk.py @@ -33,7 +33,7 @@ def test_pool_replace_disk(topology, i): "force": True, }, job=True) - # Sometimes the VM is slow so look 5 times with 1 second in between + # Sometimes the VM is slow so look 10 times with 1 second in between for _ in range(10): pool = call("pool.get_instance", pool["id"]) if len(disks(pool["topology"])) == count: