Skip to content

Commit

Permalink
BGBUILD-138: enablerepo path is not escaped when calling repoquery
Browse files Browse the repository at this point in the history
  • Loading branch information
goldmann committed Jan 20, 2011
1 parent eee56bf commit 19df0a9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
v0.8.0

* [BGBUILD-138] enablerepo path is not escaped when calling repoquery
* [BGBUILD-133] Support a consolidated configuration file
* [BGBUILD-128] Allow to specify plugin configuration using CLI
* [BGBUILD-134] Replace rubygem-commander with rubygem-thor
Expand Down
26 changes: 13 additions & 13 deletions lib/boxgrinder-build/helpers/image-helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ def mount_image(disk, mount_dir)
offsets = calculate_disk_offsets(disk)

@log.debug "Mounting image #{File.basename(disk)} in #{mount_dir}..."
FileUtils.mkdir_p(mount_dir)
FileUtils.mkdir_p("'#{mount_dir}'")

mounts = {}

offsets.each do |offset|
loop_device = get_loop_device
@exec_helper.execute("losetup -o #{offset.to_s} #{loop_device} #{disk}")
@exec_helper.execute("losetup -o #{offset.to_s} #{loop_device} '#{disk}'")
label = @exec_helper.execute("e2label #{loop_device}").strip.chomp.gsub('_', '')
label = '/' if label == ''
mounts[label] = loop_device
end

@exec_helper.execute("mount #{mounts['/']} #{mount_dir}")
@exec_helper.execute("mount #{mounts['/']} '#{mount_dir}'")

mounts.reject { |key, value| key == '/' }.each do |mount_point, loop_device|
@exec_helper.execute("mount #{loop_device} #{mount_dir}#{mount_point}")
@exec_helper.execute("mount #{loop_device} '#{mount_dir}#{mount_point}'")
end

@log.trace "Mounts:\n#{mounts}"
Expand All @@ -68,19 +68,19 @@ def umount_image(disk, mount_dir, mounts)
end

def disk_info(disk)
YAML.load(@exec_helper.execute("qemu-img info #{disk}"))
YAML.load(@exec_helper.execute("qemu-img info '#{disk}'"))
end

def convert_disk(disk, format, destination)
@log.debug "Conveting #{disk} disk to #{format} format and moving it to #{destination}..."
@log.debug "Conveting '#{disk}' disk to #{format} format and moving it to '#{destination}'..."

unless File.exists?(destination)
info = disk_info(disk)

if info['file format'] == format
@exec_helper.execute "cp #{disk} #{destination}"
@exec_helper.execute "cp '#{disk}' '#{destination}'"
else
@exec_helper.execute "qemu-img convert -f #{info['file format']} -O #{format} #{disk} #{destination}"
@exec_helper.execute "qemu-img convert -f #{info['file format']} -O #{format} '#{disk}' '#{destination}'"
end
else
@log.debug "Destination already exists, skipping disk conversion."
Expand All @@ -101,7 +101,7 @@ def calculate_disk_offsets(disk)
@log.debug "Calculating offsets for '#{File.basename(disk)}' disk..."
loop_device = get_loop_device

@exec_helper.execute("losetup #{loop_device} #{disk}")
@exec_helper.execute("losetup #{loop_device} '#{disk}'")
offsets = @exec_helper.execute("parted #{loop_device} 'unit B print' | grep -e '^ [0-9]' | awk '{ print $2 }'").scan(/\d+/)
# wait one secont before freeing loop device
sleep 1
Expand All @@ -114,11 +114,11 @@ def calculate_disk_offsets(disk)

def create_disk(disk, size)
@log.trace "Preparing disk..."
@exec_helper.execute "dd if=/dev/zero of=#{disk} bs=1 count=0 seek=#{size * 1024}M"
@exec_helper.execute "dd if=/dev/zero of='#{disk}' bs=1 count=0 seek=#{size * 1024}M"
@log.trace "Disk prepared"
end

def create_filesystem(disk, options = {})
def create_filesystem(loop_device, options = {})
options = {
:type => @appliance_config.hardware.partitions['/']['type'],
:label => '/'
Expand All @@ -128,7 +128,7 @@ def create_filesystem(disk, options = {})

case options[:type]
when 'ext3', 'ext4'
@exec_helper.execute "mke2fs -T #{options[:type]} -L '#{options[:label]}' -F #{disk}"
@exec_helper.execute "mke2fs -T #{options[:type]} -L '#{options[:label]}' -F #{loop_device}"
else
raise "Unsupported filesystem specified: #{options[:type]}"
end
Expand All @@ -138,7 +138,7 @@ def create_filesystem(disk, options = {})

def sync_files(from_dir, to_dir)
@log.debug "Syncing files between #{from_dir} and #{to_dir}..."
@exec_helper.execute "rsync -Xura #{from_dir}/* #{to_dir}"
@exec_helper.execute "rsync -Xura #{from_dir.gsub(' ', '\ ')}/* '#{to_dir}'"
@log.debug "Sync finished."
end

Expand Down
6 changes: 3 additions & 3 deletions lib/boxgrinder-build/helpers/package-helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def package(dir, package, type = :tar)
package_name = File.basename(package, '.tgz')
symlink = "#{File.dirname(package)}/#{package_name}"

FileUtils.ln_s(File.expand_path(dir), symlink)
@exec_helper.execute "tar -C #{File.dirname(package)} -hcvzf #{package} #{package_name}"
FileUtils.rm(symlink)
FileUtils.ln_s("'#{File.expand_path(dir)}'", "'#{symlink}'")
@exec_helper.execute "tar -C '#{File.dirname(package)}' -hcvzf '#{package}' '#{package_name}'"
FileUtils.rm("'#{symlink}'")
else
raise "Specified format: '#{type}' is currently unsupported."
end
Expand Down
1 change: 1 addition & 0 deletions rubygem-boxgrinder-build.spec
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ popd
- [BGBUILD-131] Check if OS is supported before executing the plugin
- [BGBUILD-72] Add support for growing (not pre-allocated) disks for KVM/Xen
- [BGBUILD-133] Support a consolidated configuration file
- [BGBUILD-138] enablerepo path is not escaped when calling repoquery

* Mon Dec 20 2010 <mgoldman@redhat.com> - 0.7.1-1
- Upstream release: 0.7.1
Expand Down
40 changes: 23 additions & 17 deletions spec/helpers/image-helper-spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,27 @@ module BoxGrinder

it "should mount image with one root partition" do
@helper.should_receive(:calculate_disk_offsets).with('disk.raw').and_return(['0'])
FileUtils.should_receive(:mkdir_p).with('mount_dir')
FileUtils.should_receive(:mkdir_p).with("'mount_dir'")
@helper.should_receive(:get_loop_device).and_return('/dev/loop0')
@exec_helper.should_receive(:execute).with('losetup -o 0 /dev/loop0 disk.raw')
@exec_helper.should_receive(:execute).with("losetup -o 0 /dev/loop0 'disk.raw'")
@exec_helper.should_receive(:execute).with('e2label /dev/loop0').and_return('/')
@exec_helper.should_receive(:execute).with('mount /dev/loop0 mount_dir')
@exec_helper.should_receive(:execute).with("mount /dev/loop0 'mount_dir'")

@helper.mount_image('disk.raw', 'mount_dir').should == {"/"=>"/dev/loop0"}
end

it "should mount image with two partitions with support for new livecd-tools partitions labels starting with '_'" do
@helper.should_receive(:calculate_disk_offsets).with('disk.raw').and_return(['322', '562'])
FileUtils.should_receive(:mkdir_p).with('mount_dir')
FileUtils.should_receive(:mkdir_p).with("'mount_dir'")
@helper.should_receive(:get_loop_device).and_return('/dev/loop0')
@exec_helper.should_receive(:execute).with('losetup -o 322 /dev/loop0 disk.raw')
@exec_helper.should_receive(:execute).with("losetup -o 322 /dev/loop0 'disk.raw'")
@exec_helper.should_receive(:execute).with('e2label /dev/loop0').and_return('_/home')
@helper.should_receive(:get_loop_device).and_return('/dev/loop1')
@exec_helper.should_receive(:execute).with('losetup -o 562 /dev/loop1 disk.raw')
@exec_helper.should_receive(:execute).with("losetup -o 562 /dev/loop1 'disk.raw'")
@exec_helper.should_receive(:execute).with('e2label /dev/loop1').and_return('_/')

@exec_helper.should_receive(:execute).with('mount /dev/loop1 mount_dir')
@exec_helper.should_receive(:execute).with('mount /dev/loop0 mount_dir/home')
@exec_helper.should_receive(:execute).with("mount /dev/loop1 'mount_dir'")
@exec_helper.should_receive(:execute).with("mount /dev/loop0 'mount_dir/home'")

@helper.mount_image('disk.raw', 'mount_dir').should == {"/"=>"/dev/loop1", "/home"=>"/dev/loop0"}
end
Expand Down Expand Up @@ -101,7 +101,7 @@ module BoxGrinder

it "should calculate disks offsets" do
@helper.should_receive(:get_loop_device).and_return('/dev/loop0')
@exec_helper.should_receive(:execute).ordered.with('losetup /dev/loop0 disk.raw')
@exec_helper.should_receive(:execute).ordered.with("losetup /dev/loop0 'disk.raw'")
@exec_helper.should_receive(:execute).ordered.with("parted /dev/loop0 'unit B print' | grep -e '^ [0-9]' | awk '{ print $2 }'").and_return("0B\n1234B\n")
@exec_helper.should_receive(:execute).ordered.with('losetup -d /dev/loop0')
@helper.should_receive(:sleep).with(1)
Expand All @@ -110,7 +110,7 @@ module BoxGrinder
end

it "should create a new empty disk image" do
@exec_helper.should_receive(:execute).with('dd if=/dev/zero of=disk.raw bs=1 count=0 seek=10240M')
@exec_helper.should_receive(:execute).with("dd if=/dev/zero of='disk.raw' bs=1 count=0 seek=10240M")

@helper.create_disk('disk.raw', 10)
end
Expand Down Expand Up @@ -156,10 +156,16 @@ module BoxGrinder
end
end

it "should sync files" do
@exec_helper.should_receive(:execute).with("rsync -Xura from_dir/* to_dir")
describe ".sync_files" do
it "should sync files" do
@exec_helper.should_receive(:execute).with("rsync -Xura from_dir/* 'to_dir'")
@helper.sync_files('from_dir', 'to_dir')
end

@helper.sync_files('from_dir', 'to_dir')
it "should sync files with a space in path" do
@exec_helper.should_receive(:execute).with("rsync -Xura from\\ /dir/* 'to_dir'")
@helper.sync_files('from /dir', 'to_dir')
end
end

it "should customize the disk image suing GuestFS" do
Expand All @@ -180,14 +186,14 @@ module BoxGrinder

describe ".convert_disk" do
it "should not convert the disk because it's in RAW format already" do
@exec_helper.should_receive(:execute).with("qemu-img info a/disk").and_return("image: build/appliances/x86_64/fedora/13/f13-basic/fedora-plugin/f13-basic-sda.qcow2\nfile format: raw\nvirtual size: 2.0G (2147483648 bytes)\ndisk size: 531M\ncluster_size: 65536")
@exec_helper.should_receive(:execute).with("cp a/disk destination")
@exec_helper.should_receive(:execute).with("qemu-img info 'a/disk'").and_return("image: build/appliances/x86_64/fedora/13/f13-basic/fedora-plugin/f13-basic-sda.qcow2\nfile format: raw\nvirtual size: 2.0G (2147483648 bytes)\ndisk size: 531M\ncluster_size: 65536")
@exec_helper.should_receive(:execute).with("cp 'a/disk' 'destination'")
@helper.convert_disk('a/disk', 'raw', 'destination')
end

it "should convert disk from vmdk to RAW format" do
@exec_helper.should_receive(:execute).with("qemu-img info a/disk").and_return("image: build/appliances/x86_64/fedora/13/f13-basic/fedora-plugin/f13-basic-sda.vmdk\nfile format: raw\nvirtual size: 2.0G (2147483648 bytes)\ndisk size: 531M\ncluster_size: 65536")
@exec_helper.should_receive(:execute).with("qemu-img convert -f raw -O vmdk a/disk destination")
@exec_helper.should_receive(:execute).with("qemu-img info 'a/disk'").and_return("image: build/appliances/x86_64/fedora/13/f13-basic/fedora-plugin/f13-basic-sda.vmdk\nfile format: raw\nvirtual size: 2.0G (2147483648 bytes)\ndisk size: 531M\ncluster_size: 65536")
@exec_helper.should_receive(:execute).with("qemu-img convert -f raw -O vmdk 'a/disk' 'destination'")
@helper.convert_disk('a/disk', 'vmdk', 'destination')
end

Expand Down
6 changes: 3 additions & 3 deletions spec/helpers/package-helper-spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ module BoxGrinder
it "should package deliverables" do
File.should_receive(:exists?).with('destination/package.tgz').and_return(false)
File.should_receive(:expand_path).with('a/dir').and_return('a/dir/expanded')
FileUtils.should_receive(:ln_s).with("a/dir/expanded", "destination/package")
FileUtils.should_receive(:rm).with("destination/package")
FileUtils.should_receive(:ln_s).with("'a/dir/expanded'", "'destination/package'")
FileUtils.should_receive(:rm).with("'destination/package'")

@exec_helper.should_receive(:execute).with('tar -C destination -hcvzf destination/package.tgz package')
@exec_helper.should_receive(:execute).with("tar -C 'destination' -hcvzf 'destination/package.tgz' 'package'")

@helper.package('a/dir', 'destination/package.tgz')
end
Expand Down

0 comments on commit 19df0a9

Please sign in to comment.