|
41 | 41 |
|
42 | 42 | describe "nor is 'sysctl kern.boottime'" do |
43 | 43 | before :each do |
44 | | - Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{@nonexistent_file}\"") |
| 44 | + Facter::Util::Uptime.stubs(:uptime_proc_uptime).returns(false) |
| 45 | + Facter::Util::Uptime.stubs(:uptime_sysctl).returns(false) |
| 46 | + Facter.fact(:kernel).stubs(:value).returns('SunOS') |
45 | 47 | end |
46 | 48 |
|
47 | | - it "should use 'kstat -p unix:::boot_time'" do |
48 | | - kstat_output_file = my_fixture('kstat_boot_time') # unix:0:system_misc:boot_time 1236919980 |
49 | | - Facter::Util::Uptime.stubs(:uptime_kstat_cmd).returns("cat \"#{kstat_output_file}\"") |
50 | | - Time.stubs(:now).returns Time.at(1236923580) #one hour later |
51 | | - Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60 |
52 | | - end |
53 | | - |
54 | | - describe "nor is 'kstat -p unix:::boot_time'" do |
55 | | - before :each do |
56 | | - Facter::Util::Uptime.stubs(:uptime_kstat_cmd).returns("cat \"#{@nonexistent_file}\"") |
57 | | - end |
| 49 | + describe "should use 'uptime' command" do |
| 50 | + # Note about uptime variations. |
| 51 | + # Solaris (I have examined 5.6, 5.7, 5.8, 5.9, 5.10 & 5.11) and HP-UX (11.00, 11.11, 11.23, 11.31) have time |
| 52 | + # right justified at at 8 characters, and two spaces before 'up'. |
| 53 | + # Solaris differs from all other Unices (and Linux) in that the plural/singular case of minutes/hours/days are |
| 54 | + # written min(s)/hr(s)/day(s) instead of min/mins/hr/hrs etc., e.g. 1 min(s), 2 min(s) as opposed to |
| 55 | + # 1 min, 2 mins, etc. |
| 56 | + # AIX (4.3.3, 5.2, 5.3, 6.1) differs from other SysV Unices in that times are padded with a leading 0 in the |
| 57 | + # hour column where necessary, and have AM/PM in uppercase, and there are three spaces before 'up'. |
| 58 | + # Tru64 (4.0, 5.1) differs from other SysV Unices in that times are in 24 hour format, and there are no |
| 59 | + # leading spaces. |
| 60 | + # Linux (RHEL, uptime version 2.0.7) differs from the SysV Unices in that only minutes before the first hour |
| 61 | + # are written as 1 min, 2 min, 3 min etc. and after that full hours are rendered 1:00 or 21:00. Time of |
| 62 | + # day was written 5:37pm and right-justified at 8 characters, with 2 spaces before 'up'. A figure in |
| 63 | + # whole days was written as 3 days, 0 min. |
| 64 | + # By version 2.0.17 the time of day was rewritten in 24hr time with seconds, right-justified at 9 characters. |
| 65 | + # By version 3.2.7 one of the spaces before 'up' had been removed. |
| 66 | + test_cases = [ |
| 67 | + [' 4:42pm up 1 min(s), 0 users, load average: 0.95, 0.25, 0.09', 1*60], |
| 68 | + ['13:16 up 58 mins, 2 users, load average: 0.00, 0.02, 0.05', 58*60], |
| 69 | + ['13:18 up 1 hr, 1 user, load average: 0.58, 0.23, 0.14', 1*60*60 ], |
| 70 | + [' 10:14pm up 3 hr(s), 0 users, load average: 0.00, 0.00, 0.00', 3*60*60 ], |
| 71 | + ['14:18 up 2 hrs, 0 users, load average: 0.33, 0.27, 0.29', 2*60*60 ], |
| 72 | + [' 9:01pm up 1:47, 0 users, load average: 0.00, 0.00, 0.00', 1*60*60 + 47*60], |
| 73 | + ['13:19 up 1:01, 1 user, load average: 0.10, 0.26, 0.21', 1*60*60 + 1*60], |
| 74 | + ['10:49 up 22:31, 0 users, load average: 0.26, 0.34, 0.27', 22*60*60 + 31*60], |
| 75 | + ['12:18 up 1 day, 0 users, load average: 0.74, 0.20, 0.10', 1*24*60*60 ], |
| 76 | + [' 2:48pm up 1 day(s), 0 users, load average: 0.21, 0.20, 0.17', 1*24*60*60 ], |
| 77 | + ['12:18 up 2 days, 0 users, load average: 0.50, 0.27, 0.16', 2*24*60*60 ], |
| 78 | + [' 1:56pm up 25 day(s), 2 users, load average: 0.59, 0.56, 0.50', 25*24*60*60 ], |
| 79 | + [' 1:29pm up 485 days, 0 users, load average: 0.00, 0.01, 0.01', 485*24*60*60 ], |
| 80 | + [' 18:11:24 up 69 days, 0 min, 0 users, load average: 0.00, 0.00, 0.00', 69*24*60*60 ], |
| 81 | + ['12:19 up 1 day, 1 min, 0 users, load average: 0.07, 0.16, 0.13', 1*24*60*60 + 1*60], |
| 82 | + [' 3:23pm up 25 day(s), 27 min(s), 2 users, load average: 0.49, 0.45, 0.46', 25*24*60*60 + 27*60], |
| 83 | + [' 02:42PM up 1 day, 39 mins, 0 users, load average: 1.49, 1.74, 1.80', 1*24*60*60 + 39*60], |
| 84 | + [' 18:13:13 up 245 days, 44 min, 1 user, load average: 0.00, 0.00, 0.00', 245*24*60*60 + 44*60], |
| 85 | + [' 6:09pm up 350 days, 2 min, 1 user, load average: 0.02, 0.03, 0.00', 350*24*60*60 + 2*60], |
| 86 | + [' 1:07pm up 174 day(s), 16 hr(s), 0 users, load average: 0.05, 0.04, 0.03', 174*24*60*60 + 16*60*60 ], |
| 87 | + [' 02:34PM up 621 days, 18 hrs, 0 users, load average: 2.67, 2.52, 2.56', 621*24*60*60 + 18*60*60 ], |
| 88 | + [' 3:30am up 108 days, 1 hr, 31 users, load average: 0.39, 0.40, 0.41', 108*24*60*60 + 1*60*60 ], |
| 89 | + ['13:18 up 1 day, 1 hr, 0 users, load average: 0.78, 0.33, 0.18', 1*24*60*60 + 1*60*60 ], |
| 90 | + ['14:18 up 1 day, 2 hrs, 0 users, load average: 1.17, 0.48, 0.41', 1*24*60*60 + 2*60*60 ], |
| 91 | + ['15:56 up 152 days, 17 hrs, 0 users, load average: 0.01, 0.06, 0.07', 152*24*60*60 + 17*60*60 ], |
| 92 | + [' 5:37pm up 25 days, 21:00, 0 users, load average: 0.01, 0.02, 0.00', 25*24*60*60 + 21*60*60 ], |
| 93 | + [' 8:59pm up 94 day(s), 3:17, 46 users, load average: 0.66, 0.67, 0.70', 94*24*60*60 + 3*60*60 + 17*60], |
| 94 | + [' 3:01pm up 4496 day(s), 21:19, 32 users, load average: 0.61, 0.62, 0.62', 4496*24*60*60 + 21*60*60 + 19*60], |
| 95 | + [' 02:42PM up 41 days, 2:38, 0 users, load average: 0.38, 0.70, 0.55', 41*24*60*60 + 2*60*60 + 38*60], |
| 96 | + [' 18:13:29 up 25 days, 21:36, 0 users, load average: 0.00, 0.00, 0.00', 25*24*60*60 + 21*60*60 + 36*60], |
| 97 | + [' 13:36:05 up 118 days, 1:15, 1 user, load average: 0.00, 0.00, 0.00', 118*24*60*60 + 1*60*60 + 15*60] |
| 98 | + ] |
58 | 99 |
|
59 | | - it "should use 'who -b'" do |
60 | | - who_b_output_file = my_fixture('who_b_boottime') # Aug 1 14:13 |
61 | | - Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat \"#{who_b_output_file}\"") |
62 | | - Time.stubs(:now).returns Time.parse("Aug 01 15:13") # one hour later |
63 | | - Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60 |
| 100 | + test_cases.each do |uptime, expected| |
| 101 | + it "should return #{expected} for #{uptime}" do |
| 102 | + Facter::Util::Resolution.stubs(:exec).with('uptime 2>/dev/null').returns(uptime) |
| 103 | + Facter.fact(:uptime_seconds).value.should == expected |
| 104 | + end |
64 | 105 | end |
65 | 106 |
|
66 | | - describe "nor is 'who -b'" do |
| 107 | + describe "nor is 'uptime' command" do |
67 | 108 | before :each do |
68 | | - Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat \"#{@nonexistent_file}\"") |
| 109 | + Facter::Util::Uptime.stubs(:uptime_executable_cmd).returns("cat \"#{@nonexistent_file}\"") |
69 | 110 | end |
70 | 111 |
|
71 | 112 | it "should return nil" do |
|
0 commit comments