|
1 | 1 | import json |
2 | 2 | import shutil |
3 | 3 | from textwrap import dedent |
| 4 | +from operator import itemgetter |
| 5 | +from pathlib import Path |
4 | 6 |
|
5 | 7 |
|
6 | 8 | class TestRemovePallet: |
@@ -275,3 +277,49 @@ def test_remove_partially_removed_pallet(self, host, create_pallet_isos, revert_ |
275 | 277 | assert result.rc == 255 |
276 | 278 | assert result.stderr.startswith('error - "minimal" argument is not a valid pallet ') |
277 | 279 | assert not host.file('/export/stack/pallets/minimal/').exists |
| 280 | + |
| 281 | + def test_pallet_hooks_removed(self, host, create_pallet_isos, revert_etc, revert_export_stack_pallets, revert_pallet_hooks): |
| 282 | + hook_dir = Path('/opt/stack/pallet_hooks/') |
| 283 | + pal_itemgetter = itemgetter('name', 'version', 'release', 'arch', 'os') |
| 284 | + |
| 285 | + # we'll pull in two pallets with the same name to make sure we don't overly remove... |
| 286 | + result = host.run(f'stack add pallet {create_pallet_isos}/test-different-release-1.0-dev.x86_64.disk1.iso') |
| 287 | + assert result.rc == 0 |
| 288 | + |
| 289 | + # Make sure it made it to the DB |
| 290 | + result = host.run('stack list pallet test-different-release output-format=json') |
| 291 | + assert result.rc == 0 |
| 292 | + |
| 293 | + first_pallet_json = json.loads(result.stdout) |
| 294 | + assert len(first_pallet_json) == 1 |
| 295 | + first_pallet_json = first_pallet_json[0] |
| 296 | + pal_hook_dir = hook_dir.joinpath('-'.join(pal_itemgetter(first_pallet_json))) |
| 297 | + |
| 298 | + # Sanity check that the pallet files got added to the filesystem |
| 299 | + assert pal_hook_dir.exists() |
| 300 | + |
| 301 | + # now add another pallet with the same name but different release |
| 302 | + result = host.run(f'stack add pallet {create_pallet_isos}/test-different-release-1.0-test.x86_64.disk1.iso') |
| 303 | + # Make sure it made it to the DB |
| 304 | + result = host.run('stack list pallet test-different-release output-format=json') |
| 305 | + assert result.rc == 0 |
| 306 | + result_json = json.loads(result.stdout) |
| 307 | + assert len(result_json) == 2 |
| 308 | + |
| 309 | + second_pallet_json = None |
| 310 | + for p in result_json: |
| 311 | + if p['release'] == 'test': |
| 312 | + second_pallet_json = p |
| 313 | + |
| 314 | + assert second_pallet_json |
| 315 | + |
| 316 | + second_pal_hook_dir = hook_dir.joinpath('-'.join(pal_itemgetter(second_pallet_json))) |
| 317 | + # Sanity check that the pallet files are both on the filesystem |
| 318 | + assert pal_hook_dir.exists() |
| 319 | + assert second_pal_hook_dir.exists() |
| 320 | + |
| 321 | + # now remove one of them, ensure it's pallet hooks dir goes away, but the other stays. |
| 322 | + result = host.run('stack remove pallet test-different-release release=test') |
| 323 | + |
| 324 | + assert pal_hook_dir.exists() |
| 325 | + assert not second_pal_hook_dir.exists() |
0 commit comments