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_installed_by_pecl, #check_iptables_rule, #check_kernel_module_loaded, #check_link, #check_mode, #check_mounted, #check_owner, #check_process, #check_resolvable, #check_routing_table, #check_running_under_supervisor, #check_selinux, #check_socket, #check_uid, #check_user, #check_yumrepo, #check_yumrepo_enabled, #escape, #get_mode

Instance Method Details

#check_access_by_user(file, user, access) ⇒ Object



94
95
96
97
98
99
# File 'lib/serverspec/commands/solaris.rb', line 94

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



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

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

#check_cron_entry(user, entry) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/serverspec/commands/solaris.rb', line 25

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, level = 3) ⇒ Object



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

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

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



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

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



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

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



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

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, version = nil) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/serverspec/commands/solaris.rb', line 8

def check_installed(package, version=nil)
  cmd = "pkg list -H #{escape(package)} 2> /dev/null"
  if version
    cmd = "#{cmd} | grep -qw -- #{escape(version)}"
  end
  cmd
end

#check_ipfilter_rule(rule) ⇒ Object



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

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

#check_ipnat_rule(rule) ⇒ Object



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

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

#check_listening(port) ⇒ Object



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

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



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

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

#check_reachable(host, port, proto, timeout) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/serverspec/commands/solaris.rb', line 101

def check_reachable(host, port, proto, timeout)
  if port.nil?
    "ping -n #{escape(host)} #{escape(timeout)}"
  else
    "nc -vvvvz#{escape(proto[0].chr)} -w #{escape(timeout)} #{escape(host)} #{escape(port)}"
  end
end

#check_running(service) ⇒ Object



21
22
23
# File 'lib/serverspec/commands/solaris.rb', line 21

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

#check_svcprop(svc, property, value) ⇒ Object



56
57
58
59
# File 'lib/serverspec/commands/solaris.rb', line 56

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

#check_svcprops(svc, property) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/serverspec/commands/solaris.rb', line 61

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



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/serverspec/commands/solaris.rb', line 34

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