kitchen-lxd_cli 0.1.6 → 2.0.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 +4 -4
- data/README.md +8 -6
- data/kitchen-lxd_cli.gemspec +1 -1
- data/lib/kitchen/driver/lxd_cli.rb +43 -24
- data/lib/kitchen/driver/lxd_cli_version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad7b7dd864e7373d8f549d39ffc1ddbb58f3d929
|
4
|
+
data.tar.gz: 1ca5ed8845e1ed386320d5f228a7f22cd1bf38da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67c2f7b009f1f3941674d9c15e08437cc18e7361309e90dfbc70941dcd54dc97f0f53e0489eb7a8cc13511ea013c04821164f9c6a2924e98364f225eab3547ed
|
7
|
+
data.tar.gz: 482187b180da0b2412be0e233fb4bbc4d8b7644a9c34da4cdee76e1d5d366eb011b666397c7d1ea9057fd31a9c806012f90c21eac535aad718dace56361d7d5e
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ A Test Kitchen Driver for LXD / LXC
|
|
6
6
|
|
7
7
|
This is a test-kitchen driver for lxd, which controls lxc. I named it LxdCli because this is my first plugin and I wanted to leave LXD driver name in case a more extensive project is put together. Although I've since added a lot more features than I originally planned.
|
8
8
|
|
9
|
-
I'm running lxd --version 0.
|
9
|
+
I'm running lxd --version 2.0.2 on ubuntu 16.04. Image setup, Networking options, etc will not work prior to 2.0.0 [Github Issue](https://github.com/lxc/lxd/issues/1259), use kitchen_lxd_cli 0.x.x for lxd 0.x. Only tested with ubuntu containers, pull requests are welcome.
|
10
10
|
|
11
11
|
I started the project because I really like the idea of developing containers, but kitchen-lxc wouldn't work with my version. I also tried docker but preferred how lxd is closer to a hypervisor virtual machine. For instance kitchen-docker my recipes that had worked on virtual machies for mongodb, the service would not start when using docker. I was able to get the service to start but liked the concept of system containers more than application containers. Ultimately I was interested in LXD and there wasn't anything out there. I was quickly able to get my mongodb recipe working. I figured I'd clean things up, and some features and publish it. Since then I've added numerous features, mainly with a focus on speeding up development of cookbooks, and exploring LXD.
|
12
12
|
|
@@ -52,8 +52,8 @@ driver:
|
|
52
52
|
image_release: trusty
|
53
53
|
profile: my_lxc_profile
|
54
54
|
config:
|
55
|
-
limits.memory:
|
56
|
-
limits.
|
55
|
+
limits.memory: 2GB
|
56
|
+
limits.cpu: 2
|
57
57
|
boot.autostart: true
|
58
58
|
domain_name: lxc
|
59
59
|
ip_gateway: 10.0.3.1
|
@@ -205,12 +205,12 @@ Default is Nil. See LXC documentation but a lxc profile can be specified. Whic
|
|
205
205
|
|
206
206
|
Default is Nil. See LXC documentation but a lxc config container key/value can be specified. [LXC Container Config Options](https://github.com/lxc/lxd/blob/master/specs/configuration.md#keyvalue-configuration-1). Config options are passed to "lxc init" command. A String or a Hash of key/value pairs is accepted.
|
207
207
|
|
208
|
-
`config: "limits.memory=
|
208
|
+
`config: "limits.memory=2GB"`
|
209
209
|
|
210
210
|
```yaml
|
211
211
|
config:
|
212
|
-
limits.memory:
|
213
|
-
limits.
|
212
|
+
limits.memory: 1GB
|
213
|
+
limits.cpu: 2
|
214
214
|
boot.autostart: true
|
215
215
|
```
|
216
216
|
|
@@ -225,6 +225,8 @@ mount:
|
|
225
225
|
mymount2:
|
226
226
|
local_path: "/my/local/path"
|
227
227
|
container_path: "/my/container/path"
|
228
|
+
# Attempts to create the local_path if it doesn't exist yet
|
229
|
+
create_source: true
|
228
230
|
```
|
229
231
|
|
230
232
|
You can mount however many directories you like. The kitchen-lxd_cli driver will run `lxc config device add <container> <name> disk <local_path>=<container_path>`
|
data/kitchen-lxd_cli.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'test-kitchen', '~> 1.4
|
21
|
+
spec.add_dependency 'test-kitchen', '~> 1.4'
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
24
24
|
spec.add_development_dependency 'rake'
|
@@ -17,6 +17,7 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
|
19
19
|
require 'kitchen'
|
20
|
+
require 'fileutils'
|
20
21
|
|
21
22
|
module Kitchen
|
22
23
|
|
@@ -40,7 +41,7 @@ module Kitchen
|
|
40
41
|
default_config :lxd_proxy_path, "#{ENV['HOME']}/.lxd_proxy"
|
41
42
|
default_config :lxd_proxy_update, false
|
42
43
|
default_config :username, "root"
|
43
|
-
|
44
|
+
|
44
45
|
required_config :public_key_path
|
45
46
|
|
46
47
|
def create(state)
|
@@ -49,7 +50,7 @@ module Kitchen
|
|
49
50
|
unless exists?
|
50
51
|
image_name = create_image_if_missing
|
51
52
|
profile_args = setup_profile_args if config[:profile]
|
52
|
-
config_args = setup_config_args
|
53
|
+
config_args = setup_config_args
|
53
54
|
info("Initializing container #{instance.name}")
|
54
55
|
run_lxc_command("init #{image_name} #{instance.name} #{profile_args} #{config_args}")
|
55
56
|
end
|
@@ -73,7 +74,7 @@ module Kitchen
|
|
73
74
|
info("Stopping container #{instance.name}")
|
74
75
|
run_lxc_command("stop #{instance.name}")
|
75
76
|
end
|
76
|
-
|
77
|
+
|
77
78
|
publish_image if config[:publish_image_before_destroy]
|
78
79
|
|
79
80
|
unless config[:never_destroy]
|
@@ -117,9 +118,10 @@ module Kitchen
|
|
117
118
|
image_os = config[:image_os]
|
118
119
|
image_os ||= image[:os]
|
119
120
|
image_release = config[:image_release]
|
120
|
-
image_release ||= image[:
|
121
|
-
debug("Ran command:
|
122
|
-
IO.popen("
|
121
|
+
image_release ||= image[:release_num]
|
122
|
+
debug("Ran command: lxc image copy #{image_os}:#{image_release} local: --alias #{image_name}")
|
123
|
+
IO.popen("lxc image copy #{image_os}:#{image_release} local: --alias #{image_name}", "w") { |pipe| puts pipe.gets rescue nil }
|
124
|
+
# IO.popen("lxd-images import #{image_os} #{image_release} --alias #{image_name}", "w") { |pipe| puts pipe.gets rescue nil }
|
123
125
|
end
|
124
126
|
|
125
127
|
return image_name
|
@@ -130,20 +132,20 @@ module Kitchen
|
|
130
132
|
if platform.downcase == "ubuntu"
|
131
133
|
case release.downcase
|
132
134
|
when "14.04", "1404", "trusty", "", nil
|
133
|
-
image = { :os => platform, :
|
135
|
+
image = { :os => platform, :release_name => "trusty", :release_num => '14.04' }
|
134
136
|
when "14.10", "1410", "utopic"
|
135
|
-
image = { :os => platform, :
|
137
|
+
image = { :os => platform, :release_name => "utopic", :release_num => '14.10' }
|
136
138
|
when "15.04", "1504", "vivid"
|
137
|
-
image = { :os => platform, :
|
139
|
+
image = { :os => platform, :release_name => "vivid", :release_num => '15.04' }
|
138
140
|
when "15.10", "1510", "wily"
|
139
|
-
image = { :os => platform, :
|
141
|
+
image = { :os => platform, :release_name => "wily", :release_num => '15.10' }
|
140
142
|
when "16.04", "1604", "xenial"
|
141
|
-
image = { :os => platform, :
|
143
|
+
image = { :os => platform, :release_name => "xenial", :release_num => '16.04' }
|
142
144
|
else
|
143
|
-
image = { :os => platform, :release => release
|
145
|
+
image = { :os => platform, :release_name => release, :release_num => release }
|
144
146
|
end
|
145
147
|
else
|
146
|
-
image = { :os => platform, :release => release }
|
148
|
+
image = { :os => platform, :release_name => release, :release_num => release }
|
147
149
|
end
|
148
150
|
return image
|
149
151
|
end
|
@@ -198,7 +200,7 @@ module Kitchen
|
|
198
200
|
|
199
201
|
if config[:ipv4]
|
200
202
|
IO.popen("bash", "r+") do |p|
|
201
|
-
p.puts("echo -e \"lxc.network.
|
203
|
+
p.puts("echo -e \"lxc.network.0.ipv4 = #{config[:ipv4]}\nlxc.network.0.ipv4.gateway = #{config[:ip_gateway]}\n\" | lxc config set #{instance.name} raw.lxc -")
|
202
204
|
p.puts("exit")
|
203
205
|
end
|
204
206
|
arg_disable_dhcp = "&& lxc exec #{instance.name} -- sed -i 's/dhcp/manual/g' /etc/network/interfaces.d/eth0.cfg"
|
@@ -213,6 +215,8 @@ module Kitchen
|
|
213
215
|
config_args = ""
|
214
216
|
if config[:config].class == String
|
215
217
|
config_args += " -c #{config[:config]}"
|
218
|
+
elsif config[:config].nil?
|
219
|
+
config_args += ""
|
216
220
|
else
|
217
221
|
config[:config].each do |key, value|
|
218
222
|
config_args += " -c #{key}=#{value}"
|
@@ -242,7 +246,13 @@ module Kitchen
|
|
242
246
|
def setup_mount_bindings
|
243
247
|
config[:mount].each do |mount_name, mount_binding|
|
244
248
|
if mount_name && mount_binding[:local_path] && mount_binding[:container_path]
|
245
|
-
|
249
|
+
# eval is used here in case there's a need to pass instance.name as variable
|
250
|
+
host_path = eval('"'+ mount_binding[:local_path] +'"')
|
251
|
+
if ! File.directory?(mount_binding[:local_path]) && mount_binding[:create_source]
|
252
|
+
debug("Source path for the #{mount_name} doesn't exist, creating #{host_path}")
|
253
|
+
FileUtils.mkdir_p(host_path)
|
254
|
+
end
|
255
|
+
run_lxc_command("config device add #{instance.name} #{mount_name} disk source=#{host_path} path=#{mount_binding[:container_path]}")
|
246
256
|
end
|
247
257
|
end if config[:mount].class == Hash
|
248
258
|
end
|
@@ -263,12 +273,19 @@ module Kitchen
|
|
263
273
|
end if config[:ipv4] && dns_servers.length == 0
|
264
274
|
|
265
275
|
if dns_servers.length > 0
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
276
|
+
if system "lxc exec #{instance.name} -- test -e /etc/redhat-release"
|
277
|
+
wait_for_path("/etc/resolv.conf")
|
278
|
+
debug("Setting up the following dns servers via /etc/resolv.conf:")
|
279
|
+
debug(dns_servers.gsub("\n", ' '))
|
280
|
+
p.puts(" echo \"#{dns_servers.chomp}\" > /etc/resolv.conf")
|
281
|
+
else
|
282
|
+
wait_for_path("/etc/resolvconf/resolv.conf.d/base")
|
283
|
+
debug("Setting up the following dns servers via /etc/resolvconf/resolv.conf.d/base:")
|
284
|
+
debug(dns_servers.gsub("\n", ' '))
|
285
|
+
p.puts(" echo \"#{dns_servers.chomp}\" > /etc/resolvconf/resolv.conf.d/base")
|
286
|
+
wait_for_path("/run/resolvconf/interface")
|
287
|
+
p.puts("resolvconf -u")
|
288
|
+
end
|
272
289
|
end
|
273
290
|
|
274
291
|
debug("Setting up /etc/hosts")
|
@@ -300,10 +317,12 @@ module Kitchen
|
|
300
317
|
begin
|
301
318
|
debug("Uploading public key...")
|
302
319
|
unless config[:username] == "root"
|
303
|
-
|
320
|
+
home_path = '/home/'
|
304
321
|
else
|
305
|
-
|
322
|
+
home_path = '/'
|
306
323
|
end
|
324
|
+
authorized_keys_path = "#{home_path}#{config[:username]}/.ssh/authorized_keys"
|
325
|
+
`lxc file push #{config[:public_key_path]} #{instance.name}#{authorized_keys_path} 2> /dev/null && lxc exec #{instance.name} -- chown #{config[:username]}:#{config[:username]} #{authorized_keys_path}`
|
307
326
|
break if $?.to_i == 0
|
308
327
|
sleep 0.3
|
309
328
|
end while true
|
@@ -362,7 +381,7 @@ module Kitchen
|
|
362
381
|
def wait_for_ip_address
|
363
382
|
info("Waiting for network to become ready")
|
364
383
|
begin
|
365
|
-
lxc_info = `lxc info #{instance.name}`.match(
|
384
|
+
lxc_info = `lxc info #{instance.name}`.match(/eth0:\tinet\t(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/)
|
366
385
|
debug("Still waiting for IP Address...")
|
367
386
|
lxc_ip = lxc_info.captures[0].to_s if lxc_info && lxc_info.captures
|
368
387
|
break if lxc_ip && lxc_ip.length > 7
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-lxd_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Braden Wright
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-kitchen
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.4
|
19
|
+
version: '1.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.4
|
26
|
+
version: '1.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
133
|
version: '0'
|
134
134
|
requirements: []
|
135
135
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.4
|
136
|
+
rubygems_version: 2.6.4
|
137
137
|
signing_key:
|
138
138
|
specification_version: 4
|
139
139
|
summary: A Test Kitchen Driver for LXD
|