Sha256: 3e6e0bc26b59cab02f148bf860af1aa365d85d50d04ab5739527f69e46efb88d

Contents?: true

Size: 924 Bytes

Versions: 6

Compression:

Stored size: 924 Bytes

Contents

module Specinfra::Backend
  class Lxc < Exec
    def initialize
      begin
        require 'lxc/extra' unless defined?(::LXC::Extra)
      rescue LoadError
        fail "LXC client library is not available. Try installing `lxc-extra' gem"
      end
    end

    def run_command(cmd, opts={})
      cmd = build_command(cmd)
      cmd = add_pre_command(cmd)
      out, ret = ct.execute do
        out = `#{cmd}  2>&1`
        [out, $?.dup]
      end
      if @example
        @example.metadata[:command] = cmd
        @example.metadata[:stdout]  = out
      end
      CommandResult.new :stdout => out, :exit_status => ret.exitstatus
    end

    def build_command(cmd)
      cmd
    end

    def add_pre_command(cmd)
      cmd
    end

    def send_file(from, to)
      FileUtils.cp(from, File.join(ct.config_item('lxc.rootfs'), to))
    end

    def ct
      @ct ||= ::LXC::Container.new(get_config(:lxc))
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
specinfra-2.25.0 lib/specinfra/backend/lxc.rb
specinfra-2.24.2 lib/specinfra/backend/lxc.rb
specinfra-2.24.1 lib/specinfra/backend/lxc.rb
specinfra-2.24.0 lib/specinfra/backend/lxc.rb
specinfra-2.23.0 lib/specinfra/backend/lxc.rb
specinfra-2.22.0 lib/specinfra/backend/lxc.rb