Skip to content

Commit

Permalink
combine system advanced tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yocalebo committed Jul 8, 2024
1 parent 234969b commit c31154f
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions tests/api2/test_system_advanced.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import pytest

from middlewared.service_exception import ValidationErrors, ValidationError
from middlewared.test.integration.utils import call
from middlewared.test.integration.utils import call, ssh


def test_valid_kernel_options():
call("system.advanced.update", {"kernel_extra_options": "zfs_arc_min=21474836480"})
call("system.advanced.update", {"kernel_extra_options": ""})


def test_invalid_kernel_options():
with pytest.raises(ValidationErrors) as ve:
call("system.advanced.update", {"kernel_extra_options": "zfs_arc_min=<21474836480>"})

assert ve.value.errors == [
ValidationError("kernel_extra_options", "Invalid syntax"),
]
@pytest.mark.parametrize(
'key,value,grep_file,sshd_config_cmd,validation_error', [
('motd', 'TrueNAS Message Of The Day', '/etc/motd', None, ''),
('login_banner', 'TrueNAS Login Banner', '/etc/login_banner', 'grep Banner /etc/ssh/sshd_config', ''),
('kernel_extra_options', 'zfs_arc_min=21474836480', None, None, ''),
('kernel_extra_options', '', None, None, ''),
('kernel_extra_options', 'zfs_arc_min=<21474836480>', None, None, 'Invalid syntax'),
],
ids=[
'Test MOTD',
'Test Login Banner',
'Test Valid Kernel Extra Options 1',
'Test Valid Kernel Extra Options 2',
'Test Invalid Kernel Extra Options 1',
],
)
def test_(key, value, grep_file, sshd_config_cmd, validation_error):
if not validation_error:
call('system.advanced.update', {key: value})
assert call('system.advanced.config')[key] == value
if grep_file is not None:
assert ssh(f'grep "{value}" {grep_file}', complete_response=True)['result']
if sshd_config_cmd is not None:
assert ssh(sshd_config_cmd, complete_response=True)['result']
else:
with pytest.raises(ValidationErrors) as ve:
call('system.advanced.update', {key: value})
assert ve.value.errors == [ValidationError(key, validation_error)]

0 comments on commit c31154f

Please sign in to comment.