Class: Serverspec::Commands::Solaris

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

Direct Known Subclasses

SmartOS, Solaris10, Solaris11

Instance Method Summary collapse

Methods inherited from Base

#check_authorized_key, #check_directory, #check_file, #check_file_contain, #check_file_contain_with_fixed_strings, #check_file_contain_with_regexp, #check_file_md5checksum, #check_file_sha256checksum, #check_group, #check_grouped, #check_installed_by_gem, #check_installed_by_npm, #check_installed_by_pecl, #check_installed_by_pip, #check_iptables_rule, #check_ipv4_address, #check_kernel_module_loaded, #check_link, #check_mail_alias, #check_mode, #check_monitored_by_god, #check_monitored_by_monit, #check_mounted, #check_owner, #check_process, #check_resolvable, #check_routing_table, #check_running_under_supervisor, #check_running_under_upstart, #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



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

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



84
85
86
# File 'lib/serverspec/commands/solaris.rb', line 84

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

#check_cron_entry(user, entry) ⇒ Object



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

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 | egrep '^enabled *true$'"
end

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



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

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

#check_gid(group, gid) ⇒ Object



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

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



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

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



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

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

#check_ipnat_rule(rule) ⇒ Object



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

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 | grep -- LISTEN | grep -- #{escape(regexp)}"
end

#check_listening_with_protocol(port, protocol) ⇒ Object



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

def check_listening_with_protocol(port, protocol)
  regexp = ".*\\.#{port} "
  "netstat -an -P #{escape(protocol)} 2> /dev/null | grep -- LISTEN | grep -- #{escape(regexp)}"
end

#check_login_shell(user, path_to_shell) ⇒ Object



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

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



108
109
110
111
112
113
114
# File 'lib/serverspec/commands/solaris.rb', line 108

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



26
27
28
# File 'lib/serverspec/commands/solaris.rb', line 26

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

#check_svcprop(svc, property, value) ⇒ Object



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

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

#check_svcprops(svc, property) ⇒ Object



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

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



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/serverspec/commands/solaris.rb', line 39

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