From 7f90c3a883a501b56923d56f70639d67eb80072f Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Sat, 6 Jun 2015 10:06:39 -0700 Subject: [PATCH 01/21] Do not create fstab by default --- resources/container.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/container.rb b/resources/container.rb index c4e13ee..3071deb 100644 --- a/resources/container.rb +++ b/resources/container.rb @@ -24,7 +24,7 @@ def initialize(*args) attribute :static_netmask, :kind_of => String, :default => '255.255.255.0' attribute :static_gateway, :kind_of => String attribute :default_config, :kind_of => [TrueClass, FalseClass], :default => true -attribute :default_fstab, :kind_of => [TrueClass, FalseClass], :default => true +attribute :default_fstab, :kind_of => [TrueClass, FalseClass], :default => false attribute :container_commands, :kind_of => Array, :default => [] attribute :initialize_commands, :kind_of => Array, :default => [] attribute :clone, :kind_of => String From cd75d8e0a65d1e148c35aaa6ccef776f21d4d81b Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Sat, 6 Jun 2015 10:07:08 -0700 Subject: [PATCH 02/21] Only set mount if file exists. Remove cgroup defaults --- providers/config.rb | 28 +--------------------------- resources/config.rb | 1 + 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/providers/config.rb b/providers/config.rb index a247df5..fbc3eda 100644 --- a/providers/config.rb +++ b/providers/config.rb @@ -15,7 +15,7 @@ def load_current_resource new_resource.rootfs @lxc.rootfs.to_path unless new_resource.rootfs new_resource.default_bridge node[:lxc][:bridge] unless new_resource.default_bridge - new_resource.mount @lxc.path.join('fstab').to_path unless new_resource.mount + new_resource.mount @lxc.path.join('fstab').to_path unless new_resource.mount || !::File.exists?(@lxc.path.join('fstab')) config = ::Lxc::FileConfig.new(@lxc.container_config) if((new_resource.network.nil? || new_resource.network.empty?)) if(config.network.empty?) @@ -38,32 +38,6 @@ def load_current_resource end end end - new_resource.cgroup( - Chef::Mixin::DeepMerge.merge( - Mash.new( - 'devices.deny' => 'a', - 'devices.allow' => [ - 'c *:* m', - 'b *:* m', - 'c 1:3 rwm', - 'c 1:5 rwm', - 'c 5:1 rwm', - 'c 5:0 rwm', - 'c 1:9 rwm', - 'c 1:8 rwm', - 'c 136:* rwm', - 'c 5:2 rwm', - 'c 254:0 rwm', - 'c 10:229 rwm', - 'c 10:200 rwm', - 'c 1:7 rwm', - 'c 10:228 rwm', - 'c 10:232 rwm' - ] - ), - new_resource.cgroup - ) - ) end action :create do diff --git a/resources/config.rb b/resources/config.rb index 81f7567..d9dfb98 100644 --- a/resources/config.rb +++ b/resources/config.rb @@ -18,3 +18,4 @@ attribute :rootfs, :kind_of => [String,Pathname] attribute :rootfs_mount, :kind_of => String attribute :pivotdir, :kind_of => String +attribute :include, :kind_of => String, :default => '/usr/share/lxc/config/common.conf' From fe61b79958ceaf0237537e2108248a3b33cbe14d Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Sat, 6 Jun 2015 15:21:39 -0700 Subject: [PATCH 03/21] Add optional support for lxc daily ppa repo --- recipes/package.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/recipes/package.rb b/recipes/package.rb index be7c247..3942837 100644 --- a/recipes/package.rb +++ b/recipes/package.rb @@ -1,3 +1,18 @@ +command 'enable lxc-daily ppa' do + execute 'apt-add-repository ppa:ubuntu-lxc/daily -y' + only_if do + node.platform_family?('debian') && + node[:lxc][:enable_daily_ppa] + end + not_if 'grep -R "^deb.*ppa.*lxc.daily" sources.list*' +end + +command 'ppa update' do + execute 'apt-get update' + action :nothing + subscribes :run, 'command[enable lxc-daily ppa]', :immediately +end + # install the server dependencies to run lxc node[:lxc][:packages].each do |lxcpkg| package lxcpkg From 015bc6a5c96e5e191eb57aa2f09502928aedb5c5 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Sat, 6 Jun 2015 15:22:00 -0700 Subject: [PATCH 04/21] Allow modifying container default attributes via node attributes --- providers/container.rb | 24 ++++++++++++++++-------- resources/container.rb | 4 ++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/providers/container.rb b/providers/container.rb index 0618e90..036f52a 100644 --- a/providers/container.rb +++ b/providers/container.rb @@ -14,6 +14,14 @@ def load_current_resource if(new_resource.static_ip && new_resource.static_gateway.nil?) raise "Static gateway must be defined when static IP is provided (Container: #{new_resource.name})" end + + if(new_resource.default_config.nil?) + new_resource.default_config node[:lxc][:default_config_enabled] + end + if(new_resource.default_fstab.nil?) + new_resource.default_fstab node[:lxc][:default_fstab_enabled] + end + new_resource.default_bridge node[:lxc][:bridge] unless new_resource.default_bridge node.run_state[:lxc] ||= Mash.new node.run_state[:lxc][:meta] ||= Mash.new @@ -49,14 +57,6 @@ def load_current_resource end end - #### Create container configuration bits - if(new_resource.default_config) - lxc_config new_resource.name do - action :create - default_bridge new_resource.default_bridge - end - end - if(new_resource.default_fstab) lxc_fstab "proc[#{new_resource.name}]" do container new_resource.name @@ -75,6 +75,14 @@ def load_current_resource end end + #### Create container configuration bits + if(new_resource.default_config) + lxc_config new_resource.name do + action :create + default_bridge new_resource.default_bridge + end + end + if(new_resource.static_ip) lxc_interface "eth0[#{new_resource.name}]" do container new_resource.name diff --git a/resources/container.rb b/resources/container.rb index 3071deb..9d22665 100644 --- a/resources/container.rb +++ b/resources/container.rb @@ -23,8 +23,8 @@ def initialize(*args) attribute :static_ip, :kind_of => String attribute :static_netmask, :kind_of => String, :default => '255.255.255.0' attribute :static_gateway, :kind_of => String -attribute :default_config, :kind_of => [TrueClass, FalseClass], :default => true -attribute :default_fstab, :kind_of => [TrueClass, FalseClass], :default => false +attribute :default_config, :kind_of => [TrueClass, FalseClass] +attribute :default_fstab, :kind_of => [TrueClass, FalseClass] attribute :container_commands, :kind_of => Array, :default => [] attribute :initialize_commands, :kind_of => Array, :default => [] attribute :clone, :kind_of => String From 0fa086fd69088ff7cc279bfc60bfd16c6ed2a405 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Sat, 6 Jun 2015 15:22:48 -0700 Subject: [PATCH 05/21] Default new attributes --- attributes/default.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/attributes/default.rb b/attributes/default.rb index 4a92166..55b4b64 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -18,6 +18,9 @@ default[:lxc][:elecksee][:version_restriction] = '~> 1.1.2' default[:lxc][:elecksee][:action] = :install +default[:lxc][:default_config_enabled] = true +default[:lxc][:default_fstab_enabled] = true + default[:lxc][:default_config][:lxc_auto] = node[:lxc][:auto_start] default[:lxc][:default_config][:use_lxc_bridge] = node[:lxc][:use_bridge] default[:lxc][:default_config][:lxc_bridge] = node[:lxc][:bridge] @@ -34,6 +37,7 @@ default[:lxc][:user_locks] = %w(ubuntu) +default[:lxc][:enable_daily_ppa] = false default[:lxc][:packages] = node.platform_family?('rhel') ? ['lxc', 'lxc-templates', 'lxc-libs', 'bridge-utils', 'libcgroup'] : ['lxc'] default[:lxc][:mirror] = 'http://archive.ubuntu.com/ubuntu' default[:lxc][:containers] = {} From 95c20a598405a0ee97d51d3145b1979eb67a8b47 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Sat, 6 Jun 2015 15:45:33 -0700 Subject: [PATCH 06/21] Fix transposed resource/attribute names --- recipes/package.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/recipes/package.rb b/recipes/package.rb index 3942837..12ec3a0 100644 --- a/recipes/package.rb +++ b/recipes/package.rb @@ -1,5 +1,5 @@ -command 'enable lxc-daily ppa' do - execute 'apt-add-repository ppa:ubuntu-lxc/daily -y' +execute 'enable lxc-daily ppa' do + command 'apt-add-repository ppa:ubuntu-lxc/daily -y' only_if do node.platform_family?('debian') && node[:lxc][:enable_daily_ppa] @@ -7,8 +7,8 @@ not_if 'grep -R "^deb.*ppa.*lxc.daily" sources.list*' end -command 'ppa update' do - execute 'apt-get update' +execute 'ppa update' do + command 'apt-get update' action :nothing subscribes :run, 'command[enable lxc-daily ppa]', :immediately end From 17d7991c43917f0b2dac653b11e6f1d1023b7686 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 9 Jun 2015 05:42:10 -0700 Subject: [PATCH 07/21] Force package upgrade when ppa is enabled --- recipes/package.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/recipes/package.rb b/recipes/package.rb index 12ec3a0..d82f87d 100644 --- a/recipes/package.rb +++ b/recipes/package.rb @@ -15,5 +15,7 @@ # install the server dependencies to run lxc node[:lxc][:packages].each do |lxcpkg| - package lxcpkg + package lxcpkg do + subscribes :upgrade, 'execute[ppa update]', :immediately + end end From 82721ca8a43e714d2f0008c7e84db22e086f05d9 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 9 Jun 2015 05:46:34 -0700 Subject: [PATCH 08/21] Fix resource name within update subscription --- recipes/package.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/package.rb b/recipes/package.rb index d82f87d..f9649f0 100644 --- a/recipes/package.rb +++ b/recipes/package.rb @@ -10,7 +10,7 @@ execute 'ppa update' do command 'apt-get update' action :nothing - subscribes :run, 'command[enable lxc-daily ppa]', :immediately + subscribes :run, 'execute[enable lxc-daily ppa]', :immediately end # install the server dependencies to run lxc From 9dba9c3db39123996d4734b8a4a0b256f2209fc1 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 9 Jun 2015 16:49:24 -0700 Subject: [PATCH 09/21] If no mount is provided, set to default fstab file and ensure exists --- providers/config.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/providers/config.rb b/providers/config.rb index fbc3eda..7dd01a6 100644 --- a/providers/config.rb +++ b/providers/config.rb @@ -15,7 +15,7 @@ def load_current_resource new_resource.rootfs @lxc.rootfs.to_path unless new_resource.rootfs new_resource.default_bridge node[:lxc][:bridge] unless new_resource.default_bridge - new_resource.mount @lxc.path.join('fstab').to_path unless new_resource.mount || !::File.exists?(@lxc.path.join('fstab')) + new_resource.mount @lxc.path.join('fstab').to_path unless new_resource.mount config = ::Lxc::FileConfig.new(@lxc.container_config) if((new_resource.network.nil? || new_resource.network.empty?)) if(config.network.empty?) @@ -47,6 +47,13 @@ def load_current_resource action :create end + file new_resource.mount do + action :create + only_if do + new_resource.mount == @lxc.path.join('fstab') && + !::File.exists?(@lxc.path.join('fstab') + end + file "lxc update_config[#{new_resource.utsname}]" do path _lxc.container_config.to_path content ::Lxc::FileConfig.generate_config(new_resource) From ef7c4d1224f6eb3156fb94865a612d09e6df2108 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 9 Jun 2015 16:52:22 -0700 Subject: [PATCH 10/21] Toss in missing paren --- providers/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/config.rb b/providers/config.rb index 7dd01a6..2e3d091 100644 --- a/providers/config.rb +++ b/providers/config.rb @@ -51,7 +51,7 @@ def load_current_resource action :create only_if do new_resource.mount == @lxc.path.join('fstab') && - !::File.exists?(@lxc.path.join('fstab') + !::File.exists?(@lxc.path.join('fstab')) end file "lxc update_config[#{new_resource.utsname}]" do From 02711aa23b83fea621ce47825f438822bcd226d3 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 9 Jun 2015 17:00:45 -0700 Subject: [PATCH 11/21] Add missing end keyword --- providers/config.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/providers/config.rb b/providers/config.rb index 2e3d091..e274e4f 100644 --- a/providers/config.rb +++ b/providers/config.rb @@ -52,6 +52,7 @@ def load_current_resource only_if do new_resource.mount == @lxc.path.join('fstab') && !::File.exists?(@lxc.path.join('fstab')) + end end file "lxc update_config[#{new_resource.utsname}]" do From 44e44855ff0df99a5a44db678bc79ffe57b83096 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 9 Jun 2015 17:05:00 -0700 Subject: [PATCH 12/21] Remove guard on file and always ensure it exists --- providers/config.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/providers/config.rb b/providers/config.rb index e274e4f..4a6eebb 100644 --- a/providers/config.rb +++ b/providers/config.rb @@ -49,10 +49,6 @@ def load_current_resource file new_resource.mount do action :create - only_if do - new_resource.mount == @lxc.path.join('fstab') && - !::File.exists?(@lxc.path.join('fstab')) - end end file "lxc update_config[#{new_resource.utsname}]" do From efdac41c2f69dcbbf036475edfbed0fac196ae9b Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Fri, 19 Jun 2015 08:51:25 -0700 Subject: [PATCH 13/21] Refactor the config LWRP to be free form and future compatible --- providers/config.rb | 70 ++++++++++++++++++++++++--------------------- resources/config.rb | 29 ++++++++----------- 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/providers/config.rb b/providers/config.rb index 4a6eebb..66158db 100644 --- a/providers/config.rb +++ b/providers/config.rb @@ -1,10 +1,13 @@ require 'securerandom' def load_current_resource - require 'elecksee/lxc_file_config' - new_resource.utsname new_resource.container if new_resource.container - new_resource.utsname new_resource.name unless new_resource.utsname + if(new_resource.container) + new_resource.utsname new_resource.container + end + unless(new_resource.struct[:utsname]) + new_resource.utsname new_resource.name + end @lxc = ::Lxc.new( new_resource.utsname, @@ -12,48 +15,51 @@ def load_current_resource :dnsmasq_lease_file => node[:lxc][:dnsmasq_lease_file] ) - new_resource.rootfs @lxc.rootfs.to_path unless new_resource.rootfs - - new_resource.default_bridge node[:lxc][:bridge] unless new_resource.default_bridge - new_resource.mount @lxc.path.join('fstab').to_path unless new_resource.mount - config = ::Lxc::FileConfig.new(@lxc.container_config) - if((new_resource.network.nil? || new_resource.network.empty?)) - if(config.network.empty?) - default_net = { - :type => :veth, - :link => new_resource.default_bridge, - :flags => :up, - :hwaddr => "00:16:3e#{SecureRandom.hex(3).gsub(/(..)/, ':\1')}" - } - else - default_net = config.network.first - default_net.delete(:ipv4) if default_net.has_key?(:ipv4) - default_net.merge!(:link => new_resource.default_bridge) - end - new_resource.network(default_net) - else - [new_resource.network].flatten.each_with_index do |net_hash, idx| - if(config.network[idx].nil? || config.network[idx][:hwaddr].nil?) - net_hash[:hwaddr] ||= "00:16:3e#{SecureRandom.hex(3).gsub(/(..)/, ':\1')}" - end - end - end + @config = ::Lxc::ConfigFile.new(@lxc.container_config.to_path) end action :create do _lxc = @lxc + _config = @config directory @lxc.path.to_path do action :create end - file new_resource.mount do - action :create + if(new_resource[:mount]) + file new_resource.mount do + action :create + end + end + + if(new_resource.resource_style.to_s == 'merge') + if(node[:lxc][:original_configs].nil?) + node.set[:lxc][:original_configs] = [] + if(node[:lxc][:original_configs][new_resource.name].nil?) + node.set[:lxc][:original_configs][new_resource.name] = _config.state_hash + end + end + _config.state._merge!(new_resource.struct) + else + _config.state = new_resource.struct end file "lxc update_config[#{new_resource.utsname}]" do path _lxc.container_config.to_path - content ::Lxc::FileConfig.generate_config(new_resource) + content _config.generate_content mode 0644 end end + +action :delete do + _lxc = @lxc + + if(node[:lxc][:original_configs] && node[:lxc][:original_configs][new_resource.name]) + node.set[:lxc][:original_configs][new_resource.name] = nil + end + + file "lxc delete_config[#{new_resource.name}]" do + path _lxc.container_config.to_path + action :delete + end +end diff --git a/resources/config.rb b/resources/config.rb index d9dfb98..c479d67 100644 --- a/resources/config.rb +++ b/resources/config.rb @@ -1,21 +1,16 @@ +attr_reader :struct + actions :create, :delete default_action :create attribute :container, :kind_of => String, :default => nil # alias for utsname -attribute :utsname, :kind_of => String, :default => nil # defaults to resource name -attribute :aa_profile, :kind_of => String, :default => nil # platform specific? -attribute :network, :kind_of => [Array, Hash] -attribute :default_bridge, :kind_of => String -attribute :static_ip, :kind_of => String -attribute :pts, :kind_of => Numeric, :default => 1024 -attribute :tty, :kind_of => Numeric, :default => 4 -attribute :arch, :kind_of => String, :default => 'amd64' -attribute :devttydir, :kind_of => String, :default => 'lxc' -attribute :cgroup, :kind_of => Hash, :default => Mash.new -attribute :cap_drop, :kind_of => [String, Array], :default => %w(sys_module mac_admin) -attribute :mount, :kind_of => String -attribute :mount_entry, :kind_of => String -attribute :rootfs, :kind_of => [String,Pathname] -attribute :rootfs_mount, :kind_of => String -attribute :pivotdir, :kind_of => String -attribute :include, :kind_of => String, :default => '/usr/share/lxc/config/common.conf' +attribute :resource_style, :equal_to => [:replace, :merge, 'replace', 'merge'], :default => :merge + +def method_missing(*args, &block) + unless(@struct) + require 'elecksee/lxc_file_config' + @struct = LxcStruct.new + @struct._set_state(:value_collapse => true) + end + @struct.method_missing(*args, &block) +end From c27ad5cc04d7bfe7ff0b3014c1a6dfc3a71a19cf Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 10 Aug 2015 10:59:38 -0700 Subject: [PATCH 14/21] Update location used for utsname --- providers/config.rb | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/providers/config.rb b/providers/config.rb index 66158db..d581de2 100644 --- a/providers/config.rb +++ b/providers/config.rb @@ -3,19 +3,19 @@ def load_current_resource if(new_resource.container) - new_resource.utsname new_resource.container + new_resource.struct.lxc.utsname new_resource.container end - unless(new_resource.struct[:utsname]) - new_resource.utsname new_resource.name + unless(new_resource.struct[:lxc] && new_resource.struct[:lxc][:utsname]) + new_resource.struct.lxc.utsname new_resource.name end @lxc = ::Lxc.new( - new_resource.utsname, + new_resource.struct.lxc.utsname, :base_dir => node[:lxc][:container_directory], :dnsmasq_lease_file => node[:lxc][:dnsmasq_lease_file] ) - @config = ::Lxc::ConfigFile.new(@lxc.container_config.to_path) + @config = ::Lxc::FileConfig.new(@lxc.container_config.to_path) end action :create do @@ -26,18 +26,12 @@ def load_current_resource action :create end - if(new_resource[:mount]) - file new_resource.mount do - action :create - end - end - if(new_resource.resource_style.to_s == 'merge') if(node[:lxc][:original_configs].nil?) - node.set[:lxc][:original_configs] = [] - if(node[:lxc][:original_configs][new_resource.name].nil?) - node.set[:lxc][:original_configs][new_resource.name] = _config.state_hash - end + node.set[:lxc][:original_configs] = {} + end + if(node[:lxc][:original_configs][new_resource.name].nil?) + node.set[:lxc][:original_configs][new_resource.name] = _config.state_hash end _config.state._merge!(new_resource.struct) else From 26afa260d27fd1ef105d7356562d01a5b5ff77b3 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 10 Aug 2015 10:59:54 -0700 Subject: [PATCH 15/21] Only define constant if not already seen. --- providers/container.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/providers/container.rb b/providers/container.rb index 036f52a..a5e6f9f 100644 --- a/providers/container.rb +++ b/providers/container.rb @@ -137,7 +137,10 @@ def load_current_resource end #### Use cached chef package from host if available - VERSION_REGEXP = %r{(\d+\.\d+\.\d+(-\d+)?)} + unless(defined?(VERSION_REGEXP)) + VERSION_REGEXP = %r{(\d+\.\d+\.\d+(-\d+)?)} + end + if(%w(debian ubuntu).include?(new_resource.template) && system('ls /opt/chef*.deb 2>&1 > /dev/null')) file_path = Dir.glob(::File.join('/opt', 'chef*.deb')).sort do |x,y| version_x = x.scan(VERSION_REGEXP).flatten.first @@ -219,7 +222,18 @@ def load_current_resource ruby_block "lxc start[#{new_resource.name}]" do block do - _lxc.start + begin + Timeout::timeout(10) do + `lxc-start -n #{new_resource.name} -d` +# _lxc.start + _lxc.container_ip(10) + end + rescue Timeout::Error + `lxc-stop -n #{_lxc.name} --kill` +# _lxc.stop + sleep(1) + retry + end end only_if do _lxc.rootfs.join('etc/chef/first_run.json').exist? || From abe9681dac4fa72749b098f516e2fbe600d2d6b8 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 10 Aug 2015 11:01:28 -0700 Subject: [PATCH 16/21] Updates for ppa usage --- attributes/default.rb | 3 ++- recipes/package.rb | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 55b4b64..7bb7586 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -19,7 +19,7 @@ default[:lxc][:elecksee][:action] = :install default[:lxc][:default_config_enabled] = true -default[:lxc][:default_fstab_enabled] = true +default[:lxc][:default_fstab_enabled] = false default[:lxc][:default_config][:lxc_auto] = node[:lxc][:auto_start] default[:lxc][:default_config][:use_lxc_bridge] = node[:lxc][:use_bridge] @@ -38,6 +38,7 @@ default[:lxc][:user_locks] = %w(ubuntu) default[:lxc][:enable_daily_ppa] = false +default[:lxc][:ppa_packages] = ['lxc', 'lxc-templates'] default[:lxc][:packages] = node.platform_family?('rhel') ? ['lxc', 'lxc-templates', 'lxc-libs', 'bridge-utils', 'libcgroup'] : ['lxc'] default[:lxc][:mirror] = 'http://archive.ubuntu.com/ubuntu' default[:lxc][:containers] = {} diff --git a/recipes/package.rb b/recipes/package.rb index f9649f0..924f99f 100644 --- a/recipes/package.rb +++ b/recipes/package.rb @@ -1,10 +1,14 @@ +package 'software-properties-common' do + only_if{ node[:lxc][:enable_daily_ppa] } +end + execute 'enable lxc-daily ppa' do command 'apt-add-repository ppa:ubuntu-lxc/daily -y' only_if do node.platform_family?('debian') && node[:lxc][:enable_daily_ppa] end - not_if 'grep -R "^deb.*ppa.*lxc.daily" sources.list*' + not_if 'grep -R "^deb.*ppa.*lxc.daily" /etc/apt/sources.list*' end execute 'ppa update' do @@ -13,9 +17,24 @@ subscribes :run, 'execute[enable lxc-daily ppa]', :immediately end +execute 'lxc ppa system upgrade' do + command 'apt-get upgrade -yq' + action :nothing + subscribes :run, 'execute[enable lxc-daily ppa]', :immediately + environment 'DEBIAN_FRONTEND' => 'noninteractive' +end + +ruby_block 'ppa lxc package list' do + block do + node.default[:lxc][:packages] = node[:lxc][:ppa_packages] + end + action :nothing + subscribes :create, 'execute[enable lxc-daily ppa]', :immediately +end + # install the server dependencies to run lxc node[:lxc][:packages].each do |lxcpkg| package lxcpkg do - subscribes :upgrade, 'execute[ppa update]', :immediately + subscribes :upgrade, 'execute[enable lxc-daily ppa]', :immediately end end From a7e4920de2c7f9316cd35f7f40fc22c155e61c8a Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 10 Aug 2015 20:09:15 -0700 Subject: [PATCH 17/21] Always generate fstab file, even when empty --- providers/container.rb | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/providers/container.rb b/providers/container.rb index a5e6f9f..97dff8d 100644 --- a/providers/container.rb +++ b/providers/container.rb @@ -108,10 +108,6 @@ def load_current_resource source 'fstab.erb' cookbook 'lxc' variables :container => new_resource.name - only_if do - node.run_state[:lxc][:fstabs] && - node.run_state[:lxc][:fstabs][new_resource.name] - end mode 0644 end @@ -222,18 +218,7 @@ def load_current_resource ruby_block "lxc start[#{new_resource.name}]" do block do - begin - Timeout::timeout(10) do - `lxc-start -n #{new_resource.name} -d` -# _lxc.start - _lxc.container_ip(10) - end - rescue Timeout::Error - `lxc-stop -n #{_lxc.name} --kill` -# _lxc.stop - sleep(1) - retry - end + _lxc.start end only_if do _lxc.rootfs.join('etc/chef/first_run.json').exist? || @@ -243,18 +228,17 @@ def load_current_resource end #### Have initialize commands for the container? Run them now - ruby_block "lxc initialize_commands[#{new_resource.name}]" do - block do - new_resource.initialize_commands.each do |cmd| + new_resource.initialize_commands.each do |cmd| + ruby_block "lxc initialize_command[#{new_resource.name}:#{cmd}]" do + block do Chef::Log.info "Running command on #{new_resource.name}: #{cmd}" _lxc.container_command(cmd, 5) end + only_if do + node.run_state[:lxc][:meta][new_resource.name][:new_container] + end + retries 5 end - only_if do - node.run_state[:lxc][:meta][new_resource.name][:new_container] && - !new_resource.initialize_commands.empty? - end - retries 5 end # Make sure we have chef in the container From 4916fc903d04ad60cd3c9ce6305c7e93b9829c19 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 10 Aug 2015 20:13:19 -0700 Subject: [PATCH 18/21] Fetch data out for safety --- templates/default/fstab.erb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/default/fstab.erb b/templates/default/fstab.erb index e5fe5aa..6793c44 100644 --- a/templates/default/fstab.erb +++ b/templates/default/fstab.erb @@ -1,5 +1,4 @@ # Chef generated fstab! -<% node.run_state[:lxc][:fstabs][@container].each do |line| -%> +<% node.run_state[:lxc].fetch(:fstabs, {}).fetch(@container, {}).each do |line| -%> <%= line %> <% end -%> - From 3eb6748380fe0df6ca82366e6b6ed7d5566a7bea Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 10 Aug 2015 20:13:43 -0700 Subject: [PATCH 19/21] Update the testing bundle --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 537d3a0..ad024cf 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,9 @@ source 'https://rubygems.org' gem 'kitchen-vagrant' +gem 'batali' gem 'batali-tk' -gem 'librarian-chef' if(ENV['DEATH_TO_OMNIBUS']) - gem 'vagrant', :git => 'https://github.com/mitchellh/vagrant', :tag => 'v1.7.2' + gem 'vagrant', :git => 'https://github.com/mitchellh/vagrant', :tag => 'v1.7.4' end From 718920e12aab41bfb7aef792882003c7395f4594 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 10 Aug 2015 20:14:06 -0700 Subject: [PATCH 20/21] Stub in vagabond for default test until everything is settled --- .kitchen.yml | 22 +++++++++++++++++++++- Batali | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.kitchen.yml b/.kitchen.yml index 1470769..ae1a6ad 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -12,8 +12,28 @@ suites: provisioner: name: chef_solo run_list: - - 'recipe[lxc-test::default]' + - 'recipe[vagabond]' attributes: + lxc: + enable_daily_ppa: true + vagabond: + bases: + centos_5: + enabled: false + centos_6: + enabled: true + centos_7: + enabled: true + ubuntu_1204: + enabled: true + ubuntu_1404: + enabled: true + debian_6: + enabled: true + debian_7: + enabled: true + debian_8: + enabled: true - name: test-container provisioner: name: chef_zero diff --git a/Batali b/Batali index bc6c67c..4d7e458 100644 --- a/Batali +++ b/Batali @@ -2,6 +2,7 @@ Batali.define do source 'https://supermarket.chef.io' cookbook 'apt' cookbook 'yum-epel' + cookbook 'vagabond', git: 'git://github.com/chrisroberts/chef-vagabond', :ref => 'develop' cookbook 'lxc-test', path: './test/fixtures/cookbooks/lxc-test' metadata From 956380bca51034f0bd4d88ff240599529e0622ee Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Fri, 25 Sep 2015 10:22:18 -0700 Subject: [PATCH 21/21] Update gem helper restriction --- attributes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/attributes/default.rb b/attributes/default.rb index 7bb7586..a052d29 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -15,7 +15,7 @@ default[:lxc][:proxy][:enable] = false -default[:lxc][:elecksee][:version_restriction] = '~> 1.1.2' +default[:lxc][:elecksee][:version_restriction] = '~> 2.0.2' default[:lxc][:elecksee][:action] = :install default[:lxc][:default_config_enabled] = true