diff --git a/tests/api2/test_480_system_advanced.py b/tests/api2/test_480_system_advanced.py index 234264a9a368c..defd9afd94dc7 100644 --- a/tests/api2/test_480_system_advanced.py +++ b/tests/api2/test_480_system_advanced.py @@ -7,7 +7,8 @@ from pytest_dependency import depends apifolder = os.getcwd() sys.path.append(apifolder) -from middlewared.test.integration.utils import call, ssh +from functions import PUT, GET, SSH_TEST +from auto_config import user, password MOTD = 'FREENAS_MOTD' SYSLOGLEVEL = "F_CRIT" @@ -17,76 +18,88 @@ def sysadv_dict(): return {} -def test_system_advanced_get(): - results = call('system.advanced.config') +def test_01_system_advanced_get(): + results = GET('/system/advanced/') + assert results.status_code == 200, results.text + assert isinstance(results.json(), dict) -def test_system_advanced_serial_port_choices(sysadv_dict): - results = call('system.advanced.serial_port_choices') - sysadv_dict['serial_choices'] = [k for k in results] - assert len(results) > 0 +def test_02_system_advanced_serial_port_choices(sysadv_dict): + results = GET('/system/advanced/serial_port_choices/') + assert results.status_code == 200, results.text + data = results.json() + sysadv_dict['serial_choices'] = [k for k in data] + assert isinstance(data, dict), data + assert len(data) > 0, data -def test_system_advanced_set_serial_port(sysadv_dict): - results = call('system.advanced.update', { +def test_03_system_advanced_set_serial_port(sysadv_dict): + results = PUT('/system/advanced/', { 'serialconsole': True, 'serialport': sysadv_dict['serial_choices'][0], }) + assert results.status_code == 200, results.text + data = results.json() + assert isinstance(data, dict), data -def test_system_advanced_check_serial_port_using_api(sysadv_dict): - results = call('system.advanced.config') - assert results['serialport'] == sysadv_dict['serial_choices'][0] +def test_04_system_advanced_check_serial_port_using_api(sysadv_dict): + results = GET('/system/advanced/') + assert results.status_code == 200, results.text + data = results.json() + assert isinstance(data, dict) + assert data['serialport'] == sysadv_dict['serial_choices'][0] -def test_system_advanced_check_serial_port_using_ssh(sysadv_dict, request): +def test_05_system_advanced_check_serial_port_using_ssh(sysadv_dict, request): cmd = f'systemctl | grep "{sysadv_dict["serial_choices"][0]}"' - results = ssh(cmd) + results = SSH_TEST(cmd, user, password) + assert results['result'] is True, results -def test_system_advanced_disable_serial_port(): - results = call('system.advanced.update', { +def test_06_system_advanced_disable_serial_port(): + results = PUT('/system/advanced/', { 'serialconsole': False, }) + assert results.status_code == 200, results.text + data = results.json() + assert isinstance(data, dict), data -def test_system_advanced_check_disabled_serial_port_using_ssh(sysadv_dict, request): - results = ssh(f'grep "{sysadv_dict["serial_choices"][0]}" /boot/loader.conf.local', complete_response=True) +def test_07_system_advanced_check_disabled_serial_port_using_ssh(sysadv_dict, request): + results = SSH_TEST(f'cat /boot/loader.conf.local | grep "{sysadv_dict["serial_choices"][0]}"', user, password) assert results['result'] is False, results -def test_system_advanced_set_motd(): - results = call('system.advanced.update', { - 'motd': MOTD, +def test_08_system_advanced_set_motd(): + results = PUT('/system/advanced/', { + 'motd': MOTD }) + assert results.status_code == 200, results.text + data = results.json() + assert isinstance(data, dict), data -def test_system_advanced_check_motd_using_api(): - results = call('system.advanced.config') - assert results['motd'] == MOTD +def test_09_system_advanced_check_motd_using_api(): + results = GET('/system/advanced/') + assert results.status_code == 200, results.text + data = results.json() + assert isinstance(data, dict) + assert data['motd'] == MOTD -def test_system_advanced_check_motd_using_ssh(request): - results = ssh(f'grep "{MOTD}" /etc/motd', complete_response=True) +def test_10_system_advanced_check_motd_using_ssh(request): + results = SSH_TEST(f'cat /etc/motd | grep "{MOTD}"', user, password) assert results['result'] is True, results -def test_system_advanced_login_banner(): - results = call('system.advanced.update', { - 'login_banner': 'TrueNAS login banner.' - }) - results = call('system.advanced.config') - assert results['login_banner'] == "TrueNAS login banner." - results = ssh('grep Banner /etc/ssh/sshd_config') - assert results['result'] is True, results +def test_11_Setting_sysloglevel(): + results = PUT("/system/advanced/", {"sysloglevel": SYSLOGLEVEL}) + assert results.status_code == 200, results.text -def test_Setting_sysloglevel(): - results = call('system.advanced.update', { - 'sysloglevel': SYSLOGLEVEL - }) - - -def test_Checking_sysloglevel_using_api(): - results = call('system.advanced.config') - assert results['sysloglevel'] == SYSLOGLEVEL +def test_12_Checking_sysloglevel_using_api(): + results = GET("/system/advanced/") + assert results.status_code == 200, results.text + data = results.json() + assert data['sysloglevel'] == SYSLOGLEVEL diff --git a/tests/api2/test_system_advanced_login_banner.py b/tests/api2/test_system_advanced_login_banner.py new file mode 100644 index 0000000000000..20efbf2bf3374 --- /dev/null +++ b/tests/api2/test_system_advanced_login_banner.py @@ -0,0 +1,15 @@ +import os +import pytest +import sys +apifolder = os.getcwd() +sys.path.append(apifolder) +from middlewared.test.integration.utils import call, ssh + +def test_system_advanced_login_banner(): + results = call('system.advanced.update', { + 'login_banner': 'TrueNAS login banner.' + }) + results = call('system.advanced.config') + assert results['login_banner'] == 'TrueNAS login banner.' + results = ssh('grep Banner /etc/ssh/sshd_config') + assert results['result'] is True, results