Class: Serverspec::Commands::Linux

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

Direct Known Subclasses

Debian, Gentoo, RedHat

Instance Method Summary collapse

Methods inherited from Base

#check_authorized_key, #check_belonging_group, #check_cron_entry, #check_directory, #check_enabled, #check_file, #check_file_contain, #check_file_contain_with_fixed_strings, #check_file_contain_with_regexp, #check_file_contain_within, #check_file_md5checksum, #check_file_sha256checksum, #check_gid, #check_group, #check_grouped, #check_home_directory, #check_installed, #check_installed_by_gem, #check_installed_by_npm, #check_installed_by_pecl, #check_installed_by_pip, #check_ipfilter_rule, #check_ipnat_rule, #check_link, #check_listening, #check_listening_with_protocol, #check_login_shell, #check_mail_alias, #check_mode, #check_monitored_by_god, #check_monitored_by_monit, #check_mounted, #check_owner, #check_process, #check_reachable, #check_resolvable, #check_routing_table, #check_running, #check_running_under_supervisor, #check_running_under_upstart, #check_socket, #check_svcprop, #check_svcprops, #check_uid, #check_user, #check_yumrepo, #check_yumrepo_enabled, #escape, #get_mode

Instance Method Details

#check_access_by_user(file, user, access) ⇒ Object



6
7
8
# File 'lib/serverspec/commands/linux.rb', line 6

def check_access_by_user(file, user, access)
  "su -s /bin/sh -c \"test -#{access} #{file}\" #{user}"
end

#check_iptables_rule(rule, table = nil, chain = nil) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/serverspec/commands/linux.rb', line 10

def check_iptables_rule(rule, table=nil, chain=nil)
  cmd = "iptables"
  cmd += " -t #{escape(table)}" if table
  cmd += " -S"
  cmd += " #{escape(chain)}" if chain
  cmd += " | grep -- #{escape(rule)}"
  cmd
end

#check_ipv4_address(interface, ip_address) ⇒ Object



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

def check_ipv4_address(interface, ip_address)
  ip_address = ip_address.dup
  if ip_address =~ /\/\d+$/
    ip_address << " "
  else
    ip_address << "/"
  end
  ip_address.gsub!(".", "\\.")
  "ip addr show #{interface} | grep 'inet #{ip_address}'"
end

#check_kernel_module_loaded(name) ⇒ Object



28
29
30
# File 'lib/serverspec/commands/linux.rb', line 28

def check_kernel_module_loaded(name)
  "lsmod | grep ^#{name}"
end

#check_selinux(mode) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/serverspec/commands/linux.rb', line 19

def check_selinux(mode)
  cmd =  ""
  cmd += "test ! -f /etc/selinux/config || (" if mode == "disabled"
  cmd += "getenforce | grep -i -- #{escape(mode)} "
  cmd += "&& grep -i -- ^SELINUX=#{escape(mode)}$ /etc/selinux/config"
  cmd += ")" if mode == "disabled"
  cmd
end

#check_zfs(zfs, property = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/serverspec/commands/linux.rb', line 47

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

#get_interface_speed_of(name) ⇒ Object



32
33
34
# File 'lib/serverspec/commands/linux.rb', line 32

def get_interface_speed_of(name)
  "ethtool #{name} | grep Speed | gawk '{print gensub(/Speed: ([0-9]+)Mb\\\/s/,\"\\\\1\",\"\")}'"
end