1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
require 'spec_helper'
describe Specinfra::HostInventory::Virtualization do
before :all do
set :os, { :family => 'linux' }
end
virt = Specinfra::HostInventory::Virtualization.new(host_inventory)
let(:host_inventory) { nil }
it 'Docker Image should return :system => "docker"' do
allow(virt.backend).to receive(:run_command).with('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.dockerinit') do
CommandResult.new(:stdout => '', :exit_status => 0)
end
expect(virt.get).to include(:system => 'docker')
end
let(:host_inventory) { nil }
it 'Debian Wheezy on OpenVZ should return :system => "openvz"' do
allow(virt.backend).to receive(:run_command).with('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.dockerinit') do
CommandResult.new(:stdout => '', :exit_status => 2)
end
allow(virt.backend).to receive(:run_command).with('test -d /proc/vz -a ! -d /proc/bc') do
CommandResult.new(:stdout => '', :exit_status => 0)
end
expect(virt.get).to include(:system => 'openvz')
end
it 'Debian on QEMU KVM should return :system => "kvm"' do
allow(virt.backend).to receive(:run_command).with('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.dockerinit') do
CommandResult.new(:stdout => '', :exit_status => 1)
end
allow(virt.backend).to receive(:run_command).with('test -d /proc/vz -a ! -d /proc/bc') do
CommandResult.new(:stdout => '', :exit_status => 1)
end
allow(virt.backend).to receive(:run_command).with('dmidecode -s system-product-name') do
CommandResult.new(:stdout => "Standard PC (Q35 + ICH9, 2009)\n", :exit_status => 0)
end
allow(virt.backend).to receive(:run_command).with('systemd-detect-virt') do
CommandResult.new(:stdout => "kvm\n", :exit_status => 0)
end
expect(virt.get).to include(:system => 'kvm')
end
let(:host_inventory) { nil }
it 'Debian Jessie on KVM should return :system => "kvm"' do
ret = virt.parse_system_product_name("KVM\n")
expect(ret).to include('kvm')
end
let(:host_inventory) { nil }
it 'CentOS 6.7 on VMware should return :system => "vmware"' do
ret = virt.parse_system_product_name("VMware Virtual Platform\n")
expect(ret).to include('vmware')
end
let(:host_inventory) { nil }
it 'Ubuntu 14.04 on VirtualBox should return :system => "vbox"' do
ret = virt.parse_system_product_name("VirtualBox\n")
expect(ret).to include('vbox')
end
end
|