Module: Unix::User

Includes:
Beaker::CommandFactory
Included in:
Host
Defined in:
lib/beaker/host/unix/user.rb

Instance Attribute Summary

Attributes included from Beaker::CommandFactory

#assertions

Instance Method Summary collapse

Methods included from Beaker::CommandFactory

#execute, #fail_test

Instance Method Details

#user_absent(name, &block) ⇒ Object



30
31
32
# File 'lib/beaker/host/unix/user.rb', line 30

def user_absent(name, &block)
  execute("if getent passwd #{name}; then userdel #{name}; fi", {}, &block)
end

#user_get(name) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/beaker/host/unix/user.rb', line 17

def user_get(name)
  execute("getent passwd #{name}") do |result|
    fail_test "failed to get user #{name}" unless /^#{name}:/.match?(result.stdout)

    yield result if block_given?
    result
  end
end

#user_listObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/beaker/host/unix/user.rb', line 4

def user_list
  execute("getent passwd") do |result|
    users = []
    result.stdout.each_line do |line|
      users << (line.match(/^([^:]+)/) or next)[1]
    end

    yield result if block_given?

    users
  end
end

#user_present(name, &block) ⇒ Object



26
27
28
# File 'lib/beaker/host/unix/user.rb', line 26

def user_present(name, &block)
  execute("if ! getent passwd #{name}; then useradd #{name}; fi", {}, &block)
end