Skip to content

Commit

Permalink
ShadowedVolHelper works if all subvols are deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Jan 10, 2017
1 parent 08a6b77 commit 01316f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/storage/shadowed_vol_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ def restore_aborted_subvols(target_part)
name = subvol["name"]
log.info "Restore subvol #{name}?"
log.debug "subvol: #{subvol}"
existing_subvol = target_part["subvol"].detect { |s| s["name"] == name}
subvols = target_part["subvol"] || []
existing_subvol = subvols.detect { |s| s["name"] == name}
if existing_subvol.nil?
log.info "Restoring subvol"
target_part["subvol"] ||= []
target_part["subvol"] << subvol
elsif existing_subvol["delete"]
log.info "Rejecting subvol deletion"
Expand Down
23 changes: 23 additions & 0 deletions test/lib/storage_shadowed_vol_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ def update_partition(target_map, path, new_part, clean_deleted: false)
subvol = find_subvol(second_root, "@/boot/grub2/i386-pc")
expect(subvol).to be_nil
end

# See bsc#1008740
context "if all the other subvolumes have been deleted" do
before do
# If all the subvolumes are deleted (not the same that 'marked for
# deletion'), the value for 'subvol' becomes nil (not empty)
root = find_partition(target_map, "/")
root.delete("subvol")
end

it "does not raise an exception" do
expect { helper.root_partition(target_map: target_map) }
.to_not raise_error
end

it "restores only the corresponding subvolumes" do
second_root = helper.root_partition(target_map: target_map)
subvolumes = second_root["subvol"].reject { |s| s["delete"] }
expect(subvolumes.map { |s| s["name"] }).to contain_exactly(
"@/boot/grub2/i386-pc", "@/boot/grub2/x86_64-efi"
)
end
end
end

context "before committing the changes" do
Expand Down

0 comments on commit 01316f8

Please sign in to comment.