Skip to content

Commit 79fa96a

Browse files
committed
BUGFIX: remove old pallet_hooks directories when removing a pallet
1 parent 4e45bf7 commit 79fa96a

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

common/src/stack/command/stack/commands/remove/pallet/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,11 @@ def clean_pallet(self, pallet):
140140
# Move up a level in the tree
141141
tree.pop()
142142

143+
# remove the pallet hooks for this pallet
144+
# not all pallets (notably retail distro media) will have hooks
145+
pallet_hook_dir = pathlib.Path(self.get_pallet_hook_directory(pallet_info=pallet))
146+
if pallet_hook_dir.exists():
147+
shutil.rmtree(self.get_pallet_hook_directory(pallet_info=pallet))
148+
143149
# Remove the pallet from the database
144150
self.db.execute('delete from rolls where id=%s', (pallet.id,))

test-framework/test-suites/integration/tests/remove/test_remove_pallet.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22
import shutil
33
from textwrap import dedent
4+
from operator import itemgetter
5+
from pathlib import Path
46

57

68
class TestRemovePallet:
@@ -275,3 +277,49 @@ def test_remove_partially_removed_pallet(self, host, create_pallet_isos, revert_
275277
assert result.rc == 255
276278
assert result.stderr.startswith('error - "minimal" argument is not a valid pallet ')
277279
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

Comments
 (0)