Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

[OHAI-458] Include Joyent SmartOS specific attributes in Ohai #133

Open
wants to merge 2 commits into from

1 participant

sawanoboly
sawanoboly

Hi,

This is code of OHAI-458.

Attribute Sample


"joyent"=>
  {"sm_uuid"=>"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
   "sm_id"=>"5",
   "sm_image_id"=>"chefserver",
   "sm_image_ver"=>"1.0.18",
   "sm_baseimage_id"=>"base64",
   "sm_baseimage_ver"=>"1.8.4",
   "sm_pkgsrc"=>"http://pkgsrc.joyent.com/sdc6/2012Q2/x86_64/All"}}

Test


$ rspec -fd --color spec/unit/plugins/joyent_spec.rb 
Run options: exclude {:requires_root=>true, :ruby_18_only=>true, :windows_only=>true}

Ohai::System plugin joyent
  without joyent
    should NOT create joyent
  with joyent
    should create joyent
    under global zone
      should ditect global zone
      should NOT create sm_id
    under smartmachine
      should retrive zone uuid
      should create sm_id

Finished in 0.01397 seconds
6 examples, 0 failures

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
58  lib/ohai/plugins/joyent.rb
... ...
@@ -0,0 +1,58 @@
  1
+# 
  2
+# Author: sawanoboriyu@higanworks.com
  3
+# Copyright (C) 2013 HiganWorks LLC
  4
+# License:: Apache License, Version 2.0
  5
+#
  6
+# Licensed under the Apache License, Version 2.0 (the "License");
  7
+# you may not use this file except in compliance with the License.
  8
+# You may obtain a copy of the License at
  9
+#
  10
+# http://www.apache.org/licenses/LICENSE-2.0
  11
+#
  12
+# Unless required by applicable law or agreed to in writing, software
  13
+# distributed under the License is distributed on an "AS IS" BASIS,
  14
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15
+# See the License for the specific language governing permissions and
  16
+# limitations under the License.
  17
+#
  18
+#
  19
+
  20
+# Reference from: sm-summary command
  21
+
  22
+provides "joyent"
  23
+require_plugin "os"
  24
+require_plugin "platform"
  25
+
  26
+if platform == "smartos" then
  27
+  joyent Mash.new
  28
+
  29
+  # get uuid
  30
+  status, stdout, stderr  = run_command(:no_status_check => true, :command => "/usr/bin/zonename")
  31
+  joyent[:sm_uuid] = stdout.chomp
  32
+
  33
+  # get zone id unless globalzone
  34
+  status, stdout, stderr  = run_command(:no_status_check => true, :command => "/usr/sbin/zoneadm list -p | awk -F: '{ print $1 }'")
  35
+  joyent[:sm_id] = stdout.chomp unless joyent[:sm_uuid] == "global"
  36
+  
  37
+  # retrieve image name and pkgsrc
  38
+  if ::File.exists?("/etc/product") then
  39
+    ::File.open("/etc/product") do |file|
  40
+      while line = file.gets
  41
+        case line
  42
+        when /^Image/
  43
+          sm_image = line.split(" ") 
  44
+          joyent[:sm_image_id] = sm_image[1]
  45
+          joyent[:sm_image_ver] = sm_image[2]
  46
+        when /^Base Image/
  47
+          sm_baseimage = line.split(" ")
  48
+          joyent[:sm_baseimage_id] = sm_baseimage[2]
  49
+          joyent[:sm_baseimage_ver] = sm_baseimage[3]
  50
+        end
  51
+      end
  52
+    end
  53
+
  54
+    ## retrieve pkgsrc
  55
+    sm_pkgsrc = ::File.read("/opt/local/etc/pkg_install.conf").split("=")
  56
+    joyent[:sm_pkgsrc] = sm_pkgsrc[1].chomp
  57
+  end
  58
+end
86  spec/unit/plugins/joyent_spec.rb
... ...
@@ -0,0 +1,86 @@
  1
+require 'spec_helper'
  2
+
  3
+
  4
+describe Ohai::System, "plugin joyent" do
  5
+  before(:each) do
  6
+    @ohai = Ohai::System.new
  7
+    @ohai.stub!(:require_plugin).and_return(true)
  8
+    #@ohai[:platform] = "smartos"
  9
+  end
  10
+
  11
+  describe "without joyent" do
  12
+    before(:each) do
  13
+      @ohai[:platform] = "otheros"
  14
+    end
  15
+
  16
+    it "should NOT create joyent" do
  17
+      @ohai._require_plugin("joyent")
  18
+      @ohai[:joyent].should be_nil
  19
+    end
  20
+  end
  21
+
  22
+  describe "with joyent" do
  23
+    before(:each) do
  24
+      @ohai[:platform] = "smartos"
  25
+    end
  26
+
  27
+    it "should create joyent" do
  28
+      @ohai._require_plugin("joyent")
  29
+      @ohai[:joyent].should_not be_nil
  30
+    end
  31
+
  32
+    describe "under global zone" do
  33
+      before(:each) do
  34
+        @status = 0
  35
+        @stdout = "global\n"
  36
+        @stderr = ""
  37
+        @ohai.stub!(:run_command).with(:no_status_check => true, :command => "/usr/bin/zonename").and_return([@status, @stdout, @stderr])
  38
+        @ohai._require_plugin("joyent")
  39
+      end
  40
+
  41
+      it "should ditect global zone" do
  42
+        @ohai[:joyent][:sm_uuid].should == "global"
  43
+      end
  44
+
  45
+      it "should NOT create sm_id" do
  46
+        @ohai[:joyent][:sm_id].should be_nil
  47
+      end
  48
+    end
  49
+
  50
+    describe "under smartmachine" do
  51
+      before(:each) do
  52
+        # stub zonename
  53
+        status = 0
  54
+        stdout = "xxxxx-xxxxx-xxxxx\n"
  55
+        stderr = ""
  56
+        @ohai.stub!(:run_command).with(:no_status_check => true, :command => "/usr/bin/zonename").and_return([status, stdout, stderr])
  57
+
  58
+        #stub zoneadm
  59
+        status = 0
  60
+        stdout = "99\n"
  61
+        stderr = ""
  62
+        @ohai.stub!(:run_command).with(:no_status_check => true, :command => "/usr/sbin/zoneadm list -p | awk -F: '{ print $1 }'").and_return([status, stdout, stderr])
  63
+      end
  64
+
  65
+      it "should retrive zone uuid" do
  66
+        @ohai._require_plugin("joyent")
  67
+        @ohai[:joyent][:sm_uuid].should == "xxxxx-xxxxx-xxxxx"
  68
+      end
  69
+
  70
+      it "should create sm_id" do
  71
+        @ohai._require_plugin("joyent")
  72
+        @ohai[:joyent][:sm_id].should == "99"
  73
+      end
  74
+
  75
+#       it "should retrive pkgsrc" do
  76
+#         # file stub /opt/local/etc/pkg_install.conf
  77
+#         file = mock
  78
+#         ::File.stub!(:read).with("/opt/local/etc/pkg_install.conf").and_return("PKG_PATH=http://pkgsrc.joyent.com/packages/SmartOS/2012Q4/x86_64/All\n")
  79
+# 
  80
+#         @ohai._require_plugin("joyent")
  81
+#         @ohai[:joyent][:sm_pkgsrc].should == "http://pkgsrc.joyent.com/packages/SmartOS/2012Q4/x86_64/All"
  82
+#       end
  83
+    end
  84
+  end
  85
+end
  86
+
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.