Class: Serverspec::Commands::Solaris

Inherits:
Base
  • Object
show all
Defined in:
lib/serverspec/commands/solaris.rb

Instance Method Summary collapse

Methods inherited from Base

#check_authorized_key, #check_directory, #check_file, #check_file_contain, #check_file_md5checksum, #check_group, #check_grouped, #check_installed_by_gem, #check_installed_by_npm, #check_iptables_rule, #check_link, #check_mode, #check_mounted, #check_owner, #check_process, #check_reachable, #check_resolvable, #check_routing_table, #check_running_under_supervisor, #check_selinux, #check_uid, #check_user, #escape, #get_mode

Instance Method Details

#check_access_by_user(file, user, access) ⇒ Object



90
91
92
93
94
95
# File 'lib/serverspec/commands/solaris.rb', line 90

def check_access_by_user file, user, access
  # http://docs.oracle.com/cd/E23823_01/html/816-5166/su-1m.html
  ## No need for login shell as it seems that behavior as superuser is favorable for us, but needs
  ## to be better tested under real solaris env
  "su #{user} -c \"test -#{access} #{file}\""
end

#check_belonging_group(user, group) ⇒ Object



73
74
75
# File 'lib/serverspec/commands/solaris.rb', line 73

def check_belonging_group user, group
  "id -Gn #{escape(user)} | grep -- #{escape(group)}"
end

#check_cron_entry(user, entry) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/serverspec/commands/solaris.rb', line 21

def check_cron_entry user, entry
  entry_escaped = entry.gsub(/\*/, '\\*')
  if user.nil?
    "crontab -l | grep -- #{escape(entry_escaped)}"
  else
    "crontab -l #{escape(user)} | grep -- #{escape(entry_escaped)}"
  end
end

#check_enabled(service) ⇒ Object



4
5
6
# File 'lib/serverspec/commands/solaris.rb', line 4

def check_enabled service
  "svcs -l #{escape(service)} 2> /dev/null | grep 'enabled      true'"
end

#check_file_contain_within(file, expected_pattern, from = nil, to = nil) ⇒ Object



66
67
68
69
70
71
# File 'lib/serverspec/commands/solaris.rb', line 66

def check_file_contain_within file, expected_pattern, from=nil, to=nil
  from ||= '1'
  to ||= '$'
  checker = check_file_contain("/dev/stdin", expected_pattern)
  "sed -n #{escape(from)},#{escape(to)}p #{escape(file)} | #{checker}"
end

#check_gid(group, gid) ⇒ Object



77
78
79
80
# File 'lib/serverspec/commands/solaris.rb', line 77

def check_gid group, gid
  regexp = "^#{group}:"
  "getent group | grep -- #{escape(regexp)} | cut -f 3 -d ':' | grep -w -- #{escape(gid)}"
end

#check_home_directory(user, path_to_home) ⇒ Object



82
83
84
# File 'lib/serverspec/commands/solaris.rb', line 82

def check_home_directory user, path_to_home
  "getent passwd #{escape(user)} | cut -f 6 -d ':' | grep -w -- #{escape(path_to_home)}"
end

#check_installed(package) ⇒ Object



8
9
10
# File 'lib/serverspec/commands/solaris.rb', line 8

def check_installed package
  "pkg list -H #{escape(package)} 2> /dev/null"
end

#check_ipfilter_rule(rule) ⇒ Object



43
44
45
# File 'lib/serverspec/commands/solaris.rb', line 43

def check_ipfilter_rule rule
  "ipfstat -io 2> /dev/null | grep -- #{escape(rule)}"
end

#check_ipnat_rule(rule) ⇒ Object



47
48
49
50
# File 'lib/serverspec/commands/solaris.rb', line 47

def check_ipnat_rule rule
  regexp = "^#{rule}$"
  "ipnat -l 2> /dev/null | grep -- #{escape(regexp)}"
end

#check_listening(port) ⇒ Object



12
13
14
15
# File 'lib/serverspec/commands/solaris.rb', line 12

def check_listening port
  regexp = "\.#{port} "
  "netstat -an 2> /dev/null | egrep 'LISTEN|Idle' | grep -- #{escape(regexp)}"
end

#check_login_shell(user, path_to_shell) ⇒ Object



86
87
88
# File 'lib/serverspec/commands/solaris.rb', line 86

def  user, path_to_shell
  "getent passwd #{escape(user)} | cut -f 7 -d ':' | grep -w -- #{escape(path_to_shell)}"
end

#check_running(service) ⇒ Object



17
18
19
# File 'lib/serverspec/commands/solaris.rb', line 17

def check_running service
  "svcs -l #{escape(service)} status 2> /dev/null |grep 'state        online'"
end

#check_svcprop(svc, property, value) ⇒ Object



52
53
54
55
# File 'lib/serverspec/commands/solaris.rb', line 52

def check_svcprop svc, property, value
  regexp = "^#{value}$"
  "svcprop -p #{escape(property)} #{escape(svc)} | grep -- #{escape(regexp)}"
end

#check_svcprops(svc, property) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/serverspec/commands/solaris.rb', line 57

def check_svcprops svc, property
  commands = []
  property.sort.each do |key, value|
    regexp = "^#{value}$"
    commands << "svcprop -p #{escape(key)} #{escape(svc)} | grep -- #{escape(regexp)}"
  end
  commands.join(' && ')
end

#check_zfs(zfs, property = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/serverspec/commands/solaris.rb', line 30

def check_zfs zfs, property=nil
  if property.nil?
    "zfs list -H #{escape(zfs)}"
  else
    commands = []
    property.sort.each do |key, value|
      regexp = "^#{value}$"
      commands << "zfs list -H -o #{escape(key)} #{escape(zfs)} | grep -- #{escape(regexp)}"
    end
    commands.join(' && ')
  end
end