Class: ProviderTesting::Sfcb

Inherits:
Object
  • Object
show all
Defined in:
lib/provider-testing/sfcb.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Sfcb

Returns a new instance of Sfcb.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/provider-testing/sfcb.rb', line 13

def initialize args = {}
  @execfile = "/usr/sbin/sfcbd"
  @port = 12345
  @pid = nil

  tmpdir = args[:tmpdir] || Dir.tmpdir

  File.directory?(tmpdir) || Dir.mkdir(tmpdir)

  @dir = File.join(tmpdir, "sfcb")
  Dir.mkdir @dir rescue nil

#    STDERR.puts "Sfcb directory at #{@dir}"

  # location of cmpi-bindings for Ruby
  @providers_dir = PROVIDERDIR

  @stage_dir = File.join(dir, "stage")
  Dir.mkdir @stage_dir rescue nil
  File.symlink("/var/lib/sfcb/stage/default.reg", File.join(@stage_dir, "default.reg")) rescue nil
  @mofs_dir = args[:mof] || File.join(@stage_dir, "mofs")
  Dir.mkdir @mofs_dir rescue nil

  @registration_dir = args[:registration] || File.join(dir, "registration")
  Dir.mkdir @registration_dir rescue nil

#    Kernel.system "sfcbrepos", "-s", @stage_dir, "-r", @registration_dir, "-f"

  @uri = URI::HTTP.build :host => 'localhost', :port => @port, :userinfo => "wsman:secret"
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



11
12
13
# File 'lib/provider-testing/sfcb.rb', line 11

def dir
  @dir
end

#pidObject (readonly)

Returns the value of attribute pid.



11
12
13
# File 'lib/provider-testing/sfcb.rb', line 11

def pid
  @pid
end

#providers_dirObject (readonly)

Returns the value of attribute providers_dir.



11
12
13
# File 'lib/provider-testing/sfcb.rb', line 11

def providers_dir
  @providers_dir
end

#registration_dirObject (readonly)

Returns the value of attribute registration_dir.



11
12
13
# File 'lib/provider-testing/sfcb.rb', line 11

def registration_dir
  @registration_dir
end

#stage_dirObject (readonly)

Returns the value of attribute stage_dir.



11
12
13
# File 'lib/provider-testing/sfcb.rb', line 11

def stage_dir
  @stage_dir
end

#uriObject (readonly)

Returns the value of attribute uri.



11
12
13
# File 'lib/provider-testing/sfcb.rb', line 11

def uri
  @uri
end

Instance Method Details

#mkcfgObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/provider-testing/sfcb.rb', line 44

def mkcfg
  @cfgfile = File.join(@dir, "sfcb.cfg")
  File.open(@cfgfile, "w+") do |f|
    # create sfcb config file

    {
  "enableHttp" => true,
  "httpPort" => @port,
  "enableHttps" => false,
  "enableSlp" => false,
      "providerSampleInterval" => 5,
  "providerTimeoutInterval" => 10,
      "keepaliveTimeout" => 2,
  "registrationDir" => @registration_dir,
  "localSocketPath" => File.join(@dir, "sfcbLocalSocket"),
  "httpSocketPath" => File.join(@dir, "sfcbHttpSocket"),
  "providerDirs" => " #{@providers_dir} /usr/lib64/sfcb /usr/lib/sfcb /usr/lib64 /usr/lib /usr/lib64/cmpi /usr/lib/cmpi"
    }.each do |k,v|
  f.puts "#{k}: #{v}"
    end
  end
end

#startObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/provider-testing/sfcb.rb', line 67

def start
  raise "Already running" if @pid
  @pid = fork
  if @pid.nil?
    # child
    sfcb_trace_file = File.join(TMPDIR, "sfcb_trace_file")
    sblim_trace_file = File.join(TMPDIR, "sblim_trace_file")
    ruby_providers_dir = PROVIDERDIR
    Dir.chdir File.expand_path("..", File.dirname(__FILE__))
    {
  "SFCB_TRACE_FILE" => sfcb_trace_file,
      "SFCB_TRACE" => 4,
      "SBLIM_TRACE_FILE" => sblim_trace_file,
      "SBLIM_TRACE" => 4,
#        "CMPI_BINDINGS_TRACE_LEVEL" => 4,
#        "CMPISFCC_DEBUG" => "true",
      "RUBY_PROVIDERS_DIR" => ruby_providers_dir
    }.each do |k,v|
      ENV[k] = v.to_s
    end
    File.delete(sfcb_trace_file) rescue nil
    File.delete(sblim_trace_file) rescue nil
    $stderr.reopen(File.join(TMPDIR, "sfcbd.err"), "w")
    $stdout.reopen(File.join(TMPDIR, "sfcbd.out"), "w")
    Kernel.exec "#{@execfile}", "-c", "#{@cfgfile}"#, "-t", "32768"
  end
  @pid
end

#stopObject



96
97
98
99
100
101
102
# File 'lib/provider-testing/sfcb.rb', line 96

def stop
  return unless @pid
  Process.kill "QUIT", @pid
  sleep 3
  Process.wait
  @pid = nil
end