testlab 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,7 +27,8 @@ node 'vagrant' do
27
27
  TestLab::Provisioner::Apt
28
28
  ]
29
29
 
30
- user 'deployer' do
30
+ user do
31
+ username 'deployer'
31
32
  password 'deployer'
32
33
  identity File.join(ENV['HOME'], '.ssh', 'id_rsa')
33
34
  public_identity File.join(ENV['HOME'], '.ssh', 'id_rsa.pub')
@@ -39,7 +39,8 @@ node 'vagrant' do
39
39
  TestLab::Provisioner::Apt
40
40
  ]
41
41
 
42
- user 'deployer' do
42
+ user do
43
+ username 'deployer'
43
44
  password 'deployer'
44
45
  identity File.join(ENV['HOME'], '.ssh', 'id_rsa')
45
46
  public_identity File.join(ENV['HOME'], '.ssh', 'id_rsa.pub')
@@ -15,10 +15,12 @@ class TestLab
15
15
  if self.users.count == 0
16
16
  case self.distro.downcase
17
17
  when 'ubuntu' then
18
- u = TestLab::User.new "ubuntu" do
18
+ u = TestLab::User.new do
19
+ username 'ubuntu'
19
20
  password 'ubuntu'
20
21
  end
21
22
  u.container = self
23
+ u
22
24
  end
23
25
  elsif self.users.any?{ |u| u.primary == true }
24
26
  self.users.find{ |u| u.primary == true }
@@ -31,7 +31,7 @@ class TestLab
31
31
 
32
32
  c.host_name = container.ip
33
33
 
34
- c.user = (options[:user] || container.primary_user.id)
34
+ c.user = (options[:user] || container.primary_user.username)
35
35
  c.password = (options[:passwd] || container.primary_user.password)
36
36
  c.keys = (options[:keys] || [container.primary_user.identity, @provider.identity].flatten.compact)
37
37
  end
@@ -43,7 +43,7 @@ class TestLab
43
43
  :chef_client_cli => chef_client_cli(container),
44
44
  :chef_client_rb => chef_client_rb(container),
45
45
  :validation_pem => validation_pem,
46
- :sudo_user => container.primary_user.id,
46
+ :sudo_user => container.primary_user.username,
47
47
  :sudo_uid => container.primary_user.uid,
48
48
  :sudo_gid => container.primary_user.gid,
49
49
  :home_dir => container.primary_user.home_dir
@@ -44,7 +44,7 @@ class TestLab
44
44
  :chef_admin => '/etc/chef-server/admin.pem',
45
45
  :local_user => ENV['USER'],
46
46
  :default_password => "p@ssw01d",
47
- :sudo_user => container.primary_user.id,
47
+ :sudo_user => container.primary_user.username,
48
48
  :sudo_uid => container.primary_user.uid,
49
49
  :sudo_gid => container.primary_user.gid,
50
50
  :home_dir => container.primary_user.home_dir
@@ -44,7 +44,7 @@ class TestLab
44
44
  :chef_client_cli => chef_client_cli(container),
45
45
  :chef_client_rb => chef_client_rb(container),
46
46
  :validation_pem => validation_pem,
47
- :sudo_user => container.primary_user.id,
47
+ :sudo_user => container.primary_user.username,
48
48
  :sudo_uid => container.primary_user.uid,
49
49
  :sudo_gid => container.primary_user.gid,
50
50
  :home_dir => container.primary_user.home_dir
@@ -42,7 +42,7 @@ class TestLab
42
42
  :chef_admin => '/etc/chef/admin.pem',
43
43
  :default_password => "p@ssw01d",
44
44
  :local_user => ENV['USER'],
45
- :sudo_user => container.primary_user.id,
45
+ :sudo_user => container.primary_user.username,
46
46
  :sudo_uid => container.primary_user.uid,
47
47
  :sudo_gid => container.primary_user.gid,
48
48
  :home_dir => container.primary_user.home_dir,
data/lib/testlab/user.rb CHANGED
@@ -16,6 +16,7 @@ class TestLab
16
16
  # Associations and Attributes
17
17
  belongs_to :container, :class_name => 'TestLab::Container'
18
18
 
19
+ attribute :username
19
20
  attribute :password
20
21
 
21
22
  attribute :identity
@@ -7,28 +7,28 @@ class TestLab
7
7
  #
8
8
  # @return [Boolean] True if successful.
9
9
  def setup
10
- @ui.logger.debug { "User Create: #{self.id} " }
10
+ @ui.logger.debug { "User Create: #{self.username} " }
11
11
 
12
12
  node_home_dir = ((self.container.node.user == "root") ? %(/root) : %(/home/#{self.container.node.user}))
13
13
  node_authkeys = File.join(node_home_dir, ".ssh", "authorized_keys")
14
14
 
15
15
  # ensure the container user exists
16
16
  container_passwd_file = File.join(self.container.fs_root, "etc", "passwd")
17
- if self.container.node.ssh.exec(%(sudo grep "#{self.id}" #{container_passwd_file}), :ignore_exit_status => true).exit_code != 0
17
+ if self.container.node.ssh.exec(%(sudo grep "#{self.username}" #{container_passwd_file}), :ignore_exit_status => true).exit_code != 0
18
18
 
19
19
  if !self.gid.nil?
20
- groupadd_command = %(groupadd --gid #{self.gid} #{self.id})
20
+ groupadd_command = %(groupadd --gid #{self.gid} #{self.username})
21
21
  self.container.node.ssh.exec(%(sudo chroot #{self.container.fs_root} /bin/bash -c '#{groupadd_command}'))
22
22
  end
23
23
 
24
24
  useradd_command = %W(useradd --create-home --shell /bin/bash --groups sudo)
25
25
  useradd_command << "--uid #{self.uid}" if !self.uid.nil?
26
26
  useradd_command << "--gid #{self.gid}" if !self.gid.nil?
27
- useradd_command << self.id
27
+ useradd_command << self.username
28
28
  useradd_command = useradd_command.flatten.compact.join(' ')
29
29
 
30
30
  self.container.lxc.attach(%(-- /bin/bash -c '#{useradd_command}'))
31
- self.container.lxc.attach(%(-- /bin/bash -c 'echo "#{self.id}:#{self.password}" | chpasswd'))
31
+ self.container.lxc.attach(%(-- /bin/bash -c 'echo "#{self.username}:#{self.password}" | chpasswd'))
32
32
  end
33
33
 
34
34
  # ensure the user user gets our node user key
@@ -62,8 +62,8 @@ class TestLab
62
62
  end
63
63
 
64
64
  # ensure the container user home directory is owned by them
65
- home_dir = self.container.lxc.attach(%(-- /bin/bash -c 'grep #{self.id} /etc/passwd | cut -d ":" -f6')).strip
66
- self.container.lxc.attach(%(-- /bin/bash -c 'sudo chown -Rv $(id -u #{self.id}):$(id -g #{self.id}) #{home_dir}'))
65
+ home_dir = self.container.lxc.attach(%(-- /bin/bash -c 'grep #{self.username} /etc/passwd | cut -d ":" -f6')).strip
66
+ self.container.lxc.attach(%(-- /bin/bash -c 'sudo chown -Rv $(id -u #{self.username}):$(id -g #{self.username}) #{home_dir}'))
67
67
 
68
68
  # ensure the sudo user group can do passwordless sudo
69
69
  self.container.lxc.attach(%(-- /bin/bash -c 'grep "sudo\tALL=\(ALL:ALL\) ALL" /etc/sudoers && sed -i "s/sudo\tALL=\(ALL:ALL\) ALL/sudo\tALL=\(ALL:ALL\) NOPASSWD: ALL/" /etc/sudoers'))
@@ -77,7 +77,7 @@ class TestLab
77
77
  #
78
78
  # @return [String] The users home directory.
79
79
  def home_dir(name=nil)
80
- username = (name || self.id)
80
+ username = (name || self.username)
81
81
  if (username == "root")
82
82
  "/root"
83
83
  else
@@ -46,9 +46,9 @@ class TestLab
46
46
  "ruby_platform" => RUBY_PLATFORM.inspect
47
47
  }
48
48
 
49
- defined?(RUBY_ENGINE) and dependencies.merge!("ruby_engine" => RUBY_ENGINE)
50
- defined?(RUBY_DESCRIPTION) and dependencies.merge!("ruby_description" => RUBY_DESCRIPTION)
51
- defined?(RUBY_RELEASE_DATE) and dependencies.merge!("ruby_release_date" => RUBY_RELEASE_DATE)
49
+ defined?(RUBY_ENGINE) and dependencies.merge!("ruby_engine" => RUBY_ENGINE.inspect)
50
+ defined?(RUBY_DESCRIPTION) and dependencies.merge!("ruby_description" => RUBY_DESCRIPTION.inspect)
51
+ defined?(RUBY_RELEASE_DATE) and dependencies.merge!("ruby_release_date" => RUBY_RELEASE_DATE.inspect)
52
52
 
53
53
  dependencies
54
54
  end
@@ -1,6 +1,6 @@
1
1
  class TestLab
2
2
  unless const_defined?(:VERSION)
3
3
  # TestLab Gem Version
4
- VERSION = "0.8.2"
4
+ VERSION = "0.8.3"
5
5
  end
6
6
  end
data/spec/testlab_spec.rb CHANGED
@@ -25,6 +25,7 @@ describe TestLab do
25
25
  @ui = ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new)
26
26
  @testlab = TestLab.new(:labfile_path => LABFILE, :ui => @ui)
27
27
  @testlab.boot
28
+ @testlab
28
29
  }
29
30
 
30
31
  describe "class" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -329,7 +329,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
329
329
  version: '0'
330
330
  segments:
331
331
  - 0
332
- hash: 3757036604992318209
332
+ hash: 1734275304878040822
333
333
  required_rubygems_version: !ruby/object:Gem::Requirement
334
334
  none: false
335
335
  requirements:
@@ -338,7 +338,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
338
338
  version: '0'
339
339
  segments:
340
340
  - 0
341
- hash: 3757036604992318209
341
+ hash: 1734275304878040822
342
342
  requirements: []
343
343
  rubyforge_project:
344
344
  rubygems_version: 1.8.25