Skip to content
Browse files

Remove linux containers, refs OC-1029.

Support for linux containers adds additional complexity without as big an
increase in performance as earlier expected. It also didn't fit cleanly into
the existing runner concept. Removing for now to keep things clean.
  • Loading branch information...
1 parent d1cbf4a commit 0e1c51a428864214057200fb0ebfb6454c10509b Andrew Crump committed
View
25 LICENSE.md
@@ -555,31 +555,6 @@ Mixlib::CLI is licensed under the Apache License, Version 2.0.
See the License for the specific language governing permissions and
limitations under the License.
-## Toft
-
-Toft is licensed under the MIT License.
-
- The MIT License (MIT)
- Copyright (c) 2012 Remy Sharp, http://remysharp.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the “Software”), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-
## Vagrant
Vagrant is licensed under the MIT License.
View
9 README.md
@@ -1,7 +1,7 @@
# Test Kitchen
-Test Kitchen pulls together some of your favorite tools (Chef, Vagrant, Toft) to
-make it easy to get started testing Chef cookbooks.
+Test Kitchen pulls together some of your favorite tools to make it easy to get
+started testing Chef cookbooks.
You define your test config in a `Kitchenfile` within your cookbook.
@@ -50,11 +50,6 @@ tested against all platforms supported by test-kitchen. Alternatively if you
have specified a platform that test-kitchen doesn't yet support a warning
message will be displayed.
-If you are using Vagrant/VirtualBox (the default) you'll notice that
-test-kitchen doesn't tear down the VirtualBox VM between different platforms.
-This is because a single VM is provisioned which then uses Linux Containers (via
-Toft) to give you faster feedback.
-
# Configurations
Very often you will want to test different independent usages or
View
5 config/Vagrantfile
@@ -78,10 +78,7 @@ project = tk_env.project
'project' => project.to_hash.merge(
'source_root' => project.guest_source_root,
'test_root' => project.guest_test_root
- ),
- 'lxc-image-urls' => Hash[*tk_env.all_platforms.map do |key, value|
- [key, value.lxc_url] if value.lxc_url
- end.flatten.compact]
+ )
},
}
View
85 cookbooks/test-kitchen/recipes/lxc.rb
@@ -1,85 +0,0 @@
-#
-# Author:: Andrew Crump (<andrew@kotirisoftware.com>)
-# Copyright:: Copyright (c) 2012 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-remote_file "/tmp/toft.deb" do
- source "http://dl.dropbox.com/u/43220259/toft-lxc_0.0.6_all.deb"
- mode "0600"
-end
-
-package "apparmor" do
- action :remove
-end
-
-package "toft-lxc" do
- source "/tmp/toft.deb"
- provider Chef::Provider::Package::Dpkg
- ignore_failure true
- action :install
-end
-
-execute "install-dependencies" do
- command "apt-get -y -f install"
- action :run
-end
-
-%w{ruby1.8 rubygems1.8}.each do |ruby18_pkg|
- package ruby18_pkg do
- action :install
- end
-end
-
-%w{json toft}.each do |toft_gem|
- gem_package toft_gem do
- gem_binary "gem1.8"
- action :install
- end
-end
-
-directory "/var/cache/lxc" do
- recursive true
- action :create
-end
-
-node['test-kitchen']['lxc-image-urls'].each_pair do |local_name, remote_image|
- # Hack for mapping platform to template names
- local_name = {'centos-6.2' => 'centos-6', 'ubuntu-11.04' => 'natty'}[local_name]
- remote_file "/var/cache/lxc/#{local_name}-i386.tar.gz" do
- source remote_image
- action :create_if_missing
- end
-end
-
-execute "lxc-prepare-host" do
- action :run
-end
-
-project = node['test-kitchen']['project']
-lxc_run_list = ['test-kitchen::default']
-lxc_run_list << "test-kitchen::#{project['language'] || 'chef'}"
-lxc_run_list << project['run_list_extras'] if project['run_list_extras']
-
-template "/usr/bin/test-kitchen-lxc" do
- variables({
- 'project' => node['test-kitchen']['project'],
- 'test_user' => node['test-kitchen']['user'],
- 'test_group' => node['test-kitchen']['group'],
- 'run_list' => lxc_run_list
- })
- mode "00700"
- action :create
-end
View
63 cookbooks/test-kitchen/templates/default/test-kitchen-lxc.erb
@@ -1,63 +0,0 @@
-#!/usr/bin/ruby1.8
-require 'rubygems'
-require 'json'
-require 'toft'
-
-module TestKitchen
- module LXC
- class Container
-
- include Toft
- Toft.cookbook_path = '/vagrant/cookbooks'
-
- def add_project_mount(node_name)
- FileUtils.mkdir_p "/var/lib/lxc/#{node_name}/rootfs<%= @project['source_root'] %>"
- open("/var/lib/lxc/#{node_name}/fstab", 'a') do |f|
- f.puts "<%= @project['source_root'] %> /var/lib/lxc/#{node_name}/rootfs<%= @project['source_root'] %> none bind 0 0"
- end
- end
-
- def remove_run_list(dna_input, dna_output)
- tk_atts = JSON.parse(File.read(dna_input))
- tk_atts.delete 'run_list'
- File.open(dna_output, 'w') {|f| f.write(JSON.pretty_generate(tk_atts)) }
- end
-
- def add_user(node, user_name)
- node.run_ssh "id -u #{user_name} &>/dev/null || useradd -U -m #{user_name}"
- end
-
- def provision(node_name, json_path, configuration_recipe)
- node = create_node(node_name, {:type => node_name})
- add_project_mount(node_name)
- node.start
- puts node.ip
- add_user(node, '<%= @test_user %>')
- node.run_ssh 'mkdir -p /tmp/chef-file-cache'
- run_list = <%= @run_list %>
- unless configuration_recipe.nil? || configuration_recipe.empty?
- run_list += [configuration_recipe]
- end
- node.run_chef run_list, {:json => json_path}
- end
-
- end
-
- command, node_name = ARGV[0..1]
- node_name = {'centos-6.2' => 'centos-6', 'ubuntu-11.04' => 'natty'}[node_name]
- container = Container.new
- case command
- when 'provision'
- configuration_recipe = ARGV[2]
- container.remove_run_list('/vagrant/.cache/dna.json', '/vagrant/.cache/lxc-dna.json')
- container.provision(node_name, '/vagrant/.cache/lxc-dna.json', configuration_recipe)
- when 'run'
- ssh_cmd = ARGV[2]
- node = container.create_node(node_name, {:type => node_name})
- node.run_ssh ssh_cmd
- when 'destroy'
- node = container.create_node(node_name, {:type => node_name})
- node.destroy
- end
- end
-end
View
6 lib/test-kitchen/platform.rb
@@ -41,7 +41,7 @@ class Version
include Chef::Mixin::ParamsValidate
attr_reader :name
- attr_writer :box, :box_url, :lxc_url
+ attr_writer :box, :box_url
def initialize(name, &block)
raise ArgumentError, "Version name must be specified" if name.nil? || name.empty?
@@ -57,10 +57,6 @@ def box_url(arg=nil)
set_or_return(:box_url, arg, {})
end
- def lxc_url(arg=nil)
- set_or_return(:lxc_url, arg, {})
- end
-
end
end
View
5 lib/test-kitchen/project/base.rb
@@ -66,10 +66,7 @@ def exclude(exclusion)
end
def run_list
- [case runner
- when 'lxc' then 'test-kitchen::lxc'
- else 'test-kitchen::default'
- end] + run_list_extras
+ ['test-kitchen::default'] + run_list_extras
end
def run_list_extras(arg=nil)
View
1 lib/test-kitchen/runner.rb
@@ -17,5 +17,4 @@
#
require 'test-kitchen/runner/base'
-require 'test-kitchen/runner/lxc'
require 'test-kitchen/runner/vagrant'
View
7 lib/test-kitchen/runner/base.rb
@@ -144,15 +144,12 @@ def self.targets
def self.for_platform(env, options)
desired_platform = env.all_platforms[options[:platform]]
- runner = if desired_platform.lxc_url
- 'lxc'
- elsif desired_platform.box_url
- 'vagrant'
+ if desired_platform.box_url
+ TestKitchen::Runner.targets['vagrant'].new(env, options)
else
raise ArgumentError,
"No runner available for platform: #{desired_platform.name}"
end
- TestKitchen::Runner.targets[runner].new(env, options)
end
end
end
View
86 lib/test-kitchen/runner/lxc.rb
@@ -1,86 +0,0 @@
-#
-# Author:: Andrew Crump (<andrew@kotirisoftware.com>)
-# Copyright:: Copyright (c) 2012 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-module TestKitchen
- module Runner
- class LXC < Base
-
- NATTY = 'ubuntu-11.04'
- LXC_HOST = NATTY
-
- attr_reader :options
- attr_writer :nested_runner
-
- def initialize(env, options={})
- super
- raise_unless_host_box_available
- @env, @options = env, options
- end
-
- def nested_runner
- @nested_runner ||=
- Runner.targets['vagrant'].new(@env, @options).tap do |vagrant|
- vagrant.platform = NATTY
- end
- end
-
- def provision
- nested_runner.provision
- nested_runner.with_target_vms(LXC_HOST) do |vm|
- nested_runner.execute_remote_command vm,
- "sudo test-kitchen-lxc provision '#{platform}' '#{test_recipe_name}'",
- "Provisioning Linux Container: #{platform} [#{configuration.name}]"
- end
- end
-
- def run_list
- ['test-kitchen::lxc']
- end
-
- def status
- raise NotImplementedError, "Not implemented"
- end
-
- def destroy
- nested_runner.with_target_vms(LXC_HOST) do |vm|
- nested_runner.execute_remote_command vm,
- "sudo test-kitchen-lxc destroy '#{platform}'",
- "Destroying Linux Container: #{platform} [#{configuration.name}]"
- end
- # TODO: Need to collect the nested VM
- #nested_runner.destroy
- end
-
- def execute_remote_command(node, command, message=nil)
- nested_runner.with_target_vms(LXC_HOST) do |vm|
- nested_runner.execute_remote_command(vm, "sudo test-kitchen-lxc run '#{node}' '#{command}'", message)
- end
- end
-
- private
-
- def raise_unless_host_box_available
- distro_name, distro_version = NATTY.split('-')
- unless env.platforms[distro_name] and env.platforms[distro_name].versions[distro_version]
- raise ArgumentError, "LXC host box '#{NATTY}' is not available"
- end
- end
-
- end
- end
-end
View
1 spec/test-kitchen/dsl_spec.rb
@@ -93,7 +93,6 @@ def env
version '10.04' do
box "ubuntu-10.04"
box_url "http://example.org/ubuntu-10.04.box"
- lxc_url "http://example.org/ubuntu-10.04.tar.gz"
end
end
end
View
158 spec/test-kitchen/runner/lxc_spec.rb
@@ -1,158 +0,0 @@
-#
-# Author:: Andrew Crump (<andrew@kotirisoftware.com>)
-# Copyright:: Copyright (c) 2012 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require_relative '../../spec_helper'
-
-require 'test-kitchen'
-
-module TestKitchen
-
- module Runner
- describe LXC do
- let(:env) do
- env = Environment.new(:ignore_kitchenfile => true)
- env.platforms['ubuntu'] = Platform.new('ubuntu') do
- version '11.04' do
- box "opscode-ubuntu-11.04"
- box_url "http://example.org/opscode-ubuntu-11.04.box"
- end
- end
- env
- end
-
- describe "#initialize" do
- it "complains if an environment is not provided" do
- lambda { Environment.new }.must_raise ArgumentError
- end
- it "accepts an environment as a constructor argument" do
- runner = LXC.new(env)
- runner.env.must_equal env
- runner.options.must_equal({})
- end
- it "optionally accepts an options too" do
- runner = LXC.new(env, {:platform => 'ubuntu'})
- runner.env.must_equal env
- runner.options.must_equal({:platform => 'ubuntu'})
- end
- it "raises if the supported host platform is not available" do
- env = Environment.new(:ignore_kitchenfile => true)
- env.platforms['centos'] = Platform.new('centos') do
- version '5.7' do
- box "opscode-centos-5.7"
- box_url "http://example.org/opscode-centos-5.7.box"
- end
- end
- lambda{ runner = LXC.new(env, {:platform => 'foo'}) }.must_raise ArgumentError,
- "LXC host box 'ubuntu-11.04' is not available"
- end
- end
- describe "#nested_runner" do
- it "wraps a nested runner which acts as the LXC host" do
- runner = LXC.new(env, {:platform => 'ubuntu'})
- runner.nested_runner = 'foo'
- runner.nested_runner.must_equal 'foo'
- end
- it "defaults the nested runner to using vagrant" do
- skip "Vagrant runner is not test friendly"
- end
- it "sets the host platform to natty" do
- skip "Vagrant runner is not test friendly"
- end
- end
- describe "#provision" do
- let(:runner) do
- runner = LXC.new(env, {:platform => 'ubuntu'})
- runner.instance_eval do
- def test_recipe_name
- 'example'
- end
- end
- runner
- end
- it "delegates the provision call to the nested runner" do
- runner.nested_runner = MiniTest::Mock.new
- runner.nested_runner.expect :provision, nil
- runner.nested_runner.expect :with_target_vms, nil, [String]
- runner.provision
- runner.nested_runner.verify
- end
- describe "delegating commands" do
- class MockRunner
- def initialize(expected_cmd, expected_log)
- @expected_cmd = expected_cmd
- @expected_log = expected_log
- end
- def provision
-
- end
- def with_target_vms(name)
- name.must_equal 'ubuntu-11.04'
- yield 'a virtual machine'
- end
- def execute_remote_command(vm, command, log)
- @executed = true
- command.must_equal @expected_cmd
- log.must_equal @expected_log
- end
- def executed_command?
- @executed ||= false
- end
- end
- it "provisions the linux container" do
- nested_runner = MockRunner.new("sudo test-kitchen-lxc provision 'ubuntu' 'example'",
- 'Provisioning Linux Container: ubuntu [example]')
- env.project = TestKitchen::Project::Cookbook.new('example')
- runner.configuration = env.project
- runner.nested_runner = nested_runner
- runner.provision
- assert runner.nested_runner.executed_command?
- end
- it "delegates commands to the remote container" do
- nested_runner = MockRunner.new("sudo test-kitchen-lxc run 'centos-6' 'ls'", nil)
- env.project = TestKitchen::Project::Cookbook.new('example')
- runner.configuration = env.project
- runner.nested_runner = nested_runner
- runner.execute_remote_command('centos-6', 'ls')
- assert runner.nested_runner.executed_command?
- end
- it "destroys the remote container" do
- nested_runner = MockRunner.new("sudo test-kitchen-lxc destroy 'ubuntu'",
- 'Destroying Linux Container: ubuntu [example]')
- env.project = TestKitchen::Project::Cookbook.new('example')
- runner.configuration = env.project
- runner.nested_runner = nested_runner
- runner.destroy
- assert runner.nested_runner.executed_command?
- end
- end
- end
- describe "#run_list" do
- it "expresses the dependency on the LXC recipe" do
- runner = LXC.new(env, {:platform => 'ubuntu'})
- runner.run_list.must_include 'test-kitchen::lxc'
- end
- end
- describe "#status" do
- it "raises because it is not implemented" do
- runner = LXC.new(env, {:platform => 'ubuntu'})
- lambda { runner.status }.must_raise NotImplementedError
- end
- end
- end
- end
-end

0 comments on commit 0e1c51a

Please sign in to comment.
Something went wrong with that request. Please try again.