Skip to content

Commit 981d00d

Browse files
committed
qcow2/sparsify: add backing format
1 parent dbeafe9 commit 981d00d

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

lib/cangallo/qcow2.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def sparsify(destination)
115115
parent = info['backing_file']
116116
parent_options = ''
117117

118-
parent_options = "-o backing_file=#{parent}" if parent
118+
parent_options = Qcow2.qemu_img_backing_file_parameter(parent) if parent
119119

120120
command = "TMPDIR=#{File.dirname(destination)} virt-sparsify #{parent_options} #{@path} #{destination}"
121121
status, stdout, stderr = systemu command

spec/qcow2_spec.rb

+20-4
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,11 @@
133133
end
134134
end
135135

136-
context 'copy image' do
136+
context 'image actions' do
137137
before :all do
138138
@qcow2_path = File.join(@tmpdir, 'base.qcow2')
139139
@raw_path = File.join(@tmpdir, 'base.raw')
140-
# # 200 Mb
141-
# Cangallo::Qcow2.create(@qcow2_path, File.join(@tmpdir, 'base.qcow2'), 2 * IMAGE_SIZE)
142-
# Cangallo::Qcow2.create(@raw_path, File.join(@tmpdir, 'base.raw'), 2 * IMAGE_SIZE)
140+
@parent_path = File.join(@tmpdir, 'child_qcow2.qcow2')
143141
end
144142

145143
it 'should be able to create it' do
@@ -182,5 +180,23 @@
182180
expect(File.basename(info['backing-filename'])).to eq('base.raw')
183181
expect(File.basename(info['backing-filename-format'])).to eq('raw')
184182
end
183+
184+
it 'should be able to sparsify it (qcow2)' do
185+
path = File.join(@tmpdir, 'sparsify.qcow2')
186+
q = Cangallo::Qcow2.new(@parent_path)
187+
q.sparsify(path)
188+
189+
expect(File).to exist(path)
190+
191+
info = Cangallo::Qcow2.new(path).info
192+
expect(info).not_to eq(nil)
193+
194+
expect(info['virtual-size']).to eq(2 * IMAGE_SIZE)
195+
expect(info['cluster-size']).to eq(65_536)
196+
expect(info['format']).to eq('qcow2')
197+
expect(info['actual-size']).to eq(200_704)
198+
expect(info['backing-filename']).to eq(nil)
199+
expect(info['backing-filename-format']).to eq(nil)
200+
end
185201
end
186202
end

0 commit comments

Comments
 (0)