Skip to content

Commit

Permalink
NAS-130912 / 25.04 / Remove REST calls in test_100_bootenv (#14407)
Browse files Browse the repository at this point in the history
* Updated test

* Updated test

* Quote conformity

* Cleanup

* Suggested changes

* Suggested changes

* Unused import

* Weird import

* Removed length

* Removed unused variable assignment
  • Loading branch information
aiden3c authored Sep 4, 2024
1 parent 205ce8d commit 8adce7a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 118 deletions.
107 changes: 0 additions & 107 deletions tests/api2/test_100_bootenv.py

This file was deleted.

68 changes: 57 additions & 11 deletions tests/api2/test_bootenv.py
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}')

0 comments on commit 8adce7a

Please sign in to comment.