kitchen-lxd 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b5f6f350edea90a709ffead687670c907a9c633
4
- data.tar.gz: bf6eb5e0662a9192eaab03da7bff0e76365e0594
3
+ metadata.gz: f28028bf2f69eaa9be7c98c1bb0f68ed5303be9e
4
+ data.tar.gz: 9d39f38481d261a1ebf3f2c1828a3630c8d2cbb8
5
5
  SHA512:
6
- metadata.gz: d666a0dcce090ba13431e6a52841ea8713068785d9efb85051bd785edb56401f1fc5b442e374e5a27219390f75846effd190fddcab291f8b30bc452fb17f42a3
7
- data.tar.gz: c8b7037a3a11d3317c688e81f117fa8f2d8397a388e16c1faf555a0e698e2d2d5d8d007b3133642a36e557ba197655aabe79b913b9154f9f250235e25737a508
6
+ metadata.gz: e223c9baca53df42e742e0367d69f64938a4e6da4e9cfdff50f75b700ce012c91ccaa04dc4f5776d0b9fa7ca1035f1d9c1228d3fc3f62f48467fdec2e8cb8746
7
+ data.tar.gz: 0da0cf8822f0a5414fcca6c153d83178934668c1ce0b3b0ab6590be32da89729bd2b4dd070ea7199ec099e45a282259f698908e1ff6b65f1d2373f9c41be9095
@@ -1,3 +1,8 @@
1
+ ## 0.3.0 (June 2, 2018)
2
+
3
+ - Introduce `config` parameter in configuration that is passed to `lxc init` as `--config`
4
+ parameter.
5
+
1
6
  ## 0.2.2 (January 30, 2018)
2
7
 
3
8
  - Fix upload bug.
data/README.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Kitchen::Lxd
2
2
 
3
+ [author]: https://github.com/DracoAter
4
+ [issues]: https://github.com/DracoAter/kitchen-lxd/issues
5
+ [license]: https://github.com/DracoAter/kitchen-lxd/blob/master/LICENSE
6
+ [repo]: https://github.com/DracoAter/kitchen-lxd
7
+ [hostnamectl bug]: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1575779
8
+ [lxd_doc]: https://github.com/lxc/lxd/blob/master/doc/containers.md
9
+
3
10
  [![Build Status](https://travis-ci.org/DracoAter/kitchen-lxd.svg?branch=master)](https://travis-ci.org/DracoAter/kitchen-lxd)
4
11
  [![Gem Version](https://badge.fury.io/rb/kitchen-lxd.svg)](https://badge.fury.io/rb/kitchen-lxd)
5
12
 
@@ -49,6 +56,7 @@ driver:
49
56
  network: lxdbr0 # default
50
57
  fix_chef_install: false # default
51
58
  fix_hostnamectl_bug: true # default
59
+ config: {} # default
52
60
 
53
61
  transport:
54
62
  name: lxd
@@ -65,6 +73,17 @@ transport:
65
73
  name: lxd
66
74
  ```
67
75
 
76
+ You can specify different keys/values under `config`. Look for list of the available items in
77
+ [Lxd Documentation][lxd_doc]. For example, if you need to start container in privileged mode, add:
78
+
79
+ ```yaml
80
+ ---
81
+ driver:
82
+ name:lxd
83
+ config:
84
+ security.privileged: true
85
+ ```
86
+
68
87
  ### Driver
69
88
 
70
89
  Available options:
@@ -75,8 +94,9 @@ binary | Path to lxc executable. | String | `lxc`
75
94
  remote | Remote LXD server to download image from, if it does not exist locally. | String | `images`
76
95
  network | Network bridge to attach to container. | String | `lxdbr0`
77
96
  wait_until_ready | Wait for the network to come up. | Boolean | `true`
97
+ config | Config key/value to apply to the new container. This hash is passed to `lxc init` command as --config parameters. | Hash | `{}`
78
98
  fix_chef_install | Apply fix, to make available installation of Chef Omnibus package. | Boolean | `false`
79
- fix_hostnamectl_bug | Apply workaround to Ubuntu [hostnamectl bug](https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1575779) in LXD. | Boolean | `true`
99
+ fix_hostnamectl_bug | Apply workaround to Ubuntu [hostnamectl bug][hostnamectl bug] in LXD. | Boolean | `true`
80
100
 
81
101
  ## Development
82
102
 
@@ -100,8 +120,3 @@ Created and maintained by [Juri Timošin][author].
100
120
  ## License
101
121
 
102
122
  Apache 2.0 (see [LICENSE][license])
103
-
104
- [author]: https://github.com/DracoAter
105
- [issues]: https://github.com/DracoAter/kitchen-lxd/issues
106
- [license]: https://github.com/DracoAter/kitchen-lxd/blob/master/LICENSE
107
- [repo]: https://github.com/DracoAter/kitchen-lxd
@@ -1,8 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
- # Author:: Juri Timošin (<draco.ater@gmail.com>)
5
+ # Author:: Juri Timoshin (<draco.ater@gmail.com>)
4
6
  #
5
- # Copyright (C) 2017, Juri Timošin
7
+ # Copyright (C) 2017, Juri Timoshin
6
8
  #
7
9
  # Licensed under the Apache License, Version 2.0 (the "License");
8
10
  # you may not use this file except in compliance with the License.
@@ -23,8 +25,9 @@ module Kitchen
23
25
  module Driver
24
26
  # Lxd driver for Kitchen.
25
27
  #
26
- # @author Juri Timošin <draco.ater@gmail.com>
28
+ # @author Juri Timoshin <draco.ater@gmail.com>
27
29
  class Lxd < Kitchen::Driver::Base
30
+ include ShellOut
28
31
  MIN_LXD_VERSION = '2.3'
29
32
 
30
33
  kitchen_driver_api_version 2
@@ -32,6 +35,7 @@ module Kitchen
32
35
  default_config :binary, 'lxc'
33
36
  default_config :remote, 'images'
34
37
  default_config :network, 'lxdbr0'
38
+ default_config :config, {}
35
39
  default_config :wait_until_ready, true
36
40
  default_config :fix_chef_install, false
37
41
  default_config :fix_hostnamectl_bug, true # https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1575779
@@ -44,33 +48,33 @@ module Kitchen
44
48
  driver.instance.name
45
49
  end
46
50
 
47
- def create( state )
48
- container.init
51
+ def create(state)
52
+ container.init(config[:config])
49
53
  container.attach_network config[:network] if config[:network]
50
54
  container.start
51
55
 
52
- state[:hostname] = instance.transport.connection( state ).wait_until_ready if config[:wait_until_ready]
53
- container.fix_chef_install( instance.platform.name ) if config[:fix_chef_install]
56
+ if config[:wait_until_ready]
57
+ state[:hostname] = instance.transport.connection(state).wait_until_ready
58
+ end
59
+ container.fix_chef_install(instance.platform.name) if config[:fix_chef_install]
54
60
  container.fix_hostnamectl_bug if config[:fix_hostnamectl_bug]
55
61
  end
56
62
 
57
- def destroy( state )
58
- instance.transport.connection( state ).close
63
+ def destroy(state)
64
+ instance.transport.connection(state).close
59
65
  state.delete :hostname
60
66
  container.destroy
61
67
  end
62
68
 
63
69
  def verify_dependencies
64
- return
65
- version = run_command( "#{config[:binary]} --version" ).strip
66
- if Gem::Version.new( version ) < Gem::Version.new( MIN_LXD_VERSION )
67
- raise UserError, "Detected old version of Lxd (#{version}), please upgrade to version "\
68
- "#{MIN_LXD_VERSION} or higher."
69
- end
70
+ version = run_command("#{config[:binary]} --version").strip
71
+ return if Gem::Version.new(version) >= Gem::Version.new(MIN_LXD_VERSION)
72
+ raise UserError, "Detected old version of Lxd (#{version}), please upgrade to version "\
73
+ "#{MIN_LXD_VERSION} or higher."
70
74
  end
71
75
 
72
76
  def container
73
- @container ||= Lxd::Container.new( logger, config )
77
+ @container ||= Lxd::Container.new(logger, config)
74
78
  end
75
79
  end
76
80
  end
@@ -1,8 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
- # Author:: Juri Timošin (<draco.ater@gmail.com>)
5
+ # Author:: Juri Timoshin (<draco.ater@gmail.com>)
4
6
  #
5
- # Copyright (C) 2017, Juri Timošin
7
+ # Copyright (C) 2017, Juri Timoshin
6
8
  #
7
9
  # Licensed under the Apache License, Version 2.0 (the "License");
8
10
  # you may not use this file except in compliance with the License.
@@ -29,33 +31,35 @@ module Kitchen
29
31
  attr_reader :logger
30
32
  attr_reader :state
31
33
 
32
- def initialize( logger, opts )
34
+ def initialize(logger, opts)
33
35
  @logger = logger
34
36
  @name = opts[:container]
35
37
  @image = opts[:image]
36
38
  @remote = opts[:remote]
37
39
  @binary = opts[:binary]
40
+ @fix_hostnamectl_bug = opts[:fix_hostnamectl_bug]
38
41
  end
39
42
 
40
- def init
43
+ def init(config={})
41
44
  return if created?
42
45
  download_image unless image_exists?
43
- run_command "#@binary init #@image #@name"
46
+ config_args = config.map{|k, v| "-c #{k}='#{v}'" }.join(' ')
47
+ run_command "#{@binary} init #{@image} #{@name} #{config_args}"
44
48
  end
45
49
 
46
- def attach_network( network )
50
+ def attach_network(network)
47
51
  return if device_attached? network
48
- run_command "#@binary network attach #{network} #@name"
52
+ run_command "#{@binary} network attach #{network} #{@name}"
49
53
  end
50
54
 
51
55
  def start
52
56
  return if running?
53
- run_command "#@binary start #@name"
57
+ run_command "#{@binary} start #{@name}"
54
58
  end
55
59
 
56
60
  def destroy
57
61
  return unless created?
58
- run_command "#@binary delete #@name --force"
62
+ run_command "#{@binary} delete #{@name} --force"
59
63
  end
60
64
 
61
65
  def wait_until_ready
@@ -66,55 +70,58 @@ module Kitchen
66
70
  i[:family] == 'inet'
67
71
  end
68
72
  return inet[:address] if inet
69
- sleep 1 unless defined?( Kitchen::Driver::UnitTest )
73
+ sleep 1 unless defined?(Kitchen::Driver::UnitTest)
70
74
  end
71
75
  nil
72
76
  end
73
77
 
74
78
  def download_image
75
- run_command "#@binary image copy --copy-aliases #@remote:#@image local:"
79
+ run_command "#{@binary} image copy --copy-aliases #{@remote}:#{@image} local:"
76
80
  end
77
81
 
78
- def execute( command )
82
+ def execute(command)
79
83
  return if command.nil? or command.empty?
80
- run_command "#@binary exec #@name -- #{command}"
84
+ fix_hostnamectl_bug if @fix_hostnamectl_bug
85
+ run_command "#{@binary} exec #{@name} -- #{command}"
81
86
  end
82
87
 
83
88
  def login_command
84
- LoginCommand.new( "#@binary exec #@name -- sh", {} )
89
+ LoginCommand.new("#{@binary} exec #{@name} -- $(#{@binary} exec #{@name} -- head -1 "\
90
+ '/etc/passwd | cut -d: -f7)', {})
85
91
  end
86
92
 
87
- def upload( locals, remote )
88
- # Mixlib::ShellOut.new("#@binary file push --verbose --debug -r #{locals.join(' ')} #@name#{remote}" ).run_command
89
- run_command "#@binary file push -r #{locals.join(' ')} #@name#{remote}"
93
+ def upload(locals, remote)
94
+ return if locals.nil? or locals.empty?
95
+ run_command "#{@binary} file push -r #{locals.join(' ')} #{@name}#{remote}"
90
96
  end
91
97
 
92
- def fix_chef_install( platform )
98
+ def fix_chef_install(platform)
93
99
  case platform
94
100
  when /ubuntu/, /debian/
95
- execute "apt install -y wget"
101
+ execute 'apt-get update'
102
+ execute 'apt-get install -y wget'
96
103
  when /rhel/, /centos/
97
104
  execute 'yum install -y sudo wget'
98
105
  end
99
106
  end
100
107
 
101
108
  def fix_hostnamectl_bug
102
- logger.info "Replace /usr/bin/hostnamectl with /usr/bin/true, because of bug in Ubuntu. (https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1575779)"
103
- execute 'rm /usr/bin/hostnamectl'
104
- execute 'ln -s /usr/bin/true /usr/bin/hostnamectl'
109
+ logger.info 'Replace /usr/bin/hostnamectl with /usr/bin/true, because of bug in Ubuntu'\
110
+ '. (https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1575779)'
111
+ run_command "#{@binary} exec #{@name} -- ln -fs /usr/bin/true /usr/bin/hostnamectl"
105
112
  end
106
113
 
107
- # private
114
+ # private
108
115
 
109
116
  def image_exists?
110
117
  !JSON.parse(
111
- run_command( "#@binary image list #@image --format json" ), symbolize_names: true
118
+ run_command("#{@binary} image list #{@image} --format json"), symbolize_names: true
112
119
  ).empty?
113
120
  end
114
121
 
115
122
  def fetch_state
116
123
  @state = JSON.parse(
117
- run_command( "#@binary list #@name --format json" ), symbolize_names: true
124
+ run_command("#{@binary} list #{@name} --format json"), symbolize_names: true
118
125
  ).first
119
126
  end
120
127
 
@@ -126,7 +133,7 @@ module Kitchen
126
133
  !fetch_state.nil?
127
134
  end
128
135
 
129
- def device_attached?( network )
136
+ def device_attached?(network)
130
137
  fetch_state.dig(:devices, network.to_sym) ? true : false
131
138
  end
132
139
  end
@@ -1,8 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
- # Author:: Juri Timošin (<draco.ater@gmail.com>)
5
+ # Author:: Juri Timoshin (<draco.ater@gmail.com>)
4
6
  #
5
- # Copyright (C) 2017, Juri Timošin
7
+ # Copyright (C) 2017, Juri Timoshin
6
8
  #
7
9
  # Licensed under the Apache License, Version 2.0 (the "License");
8
10
  # you may not use this file except in compliance with the License.
@@ -20,7 +22,7 @@ module Kitchen
20
22
  module Driver
21
23
  class Lxd
22
24
  # Version string for Lxd Kitchen driver
23
- VERSION = '0.2.2'
25
+ VERSION = '0.3.0'
24
26
  end
25
27
  end
26
28
  end
@@ -1,8 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
- # Author:: Juri Timošin (<draco.ater@gmail.com>)
5
+ # Author:: Juri Timoshin (<draco.ater@gmail.com>)
4
6
  #
5
- # Copyright (C) 2017, Juri Timošin
7
+ # Copyright (C) 2017, Juri Timoshin
6
8
  #
7
9
  # Licensed under the Apache License, Version 2.0 (the "License");
8
10
  # you may not use this file except in compliance with the License.
@@ -23,7 +25,7 @@ module Kitchen
23
25
  module Transport
24
26
  # Transport for Lxd driver for Kitchen.
25
27
  #
26
- # @author Juri Timošin <draco.ater@gmail.com>
28
+ # @author Juri Timoshin <draco.ater@gmail.com>
27
29
  class Lxd < Base
28
30
  kitchen_transport_api_version 2
29
31
 
@@ -31,16 +33,16 @@ module Kitchen
31
33
  transport.instance.driver.container
32
34
  end
33
35
 
34
- def connection( state, &block )
35
- @connection = Connection.new( config.to_hash.merge( state ), &block )
36
+ def connection(state, &block)
37
+ @connection = Connection.new(config.to_hash.merge(state), &block)
36
38
  end
37
39
 
38
40
  class Connection < Base::Connection
39
41
  extend Forwardable
40
42
 
41
- def initialize( opts )
43
+ def initialize(opts)
42
44
  @container = opts[:container]
43
- super( opts )
45
+ super(opts)
44
46
  end
45
47
 
46
48
  def_delegators :@container, :execute, :login_command, :upload, :wait_until_ready
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-lxd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juri Timošin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-30 00:00:00.000000000 Z
11
+ date: 2018-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.17'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: ci_reporter_minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '12.0'
33
+ version: '1.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '12.0'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.5'
55
55
  - !ruby/object:Gem::Dependency
56
- name: ci_reporter_minitest
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.0'
61
+ version: '12.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.0'
68
+ version: '12.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement