kitchen-lxc 0.0.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ *.lock
3
+ .bundle
4
+ .kitchen
5
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem"s dependencies in kitchen-lxc.gemspec
4
+ gemspec
5
+
6
+ gem "test-kitchen", :git => "git://github.com/opscode/test-kitchen.git", :branch => "1.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sean Porter
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # Kitchen LXC
2
+
3
+ The LXC driver for the Chef convergence integration test harness, [Test Kitchen](https://github.com/opscode/test-kitchen/tree/1.0).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your Chef cookbooks's Gemfile:
8
+
9
+ gem 'kitchen-lxc'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install kitchen-lxc
18
+
19
+ ## Usage
20
+
21
+ ### Configuration
22
+
23
+ `.kitchen.local.yml`
24
+
25
+ ```
26
+ driver_plugin: lxc
27
+
28
+ platforms:
29
+ - name: distribution
30
+ driver_config:
31
+ base_container: "distribution-release" # your base container name
32
+ username: "foo" # defaults to "root"
33
+ password: "bar" # defaults to "root"
34
+ ```
35
+
36
+ ### Example
37
+
38
+ ```
39
+ $ kitchen create
40
+ -----> Starting Kitchen
41
+ -----> Creating <default-ubuntu>
42
+ [lxc command] BEGIN (sudo lxc-clone -o ubuntu-1204 -n default-ubuntu-a5fb8a)
43
+ Tweaking configuration
44
+ Copying rootfs...
45
+ Updating rootfs...
46
+ 'default-ubuntu-a5fb8a' created
47
+ [lxc command] END (0m6.17s)
48
+ [lxc command] BEGIN (sudo lxc-start -n default-ubuntu-a5fb8a -d)
49
+ [lxc command] END (0m0.01s)
50
+ [lxc command] BEGIN (sudo lxc-wait -n default-ubuntu-a5fb8a -s RUNNING)
51
+ [lxc command] END (0m1.05s)
52
+ Finished creating <default-ubuntu> (0m7.42s).
53
+ -----> Creating <default-centos>
54
+ [lxc command] BEGIN (sudo lxc-clone -o centos-6 -n default-centos-58fced)
55
+ Tweaking configuration
56
+ Copying rootfs...
57
+ Updating rootfs...
58
+ 'default-centos-58fced' created
59
+ [lxc command] END (0m6.68s)
60
+ [lxc command] BEGIN (sudo lxc-start -n default-centos-58fced -d)
61
+ [lxc command] END (0m0.02s)
62
+ [lxc command] BEGIN (sudo lxc-wait -n default-centos-58fced -s RUNNING)
63
+ [lxc command] END (0m1.05s)
64
+ Finished creating <default-centos> (0m13.92s).
65
+ -----> Kitchen is finished. (0m21.45s)
66
+ $ kitchen destroy
67
+ -----> Starting Kitchen
68
+ -----> Destroying <default-ubuntu>
69
+ [lxc command] BEGIN (sudo lxc-destroy -n default-ubuntu-a5fb8a -f)
70
+ [lxc command] END (0m1.18s)
71
+ Finished destroying <default-ubuntu> (0m1.21s).
72
+ -----> Destroying <default-centos>
73
+ [lxc command] BEGIN (sudo lxc-destroy -n default-centos-58fced -f)
74
+ [lxc command] END (0m1.14s)
75
+ Finished destroying <default-centos> (0m1.17s).
76
+ -----> Kitchen is finished. (0m2.45s)
77
+ ```
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |test|
5
+ test.pattern = "test/*_tests.rb"
6
+ end
7
+
8
+ task :default => "test"
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = "kitchen-lxc"
3
+ gem.version = "0.0.1.beta1"
4
+ gem.authors = ["Sean Porter"]
5
+ gem.email = ["portertech@gmail.com"]
6
+ gem.description = "LXC driver for Test Kitchen"
7
+ gem.summary = "LXC driver for Test Kitchen"
8
+ gem.homepage = "https://github.com/portertech/kitchen-lxc"
9
+ gem.license = "MIT"
10
+ gem.has_rdoc = false
11
+
12
+ gem.add_dependency("test-kitchen", ">= 1.0.0.alpha.0")
13
+
14
+ gem.add_development_dependency("rake")
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,68 @@
1
+ require "securerandom"
2
+ require "kitchen"
3
+
4
+ module Kitchen
5
+
6
+ module Driver
7
+
8
+ class Lxc < Kitchen::Driver::SSHBase
9
+
10
+ default_config :use_sudo, true
11
+ default_config :dhcp_lease_file, "/var/lib/misc/dnsmasq.leases"
12
+ default_config :port, "22"
13
+ default_config :username, "root" # most LXC templates use this
14
+ default_config :password, "root" # most LXC templates use this
15
+
16
+ def create(state)
17
+ state[:container_id] = instance.name + "-" + ::SecureRandom.hex(3)
18
+ clone_container(state)
19
+ start_container(state)
20
+ state[:hostname] = container_ip(state)
21
+ wait_for_sshd(state[:hostname])
22
+ end
23
+
24
+ def destroy(state)
25
+ if state[:container_id]
26
+ destroy_container(state)
27
+ end
28
+ end
29
+
30
+ protected
31
+
32
+ def clone_container(state)
33
+ run_command("lxc-clone -o #{config[:base_container]} -n #{state[:container_id]}")
34
+ end
35
+
36
+ def start_container(state)
37
+ run_command("lxc-start -n #{state[:container_id]} -d")
38
+ run_command("lxc-wait -n #{state[:container_id]} -s RUNNING")
39
+ end
40
+
41
+ def destroy_container(state)
42
+ run_command("lxc-destroy -n #{state[:container_id]} -f")
43
+ end
44
+
45
+ def container_ip(state)
46
+ if ::File.exists?(config[:dhcp_lease_file])
47
+ 30.times do
48
+ leases = ::File.readlines(config[:dhcp_lease_file]).map{ |line| line.split(" ") }
49
+ leases.each do |lease|
50
+ if lease.include?(state[:container_id])
51
+ return lease[2]
52
+ end
53
+ end
54
+ sleep 3
55
+ end
56
+ else
57
+ raise ActionFailed, "LXC DHCP lease file does not exist '#{config[:dhcp_lease_file]}'"
58
+ end
59
+ raise ActionFailed, "Could not determine IP address for LXC container '#{state[:container_id]}'"
60
+ end
61
+
62
+ end
63
+
64
+ class LXC < Lxc; end
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,31 @@
1
+ require "minitest/spec"
2
+ require "minitest/autorun"
3
+ require "stringio"
4
+
5
+ require File.join(File.dirname(__FILE__), "..", "lib", "kitchen", "driver", "lxc")
6
+
7
+ describe Kitchen::Driver::Lxc do
8
+
9
+ before do
10
+ @logger_output = StringIO.new
11
+ driver_options = {
12
+ :kitchen_root => File.dirname(__FILE__),
13
+ :base_container => "ubuntu-1204"
14
+ }
15
+ instance_options = {
16
+ :logger => Kitchen::Logger.new(:stdout => @logger_output),
17
+ :suite => Kitchen::Suite.new(:name => "test", :run_list => Array.new),
18
+ :platform => Kitchen::Platform.new(:name => "ubuntu-1204"),
19
+ :driver => Kitchen::Driver::Lxc.new(driver_options)
20
+ }
21
+ @instance = Kitchen::Instance.new(instance_options)
22
+ end
23
+
24
+ it "can clone a base lxc container" do
25
+ @instance.create
26
+ @logger_output.string.must_match(/Finished creating <test-ubuntu-1204>/i)
27
+ @instance.destroy
28
+ @logger_output.string.must_match(/Finished destroying <test-ubuntu-1204>/i)
29
+ end
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-lxc
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: 6
5
+ version: 0.0.1.beta1
6
+ platform: ruby
7
+ authors:
8
+ - Sean Porter
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ type: :runtime
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0.alpha.0
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: 1.0.0.alpha.0
29
+ name: test-kitchen
30
+ - !ruby/object:Gem::Dependency
31
+ type: :development
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ name: rake
46
+ description: LXC driver for Test Kitchen
47
+ email:
48
+ - portertech@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - kitchen-lxc.gemspec
59
+ - lib/kitchen/driver/lxc.rb
60
+ - test/lxc_driver_tests.rb
61
+ homepage: https://github.com/portertech/kitchen-lxc
62
+ licenses:
63
+ - MIT
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>'
78
+ - !ruby/object:Gem::Version
79
+ version: 1.3.1
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.24
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: LXC driver for Test Kitchen
86
+ test_files:
87
+ - test/lxc_driver_tests.rb