diff --git a/tests/api2/test_100_bootenv.py b/tests/api2/test_100_bootenv.py deleted file mode 100644 index 8202125574f6e..0000000000000 --- a/tests/api2/test_100_bootenv.py +++ /dev/null @@ -1,107 +0,0 @@ -import sys -import os -from time import sleep -from unittest.mock import ANY - -apifolder = os.getcwd() -sys.path.append(apifolder) -from functions import POST, DELETE, GET, PUT, wait_on_job - - -def test_01_get_the_activated_bootenv(): - global active_be_id - results = GET('/bootenv/?activated=True') - assert results.status_code == 200, results.text - active_be_id = results.json()[0]['id'] - - -def test_02_create_be_duplicate_name(): - payload = {"name": active_be_id, "source": active_be_id} - results = POST("/bootenv/", payload) - assert results.status_code == 422, results.text - assert results.json() == {"bootenv_create.name": ANY} - - -def test_02_creating_a_new_boot_environment_from_the_active_boot_environment(): - payload = {"name": "bootenv01", "source": active_be_id} - results = POST("/bootenv/", payload) - assert results.status_code == 200, results.text - sleep(1) - - -def test_03_look_new_bootenv_is_created(): - assert len(GET('/bootenv?name=bootenv01').json()) == 1 - - -def test_04_activate_bootenv01(): - results = POST("/bootenv/id/bootenv01/activate/", None) - assert results.status_code == 200, results.text - - -# Update tests -def test_05_cloning_a_new_boot_environment(): - payload = {"name": "bootenv02", "source": "bootenv01"} - results = POST("/bootenv/", payload) - assert results.status_code == 200, results.text - sleep(1) - - -def test_06_activate_bootenv02(): - payload = None - results = POST("/bootenv/id/bootenv02/activate/", payload) - assert results.status_code == 200, results.text - - -def test_07_change_boot_environment_name(): - payload = {"name": "bootenv03"} - results = PUT("/bootenv/id/bootenv01/", payload) - assert results.status_code == 200, results.text - - -def test_08_set_keep_attribute_true(): - payload = {"keep": True} - results = POST("/bootenv/id/bootenv03/set_attribute/", payload) - assert results.status_code == 200, results.text - - -def test_09_activate_bootenv03(): - payload = None - results = POST("/bootenv/id/bootenv03/activate/", payload) - assert results.status_code == 200, results.text - - -# Delete tests -def test_10_removing_a_boot_environment_02(): - global job_id - results = DELETE("/bootenv/id/bootenv02/") - assert results.status_code == 200, results.text - job_id = results.json() - - -def test_11_verify_the_removing_be_job_is_successfull(request): - job_status = wait_on_job(job_id, 180) - assert job_status['state'] == 'SUCCESS', str(job_status['results']) - - -def test_12_set_keep_attribute_true(): - payload = {"keep": False} - results = POST("/bootenv/id/bootenv03/set_attribute/", payload) - assert results.status_code == 200, results.text - - -def test_13_activate_default(): - payload = None - results = POST(f"/bootenv/id/{active_be_id}/activate/", payload) - assert results.status_code == 200, results.text - - -def test_14_removing_a_boot_environment_03(): - global job_id - results = DELETE("/bootenv/id/bootenv03/") - assert results.status_code == 200, results.text - job_id = results.json() - - -def test_15_verify_the_removing_be_job_is_successfull(request): - job_status = wait_on_job(job_id, 180) - assert job_status['state'] == 'SUCCESS', str(job_status['results']) diff --git a/tests/api2/test_bootenv.py b/tests/api2/test_bootenv.py index 62dc0cb728098..8d8c63f97ac48 100644 --- a/tests/api2/test_bootenv.py +++ b/tests/api2/test_bootenv.py @@ -1,24 +1,70 @@ +import errno + +import pytest + +from middlewared.service_exception import ValidationErrors, ValidationError from middlewared.test.integration.utils import call, ssh +def test_get_default_environment_and_make_new_one(): + active_be_id = call('bootenv.query', [['activated', '=', True]], {'get': True})['id'] + + # create duplicate name to test failure + with pytest.raises(ValidationErrors) as ve: + call('bootenv.create', {'name': active_be_id, 'source': active_be_id}) + assert ve.value.errors == [ + ValidationError('bootenv_create.name', f'The name "{active_be_id}" already exists', errno.EEXIST) + ] + + # create new bootenv and activate it + call('bootenv.create', {'name': 'bootenv01', 'source': active_be_id}) + call('bootenv.query', [['name', '=', 'bootenv01']], {'get': True}) + call('bootenv.activate', 'bootenv01') + + +# Update tests +def test_cloning_a_new_boot_environment(): + call('bootenv.create', {'name': 'bootenv02', 'source': 'bootenv01'}) + call('bootenv.activate', 'bootenv02') + + +def test_change_boot_environment_name_and_attributes(): + call('bootenv.update', 'bootenv01', {'name': 'bootenv03'}) + call('bootenv.set_attribute', 'bootenv03', {'keep': True}) + call('bootenv.activate', 'bootenv03') + assert call('bootenv.query', [['activated', '=', True]], {'get': True})['id'] == 'bootenv3' + + +# Delete tests +def test_activate_original_bootenv(): + be_id = call('bootenv.query', [['name', '!=', 'bootenv03']], {'get': True})["id"] + call('bootenv.activate', be_id) + + +def test_removing_boot_environments(): + call('bootenv.set_attribute', 'bootenv03', {'keep': False}) + call('bootenv.delete', 'bootenv02', job=True) + call('bootenv.delete', 'bootenv03', job=True) + + def test_promote_current_be_datasets(): - var_log = ssh("df | grep /var/log").split()[0] + var_log = ssh('df | grep /var/log').split()[0] - snapshot_name = "snap-1" - snapshot = f"{var_log}@{snapshot_name}" - ssh(f"zfs snapshot {snapshot}") + snapshot_name = 'snap-1' + snapshot = f'{var_log}@{snapshot_name}' + ssh(f'zfs snapshot {snapshot}') try: - clone = "boot-pool/ROOT/clone" + clone = 'boot-pool/ROOT/clone' ssh(f"zfs clone {snapshot} {clone}") try: - ssh(f"zfs promote {clone}") + ssh(f'zfs promote {clone}') - assert ssh(f"zfs get -H -o value origin {var_log}").strip() == f"{clone}@{snapshot_name}" + assert ssh(f'zfs get -H -o value origin {var_log}').strip() == f'{clone}@{snapshot_name}' - call("bootenv.promote_current_be_datasets") + call('bootenv.promote_current_be_datasets') - assert ssh(f"zfs get -H -o value origin {var_log}").strip() == "-" + assert ssh(f'zfs get -H -o value origin {var_log}').strip() == '-' finally: - ssh(f"zfs destroy {clone}") + ssh(f'zfs destroy {clone}') finally: - ssh(f"zfs destroy {snapshot}") + ssh(f'zfs destroy {snapshot}')