~ubuntu-branches/ubuntu/utopic/facter/utopic

« back to all changes in this revision

Viewing changes to spec/unit/memory_spec.rb

  • Committer: Jamie Strandboge
  • Author(s): Adam Gandelman
  • Date: 2012-01-30 21:33:01 UTC
  • Revision ID: jamie@canonical.com-20120130213301-7swdz4hu5f69yhmj
Tags: 1.6.4-2ubuntu1
* Merge from Debian testing (LP: #922788). Remaining changes:
  - debian/rules: use what we had in natty; we don't want ruby-pkg-tools
    in main. (LP: #408402)
  - debian/control: Continue using ruby + libopenssl-ruby as Build-Depends
    even tho Debian has moved to gem2deb (not in main). Move ruby-json to
    Suggests.
  - debian/rules: Use dh_prep instead of dh_clean, add build-arch +
    build-indep targets
  - debian/control: Make binary package depend on ruby1.8 explicitly.
* Dropped changes:
  - debian/control: Update debhelper Build-Depends to 8 (Updated in Debian)
* Move dmidecode from Depends to Recommends (Closes: #651501)
* New upstream release
* Add dependency on dmidecode
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
require 'facter'
6
6
 
7
7
describe "Memory facts" do
8
 
    before do
9
 
        # We need these facts loaded, but they belong to a file with a
10
 
        # different name, so load the file explicitly.
11
 
        Facter.collection.loader.load(:memory)
12
 
    end
13
 
 
14
 
    after do
15
 
        Facter.clear
 
8
  before do
 
9
    # We need these facts loaded, but they belong to a file with a
 
10
    # different name, so load the file explicitly.
 
11
    Facter.collection.loader.load(:memory)
 
12
  end
 
13
 
 
14
  after do
 
15
    Facter.clear
 
16
  end
 
17
 
 
18
  it "should return the current swap size" do
 
19
 
 
20
    Facter.fact(:kernel).stubs(:value).returns("Darwin")
 
21
    Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M  used = 0.00M  free = 64.00M  (encrypted)")
 
22
    swapusage = "vm.swapusage: total = 64.00M  used = 0.00M  free = 64.00M  (encrypted)"
 
23
 
 
24
    if swapusage =~ /total = (\S+).*/
 
25
      Facter.fact(:swapfree).value.should == $1
 
26
    end
 
27
  end
 
28
 
 
29
  it "should return the current swap free" do
 
30
    Facter.fact(:kernel).stubs(:value).returns("Darwin")
 
31
    Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M  used = 0.00M  free = 64.00M  (encrypted)")
 
32
    swapusage = "vm.swapusage: total = 64.00M  used = 0.00M  free = 64.00M  (encrypted)"
 
33
 
 
34
    if swapusage =~ /free = (\S+).*/
 
35
      Facter.fact(:swapfree).value.should == $1
 
36
    end
 
37
  end
 
38
 
 
39
  it "should return whether swap is encrypted" do
 
40
    Facter.fact(:kernel).stubs(:value).returns("Darwin")
 
41
    Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M  used = 0.00M  free = 64.00M  (encrypted)")
 
42
    swapusage = "vm.swapusage: total = 64.00M  used = 0.00M  free = 64.00M  (encrypted)"
 
43
 
 
44
    swapusage =~ /\(encrypted\)/
 
45
    Facter.fact(:swapencrypted).value.should == true
 
46
  end
 
47
 
 
48
  describe "on OpenBSD" do
 
49
    before :each do
 
50
      Facter.clear
 
51
      Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
 
52
 
 
53
      swapusage = "total: 148342k bytes allocated = 0k used, 148342k available"
 
54
      Facter::Util::Resolution.stubs(:exec).with('swapctl -s').returns(swapusage)
 
55
 
 
56
      vmstat = <<EOS
 
57
 procs  memory     page          disks  traps      cpu
 
58
 r b w  avm   fre  flt  re  pi  po  fr  sr cd0 sd0  int   sys   cs us sy id
 
59
 0 0 0  11048  181028   39   0   0   0   0   0   0   1  3  90   17  0  0 100
 
60
EOS
 
61
      Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat)
 
62
 
 
63
      Facter::Util::Resolution.stubs(:exec).with("sysctl hw.physmem | cut -d'=' -f2").returns('267321344')
 
64
 
 
65
      Facter.collection.loader.load(:memory)
 
66
    end
 
67
 
 
68
    after :each do
 
69
      Facter.clear
 
70
    end
 
71
 
 
72
    it "should return the current swap free" do
 
73
      Facter.fact(:swapfree).value.should == "144.87 MB"
16
74
    end
17
75
 
18
76
    it "should return the current swap size" do
19
 
 
20
 
        Facter.fact(:kernel).stubs(:value).returns("Darwin")
21
 
        Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M  used = 0.00M  free = 64.00M  (encrypted)")
22
 
        swapusage = "vm.swapusage: total = 64.00M  used = 0.00M  free = 64.00M  (encrypted)"
23
 
 
24
 
        if swapusage =~ /total = (\S+).*/
25
 
            Facter.fact(:swapfree).value.should == $1
26
 
        end
27
 
    end
28
 
 
29
 
    it "should return the current swap free" do
30
 
        Facter.fact(:kernel).stubs(:value).returns("Darwin")
31
 
        Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M  used = 0.00M  free = 64.00M  (encrypted)")
32
 
        swapusage = "vm.swapusage: total = 64.00M  used = 0.00M  free = 64.00M  (encrypted)"
33
 
 
34
 
        if swapusage =~ /free = (\S+).*/
35
 
            Facter.fact(:swapfree).value.should == $1
36
 
        end
37
 
    end
38
 
 
39
 
    it "should return whether swap is encrypted" do
40
 
        Facter.fact(:kernel).stubs(:value).returns("Darwin")
41
 
        Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M  used = 0.00M  free = 64.00M  (encrypted)")
42
 
        swapusage = "vm.swapusage: total = 64.00M  used = 0.00M  free = 64.00M  (encrypted)"
43
 
 
44
 
        swapusage =~ /\(encrypted\)/
45
 
        Facter.fact(:swapencrypted).value.should == true
46
 
    end
47
 
 
48
 
    describe "on OpenBSD" do
49
 
        before :each do
50
 
            Facter.clear
51
 
            Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
52
 
 
53
 
            swapusage = "total: 148342k bytes allocated = 0k used, 148342k available"
54
 
            Facter::Util::Resolution.stubs(:exec).with('swapctl -s').returns(swapusage)
55
 
 
56
 
            vmstat = <<EOS
57
 
 procs    memory       page                    disks    traps          cpu
58
 
 r b w    avm     fre  flt  re  pi  po  fr  sr cd0 sd0  int   sys   cs us sy id
59
 
 0 0 0  11048  181028   39   0   0   0   0   0   0   1    3    90   17  0  0 100
60
 
EOS
61
 
            Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat)
62
 
 
63
 
            Facter::Util::Resolution.stubs(:exec).with("sysctl hw.physmem | cut -d'=' -f2").returns('267321344')
64
 
 
65
 
            Facter.collection.loader.load(:memory)
66
 
        end
67
 
 
68
 
        after :each do
69
 
            Facter.clear
70
 
        end
71
 
 
72
 
        it "should return the current swap free" do
73
 
            Facter.fact(:swapfree).value.should == "144.87 MB"
74
 
        end
75
 
 
76
 
        it "should return the current swap size" do
77
 
            Facter.fact(:swapsize).value.should == "144.87 MB"
78
 
        end
79
 
 
80
 
        it "should return the current memorysize" do
81
 
            Facter.fact(:memorytotal).value.should == "254.94 MB"
82
 
        end
83
 
    end
84
 
 
85
 
    describe "on DragonFly BSD" do
86
 
        before :each do
87
 
            Facter.clear
88
 
            Facter.fact(:kernel).stubs(:value).returns("dragonfly")
89
 
 
90
 
            swapusage = "total: 148342k bytes allocated = 0k used, 148342k available"
91
 
            Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n hw.pagesize').returns("4096")
92
 
            Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_size').returns("128461")
93
 
            Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_anon_use').returns("2635")
94
 
            Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_cache_use').returns("0")
95
 
 
96
 
            vmstat = <<EOS
97
 
 procs      memory      page                    disks     faults      cpu
98
 
 r b w     avm    fre  flt  re  pi  po  fr  sr da0 sg1   in   sy  cs us sy id
 
77
      Facter.fact(:swapsize).value.should == "144.87 MB"
 
78
    end
 
79
 
 
80
    it "should return the current memorysize" do
 
81
      Facter.fact(:memorytotal).value.should == "254.94 MB"
 
82
    end
 
83
  end
 
84
 
 
85
  describe "on DragonFly BSD" do
 
86
    before :each do
 
87
      Facter.clear
 
88
      Facter.fact(:kernel).stubs(:value).returns("dragonfly")
 
89
 
 
90
      swapusage = "total: 148342k bytes allocated = 0k used, 148342k available"
 
91
      Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n hw.pagesize').returns("4096")
 
92
      Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_size').returns("128461")
 
93
      Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_anon_use').returns("2635")
 
94
      Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_cache_use').returns("0")
 
95
 
 
96
      vmstat = <<EOS
 
97
 procs    memory    page          disks   faults    cpu
 
98
 r b w   avm  fre  flt  re  pi  po  fr  sr da0 sg1   in   sy  cs us sy id
99
99
 0 0 0   33152  13940 1902120 2198 53119 11642 6544597 5460994   0   0 6148243 7087927 3484264  0  1 9
100
100
EOS
101
 
            Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat)
102
 
 
103
 
            Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.physmem").returns('248512512')
104
 
 
105
 
            Facter.collection.loader.load(:memory)
106
 
        end
107
 
 
108
 
        after :each do
109
 
            Facter.clear
110
 
        end
111
 
 
112
 
        it "should return the current swap free" do
113
 
            Facter.fact(:swapfree).value.should == "491.51 MB"
114
 
        end
115
 
 
116
 
        it "should return the current swap size" do
117
 
            Facter.fact(:swapsize).value.should == "501.80 MB"
118
 
        end
119
 
 
120
 
        it "should return the current memorysize" do
121
 
            Facter.fact(:memorytotal).value.should == "237.00 MB"
122
 
        end
123
 
    end
124
 
 
125
 
    describe "on Windows" do
126
 
        before :each do
127
 
             Facter.clear
128
 
             Facter.fact(:kernel).stubs(:value).returns("windows")
129
 
             Facter.collection.loader.load(:memory)
130
 
 
131
 
             require 'facter/util/wmi'
132
 
        end
133
 
 
134
 
        it "should return free memory" do
135
 
             os = stubs 'os'
136
 
             os.stubs(:FreePhysicalMemory).returns("3415624")
137
 
             Facter::Util::WMI.stubs(:execquery).returns([os])
138
 
 
139
 
             Facter.fact(:MemoryFree).value.should == '3.26 GB'
140
 
        end
141
 
 
142
 
        it "should return total memory" do
143
 
             computer = stubs 'computer'
144
 
             computer.stubs(:TotalPhysicalMemory).returns("4193837056")
145
 
             Facter::Util::WMI.stubs(:execquery).returns([computer])
146
 
 
147
 
             Facter.fact(:MemoryTotal).value.should == '3.91 GB'
148
 
        end
149
 
    end
 
101
      Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat)
 
102
 
 
103
      Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.physmem").returns('248512512')
 
104
 
 
105
      Facter.collection.loader.load(:memory)
 
106
    end
 
107
 
 
108
    after :each do
 
109
      Facter.clear
 
110
    end
 
111
 
 
112
    it "should return the current swap free" do
 
113
      Facter.fact(:swapfree).value.should == "491.51 MB"
 
114
    end
 
115
 
 
116
    it "should return the current swap size" do
 
117
      Facter.fact(:swapsize).value.should == "501.80 MB"
 
118
    end
 
119
 
 
120
    it "should return the current memorysize" do
 
121
      Facter.fact(:memorytotal).value.should == "237.00 MB"
 
122
    end
 
123
  end
 
124
 
 
125
  describe "on Windows" do
 
126
    before :each do
 
127
      Facter.clear
 
128
      Facter.fact(:kernel).stubs(:value).returns("windows")
 
129
      Facter.collection.loader.load(:memory)
 
130
 
 
131
      require 'facter/util/wmi'
 
132
    end
 
133
 
 
134
    it "should return free memory" do
 
135
      os = stubs 'os'
 
136
      os.stubs(:FreePhysicalMemory).returns("3415624")
 
137
      Facter::Util::WMI.stubs(:execquery).returns([os])
 
138
 
 
139
      Facter.fact(:MemoryFree).value.should == '3.26 GB'
 
140
    end
 
141
 
 
142
    it "should return total memory" do
 
143
      computer = stubs 'computer'
 
144
      computer.stubs(:TotalPhysicalMemory).returns("4193837056")
 
145
      Facter::Util::WMI.stubs(:execquery).returns([computer])
 
146
 
 
147
      Facter.fact(:MemoryTotal).value.should == '3.91 GB'
 
148
    end
 
149
  end
150
150
end