lib/specinfra/command/base.rb in specinfra-1.27.5 vs lib/specinfra/command/base.rb in specinfra-2.0.0.beta1
- old
+ new
@@ -27,12 +27,12 @@
def check_yumrepo_enabled(repository)
raise NotImplementedError.new
end
def check_mounted(path)
- regexp = "on #{path} "
- "mount | grep -- '#{escape(regexp)}'"
+ regexp = "on #{path}"
+ "mount | grep -w -- #{escape(regexp)}"
end
def check_routing_table(destination)
"ip route | grep -E '^#{destination} |^default '"
end
@@ -57,18 +57,10 @@
def check_file(file)
"test -f #{escape(file)}"
end
- def get_file_mtime(file)
- "stat -c %Y #{escape(file)}"
- end
-
- def get_file_size(file)
- "stat -c %s #{escape(file)}"
- end
-
def check_socket(file)
"test -S #{escape(file)}"
end
def check_directory(directory)
@@ -78,11 +70,11 @@
def check_user(user)
"id #{escape(user)}"
end
def check_group(group)
- "getent group #{escape(group)}"
+ "getent group | grep -wq -- #{escape(group)}"
end
def check_installed(package, version=nil)
raise NotImplementedError.new
end
@@ -127,28 +119,24 @@
def check_process(process)
"ps aux | grep -w -- #{escape(process)} | grep -qv grep"
end
- def check_process_count(process, count)
- "test $(ps aux | grep -w -- #{escape(process)} | grep -v grep | wc -l) -eq #{escape(count)}"
- end
-
def get_process(process, opts)
"ps -C #{escape(process)} -o #{opts[:format]} | head -1"
end
def check_file_contain(file, expected_pattern)
"#{check_file_contain_with_regexp(file, expected_pattern)} || #{check_file_contain_with_fixed_strings(file, expected_pattern)}"
end
def check_file_contain_with_regexp(file, expected_pattern)
- "grep -qs -- #{escape(expected_pattern)} #{escape(file)}"
+ "grep -q -- #{escape(expected_pattern)} #{escape(file)}"
end
def check_file_contain_with_fixed_strings(file, expected_pattern)
- "grep -qFs -- #{escape(expected_pattern)} #{escape(file)}"
+ "grep -qF -- #{escape(expected_pattern)} #{escape(file)}"
end
def check_file_checksum(file, expected)
regexp = "^#{expected}"
"cksum #{escape(file)} | grep -iw -- #{escape(regexp)}"
@@ -166,11 +154,10 @@
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)}"
- sed += " | sed -n 1,#{escape(to)}p" if from != '1' and to != '$'
checker_with_regexp = check_file_contain_with_regexp("-", expected_pattern)
checker_with_fixed = check_file_contain_with_fixed_strings("-", expected_pattern)
"#{sed} | #{checker_with_regexp} || #{sed} | #{checker_with_fixed}"
end
@@ -199,11 +186,11 @@
regexp = "^#{group}$"
"stat -c %G #{escape(file)} | grep -- #{escape(regexp)}"
end
def check_cron_entry(user, entry)
- entry_escaped = entry.gsub(/\*/, '\\*').gsub(/\[/, '\\[').gsub(/\]/, '\\]')
+ entry_escaped = entry.gsub(/\*/, '\\*')
if user.nil?
"crontab -l | grep -v \"#\" -- | grep -- #{escape(entry_escaped)}"
else
"crontab -u #{escape(user)} -l | grep -v \"#\" | grep -- #{escape(entry_escaped)}"
end
@@ -256,14 +243,10 @@
def check_belonging_group(user, group)
"id #{escape(user)} | awk '{print $3}' | grep -- #{escape(group)}"
end
- def check_primary_group(group)
- raise NotImplementedError.new
- end
-
def check_gid(group, gid)
regexp = "^#{group}"
"getent group | grep -w -- #{escape(regexp)} | cut -f 3 -d ':' | grep -w -- #{escape(gid)}"
end
@@ -287,14 +270,10 @@
def check_iptables_rule(rule, table=nil, chain=nil)
raise NotImplementedError.new
end
- def check_ip6tables_rule(rule, table=nil, chain=nil)
- raise NotImplementedError.new
- end
-
def check_zfs(zfs, property=nil, value=nil)
raise NotImplementedError.new
end
def get_mode(file)
@@ -330,14 +309,10 @@
end
def check_ipv4_address(interface, ip_address)
raise NotImplementedError.new
end
-
- def check_ipv6_address(interface, ip_address)
- raise NotImplementedError.new
- end
def check_mail_alias(recipient, target)
target = "[[:space:]]#{target}"
"getent aliases #{escape(recipient)} | grep -- #{escape(target)}$"
end
@@ -349,13 +324,9 @@
def check_container(container)
raise NotImplementedError.new
end
def check_cotainer_running(container)
- raise NotImplementedError.new
- end
-
- def check_immutable(file)
raise NotImplementedError.new
end
def get_package_version(package, opts=nil)
raise NotImplementedError.new