-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-130912 / 25.04 / Remove REST calls in test_100_bootenv (#14407)
* Updated test * Updated test * Quote conformity * Cleanup * Suggested changes * Suggested changes * Unused import * Weird import * Removed length * Removed unused variable assignment
- Loading branch information
Showing
2 changed files
with
57 additions
and
118 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}') |