Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-132498 / 25.04 / audit when pool is exported #14967

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/middlewared/middlewared/plugins/pool_/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ def cleanup_after_export(self, poolinfo, opts):
Bool('restart_services', default=False),
Bool('destroy', default=False),
),
audit="Pool Export", audit_callback=True,
)
@returns()
@job(lock='pool_export')
async def export(self, job, oid, options):
async def export(self, job, audit_callback, oid, options):
"""
Export pool of `id`.

Expand Down Expand Up @@ -79,6 +80,7 @@ async def export(self, job, oid, options):
be disabled before exporting the last zpool on the system.
"""
pool = await self.middleware.call('pool.get_instance', oid)
audit_callback(pool['name'])
root_ds = await self.middleware.call('pool.dataset.query', [['id', '=', pool['name']]])
if root_ds and root_ds[0]['locked'] and os.path.exists(root_ds[0]['mountpoint']):
# We should be removing immutable flag in this case if the path exists
Expand Down
40 changes: 19 additions & 21 deletions tests/api2/test_006_pool_and_sysds.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,27 +147,25 @@ def test_003_verify_unused_disk_and_sysds_functionality_on_2nd_pool(ws_client, p
assert len(unused_disks) >= 1

temp_pool_name = 'temp'
try:
pool = ws_client.call(
'pool.create', {
'name': temp_pool_name,
'topology': {'data': [{'type': 'STRIPE', 'disks': [unused_disks[0]['name']]}]}
},
job=True
)
except Exception as e:
assert False, e
else:
pool_data[pool['name']] = pool
disk_deets = ws_client.call('disk.details')
# disk should not show up in `exported_zpool` keys since it's still imported
assert not any((i['exported_zpool'] == pool['name'] for i in disk_deets['unused']))
# disk should show up in `imported_zpool` key
assert any((i['imported_zpool'] == pool['name'] for i in disk_deets['used']))

sysds = ws_client.call('systemdataset.config')
assert pool['name'] != sysds['pool']
assert f'{pool["name"]}/.system' != sysds['basename']

pool = ws_client.call(
'pool.create', {
'name': temp_pool_name,
'topology': {'data': [{'type': 'STRIPE', 'disks': [unused_disks[0]['name']]}]}
},
job=True
)

pool_data[pool['name']] = pool
disk_deets = ws_client.call('disk.details')
# disk should not show up in `exported_zpool` keys since it's still imported
assert not any((i['exported_zpool'] == pool['name'] for i in disk_deets['unused']))
# disk should show up in `imported_zpool` key
assert any((i['imported_zpool'] == pool['name'] for i in disk_deets['used']))

sysds = ws_client.call('systemdataset.config')
assert pool['name'] != sysds['pool']
assert f'{pool["name"]}/.system' != sysds['basename']

# explicitly migrate sysdataset to temp pool
try:
Expand Down
29 changes: 28 additions & 1 deletion tests/api2/test_audit_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from middlewared.test.integration.assets.pool import another_pool
from middlewared.test.integration.utils import call
from middlewared.test.integration.utils.audit import expect_audit_log
from middlewared.test.integration.utils.audit import expect_audit_log, expect_audit_method_calls


def test_pool_update_audit_success():
Expand Down Expand Up @@ -37,3 +37,30 @@ def test_pool_update_audit_error():
}]):
with pytest.raises(Exception):
call('pool.update', *params, job=True)


def test_pool_create_and_export_audit():
unused_disks = call('disk.get_unused')
assert len(unused_disks) >= 1

pool_name = 'TempPool'
create_payload = {
'name': pool_name,
'topology': {'data': [{'type': 'STRIPE', 'disks': [unused_disks[0]['name']]}]}
}

with expect_audit_method_calls([{
'method': 'pool.create',
'params': [create_payload],
'description': f'Pool create {pool_name}',
}]):
pool_id = call('pool.create', create_payload, job=True)['id']

export_payload = {'destroy': True}

with expect_audit_method_calls([{
'method': 'pool.export',
'params': [pool_id, export_payload],
'description': f'Pool Export {pool_name}',
}]):
call('pool.export', pool_id, export_payload, job=True)
Loading