kitchen-lxd_cli 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd56e6cb62ec4b0bf4f099521e195d42bacb3a90
4
- data.tar.gz: ee398952d35afd1145877c0e587a82b01f63195c
3
+ metadata.gz: b72ba2a22edb8adb3ee21e394eb133b532270a33
4
+ data.tar.gz: e758ef7199090d29672a0715b064bedcb6fe578e
5
5
  SHA512:
6
- metadata.gz: f842f5c0031c0dbaa23dc839f57905981bfbae95f436da9c55f5903b452e19cb342f455273adfd737c84e1980b081fe331b4150d90727bc4f7544933bc9893b4
7
- data.tar.gz: 1f6180cb8e220ee0e86ea6da7b884ce083f1cd3d297b9eb6d816f2fa0936691924ae76f8917c780721a1134be0586de7ed8590d2781a3a7eb4d9a7bfb02076fe
6
+ metadata.gz: 1bc3eef0b7531b1fafe449d87618ee64015e8e184dbf194d23c2b8914c9f9a4ed5197c490aca7d27b9bf628d8dbb28e40db49b4505e320035643ec7c2806690f
7
+ data.tar.gz: b12cc296130ace2e4f5f55553da219972e8d3d70c0802007b4747efa55c8f3e8706598ec561c613ac1ef435282110be084d7dd6522302d6ba013e82112ad2f6f
data/README.md CHANGED
@@ -75,12 +75,12 @@ driver:
75
75
  ipv4: 10.0.3.99/24
76
76
  ip_gateway: 10.0.3.1
77
77
  verifier_path: "/opt/verifier"
78
- stop_instead_of_destroy: true
79
78
  publish_image_name: "kitchen-base-ubuntu-1404"
80
79
  use_publish_image: true
81
80
  publish_image_before_destroy: true
82
81
  publish_image_overwrite: true
83
82
  enable_wait_for_ssh_login: false
83
+ username: kitchen-user
84
84
 
85
85
 
86
86
 
@@ -363,6 +363,12 @@ Default is false. If set to true container will loop until it can login to ssh,
363
363
 
364
364
  NOTE: Hope is that I can resolve the issues of needing to wait by writing a transport that uses lxc commands and not ssh, also will improve sped since ssh login is slow.
365
365
 
366
+ ### username
367
+
368
+ Default is `root`. If set to another user name will create home directory and set to `${username} ALL=(ALL) NOPASSWD: ALL` on `/etc/sudoers`.
369
+
370
+ `username: kitchen-user`
371
+
366
372
  ### <a name="config-require-chef-omnibus"></a> require\_chef\_omnibus
367
373
 
368
374
  Determines whether or not a Chef [Omnibus package][chef_omnibus_dl] will be
@@ -39,6 +39,7 @@ module Kitchen
39
39
  default_config :never_destroy, false
40
40
  default_config :lxd_proxy_path, "#{ENV['HOME']}/.lxd_proxy"
41
41
  default_config :lxd_proxy_update, false
42
+ default_config :username, "root"
42
43
 
43
44
  required_config :public_key_path
44
45
 
@@ -57,6 +58,7 @@ module Kitchen
57
58
  configure_dns
58
59
  lxc_ip = wait_for_ip_address
59
60
  state[:hostname] = lxc_ip
61
+ state[:username] = config[:username]
60
62
  setup_ssh_access
61
63
  wait_for_ssh_login(lxc_ip) if config[:enable_wait_for_ssh_login] == "true"
62
64
  IO.popen("lxc exec #{instance.name} bash", "r+") do |p|
@@ -286,11 +288,22 @@ module Kitchen
286
288
 
287
289
  def setup_ssh_access
288
290
  info("Setting up public key #{config[:public_key_path]} on #{instance.name}")
289
- wait_for_path("/root/.ssh")
291
+ unless config[:username] == "root"
292
+ create_ssh_user
293
+ info("Checking /home/#{config[:username]}/.ssh on #{instance.name}")
294
+ wait_for_path("/home/#{config[:username]}/.ssh")
295
+ else
296
+ info("Check /#{config[:username]}/.ssh on #{instance.name}")
297
+ wait_for_path("/#{config[:username]}/.ssh")
298
+ end
290
299
 
291
300
  begin
292
301
  debug("Uploading public key...")
293
- `lxc file push #{config[:public_key_path]} #{instance.name}/root/.ssh/authorized_keys 2> /dev/null`
302
+ unless config[:username] == "root"
303
+ `lxc file push #{config[:public_key_path]} #{instance.name}/home/#{config[:username]}/.ssh/authorized_keys 2> /dev/null`
304
+ else
305
+ `lxc file push #{config[:public_key_path]} #{instance.name}/#{config[:username]}/.ssh/authorized_keys 2> /dev/null`
306
+ end
294
307
  break if $?.to_i == 0
295
308
  sleep 0.3
296
309
  end while true
@@ -298,6 +311,14 @@ module Kitchen
298
311
  debug("Finished Copying public key from #{config[:public_key_path]} to #{instance.name}")
299
312
  end
300
313
 
314
+ def create_ssh_user
315
+ info("Create user #{config[:username]} on #{instance.name}")
316
+ `lxc exec #{instance.name} -- useradd -m -G sudo #{config[:username]} -s /bin/bash`
317
+ `lxc exec #{instance.name} -- mkdir /home/#{config[:username]}/.ssh`
318
+ `lxc exec #{instance.name} -- chown #{config[:username]}:#{config[:username]} /home/#{config[:username]}/.ssh`
319
+ `lxc exec #{instance.name} -- sh -c "echo '#{config[:username]} ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers"`
320
+ end
321
+
301
322
  def install_proxy
302
323
  IO.popen("bash", "w") do |p|
303
324
  if config[:lxd_proxy_verify] == true
@@ -364,11 +385,11 @@ module Kitchen
364
385
  def wait_for_ssh_login(ip)
365
386
  begin
366
387
  debug("Trying to login into #{ip} via SSH...")
367
- `ssh root@#{ip} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no 'true' > /dev/null 2>&1`
388
+ `ssh #{config[:username]}@#{ip} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no 'true' > /dev/null 2>&1`
368
389
  break if $?.to_i == 0
369
390
  sleep 0.3
370
391
  end while true
371
- debug("SSH is up, able to login at root@#{ip}")
392
+ debug("SSH is up, able to login at #{config[:username]}@#{ip}")
372
393
  end
373
394
 
374
395
  def run_lxc_command(cmd)
@@ -21,6 +21,6 @@ module Kitchen
21
21
  module Driver
22
22
 
23
23
  # Version string for LxdCli Kitchen driver
24
- LXD_CLI_VERSION = "0.1.5"
24
+ LXD_CLI_VERSION = "0.1.6"
25
25
  end
26
26
  end
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.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Braden Wright
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-14 00:00:00.000000000 Z
11
+ date: 2015-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen