kitchen-lxd 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c5051caa8743e2a50fdd4459826900f61e16e03
4
+ data.tar.gz: 181a7f2dfc1b10900c35e64c33c068c557bb5fe9
5
+ SHA512:
6
+ metadata.gz: 755ce3b4da2ad088ec556d84de20f076c6f7b5d8b7cd9d41d4697fd46de9984c1781a30e83e77234aba73de0b160f7785eba5a30c10e1580f62ce1e8d9409757
7
+ data.tar.gz: 0a7ec97eff31370f3297fefdcf240c5bb56703136ff77f012c128cc3ff4cc574b55ac8db17c9fcb3dbfc79f458f6bd11dd8e1f5bd07310907c6b70f4e702784a
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.1.0 / Unreleased
2
+
3
+ - Initial release
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Author:: Juri Timošin (<draco.ater@gmail.com>)
2
+
3
+ Copyright (C) 2017, Juri Timošin
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # <a name="title"></a> Kitchen::Lxd
2
+
3
+ [![Build Status](https://travis-ci.org/zeroturnaround/kitchen-lxd.svg?branch=master)](https://travis-ci.org/zeroturnaround/kitchen-lxd)
4
+
5
+ A Test Kitchen Driver for Lxd.
6
+
7
+ ## <a name="requirements"></a> Requirements
8
+
9
+ ### Lxd
10
+
11
+ Lxd version of 2.3 (the one where "lxc network" commands were introduced) or higher is required for
12
+ this driver which means that a native package must be installed on the system running Test Kitchen.
13
+ You must also prepare a container to be used by Test Kitchen. For that make sure there is ssh daemon
14
+ installed and starting on boot. ( On Ubuntu it can be done by simply installing 'openssh-server'
15
+ package. ) You can also install Chef Client there, if you do not want Test Kitchen to install it
16
+ every time the container is started.
17
+
18
+ ## <a name="installation"></a> Installation and Setup
19
+
20
+ Install using command line:
21
+
22
+ ```bash
23
+ gem install kitchen-lxd
24
+ ```
25
+
26
+ ## <a name="config"></a> Configuration
27
+
28
+ Available options:
29
+
30
+ - image
31
+ - container
32
+ - require_chef_omnibus
33
+
34
+ ### image
35
+
36
+ Define from which lxd image the container will be created.
37
+
38
+ ```yaml
39
+ ---
40
+ driver:
41
+ image: ubuntu/xenial/amd64
42
+ ```
43
+
44
+ The default is value of `platform name`.
45
+
46
+ ```yaml
47
+ ---
48
+ platforms:
49
+ - name: kitchen-xenial64
50
+ ```
51
+
52
+ In this case: 'kitchen-xenial64', expecting to have an lxd image with this name locally.
53
+
54
+ ### container
55
+
56
+ Created container name.
57
+
58
+ ```yaml
59
+ ---
60
+ driver:
61
+ container_name: my_name
62
+ ```
63
+
64
+ The default is value of `kitchen instance name`.
65
+
66
+ ```yaml
67
+ ---
68
+ platforms:
69
+ - name: kitchen-xenial64
70
+
71
+ suites:
72
+ - name: webserver
73
+ ```
74
+
75
+ In this case: 'webserver-kitchen-xenial64'.
76
+
77
+ ### <a name="config-require-chef-omnibus"></a> require\_chef\_omnibus
78
+
79
+ Determines whether or not a Chef [Omnibus package][chef_omnibus_dl] will be
80
+ installed. There are several different behaviors available:
81
+
82
+ - `true` - the latest release will be installed. Subsequent converges
83
+ will skip re-installing if chef is present.
84
+ - `latest` - the latest release will be installed. Subsequent converges
85
+ will always re-install even if chef is present.
86
+ - `<VERSION_STRING>` (ex: `10.24.0`) - the desired version string will
87
+ be passed the the install.sh script. Subsequent converges will skip if
88
+ the installed version and the desired version match.
89
+ - `false` or `nil` - no chef is installed.
90
+
91
+ The default value is unset, or `nil`.
92
+
93
+ ## <a name="development"></a> Development
94
+
95
+ - Source hosted at [GitHub][repo]
96
+ - Report issues/questions/feature requests on [GitHub Issues][issues]
97
+
98
+ Pull requests are very welcome! Make sure your patches are well tested.
99
+ Ideally create a topic branch for every separate change you make. For
100
+ example:
101
+
102
+ 1. Fork the repo
103
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
104
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
105
+ 4. Push to the branch (`git push origin my-new-feature`)
106
+ 5. Create new Pull Request
107
+
108
+ ## <a name="authors"></a> Authors
109
+
110
+ Created and maintained by [ZeroTurnaround][author].
111
+
112
+ ## <a name="license"></a> License
113
+
114
+ Apache 2.0 (see [LICENSE][license])
115
+
116
+
117
+ [author]: https://github.com/zeroturnaround
118
+ [issues]: https://github.com/zeroturnaround/kitchen-lxd/issues
119
+ [license]: https://github.com/zeroturnaround/kitchen-lxd/blob/master/LICENSE
120
+ [repo]: https://github.com/zeroturnaround/kitchen-lxd
121
+ [driver_usage]: http://docs.kitchen-ci.org/drivers/usage
122
+ [chef_omnibus_dl]: http://www.chef.io/chef/install/
@@ -0,0 +1,89 @@
1
+ require 'kitchen'
2
+ require 'json'
3
+
4
+ module Kitchen
5
+ module Driver
6
+ class Lxd < Kitchen::Driver::Base
7
+ class Container
8
+ include ShellOut
9
+ include Logging
10
+
11
+ attr_reader :logger
12
+ attr_reader :state
13
+
14
+ def initialize( name, image, logger )
15
+ @name = name
16
+ @image = image
17
+ @logger = logger
18
+ update_state
19
+ end
20
+
21
+ def init
22
+ unless created?
23
+ run_command "lxc init #@image #@name"
24
+ update_state
25
+ end
26
+ end
27
+
28
+ def attach_network( network )
29
+ unless device_attached? network
30
+ run_command "lxc network attach #{network} #@name"
31
+ update_state
32
+ end
33
+ end
34
+
35
+ def start
36
+ unless running?
37
+ run_command "lxc start #@name"
38
+ update_state
39
+ end
40
+ end
41
+
42
+ def prepare_ssh
43
+ run_command "lxc exec #@name mkdir -- -p /root/.ssh"
44
+ run_command "lxc file push ~/.ssh/id_rsa.pub #@name/root/.ssh/authorized_keys"
45
+ run_command "lxc exec #@name chown -- root:root /root/.ssh/authorized_keys"
46
+ end
47
+
48
+ def destroy
49
+ if created?
50
+ run_command "lxc delete #@name --force"
51
+ update_state
52
+ end
53
+ end
54
+
55
+ def wait_for_ipv4
56
+ info 'Wait for network to become ready.'
57
+ 9.times do
58
+ update_state
59
+ inet = @state[:state][:network][:eth0][:addresses].detect do |i|
60
+ i[:family] == 'inet'
61
+ end
62
+ return inet[:address] if inet
63
+ sleep 1 unless defined?( Minitest )
64
+ end
65
+ nil
66
+ end
67
+
68
+ private
69
+
70
+ def update_state
71
+ @state = JSON.parse( run_command( "lxc list #@name --format json" ),
72
+ symbolize_names: true ).first
73
+ end
74
+
75
+ def running?
76
+ @state[:status] == 'Running'
77
+ end
78
+
79
+ def created?
80
+ !@state.nil?
81
+ end
82
+
83
+ def device_attached?( network )
84
+ @state[:devices] and @state[:devices][network.to_sym]
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,59 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Juri Timošin (<draco.ater@gmail.com>)
4
+ #
5
+ # Copyright (C) 2017, Juri Timošin
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require 'kitchen'
20
+ require_relative 'lxd/container'
21
+
22
+ module Kitchen
23
+ module Driver
24
+ # Lxd driver for Kitchen.
25
+ #
26
+ # @author Juri Timošin <draco.ater@gmail.com>
27
+ class Lxd < Kitchen::Driver::Base
28
+ kitchen_driver_api_version 2
29
+
30
+ default_config( :image ){|driver| driver.instance.platform.name }
31
+ default_config( :container ){|driver| driver.instance.name }
32
+
33
+ attr_accessor :container
34
+
35
+ def create( state )
36
+ container.init
37
+ container.attach_network 'lxdbr0'
38
+ container.start
39
+ container.prepare_ssh
40
+
41
+ state[:hostname] = container.wait_for_ipv4
42
+ instance.transport.connection( state ).wait_until_ready
43
+ end
44
+
45
+ def destroy( state )
46
+ instance.transport.connection( state ).close
47
+ state.delete :hostname
48
+ container.destroy
49
+ end
50
+
51
+ private
52
+
53
+ def container
54
+ @container = Lxd::Container.new( config[:container], config[:image], logger ) if @container.nil?
55
+ @container
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Juri Timošin (<draco.ater@gmail.com>)
4
+ #
5
+ # Copyright (C) 2017, Juri Timošin
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ module Kitchen
20
+ module Driver
21
+ # Version string for Lxd Kitchen driver
22
+ LXD_VERSION = '0.1.0'
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-lxd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Juri Timošin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test-kitchen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ci_reporter_minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ description: Kitchen::Driver::Lxd - an Lxd driver for Test Kitchen.
98
+ email:
99
+ - draco.ater@gmail.com
100
+ - juri.timoshin@zeroturnaround.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - CHANGELOG.md
106
+ - LICENSE
107
+ - README.md
108
+ - lib/kitchen/driver/lxd.rb
109
+ - lib/kitchen/driver/lxd/container.rb
110
+ - lib/kitchen/driver/version.rb
111
+ homepage: https://github.com/zeroturnaround/kitchen-lxd
112
+ licenses:
113
+ - Apache-2.0
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '2.0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.5.1
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: An Lxd driver for Test Kitchen.
135
+ test_files: []