[DRE-commits] [ruby-specinfra] 01/08: New upstream version 2.70.0

Unit 193 unit193-guest at moszumanska.debian.org
Wed Jul 26 23:38:35 UTC 2017


This is an automated email from the git hooks/post-receive script.

unit193-guest pushed a commit to branch master
in repository ruby-specinfra.

commit ebdbd1548d9c3815f03e4424415e7fe1cc5ea5d1
Author: Unit 193 <unit193 at ubuntu.com>
Date:   Wed Jul 26 19:31:32 2017 -0400

    New upstream version 2.70.0
---
 Rakefile                                           |  8 ++-
 appveyor.yml                                       |  4 ++
 lib/specinfra/backend.rb                           |  1 +
 lib/specinfra/backend/cmd.rb                       |  2 +-
 lib/specinfra/backend/docker.rb                    | 19 ++++---
 lib/specinfra/backend/jexec.rb                     | 47 ++++++++++++++++
 lib/specinfra/backend/powershell/script_helper.rb  |  8 ++-
 lib/specinfra/command.rb                           | 15 ++++++
 lib/specinfra/command/aix/base/group.rb            |  9 +++-
 lib/specinfra/command/alpine/base/host.rb          | 11 ++++
 lib/specinfra/command/base/kvm_guest.rb            |  2 +
 lib/specinfra/command/debian/base/package.rb       |  5 +-
 lib/specinfra/command/debian/base/port.rb          |  9 ++++
 lib/specinfra/command/debian/base/service.rb       |  8 +++
 lib/specinfra/command/elementary.rb                |  1 +
 lib/specinfra/command/elementary/base.rb           |  2 +
 lib/specinfra/command/freebsd/base/group.rb        | 14 +++++
 lib/specinfra/command/freebsd/base/interface.rb    |  8 +++
 .../command/freebsd/base/kernel_module.rb          |  7 +++
 .../command/freebsd/base/routing_table.rb          |  2 +-
 lib/specinfra/command/freebsd/base/zfs.rb          |  5 ++
 lib/specinfra/command/freebsd/v11.rb               |  2 +
 lib/specinfra/command/freebsd/v11/interface.rb     | 11 ++++
 lib/specinfra/command/gentoo/base/package.rb       | 19 ++++++-
 lib/specinfra/command/linux/base/kvm_guest.rb      | 15 ++++++
 lib/specinfra/command/linux/base/selinux.rb        | 23 +++++++-
 lib/specinfra/command/redhat/base/package.rb       | 14 ++---
 lib/specinfra/configuration.rb                     |  1 +
 lib/specinfra/helper/detect_os/coreos.rb           |  2 +-
 lib/specinfra/helper/detect_os/suse.rb             | 13 ++---
 lib/specinfra/host_inventory.rb                    |  2 +
 lib/specinfra/host_inventory/facter.rb             | 17 ++++++
 lib/specinfra/host_inventory/ohai.rb               | 21 ++++++++
 lib/specinfra/host_inventory/virtualization.rb     | 12 ++---
 lib/specinfra/processor.rb                         | 25 ++++++---
 lib/specinfra/version.rb                           |  2 +-
 spec/command/debian/package_spec.rb                | 32 +++++++++++
 spec/command/debian9/port_spec.rb                  |  9 ++++
 spec/command/debian9/service_spec.rb               |  9 ++++
 spec/command/freebsd/interface_spec.rb             |  8 +++
 spec/command/linux/selinux_spec.rb                 | 21 ++++----
 spec/command/redhat/package_spec.rb                | 28 +++++++++-
 spec/helper/detect_os/debian_spec.rb               | 55 ++++++++++++++++++-
 spec/helper/detect_os/suse_spec.rb                 | 28 ++++++++--
 spec/host_inventory/linux/virtualization_spec.rb   | 14 ++---
 spec/processor_spec.rb                             | 63 ++++++++++++++++++++++
 specinfra.gemspec                                  |  2 +-
 47 files changed, 548 insertions(+), 87 deletions(-)

diff --git a/Rakefile b/Rakefile
index 4d52a10..135c1c7 100644
--- a/Rakefile
+++ b/Rakefile
@@ -10,10 +10,10 @@ if defined?(RSpec)
   task :default => 'spec:all'
 
   namespace :spec do
-    task :all => [ :helper, :backend, :configuration, :command, :host_inventory ]
+    task :all => [ :helper, :backend, :configuration, :processor, :command, :host_inventory ]
 
     RSpec::Core::RakeTask.new(:helper) do |t|
-      t.pattern = "spec/helper/*_spec.rb"
+      t.pattern = "spec/helper/**/*_spec.rb"
     end
 
     task :backend => 'backend:all'
@@ -33,6 +33,10 @@ if defined?(RSpec)
       t.pattern = "spec/configuration_spec.rb"
     end
 
+    RSpec::Core::RakeTask.new(:processor) do |t|
+      t.pattern = "spec/processor_spec.rb"
+    end
+
     RSpec::Core::RakeTask.new(:command) do |t|
       t.pattern = "spec/command/**/*.rb"
     end
diff --git a/appveyor.yml b/appveyor.yml
index 46fa28f..908dcf8 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -14,6 +14,10 @@ environment:
     - ruby_version: "21"
     - ruby_version: "22"
 
+matrix:
+  allow_failures:
+    - ruby_version: "193"
+
 clone_depth: 5
 
 cache:
diff --git a/lib/specinfra/backend.rb b/lib/specinfra/backend.rb
index 185abb5..bbe976c 100644
--- a/lib/specinfra/backend.rb
+++ b/lib/specinfra/backend.rb
@@ -10,3 +10,4 @@ require 'specinfra/backend/winrm'
 require 'specinfra/backend/shell_script'
 require 'specinfra/backend/dockerfile'
 require 'specinfra/backend/telnet'
+require 'specinfra/backend/jexec'
diff --git a/lib/specinfra/backend/cmd.rb b/lib/specinfra/backend/cmd.rb
index 71b3f59..a7cb1ff 100644
--- a/lib/specinfra/backend/cmd.rb
+++ b/lib/specinfra/backend/cmd.rb
@@ -18,7 +18,7 @@ module Specinfra
           psh.sub!(":", "")
           psh = psh.prepend("/cygdrive/")
         end
-        result = execute_script %Q{#{psh} -encodedCommand #{encode_script(script)}}
+        result = execute_script %Q{#{psh} -NoProfile -encodedCommand #{encode_script(script)}}
 
         if @example
           @example.metadata[:command] = script
diff --git a/lib/specinfra/backend/docker.rb b/lib/specinfra/backend/docker.rb
index 8627f41..f85d21a 100644
--- a/lib/specinfra/backend/docker.rb
+++ b/lib/specinfra/backend/docker.rb
@@ -27,18 +27,10 @@ module Specinfra
 
       def run_command(cmd, opts={})
         cmd = build_command(cmd)
-        cmd = add_pre_command(cmd)
+        run_pre_command(opts)
         docker_run!(cmd, opts)
       end
 
-      def build_command(cmd)
-        cmd
-      end
-
-      def add_pre_command(cmd)
-        cmd
-      end
-
       def send_file(from, to)
         if @base_image
           @images << commit_container if @container
@@ -95,7 +87,7 @@ module Specinfra
 
       def docker_run!(cmd, opts={})
         opts.merge!(get_config(:docker_container_exec_options) || {})
-        stdout, stderr, status = @container.exec(['/bin/sh', '-c', cmd], opts)
+        stdout, stderr, status = @container.exec(cmd.shellsplit, opts)
 
         CommandResult.new :stdout => stdout.join, :stderr => stderr.join,
         :exit_status => status
@@ -115,6 +107,13 @@ module Specinfra
           ::Docker::Image.create('fromImage' => name)
         end
       end
+
+      def run_pre_command(opts)
+        if get_config(:pre_command)
+          cmd = build_command(get_config(:pre_command))
+          docker_run!(cmd, opts)
+        end
+      end
     end
   end
 end
diff --git a/lib/specinfra/backend/jexec.rb b/lib/specinfra/backend/jexec.rb
new file mode 100644
index 0000000..3dfede5
--- /dev/null
+++ b/lib/specinfra/backend/jexec.rb
@@ -0,0 +1,47 @@
+module Specinfra
+  module Backend
+    class Jexec < Exec
+      def initialize(config = {})
+        super(config)
+        jname = get_config(:jail_name)
+        jroot = `jls -j #{jname} path`.strip
+        fail 'fail to get jail path!' if jroot.to_s.empty?
+        set_config(:jail_root, jroot)
+      end
+
+      def send_file(from, to)
+        jroot = get_config(:jail_root)
+        FileUtils.cp(from, "#{jroot}/#{to}")
+      end
+
+      def send_directory(from, to)
+        jroot = get_config(:jail_root)
+        FileUtils.cp_r("#{jroot}/#{from}", to)
+      end
+
+      def build_command(cmd)
+        shell = get_config(:shell) || '/bin/sh'
+        cmd = cmd.shelljoin if cmd.is_a?(Array)
+        shell = shell.shellescape
+
+        if get_config(:interactive_shell)
+          shell << " -i"
+        end
+
+        if get_config(:login_shell)
+          shell << " -l"
+        end
+
+        cmd = "#{shell} -c #{cmd.to_s.shellescape}"
+
+        path = get_config(:path)
+        if path
+          cmd = %Q{env PATH="#{path}" #{cmd}}
+        end
+
+        jname = get_config(:jail_name)
+        "jexec #{jname} #{cmd}"
+      end
+    end
+  end
+end
diff --git a/lib/specinfra/backend/powershell/script_helper.rb b/lib/specinfra/backend/powershell/script_helper.rb
index d4b493f..83ca364 100644
--- a/lib/specinfra/backend/powershell/script_helper.rb
+++ b/lib/specinfra/backend/powershell/script_helper.rb
@@ -8,7 +8,7 @@ module Specinfra
           path = get_config(:path)
           if path
             cmd.strip!
-            cmd = 
+            cmd =
 <<-EOF
 $env:path = "#{path};$env:path"
 #{cmd}
@@ -21,12 +21,10 @@ EOF
           path = get_config(:path)
           if get_config(:pre_command)
             cmd.strip!
-            cmd = 
+            cmd =
 <<-EOF
-if (#{get_config(:pre_command)})
-{
+#{get_config(:pre_command)}
 #{cmd}
-}
 EOF
             cmd = "$env:path = \"#{path};$env:path\"\n#{cmd}" if path
           end
diff --git a/lib/specinfra/command.rb b/lib/specinfra/command.rb
index 897bbad..50661a7 100644
--- a/lib/specinfra/command.rb
+++ b/lib/specinfra/command.rb
@@ -35,6 +35,7 @@ require 'specinfra/command/base/iptables'
 require 'specinfra/command/base/ip6tables'
 require 'specinfra/command/base/kernel_module'
 require 'specinfra/command/base/lxc_container'
+require 'specinfra/command/base/kvm_guest'
 require 'specinfra/command/base/localhost'
 require 'specinfra/command/base/mail_alias'
 require 'specinfra/command/base/package'
@@ -62,6 +63,7 @@ require 'specinfra/command/linux/base/iptables'
 require 'specinfra/command/linux/base/ip6tables'
 require 'specinfra/command/linux/base/kernel_module'
 require 'specinfra/command/linux/base/lxc_container'
+require 'specinfra/command/linux/base/kvm_guest'
 require 'specinfra/command/linux/base/package'
 require 'specinfra/command/linux/base/ppa'
 require 'specinfra/command/linux/base/selinux'
@@ -127,6 +129,7 @@ require 'specinfra/command/aix/base/user'
 # Alpine (inherit Linux)
 require 'specinfra/command/alpine'
 require 'specinfra/command/alpine/base'
+require 'specinfra/command/alpine/base/host'
 require 'specinfra/command/alpine/base/package'
 require 'specinfra/command/alpine/base/process'
 require 'specinfra/command/alpine/base/service'
@@ -161,6 +164,7 @@ require 'specinfra/command/debian'
 require 'specinfra/command/debian/base'
 require 'specinfra/command/debian/base/package'
 require 'specinfra/command/debian/base/ppa'
+require 'specinfra/command/debian/base/port'
 require 'specinfra/command/debian/base/service'
 
 # Debian V8 (inherit Debian)
@@ -185,6 +189,10 @@ require 'specinfra/command/ubuntu/v15/service'
 require 'specinfra/command/linuxmint'
 require 'specinfra/command/linuxmint/base'
 
+# elementary OS (inherit Ubuntu)
+require 'specinfra/command/elementary'
+require 'specinfra/command/elementary/base'
+
 # Cumulus Networks (inherit Debian)
 require 'specinfra/command/cumulus'
 require 'specinfra/command/cumulus/base'
@@ -230,14 +238,17 @@ require 'specinfra/command/sles/v12/service'
 require 'specinfra/command/freebsd'
 require 'specinfra/command/freebsd/base'
 require 'specinfra/command/freebsd/base/file'
+require 'specinfra/command/freebsd/base/group'
 require 'specinfra/command/freebsd/base/host'
 require 'specinfra/command/freebsd/base/interface'
 require 'specinfra/command/freebsd/base/inventory'
+require 'specinfra/command/freebsd/base/kernel_module'
 require 'specinfra/command/freebsd/base/package'
 require 'specinfra/command/freebsd/base/port'
 require 'specinfra/command/freebsd/base/service'
 require 'specinfra/command/freebsd/base/routing_table'
 require 'specinfra/command/freebsd/base/user'
+require 'specinfra/command/freebsd/base/zfs'
 
 # FreeBSD V6 (inherit FreeBSD)
 require 'specinfra/command/freebsd/v6'
@@ -256,6 +267,10 @@ require 'specinfra/command/freebsd/v8/package'
 require 'specinfra/command/freebsd/v9'
 require 'specinfra/command/freebsd/v9/package'
 
+# FreeBSD V11 (inherit FreeBSD)
+require 'specinfra/command/freebsd/v11'
+require 'specinfra/command/freebsd/v11/interface'
+
 # OpenBSD (inherit Base)
 require 'specinfra/command/openbsd'
 require 'specinfra/command/openbsd/base'
diff --git a/lib/specinfra/command/aix/base/group.rb b/lib/specinfra/command/aix/base/group.rb
index e4a3f9f..ddb5e30 100644
--- a/lib/specinfra/command/aix/base/group.rb
+++ b/lib/specinfra/command/aix/base/group.rb
@@ -1,8 +1,13 @@
 class Specinfra::Command::Aix::Base::Group < Specinfra::Command::Base::Group
   class << self
+
+    def check_exists(group)
+      "lsgroup #{escape(group)}"
+    end
+
     def check_has_gid(group, gid)
-      regexp = "^#{group}"
-      "cat etc/group | grep -w -- #{escape(regexp)} | cut -f 3 -d ':' | grep -w -- #{escape(gid)}"
+      "lsgroup -a id #{escape(group)} | cut -f 2 -d '=' | grep -w -- #{escape(gid)}"
     end
+
   end
 end
diff --git a/lib/specinfra/command/alpine/base/host.rb b/lib/specinfra/command/alpine/base/host.rb
new file mode 100644
index 0000000..564c0f3
--- /dev/null
+++ b/lib/specinfra/command/alpine/base/host.rb
@@ -0,0 +1,11 @@
+class Specinfra::Command::Alpine::Base::Host < Specinfra::Command::Base::Host
+  class << self
+    def check_is_reachable(host, port, proto, timeout)
+      if port.nil?
+        "ping -w #{escape(timeout)} -c 2 -n #{escape(host)}"
+      else
+        "nc -w #{escape(timeout)} -vvvvz#{proto.downcase.start_with?('u') ? 'u' : ''} #{escape(host)} #{escape(port)}"
+      end
+    end
+  end
+end
diff --git a/lib/specinfra/command/base/kvm_guest.rb b/lib/specinfra/command/base/kvm_guest.rb
new file mode 100644
index 0000000..53460d1
--- /dev/null
+++ b/lib/specinfra/command/base/kvm_guest.rb
@@ -0,0 +1,2 @@
+class Specinfra::Command::Base::KvmGuest < Specinfra::Command::Base
+end
diff --git a/lib/specinfra/command/debian/base/package.rb b/lib/specinfra/command/debian/base/package.rb
index 56f6b66..bd4253f 100644
--- a/lib/specinfra/command/debian/base/package.rb
+++ b/lib/specinfra/command/debian/base/package.rb
@@ -3,7 +3,7 @@ class Specinfra::Command::Debian::Base::Package < Specinfra::Command::Linux::Bas
     def check_is_installed(package, version=nil)
       escaped_package = escape(package)
       if version
-        cmd = "dpkg-query -f '${Status} ${Version}' -W #{escaped_package} | grep -E '^(install|hold) ok installed #{escape(version)}$'"
+        cmd = "dpkg-query -f '${Status} ${Version}' -W #{escaped_package} | grep -E '^(install|hold) ok installed #{Regexp.escape(version)}$'"
       else
         cmd = "dpkg-query -f '${Status}' -W #{escaped_package} | grep -E '^(install|hold) ok installed$'"
       end
@@ -18,7 +18,7 @@ class Specinfra::Command::Debian::Base::Package < Specinfra::Command::Linux::Bas
       else
         full_package = package
       end
-      "DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' #{option} install #{full_package}"
+      "DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' #{option} install #{escape(full_package)}"
     end
 
     def get_version(package, opts=nil)
@@ -30,4 +30,3 @@ class Specinfra::Command::Debian::Base::Package < Specinfra::Command::Linux::Bas
     end
   end
 end
-
diff --git a/lib/specinfra/command/debian/base/port.rb b/lib/specinfra/command/debian/base/port.rb
index be5e1d6..0ca715a 100644
--- a/lib/specinfra/command/debian/base/port.rb
+++ b/lib/specinfra/command/debian/base/port.rb
@@ -1,2 +1,11 @@
 class Specinfra::Command::Debian::Base::Port < Specinfra::Command::Linux::Base::Port
+  class << self
+    def create(os_info=nil)
+      if (os_info || os)[:release].to_i < 8
+        self
+      else
+        Specinfra::Command::Debian::V8::Port
+      end
+    end
+  end
 end
diff --git a/lib/specinfra/command/debian/base/service.rb b/lib/specinfra/command/debian/base/service.rb
index 21849fc..5cf4a84 100644
--- a/lib/specinfra/command/debian/base/service.rb
+++ b/lib/specinfra/command/debian/base/service.rb
@@ -1,5 +1,13 @@
 class Specinfra::Command::Debian::Base::Service < Specinfra::Command::Linux::Base::Service
   class << self
+    def create(os_info=nil)
+      if (os_info || os)[:release].to_i < 8
+        self
+      else
+        Specinfra::Command::Debian::V8::Service
+      end
+    end
+
     def check_is_enabled(service, level=3)
       # Until everything uses Upstart, this needs an OR.
       "ls /etc/rc#{level}.d/ | grep -- '^S..#{escape(service)}$' || grep '^\s*start on' /etc/init/#{escape(service)}.conf"
diff --git a/lib/specinfra/command/elementary.rb b/lib/specinfra/command/elementary.rb
new file mode 100644
index 0000000..f0dde3e
--- /dev/null
+++ b/lib/specinfra/command/elementary.rb
@@ -0,0 +1 @@
+class Specinfra::Command::Elementary; end
diff --git a/lib/specinfra/command/elementary/base.rb b/lib/specinfra/command/elementary/base.rb
new file mode 100644
index 0000000..070b228
--- /dev/null
+++ b/lib/specinfra/command/elementary/base.rb
@@ -0,0 +1,2 @@
+class Specinfra::Command::Elementary::Base < Specinfra::Command::Ubuntu::Base
+end
diff --git a/lib/specinfra/command/freebsd/base/group.rb b/lib/specinfra/command/freebsd/base/group.rb
new file mode 100644
index 0000000..805c9df
--- /dev/null
+++ b/lib/specinfra/command/freebsd/base/group.rb
@@ -0,0 +1,14 @@
+class Specinfra::Command::Freebsd::Base::Group < Specinfra::Command::Base::Group
+  class << self
+    def update_gid(group, gid)
+      "pw groupmod #{escape(group)} -g #{escape(gid)}"
+    end
+
+    def add(group, options)
+      command = %w[pw group add]
+      command << '-g' << escape(options[:gid])  if options[:gid]
+      command << escape(group)
+      command.join(' ')
+    end
+  end
+end
diff --git a/lib/specinfra/command/freebsd/base/interface.rb b/lib/specinfra/command/freebsd/base/interface.rb
index 821fbae..ae303c5 100644
--- a/lib/specinfra/command/freebsd/base/interface.rb
+++ b/lib/specinfra/command/freebsd/base/interface.rb
@@ -4,6 +4,14 @@ class Specinfra::Command::Freebsd::Base::Interface < Specinfra::Command::Base::I
       "ifconfig #{name}"
     end
 
+    def get_speed_of(name)
+      "ifconfig #{name} | awk '/media:/{if(match($0,/[0-9]+/)){ print substr($0, RSTART, RLENGTH);}}'"
+    end
+
+    def get_mtu_of(name)
+      "ifconfig #{name} | awk '/mtu /{print $NF}'"
+    end
+
     def check_has_ipv4_address(interface, ip_address)
       ip_address = ip_address.dup
       if ip_address =~ /\/\d+$/
diff --git a/lib/specinfra/command/freebsd/base/kernel_module.rb b/lib/specinfra/command/freebsd/base/kernel_module.rb
new file mode 100644
index 0000000..67c95fc
--- /dev/null
+++ b/lib/specinfra/command/freebsd/base/kernel_module.rb
@@ -0,0 +1,7 @@
+class Specinfra::Command::Freebsd::Base::KernelModule < Specinfra::Command::Base::KernelModule
+  class << self
+    def check_is_loaded(name)
+      "kldstat -q -m #{name}"
+    end
+  end
+end
diff --git a/lib/specinfra/command/freebsd/base/routing_table.rb b/lib/specinfra/command/freebsd/base/routing_table.rb
index c042b60..7a49349 100644
--- a/lib/specinfra/command/freebsd/base/routing_table.rb
+++ b/lib/specinfra/command/freebsd/base/routing_table.rb
@@ -1,7 +1,7 @@
 class Specinfra::Command::Freebsd::Base::RoutingTable < Specinfra::Command::Base::RoutingTable
   class << self
     def check_has_entry(destination)
-      %Q{netstat -rnW | grep #{destination} | awk '{print $1, "via", $2, "dev", $7, " "}'}
+      %Q{netstat -rnW | grep #{destination} | awk '{print $1, "via", $2, "dev", $6, " "}'}
     end
 
     alias :get_entry :check_has_entry
diff --git a/lib/specinfra/command/freebsd/base/zfs.rb b/lib/specinfra/command/freebsd/base/zfs.rb
new file mode 100644
index 0000000..83269de
--- /dev/null
+++ b/lib/specinfra/command/freebsd/base/zfs.rb
@@ -0,0 +1,5 @@
+class Specinfra::Command::Freebsd::Base::Zfs < Specinfra::Command::Base::Zfs
+  class << self
+    include Specinfra::Command::Module::Zfs
+  end
+end
diff --git a/lib/specinfra/command/freebsd/v11.rb b/lib/specinfra/command/freebsd/v11.rb
new file mode 100644
index 0000000..9038f34
--- /dev/null
+++ b/lib/specinfra/command/freebsd/v11.rb
@@ -0,0 +1,2 @@
+class Specinfra::Command::Freebsd::V11 < Specinfra::Command::Freebsd::Base
+end
diff --git a/lib/specinfra/command/freebsd/v11/interface.rb b/lib/specinfra/command/freebsd/v11/interface.rb
new file mode 100644
index 0000000..9702c01
--- /dev/null
+++ b/lib/specinfra/command/freebsd/v11/interface.rb
@@ -0,0 +1,11 @@
+class Specinfra::Command::Freebsd::V11::Interface < Specinfra::Command::Freebsd::Base::Interface
+  class << self
+    def get_ipv4_address(interface)
+      "ifconfig -f inet:cidr #{interface} inet | awk '/inet /{print $2}'"
+    end
+
+    def get_ipv6_address(interface)
+      "ifconfig -f inet6:cidr #{interface} inet6 | awk '/inet6 /{print $2}' | tail -1"
+    end
+  end
+end
diff --git a/lib/specinfra/command/gentoo/base/package.rb b/lib/specinfra/command/gentoo/base/package.rb
index 401a8f8..bda2e19 100644
--- a/lib/specinfra/command/gentoo/base/package.rb
+++ b/lib/specinfra/command/gentoo/base/package.rb
@@ -1,7 +1,24 @@
 class Specinfra::Command::Gentoo::Base::Package < Specinfra::Command::Linux::Base::Package
   class << self
     def check_is_installed(package, version=nil)
-      "eix #{escape(package)} --installed | grep -v \"No matches found.\""
+      "eix #{escape(package)} --installed | grep -v \"No matches found\""
+    end
+
+    def get_version(package, opts=nil)
+      "equery -q list #{package} | sed -e 's!^.*/?#{package}-!!'"
+    end
+
+    def install(package, version=nil, option='')
+      if version
+        full_package = "=#{package}-#{version}"
+      else
+        full_package = package
+      end
+      cmd = "emerge #{option} #{full_package}"
+    end
+
+    def remove(package, option='')
+      cmd = "emerge --unmerge #{option} #{package}"
     end
   end
 end
diff --git a/lib/specinfra/command/linux/base/kvm_guest.rb b/lib/specinfra/command/linux/base/kvm_guest.rb
new file mode 100644
index 0000000..1fb239c
--- /dev/null
+++ b/lib/specinfra/command/linux/base/kvm_guest.rb
@@ -0,0 +1,15 @@
+class Specinfra::Command::Linux::Base::KvmGuest < Specinfra::Command::Base::KvmGuest
+  class << self
+    def check_exists(guest)
+      "virsh -c qemu:///system list --all --name | grep -w '^#{escape(guest)}$'"
+    end
+
+    def check_is_running(guest)
+      "virsh -c qemu:///system list --name | grep -w '^#{escape(guest)}$'"
+    end
+
+    def check_is_enabled(guest)
+      "virsh -c qemu:///system dominfo #{escape(guest)} | grep -E '^Autostart:\s+enable$'"
+    end
+  end
+end
diff --git a/lib/specinfra/command/linux/base/selinux.rb b/lib/specinfra/command/linux/base/selinux.rb
index 05606d5..7345442 100644
--- a/lib/specinfra/command/linux/base/selinux.rb
+++ b/lib/specinfra/command/linux/base/selinux.rb
@@ -1,12 +1,31 @@
 class Specinfra::Command::Linux::Base::Selinux < Specinfra::Command::Base::Selinux
   class << self
     def check_has_mode(mode, policy = nil)
+
       cmd =  ""
-      cmd += "test ! -f /etc/selinux/config || (" if mode == "disabled"
-      cmd += "getenforce | grep -i -- #{escape(mode)}"
+
+      # If disabled, then the absence of /etc/selinux/config is sufficient
+      cmd += "test ! -f /etc/selinux/config || " if mode == "disabled"
+
+      # If disabled, wrap the rest of the test in parentheses
+      # i.e. only test this stuff if /etc/selinux/config exists
+      cmd += "( ( " if mode == "disabled"
+
+      # Does getenforce return the same value as we are checking for?
+      cmd += "(getenforce | grep -i -- #{escape(mode)})"
+
+      # If disabled, then permissive is considered a pass
+      cmd += " || (getenforce | grep -i -- #{escape('permissive')}) )" if mode == "disabled"
+
+      # Ensure that /etc/selinux/config contains the mode we specify
       cmd += %Q{ && grep -iE -- '^\\s*SELINUX=#{escape(mode)}\\>' /etc/selinux/config}
+
+      # If we have specified a policy, ensure that is included in /etc/selinux/config
       cmd += %Q{ && grep -iE -- '^\\s*SELINUXTYPE=#{escape(policy)}\\>' /etc/selinux/config} if policy != nil
+
+      # End parenthesis for tests when /etc/selinux/config exists
       cmd += ")" if mode == "disabled"
+
       cmd
     end
   end
diff --git a/lib/specinfra/command/redhat/base/package.rb b/lib/specinfra/command/redhat/base/package.rb
index 75c5426..dd45082 100644
--- a/lib/specinfra/command/redhat/base/package.rb
+++ b/lib/specinfra/command/redhat/base/package.rb
@@ -3,7 +3,8 @@ class Specinfra::Command::Redhat::Base::Package < Specinfra::Command::Linux::Bas
     def check_is_installed(package, version=nil)
       cmd = "rpm -q #{escape(package)}"
       if version
-        cmd = "#{cmd} | grep -w -- #{escape(package)}-#{escape(version)}"
+        full_package = "#{package}-#{version}"
+        cmd = "#{cmd} | grep -w -- #{Regexp.escape(full_package)}"
       end
       cmd
     end
@@ -20,7 +21,7 @@ class Specinfra::Command::Redhat::Base::Package < Specinfra::Command::Linux::Bas
       else
         full_package = package
       end
-      cmd = "yum -y #{option} install #{full_package}"
+      cmd = "yum -y #{option} install #{escape(full_package)}"
     end
 
     def remove(package, option='')
@@ -28,12 +29,3 @@ class Specinfra::Command::Redhat::Base::Package < Specinfra::Command::Linux::Bas
     end
   end
 end
-
-
-
-
-
-
-
-
-
diff --git a/lib/specinfra/configuration.rb b/lib/specinfra/configuration.rb
index f24b9eb..bc3dc89 100644
--- a/lib/specinfra/configuration.rb
+++ b/lib/specinfra/configuration.rb
@@ -25,6 +25,7 @@ module Specinfra
         :ssh_without_env,
         :dockerfile_finalizer,
         :telnet_options,
+        :jail_name,
       ].freeze
 
       def defaults
diff --git a/lib/specinfra/helper/detect_os/coreos.rb b/lib/specinfra/helper/detect_os/coreos.rb
index 056db2a..d506989 100644
--- a/lib/specinfra/helper/detect_os/coreos.rb
+++ b/lib/specinfra/helper/detect_os/coreos.rb
@@ -6,7 +6,7 @@ class Specinfra::Helper::DetectOs::Coreos < Specinfra::Helper::DetectOs
       lsb_release = run_command("cat /etc/lsb-release")
       if lsb_release.success?
         lsb_release.stdout.each_line do |line|
-          distro  = line.split('=').last.strip if line =~ /^DISTRIB_ID=/
+          distro  = 'coreos' if line.include? "CoreOS"
           release = line.split('=').last.strip if line =~ /^DISTRIB_RELEASE=/
         end
       end
diff --git a/lib/specinfra/helper/detect_os/suse.rb b/lib/specinfra/helper/detect_os/suse.rb
index 75d11f4..4f60db4 100644
--- a/lib/specinfra/helper/detect_os/suse.rb
+++ b/lib/specinfra/helper/detect_os/suse.rb
@@ -1,13 +1,14 @@
 class Specinfra::Helper::DetectOs::Suse < Specinfra::Helper::DetectOs
   def detect
-    if run_command('ls /etc/SuSE-release').success?
-      line = run_command('cat /etc/SuSE-release').stdout
-      if line =~ /SUSE Linux Enterprise Server (\d+)/
-        release = $1
+    if run_command('ls /etc/os-release').success? and run_command('zypper -V').success?
+      line = run_command('cat /etc/os-release').stdout
+      if line =~ /ID=opensuse/
+        family = 'opensuse'
+      elsif line =~ /NAME=\"SLES"/
         family = 'sles'
-      elsif line =~ /openSUSE (\d+\.\d+|\d+)/
+      end
+      if line =~ /VERSION_ID=\"(\d+\.\d+|\d+)\"/
         release = $1
-        family = 'opensuse'
       end
       { :family => family, :release => release }
     end
diff --git a/lib/specinfra/host_inventory.rb b/lib/specinfra/host_inventory.rb
index d94bd63..3e90c8d 100644
--- a/lib/specinfra/host_inventory.rb
+++ b/lib/specinfra/host_inventory.rb
@@ -15,6 +15,8 @@ module Specinfra
       block_device
       user
       group
+      facter
+      ohai
     }
 
     include Enumerable
diff --git a/lib/specinfra/host_inventory/facter.rb b/lib/specinfra/host_inventory/facter.rb
new file mode 100644
index 0000000..d860a93
--- /dev/null
+++ b/lib/specinfra/host_inventory/facter.rb
@@ -0,0 +1,17 @@
+module Specinfra
+  class HostInventory
+    class Facter < Base
+      require 'yaml'
+
+      def get
+        begin
+          ret = backend.run_command('facter --puppet --yaml')
+        rescue StandardError
+          nil
+        end
+
+        ret.exit_status.zero? ? YAML.load(ret.stdout) : nil
+      end
+    end
+  end
+end
diff --git a/lib/specinfra/host_inventory/ohai.rb b/lib/specinfra/host_inventory/ohai.rb
new file mode 100644
index 0000000..289e0bc
--- /dev/null
+++ b/lib/specinfra/host_inventory/ohai.rb
@@ -0,0 +1,21 @@
+module Specinfra
+  class HostInventory
+    class Ohai < Base
+      def get
+        begin
+          require 'json'
+        rescue LoadError
+          return nil
+        end
+
+        begin
+          ret = backend.run_command('ohai --log_level error')
+        rescue StandardError
+          nil
+        end
+
+        ret.exit_status.zero? ? JSON.parse(ret.stdout) : nil
+      end
+    end
+  end
+end
diff --git a/lib/specinfra/host_inventory/virtualization.rb b/lib/specinfra/host_inventory/virtualization.rb
index cfb0327..81305c3 100644
--- a/lib/specinfra/host_inventory/virtualization.rb
+++ b/lib/specinfra/host_inventory/virtualization.rb
@@ -3,13 +3,13 @@ module Specinfra
     class Virtualization < Base
       def get
         res = {}
-        ## docker 
-        if backend.run_command('ls /.dockerinit').success?
+        ## docker
+        if backend.run_command('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.dockerinit').success?
           res[:system] = 'docker'
           return res
         end
 
-        ## OpenVZ on Linux 
+        ## OpenVZ on Linux
         if backend.run_command('test -d /proc/vz -a ! -d /proc/bc').success?
           res[:system] = 'openvz'
           return res
@@ -18,7 +18,7 @@ module Specinfra
         cmd = backend.command.get(:get_inventory_system_product_name)
         ret = backend.run_command(cmd)
         if ret.exit_status == 0
-           res[:system] = parse_system_product_name(ret.stdout)   
+           res[:system] = parse_system_product_name(ret.stdout)
            return res
         end
 
@@ -27,8 +27,8 @@ module Specinfra
           res[:system] = parse_systemd_detect_virt_output(ret.stdout)
         end
 
-        res 
-      end 
+        res
+      end
 
       def parse_system_product_name(ret)
         product_name = case ret
diff --git a/lib/specinfra/processor.rb b/lib/specinfra/processor.rb
index e6920bf..1a79b9a 100644
--- a/lib/specinfra/processor.rb
+++ b/lib/specinfra/processor.rb
@@ -89,14 +89,23 @@ module Specinfra
       end
 
       mount = ret.stdout.scan(/\S+/)
-      actual_attr    = { :device => mount[0], :type => mount[4] }
-      mount[5].gsub(/\(|\)/, '').split(',').each do |option|
-        name, val = option.split('=')
-        if val.nil?
-          actual_attr[name.to_sym] = true
-        else
-          val = val.to_i if val.match(/^\d+$/)
-          actual_attr[name.to_sym] = val
+      actual_attr = { }
+      actual_attr[:device] = mount[0]
+      # Output of mount depends on os:
+      # a)  proc on /proc type proc (rw,noexec,nosuid,nodev)
+      # b)  procfs on /proc (procfs, local)
+      actual_attr[:type] = mount[4] if mount[3] == 'type' # case a.
+      if match = ret.stdout.match(/\((.*)\)/)
+        options = match[1].split(',')
+        actual_attr[:type] ||= options.shift              # case b.
+        options.each do |option|
+          name, val = option.split('=')
+          if val.nil?
+            actual_attr[name.strip.to_sym] = true
+          else
+            val = val.to_i if val.match(/^\d+$/)
+            actual_attr[name.strip.to_sym] = val
+          end
         end
       end
 
diff --git a/lib/specinfra/version.rb b/lib/specinfra/version.rb
index 2b16a7b..5dc3e08 100644
--- a/lib/specinfra/version.rb
+++ b/lib/specinfra/version.rb
@@ -1,3 +1,3 @@
 module Specinfra
-  VERSION = "2.66.0"
+  VERSION = "2.70.0"
 end
diff --git a/spec/command/debian/package_spec.rb b/spec/command/debian/package_spec.rb
new file mode 100644
index 0000000..b73973c
--- /dev/null
+++ b/spec/command/debian/package_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+property[:os] = nil
+set :os, :family => 'debian'
+
+describe get_command(:check_package_is_installed, 'telnet') do
+  it { should eq "dpkg-query -f '${Status}' -W telnet | grep -E '^(install|hold) ok installed$'" }
+end
+
+describe get_command(:check_package_is_installed, 'telnet', '0.17-36build2') do
+  it { should eq "dpkg-query -f '${Status} ${Version}' -W telnet | grep -E '^(install|hold) ok installed 0\\.17\\-36build2$'" }
+end
+
+describe get_command(:check_package_is_installed, 'linux-headers-$(uname -r)') do
+  it 'should be escaped (that is, command substitution should not work)' do
+    should eq "dpkg-query -f '${Status}' -W linux-headers-\\$\\(uname\\ -r\\) | grep -E '^(install|hold) ok installed$'"
+  end
+end
+
+describe get_command(:install_package, 'telnet') do
+  it { should eq "DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold'  install telnet" }
+end
+
+describe get_command(:install_package, 'telnet', '0.17-36build2') do
+  it { should eq "DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold'  install telnet\\=0.17-36build2" }
+end
+
+describe get_command(:install_package, 'linux-headers-$(uname -r)') do
+  it 'should be escaped (that is, command substitution should not work)' do
+    should eq "DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold'  install linux-headers-\\$\\(uname\\ -r\\)"
+  end
+end
diff --git a/spec/command/debian9/port_spec.rb b/spec/command/debian9/port_spec.rb
new file mode 100644
index 0000000..75f9cb7
--- /dev/null
+++ b/spec/command/debian9/port_spec.rb
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+property[:os] = nil
+set :os, :family => 'debian', :release => '9'
+
+describe get_command(:check_port_is_listening, '80') do
+  it { should eq 'ss -tunl | grep -- :80\ ' }
+end
+
diff --git a/spec/command/debian9/service_spec.rb b/spec/command/debian9/service_spec.rb
new file mode 100644
index 0000000..f56c501
--- /dev/null
+++ b/spec/command/debian9/service_spec.rb
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+property[:os] = nil
+set :os, :family => 'debian', :release => '9'
+
+describe get_command(:check_service_is_enabled, 'apache') do
+  it { should eq 'systemctl --quiet is-enabled apache||ls /etc/rc[S5].d/S??apache >/dev/null 2>/dev/null' }
+end
+
diff --git a/spec/command/freebsd/interface_spec.rb b/spec/command/freebsd/interface_spec.rb
index 23fe171..5d6a6be 100644
--- a/spec/command/freebsd/interface_spec.rb
+++ b/spec/command/freebsd/interface_spec.rb
@@ -38,3 +38,11 @@ end
 describe get_command(:get_interface_link_state, 'vtnet0') do
   it { should eq %Q{ifconfig -u vtnet0 2>&1 | awk -v s=up '/status:/ && $2 != "active" { s="down" }; END {print s}'} }
 end
+
+describe get_command(:get_interface_speed_of, 'vtnet0') do
+  it { should eq "ifconfig vtnet0 | awk '/media:/{if(match($0,/[0-9]+/)){ print substr($0, RSTART, RLENGTH);}}'" }
+end
+
+describe get_command(:get_interface_mtu_of, 'vtnet0') do
+  it { should eq "ifconfig vtnet0 | awk '/mtu /{print $NF}'" }
+end
diff --git a/spec/command/linux/selinux_spec.rb b/spec/command/linux/selinux_spec.rb
index 88b0dc2..b52768d 100644
--- a/spec/command/linux/selinux_spec.rb
+++ b/spec/command/linux/selinux_spec.rb
@@ -4,24 +4,25 @@ property[:os] = nil
 set :os, :family => 'linux'
 
 describe get_command(:check_selinux_has_mode, 'disabled') do
-  it do 
-    should eq %Q{test ! -f /etc/selinux/config || (} +
-              %Q{getenforce | grep -i -- disabled} +
+  it do
+    should eq %Q{test ! -f /etc/selinux/config || ( ( (} +
+              %Q{getenforce | grep -i -- disabled) ||} +
+              %Q{ (getenforce | grep -i -- permissive) )} +
               %Q{ && grep -iE -- '^\\s*SELINUX=disabled\\>' /etc/selinux/config)}
-  end 
+  end
 end
 
 describe get_command(:check_selinux_has_mode, 'permissive', nil) do
-  it do 
-    should eq %Q{getenforce | grep -i -- permissive} +
+  it do
+    should eq %Q{(getenforce | grep -i -- permissive)} +
               %Q{ && grep -iE -- '^\\s*SELINUX=permissive\\>' /etc/selinux/config}
-  end 
+  end
 end
 
 describe get_command(:check_selinux_has_mode, 'enforcing', 'targeted') do
-  it do 
-    should eq %Q{getenforce | grep -i -- enforcing} +
+  it do
+    should eq %Q{(getenforce | grep -i -- enforcing)} +
               %Q{ && grep -iE -- '^\\s*SELINUX=enforcing\\>' /etc/selinux/config} +
               %Q{ && grep -iE -- '^\\s*SELINUXTYPE=targeted\\>' /etc/selinux/config}
-  end 
+  end
 end
diff --git a/spec/command/redhat/package_spec.rb b/spec/command/redhat/package_spec.rb
index 83d1fb1..b628d05 100644
--- a/spec/command/redhat/package_spec.rb
+++ b/spec/command/redhat/package_spec.rb
@@ -3,6 +3,30 @@ require 'spec_helper'
 property[:os] = nil
 set :os, { :family => 'redhat' }
 
-describe  get_command(:check_package_is_installed, 'httpd') do
-  it { should eq 'rpm -q httpd' }
+describe  get_command(:check_package_is_installed, 'telnet') do
+  it { should eq 'rpm -q telnet' }
+end
+
+describe  get_command(:check_package_is_installed, 'telnet', '0.17-48.el6.x86_64') do
+  it { should eq 'rpm -q telnet | grep -w -- telnet\\-0\\.17\\-48\\.el6\\.x86_64' }
+end
+
+describe  get_command(:check_package_is_installed, 'linux-headers-$(uname -r)') do
+  it 'should be escaped (that is, command substitution should not work' do
+    should eq 'rpm -q linux-headers-\\$\\(uname\\ -r\\)'
+  end
+end
+
+describe get_command(:install_package, 'telnet') do
+  it { should eq "yum -y  install telnet" }
+end
+
+describe get_command(:install_package, 'telnet', '0.17-48.el6.x86_64') do
+  it { should eq "yum -y  install telnet-0.17-48.el6.x86_64" }
+end
+
+describe get_command(:install_package, 'linux-headers-$(uname -r)') do
+  it 'should be escaped (that is, command substitution should no work)' do
+    should eq "yum -y  install linux-headers-\\$\\(uname\\ -r\\)"
+  end
 end
diff --git a/spec/helper/detect_os/debian_spec.rb b/spec/helper/detect_os/debian_spec.rb
index 9b59eca..4f43df9 100644
--- a/spec/helper/detect_os/debian_spec.rb
+++ b/spec/helper/detect_os/debian_spec.rb
@@ -2,16 +2,67 @@ require 'spec_helper'
 require 'specinfra/helper/detect_os/debian'
 
 describe Specinfra::Helper::DetectOs::Debian do
-  darwin = Specinfra::Helper::DetectOs::Debian.new(Specinfra.backend)
+  debian = Specinfra::Helper::DetectOs::Debian.new(Specinfra.backend)
 
   it 'Should return debian 8.5 when jessie is installed.' do
     allow(debian).to receive(:run_command).with('cat /etc/debian_version') {
       CommandResult.new(:stdout => "8.5\n", :exit_status => 0)
     }
-    expect(darwin.detect).to include(
+    allow(debian).to receive(:run_command).with('lsb_release -ir') {
+      CommandResult.new(:stdout => "8.5\n", :exit_status => 1)
+    }
+    allow(debian).to receive(:run_command).with('cat /etc/lsb-release') {
+      CommandResult.new(:stdout => "8.5\n", :exit_status => 1)
+    }
+    expect(debian.detect).to include(
       :family  => 'debian',
       :release => '8.5'
     )
   end
+  it 'Should return ubuntu 16.10 when yakkety is installed.' do
+    allow(debian).to receive(:run_command).with('cat /etc/debian_version') {
+      CommandResult.new(:stdout => "stretch/sid", :exit_status => 0)
+    }
+    allow(debian).to receive(:run_command).with('lsb_release -ir') {
+      CommandResult.new(:stdout => "Distributor ID:Ubuntu\nRelease:16.10\n", :exit_status => 0)
+    }
+    allow(debian).to receive(:run_command).with('cat /etc/lsb-release') {
+      CommandResult.new(:stdout => "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=16.10\nDISTRIB_CODENAME=yakkety\nDISTRIB_DESCRIPTION=\"Ubuntu 16.10\"", :exit_status => 0)
+    }
+    expect(debian.detect).to include(
+      :family  => 'ubuntu',
+      :release => '16.10'
+    )
+  end
+  it 'Should return ubuntu 16.04 when xenial is installed.' do
+    allow(debian).to receive(:run_command).with('cat /etc/debian_version') {
+      CommandResult.new(:stdout => "stretch/sid", :exit_status => 0)
+    }
+    allow(debian).to receive(:run_command).with('lsb_release -ir') {
+      CommandResult.new(:stdout => "Distributor ID:Ubuntu\nRelease:16.04\n", :exit_status => 0)
+    }
+    allow(debian).to receive(:run_command).with('cat /etc/lsb-release') {
+      CommandResult.new(:stdout => "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=16.04\nDISTRIB_CODENAME=xenial\nDISTRIB_DESCRIPTION=\"Ubuntu 16.04.2 LTS\"", :exit_status => 0)
+    }
+    expect(debian.detect).to include(
+      :family  => 'ubuntu',
+      :release => '16.04'
+    )
+  end
+  it 'Should return ubuntu 16.04 when xenial is installed in docker.' do
+    allow(debian).to receive(:run_command).with('cat /etc/debian_version') {
+      CommandResult.new(:stdout => "stretch/sid", :exit_status => 0)
+    }
+    allow(debian).to receive(:run_command).with('lsb_release -ir') {
+      CommandResult.new(:stdout => 'lsb-release is not installed in docker image by default', :exit_status => 1)
+    }
+    allow(debian).to receive(:run_command).with('cat /etc/lsb-release') {
+      CommandResult.new(:stdout => "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=16.04\nDISTRIB_CODENAME=xenial\nDISTRIB_DESCRIPTION=\"Ubuntu 16.04.2 LTS\"", :exit_status => 0)
+    }
+    expect(debian.detect).to include(
+      :family  => 'ubuntu',
+      :release => '16.04'
+    )
+  end
 end
 
diff --git a/spec/helper/detect_os/suse_spec.rb b/spec/helper/detect_os/suse_spec.rb
index 2144882..ad29267 100644
--- a/spec/helper/detect_os/suse_spec.rb
+++ b/spec/helper/detect_os/suse_spec.rb
@@ -3,22 +3,40 @@ require 'specinfra/helper/detect_os/suse'
 
 describe Specinfra::Helper::DetectOs::Suse do
   suse = Specinfra::Helper::DetectOs::Suse.new(:exec)
-  it 'Should return opensuse 13 when openSUSE 13.2 is installed.' do
+  it 'Should return opensuse 42.2 when openSUSE 42.2 is installed.' do
     allow(suse).to receive(:run_command) {
-        CommandResult.new(:stdout => 'openSUSE 13.2 (x86_64)', :exit_status => 0)
+        CommandResult.new(:stdout => "NAME=\"openSUSE Leap\"\nVERSION=\"42.2\"\nID=opensuse\nID_LIKE=\"suse\"\nVERSION_ID=\"42.2\"\nPRETTY_NAME=\"openSUSE Leap 42.2\"\nANSI_COLOR=\"0;32\"\nCPE_NAME=\"cpe:/o:opensuse:leap:42.2\"\nBUG_REPORT_URL=\"https://bugs.opensuse.org\"\nHOME_URL=\"https://www.opensuse.org/\"\n", :exit_status => 0)
+    }
+    expect(suse.detect).to include(
+      :family  => 'opensuse',
+      :release => '42.2'
+    )
+  end
+  it 'Should return opensuse 13.2 when openSUSE 13.2 is installed.' do
+    allow(suse).to receive(:run_command) {
+        CommandResult.new(:stdout => "NAME=openSUSE\nVERSION=\"13.2 (Harlequin)\"\nVERSION_ID=\"13.2\"\nPRETTY_NAME=\"openSUSE 13.2 (Harlequin) (x86_64)\"\nID=opensuse\nANSI_COLOR=\"0;32\"\nCPE_NAME=\"cpe:/o:opensuse:opensuse:13.2\"\nBUG_REPORT_URL=\"https://bugs.opensuse.org\"\nHOME_URL=\"https://opensuse.org/\"\nID_LIKE=\"suse\"\n", :exit_status => 0)
     }
     expect(suse.detect).to include(
       :family  => 'opensuse',
       :release => '13.2'
     )
   end
-  it 'Should return sles 12 when SUSE Linux Enterprise Server 12 is installed.' do
+  it 'Should return sles 12.2 when SUSE Linux Enterprise Server 12.2 is installed.' do
+    allow(suse).to receive(:run_command) {
+      CommandResult.new(:stdout => "NAME=\"SLES\"\nVERSION=\"12.2\"\nVERSION_ID=\"12.2\"\nPRETTY_NAME=\"SUSE Linux Enterprise Server 12\"\nID=\"sles\"\nANSI_COLOR=\"0;32\"\nCPE_NAME=\"cpe:/o:suse:sles:12\"\n", :exit_status => 0)
+    }
+    expect(suse.detect).to include(
+      :family  => 'sles',
+      :release => '12.2'
+    )
+  end
+  it 'Should return sles 11.4 when SUSE Linux Enterprise Server 11.4 is installed.' do
     allow(suse).to receive(:run_command) {
-      CommandResult.new(:stdout => 'SUSE Linux Enterprise Server 12', :exit_status => 0)
+      CommandResult.new(:stdout => "NAME=\"SLES\"\nVERSION=\"11.4\"\nVERSION_ID=\"11.4\"\nPRETTY_NAME=\"SUSE Linux Enterprise Server 11 SP4\"\nID=\"sles\"\nANSI_COLOR=\"0;32\"\nCPE_NAME=\"cpe:/o:suse:sles:11:4\"", :exit_status => 0)
     }
     expect(suse.detect).to include(
       :family  => 'sles',
-      :release => '12'
+      :release => '11.4'
     )
   end
 end
diff --git a/spec/host_inventory/linux/virtualization_spec.rb b/spec/host_inventory/linux/virtualization_spec.rb
index 5b844f1..d96e586 100644
--- a/spec/host_inventory/linux/virtualization_spec.rb
+++ b/spec/host_inventory/linux/virtualization_spec.rb
@@ -5,23 +5,23 @@ describe Specinfra::HostInventory::Virtualization do
     set :os, { :family => 'linux' }
   end
 
-  virt = Specinfra::HostInventory::Virtualization.new(host_inventory) 
+  virt = Specinfra::HostInventory::Virtualization.new(host_inventory)
   let(:host_inventory) { nil }
   it 'Docker Image should return :system => "docker"' do
-    allow(virt.backend).to receive(:run_command).with('ls /.dockerinit') do 
-      CommandResult.new(:stdout => '/.dockerinit', :exit_status => 0)
-    end  
+    allow(virt.backend).to receive(:run_command).with('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.dockerinit') do
+      CommandResult.new(:stdout => '', :exit_status => 0)
+    end
     expect(virt.get).to include(:system => 'docker')
   end
 
   let(:host_inventory) { nil }
   it 'Debian Wheezy on OpenVZ should return :system => "openvz"' do
-    allow(virt.backend).to receive(:run_command).with('ls /.dockerinit') do
+    allow(virt.backend).to receive(:run_command).with('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.dockerinit') do
       CommandResult.new(:stdout => '', :exit_status => 2)
-    end 
+    end
     allow(virt.backend).to receive(:run_command).with('test -d /proc/vz -a ! -d /proc/bc') do
       CommandResult.new(:stdout => '', :exit_status => 0)
-    end 
+    end
     expect(virt.get).to include(:system => 'openvz')
   end
 
diff --git a/spec/processor_spec.rb b/spec/processor_spec.rb
new file mode 100644
index 0000000..ce1f86e
--- /dev/null
+++ b/spec/processor_spec.rb
@@ -0,0 +1,63 @@
+require 'spec_helper'
+
+describe Specinfra::Processor do
+  describe 'check_file_is_mounted' do
+    let(:path) { '/proc' }
+    let(:cmd) { Specinfra.command.get(:check_file_is_mounted, path) }
+
+    def mock_output(stdout)
+      Specinfra::CommandResult.new :stdout => stdout
+    end
+
+    context 'freebsd' do
+      before do
+        allow(Specinfra.backend).to receive(:run_command).with(cmd) { mock_output 'procfs on /proc (procfs, local)' }
+      end
+      it 'true when fs type matches' do
+        expect(Specinfra::Processor.check_file_is_mounted(path, {:type => 'procfs'}, false)).to eq(true)
+      end
+      it 'false when fs type is different' do
+        expect(Specinfra::Processor.check_file_is_mounted(path, {:type => 'ufs'}, false)).to eq(false)
+      end
+      it 'true when option matches' do
+        expect(Specinfra::Processor.check_file_is_mounted(path, {:local => true}, false)).to eq(true)
+      end
+      it 'false when option is different' do
+        expect(Specinfra::Processor.check_file_is_mounted(path, {:async => true}, false)).to eq(false)
+      end
+      context 'only_with' do
+        it 'false when extra options present' do
+          expect(Specinfra::Processor.check_file_is_mounted(path, {:local => true, :async => true}, true)).to eq(false)
+        end
+        it 'true when all options met' do
+          expect(Specinfra::Processor.check_file_is_mounted(path, {:device => "procfs", :type => "procfs", :local => true}, true)).to eq(true)
+        end
+      end
+    end
+    context 'linux' do
+      before do
+        allow(Specinfra.backend).to receive(:run_command).with(cmd) { mock_output 'proc on /proc type proc (rw,noexec,nosuid,nodev)' }
+      end
+      it 'true when fs type matches' do
+        expect(Specinfra::Processor.check_file_is_mounted(path, {:type => 'proc'}, false)).to eq(true)
+      end
+      it 'false when fs type is different' do
+        expect(Specinfra::Processor.check_file_is_mounted(path, {:type => 'ufs'}, false)).to eq(false)
+      end
+      it 'true when option matches' do
+        expect(Specinfra::Processor.check_file_is_mounted(path, {:noexec => true, :nosuid => true}, false)).to eq(true)
+      end
+      it 'false when option is different' do
+        expect(Specinfra::Processor.check_file_is_mounted(path, {:noexec => true, :unknown => true}, false)).to eq(false)
+      end
+      context 'only_with' do
+        it 'false when extra options present' do
+          expect(Specinfra::Processor.check_file_is_mounted(path, {:noexec => true, :nosuid => true}, true)).to eq(false)
+        end
+        it 'true when all options are same' do
+          expect(Specinfra::Processor.check_file_is_mounted(path, {:noexec => true, :nosuid => true, :nodev => true, :rw => true, :device => "proc", :type => "proc"}, true)).to eq(true)
+        end
+      end
+    end
+  end
+end
diff --git a/specinfra.gemspec b/specinfra.gemspec
index 769f000..b175e61 100644
--- a/specinfra.gemspec
+++ b/specinfra.gemspec
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
   spec.require_paths = ["lib"]
 
   spec.add_runtime_dependency "net-scp"
-  spec.add_runtime_dependency "net-ssh", ">= 2.7", "< 4.0"
+  spec.add_runtime_dependency "net-ssh", ">= 2.7", "< 5.0"
   spec.add_runtime_dependency "net-telnet"
   spec.add_runtime_dependency "sfl"
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-specinfra.git



More information about the Pkg-ruby-extras-commits mailing list