Module: Unix::Group

Includes:
Beaker::CommandFactory
Included in:
Host
Defined in:
lib/beaker/host/unix/group.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

#group_absent(name, &block) ⇒ Object



37
38
39
# File 'lib/beaker/host/unix/group.rb', line 37

def group_absent(name, &block)
  execute("if getent group #{name}; then groupdel #{name}; fi", {}, &block)
end

#group_get(name, &block) ⇒ Object



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

def group_get(name, &block)
  execute("getent group #{name}") do |result|
    fail_test "failed to get group #{name}" unless result.stdout =~ /^#{name}:.*:[0-9]+:/

    yield result if block_given?
  end
end

#group_gid(name) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/beaker/host/unix/group.rb', line 25

def group_gid(name)
  execute("getent group #{name}") do |result|
    # Format is:
    # wheel:x:10:root
    result.stdout.split(':')[2]
  end
end

#group_list(&block) ⇒ Object



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

def group_list(&block)
  execute("getent group") do |result|
    groups = []
    result.stdout.each_line do |line|
      groups << (line.match(/^([^:]+)/) or next)[1]
    end

    yield result if block_given?

    groups
  end
end

#group_present(name, &block) ⇒ Object



33
34
35
# File 'lib/beaker/host/unix/group.rb', line 33

def group_present(name, &block)
  execute("if ! getent group #{name}; then groupadd #{name}; fi", {}, &block)
end