Bring back support for xen,lxc and qemu

The packages to install are now attributes.

Change-Id: I84ce8ba5960bfaf93b9b239631499e9f6ba56aae
This commit is contained in:
Sascha Peilicke
2013-03-14 09:37:53 +01:00
committed by Sascha Peilicke
parent d496d4081f
commit 576ac98a30
4 changed files with 175 additions and 0 deletions

View File

@@ -223,6 +223,9 @@ when "fedora", "redhat", "centos", "suse" # :pragma-foodcritic: ~FC024 - won't f
if platform == "suse"
default["openstack"]["compute"]["platform"]["common_packages"] = ["openstack-nova"]
default["openstack"]["compute"]["ceilometer"]["api"]["auth"]["cache_dir"] = "/var/cache/ceilometer"
default["openstack"]["compute"]["platform"]["kvm_packages"] = ["kvm"]
default["openstack"]["compute"]["platform"]["xen_packages"] = ["kernel-xen", "xen", "xen-tools"]
default["openstack"]["compute"]["platform"]["lxc_packages"] = ["lxc"]
end
when "ubuntu"

View File

@@ -26,6 +26,85 @@ platform_options["libvirt_packages"].each do |pkg|
end
end
def set_boot_kernel_and_trigger_reboot(flavor='default')
# only default and xen flavor is supported by this helper right now
default_boot, current_default = 0, nil
# parse menu.lst, to find boot index for selected flavor
File.open('/boot/grub/menu.lst') do |f|
f.lines.each do |line|
current_default = line.scan(/\d/).first.to_i if line.start_with?('default')
if line.start_with?('title')
if flavor.eql?('xen')
# found boot index
break if line.include?('Xen')
else
# take first kernel as default, unless we are searching for xen
# kernel
break
end
default_boot += 1
end
end
end
# change default option for /boot/grub/menu.lst
unless current_default.eql?(default_boot)
puts "changed grub default to #{default_boot}"
%x[sed -i -e "s;^default.*;default #{default_boot};" /boot/grub/menu.lst]
end
# trigger reboot through reboot_handler, if kernel-$flavor is not yet
# running
unless %x[uname -r].include?(flavor)
node.run_state["reboot"] = true
end
end
# on suse nova-compute don't depends on any virtualization mechanism
case node["platform"]
when "suse"
case node["openstack"]["compute"]["libvirt"]["virt_type"]
when "kvm"
node["openstack"]["compute"]["platform"]["kvm_packages"].each do |pkg|
package pkg do
action :install
end
end
execute "loading kvm modules" do
command "grep -q vmx /proc/cpuinfo && /sbin/modprobe kvm-intel; grep -q svm /proc/cpuinfo && /sbin/modprobe kvm-amd; /sbin/modprobe vhost-net"
end
# NOTE(saschpe): Allow switching from XEN to KVM:
set_boot_kernel_and_trigger_reboot
when "xen"
node["openstack"]["compute"]["platform"]["xen_packages"].each do |pkg|
package pkg do
action :install
end
end
set_boot_kernel_and_trigger_reboot('xen')
when "qemu"
node["openstack"]["compute"]["platform"]["kvm_packages"].each do |pkg|
package pkg do
action :install
end
end
when "lxc"
node["openstack"]["compute"]["platform"]["lxc_packages"].each do |pkg|
package pkg do
action :install
end
end
service "boot.cgroup" do
action [:enable, :start]
end
end
end
group node["openstack"]["compute"]["libvirt"]["group"] do
append true
members [node["openstack"]["compute"]["group"]]

View File

@@ -0,0 +1,88 @@
require "spec_helper"
describe "openstack-compute::libvirt" do
describe "suse" do
before do
compute_stubs
@chef_run = ::ChefSpec::ChefRunner.new ::OPENSUSE_OPTS
@chef_run.converge "openstack-compute::libvirt"
end
it "installs libvirt packages" do
expect(@chef_run).to install_package "libvirt"
end
it "starts libvirt" do
expect(@chef_run).to start_service "libvirtd"
end
it "starts libvirt on boot" do
expect(@chef_run).to set_service_to_start_on_boot "libvirtd"
end
describe "libvirtd" do
before do
@file = @chef_run.template "/etc/sysconfig/libvirtd"
end
it "has proper owner" do
expect(@file).to be_owned_by "root", "root"
end
it "has proper modes" do
expect(sprintf("%o", @file.mode)).to eq "644"
end
it "template contents" do
pending "TODO: implement"
end
it "notifies libvirt-bin restart" do
expect(@file).to notify "service[libvirt-bin]", :restart
end
end
it "installs kvm packages" do
expect(@chef_run).to install_package "kvm"
end
it "installs qemu packages" do
chef_run = ::ChefSpec::ChefRunner.new ::OPENSUSE_OPTS do |node|
node.set["openstack"]["compute"]["libvirt"]["virt_type"] = "qemu"
end
chef_run.converge "openstack-compute::libvirt"
expect(chef_run).to install_package "kvm"
end
it "installs xen packages" do
chef_run = ::ChefSpec::ChefRunner.new ::OPENSUSE_OPTS do |node|
node.set["openstack"]["compute"]["libvirt"]["virt_type"] = "xen"
end
chef_run.converge "openstack-compute::libvirt"
["kernel-xen", "xen", "xen-tools"].each do |pkg|
expect(chef_run).to install_package pkg
end
end
describe "lxc" do
before do
@chef_run_lxc = ::ChefSpec::ChefRunner.new ::OPENSUSE_OPTS do |node|
node.set["openstack"]["compute"]["libvirt"]["virt_type"] = "lxc"
end
@chef_run_lxc.converge "openstack-compute::libvirt"
end
it "installs packages" do
expect(@chef_run_lxc).to install_package "lxc"
end
it "starts boot.cgroupslxc" do
expect(@chef_run_lxc).to start_service "boot.cgroup"
end
it "starts boot.cgroups on boot" do
expect(@chef_run_lxc).to set_service_to_start_on_boot "boot.cgroup"
end
end
end
end

View File

@@ -1,6 +1,11 @@
require "chefspec"
::LOG_LEVEL = :fatal
::OPENSUSE_OPTS = {
:platform => "opensuse",
:version => "12.3",
:log_level => ::LOG_LEVEL
}
::REDHAT_OPTS = {
:platform => "redhat",
:version => "6.3",