linux_admin 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ae83085610c76ae512132f71299833426b68c566
4
+ data.tar.gz: 37a232193db39e75850aee03e397c87988a9b99f
5
+ SHA512:
6
+ metadata.gz: 41b4c8a63752bcbcb11fdd9f20161847a861e88d2c86f4b1f34cf21238d5e069a04d8e6a498e53d0f1d7f1f3d844c9394100232137f24477ca8d44e1a09cb273
7
+ data.tar.gz: 7347bac8c99654f4a357907ca81deac4e7466d8b3b135ddaafa7fc7a1522727fa2a259c66d0bd2c2ce0d48b11340701f7bad978614ffa03de5c2a1b3c7bd80cd
data/README.md CHANGED
@@ -1,17 +1,15 @@
1
1
  # LinuxAdmin
2
- [![Gem Version](https://badge.fury.io/rb/linux_admin.png)](http://badge.fury.io/rb/linux_admin)
3
- [![Build Status](https://travis-ci.org/ManageIQ/linux_admin.png)](https://travis-ci.org/ManageIQ/linux_admin)
4
- [![Code Climate](https://codeclimate.com/github/ManageIQ/linux_admin.png)](https://codeclimate.com/github/ManageIQ/linux_admin)
5
- [![Coverage Status](https://coveralls.io/repos/ManageIQ/linux_admin/badge.png?branch=master)](https://coveralls.io/r/ManageIQ/linux_admin)
6
- [![Dependency Status](https://gemnasium.com/ManageIQ/linux_admin.png)](https://gemnasium.com/ManageIQ/linux_admin)
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/linux_admin.svg)](http://badge.fury.io/rb/linux_admin)
4
+ [![Build Status](https://travis-ci.org/ManageIQ/linux_admin.svg)](https://travis-ci.org/ManageIQ/linux_admin)
5
+ [![Code Climate](http://img.shields.io/codeclimate/github/ManageIQ/linux_admin.svg)](https://codeclimate.com/github/ManageIQ/linux_admin)
6
+ [![Coverage Status](http://img.shields.io/coveralls/ManageIQ/linux_admin.svg)](https://coveralls.io/r/ManageIQ/linux_admin)
7
+ [![Dependency Status](https://gemnasium.com/ManageIQ/linux_admin.svg)](https://gemnasium.com/ManageIQ/linux_admin)
7
8
 
8
9
  LinuxAdmin is a module to simplify management of linux systems.
9
10
  It should be a single place to manage various system level configurations,
10
11
  registration, updates, etc.
11
12
 
12
- ## Supported Rubies
13
- * MRI 1.9
14
-
15
13
  ## Installation
16
14
 
17
15
  Add this line to your application's Gemfile:
@@ -53,11 +53,11 @@ class LinuxAdmin
53
53
  end
54
54
 
55
55
  def detected_by_etc_release?
56
- release_file && File.exists?(release_file)
56
+ release_file && File.exist?(release_file)
57
57
  end
58
58
 
59
59
  def command(name)
60
- @path.collect { |dir| "#{dir}/#{name}" }.detect { |cmd| File.exists?(cmd) }
60
+ @path.collect { |dir| "#{dir}/#{name}" }.detect { |cmd| File.exist?(cmd) }
61
61
  end
62
62
 
63
63
  def info(pkg)
@@ -16,7 +16,7 @@ class LinuxAdmin
16
16
  end
17
17
 
18
18
  def data
19
- @data ||= File.exists?(PATH) ? File.read(PATH) : ""
19
+ @data ||= File.exist?(PATH) ? File.read(PATH) : ""
20
20
  end
21
21
 
22
22
  def refresh
@@ -70,7 +70,6 @@ class LinuxAdmin
70
70
 
71
71
  def write!
72
72
  content = ''
73
- comment_index = 0
74
73
  @entries.each do |entry|
75
74
  if entry.has_content?
76
75
  content << entry.formatted_columns(@maximum_column_lengths) << "\n"
@@ -11,11 +11,8 @@ class LinuxAdmin
11
11
 
12
12
  DEVICE_PATH = Pathname.new('/dev/')
13
13
 
14
- # path to logical volume
15
- attr_accessor :path
16
-
17
14
  # logical volume name
18
- attr_accessor :name
15
+ attr_reader :name
19
16
 
20
17
  # volume group name
21
18
  attr_accessor :volume_group
@@ -35,6 +32,11 @@ class LinuxAdmin
35
32
  # major device number of logical volume
36
33
  # minor device number of logical volume
37
34
 
35
+ # path to logical volume
36
+ def path
37
+ "/dev/#{self.volume_group.name}/#{self.name}"
38
+ end
39
+
38
40
  def path=(value)
39
41
  @path = value.include?(File::SEPARATOR) ? value : DEVICE_PATH.join(@volume_group.name, value)
40
42
  end
@@ -57,10 +59,6 @@ class LinuxAdmin
57
59
  self
58
60
  end
59
61
 
60
- def path
61
- "/dev/#{self.volume_group.name}/#{self.name}"
62
- end
63
-
64
62
  private
65
63
 
66
64
  def self.bytes_to_string(bytes)
@@ -7,7 +7,7 @@ class LinuxAdmin
7
7
 
8
8
  def registered?
9
9
  id = ""
10
- if File.exists?(systemid_file)
10
+ if File.exist?(systemid_file)
11
11
  xml = Nokogiri.XML(File.read(systemid_file))
12
12
  id = xml.xpath('/params/param/value/struct/member[name="system_id"]/value/string').text
13
13
  end
@@ -103,4 +103,4 @@ class LinuxAdmin
103
103
  "/etc/sysconfig/rhn/systemid"
104
104
  end
105
105
  end
106
- end
106
+ end
@@ -9,7 +9,7 @@ class LinuxAdmin
9
9
  raise
10
10
  end
11
11
 
12
- SATELLITE6_SERVER_CERT_PATH = "pub/candlepin-cert-consumer-latest.noarch.rpm"
12
+ SATELLITE6_SERVER_CERT_PATH = "pub/katello-ca-consumer-latest.noarch.rpm"
13
13
 
14
14
  def validate_credentials(options)
15
15
  !!organizations(options)
@@ -1,3 +1,3 @@
1
1
  class LinuxAdmin
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
@@ -10,9 +10,9 @@ class LinuxAdmin
10
10
  def self.process_volume_display_line(line)
11
11
  groups = VolumeGroup.scan
12
12
  fields = line.split(':')
13
- vgname = fields[1]
14
- vg = groups.find { |vg| vg.name == vgname }
15
- return fields, vg
13
+ vgname = fields[1]
14
+ vg = groups.find { |g| g.name == vgname }
15
+ return fields, vg
16
16
  end
17
17
 
18
18
  protected
@@ -55,7 +55,12 @@ class LinuxAdmin
55
55
  cmd = "yum -y update"
56
56
  params = {nil => packages} unless packages.blank?
57
57
 
58
- run!(cmd, :params => params)
58
+ out = run!(cmd, :params => params)
59
+
60
+ # Handle errors that exit 0 https://bugzilla.redhat.com/show_bug.cgi?id=1141318
61
+ raise AwesomeSpawn::CommandResultError.new(out.error, out) if out.error.include?("No Match for argument")
62
+
63
+ out
59
64
  end
60
65
 
61
66
  def self.version_available(*packages)
@@ -110,11 +115,11 @@ class LinuxAdmin
110
115
  next if line.start_with?(index_start)
111
116
  next if !collect_content
112
117
 
113
- repo_id, repo_name, status = line.split(/\s{2,}/)
118
+ repo_id, _repo_name, _status = line.split(/\s{2,}/)
114
119
  array.push(repo_id)
115
120
  end
116
121
  end
117
122
  end
118
123
  end
119
124
 
120
- Dir.glob(File.join(File.dirname(__FILE__), "yum", "*.rb")).each { |f| require f }
125
+ Dir.glob(File.join(File.dirname(__FILE__), "yum", "*.rb")).each { |f| require f }
data/spec/common_spec.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe LinuxAdmin::Common do
4
2
  subject { Class.new { include LinuxAdmin::Common }.new }
5
3
 
@@ -10,12 +8,12 @@ describe LinuxAdmin::Common do
10
8
  end
11
9
 
12
10
  it "#run" do
13
- AwesomeSpawn.should_receive(:run).with("echo", nil => "test")
11
+ expect(AwesomeSpawn).to receive(:run).with("echo", nil => "test")
14
12
  subject.run("echo", nil => "test")
15
13
  end
16
14
 
17
15
  it "#run!" do
18
- AwesomeSpawn.should_receive(:run!).with("echo", nil => "test")
16
+ expect(AwesomeSpawn).to receive(:run!).with("echo", nil => "test")
19
17
  subject.run!("echo", nil => "test")
20
18
  end
21
19
  end
data/spec/deb_spec.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe LinuxAdmin::Deb do
4
2
  describe "#info" do
5
3
  it "returns package metadata" do
@@ -39,16 +37,16 @@ Origin: Ubuntu
39
37
  Supported: 9m
40
38
  Task: kubuntu-desktop, kubuntu-full, kubuntu-active, kubuntu-active-desktop, kubuntu-active-full, kubuntu-active, edubuntu-desktop-gnome, ubuntustudio-font-meta
41
39
  EOS
42
- described_class.should_receive(:run!).
40
+ expect(described_class).to receive(:run!).
43
41
  with(described_class::APT_CACHE_CMD, :params => ["show", "ruby"]).
44
42
  and_return(double(:output => data))
45
43
  metadata = described_class.info("ruby")
46
- metadata['package'].should == 'ruby'
47
- metadata['priority'].should == 'optional'
48
- metadata['section'].should == 'interpreters'
49
- metadata['architecture'].should == 'all'
50
- metadata['version'].should == '4.9'
51
- metadata['origin'].should == 'Ubuntu'
44
+ expect(metadata['package']).to eq('ruby')
45
+ expect(metadata['priority']).to eq('optional')
46
+ expect(metadata['section']).to eq('interpreters')
47
+ expect(metadata['architecture']).to eq('all')
48
+ expect(metadata['version']).to eq('4.9')
49
+ expect(metadata['origin']).to eq('Ubuntu')
52
50
  end
53
51
  end
54
52
  end
data/spec/disk_spec.rb CHANGED
@@ -1,21 +1,19 @@
1
- require 'spec_helper'
2
-
3
1
  describe LinuxAdmin::Disk do
4
2
  describe "#local" do
5
3
  it "returns local disks" do
6
- Dir.should_receive(:glob).with(['/dev/[vhs]d[a-z]', '/dev/xvd[a-z]']).
4
+ expect(Dir).to receive(:glob).with(['/dev/[vhs]d[a-z]', '/dev/xvd[a-z]']).
7
5
  and_return(['/dev/hda', '/dev/sda'])
8
6
  disks = LinuxAdmin::Disk.local
9
7
  paths = disks.collect { |disk| disk.path }
10
- paths.should include('/dev/hda')
11
- paths.should include('/dev/sda')
8
+ expect(paths).to include('/dev/hda')
9
+ expect(paths).to include('/dev/sda')
12
10
  end
13
11
  end
14
12
 
15
13
  describe "#size" do
16
14
  it "uses fdisk" do
17
15
  disk = LinuxAdmin::Disk.new :path => '/dev/hda'
18
- disk.should_receive(:run!).
16
+ expect(disk).to receive(:run!).
19
17
  with(disk.cmd(:fdisk),
20
18
  :params => {"-l" => nil}).
21
19
  and_return(double(:output => ""))
@@ -38,15 +36,15 @@ Disk identifier: 0x3ddb508b
38
36
  eos
39
37
 
40
38
  disk = LinuxAdmin::Disk.new :path => '/dev/hda'
41
- disk.stub(:run!).and_return(double(:output => fdisk))
42
- disk.size.should == 500.1.gigabytes
39
+ allow(disk).to receive(:run!).and_return(double(:output => fdisk))
40
+ expect(disk.size).to eq(500.1.gigabytes)
43
41
  end
44
42
  end
45
43
 
46
44
  describe "#partitions" do
47
45
  it "uses parted" do
48
46
  disk = LinuxAdmin::Disk.new :path => '/dev/hda'
49
- disk.should_receive(:run).
47
+ expect(disk).to receive(:run).
50
48
  with(disk.cmd(:parted),
51
49
  :params => { nil => %w(--script /dev/hda print) }).and_return(double(:output => ""))
52
50
  disk.partitions
@@ -54,8 +52,8 @@ eos
54
52
 
55
53
  it "returns [] on non-zero parted rc" do
56
54
  disk = LinuxAdmin::Disk.new :path => '/dev/hda'
57
- disk.should_receive(:run).and_return(double(:output => "", :exit_status => 1))
58
- disk.partitions.should == []
55
+ expect(disk).to receive(:run).and_return(double(:output => "", :exit_status => 1))
56
+ expect(disk.partitions).to eq([])
59
57
  end
60
58
 
61
59
  it "sets partitons" do
@@ -72,29 +70,29 @@ Number Start End Size Type File system Flags
72
70
  3 162GB 163GB 1074MB logical linux-swap(v1)
73
71
  eos
74
72
  disk = LinuxAdmin::Disk.new
75
- disk.should_receive(:run).and_return(double(:output => partitions))
76
-
77
- disk.partitions[0].id.should == 1
78
- disk.partitions[0].disk.should == disk
79
- disk.partitions[0].size.should == 80.5.gigabytes
80
- disk.partitions[0].start_sector.should == 1259.megabytes
81
- disk.partitions[0].end_sector.should == 81.8.gigabytes
82
- disk.partitions[0].partition_type.should == 'primary'
83
- disk.partitions[0].fs_type.should == 'ntfs'
84
- disk.partitions[1].id.should == 2
85
- disk.partitions[1].disk.should == disk
86
- disk.partitions[1].size.should == 80.5.gigabytes
87
- disk.partitions[1].start_sector.should == 81.8.gigabytes
88
- disk.partitions[1].end_sector.should == 162.gigabytes
89
- disk.partitions[1].partition_type.should == 'primary'
90
- disk.partitions[1].fs_type.should == 'ext4'
91
- disk.partitions[2].id.should == 3
92
- disk.partitions[2].disk.should == disk
93
- disk.partitions[2].size.should == 1074.megabytes
94
- disk.partitions[2].start_sector.should == 162.gigabytes
95
- disk.partitions[2].end_sector.should == 163.gigabytes
96
- disk.partitions[2].partition_type.should == 'logical'
97
- disk.partitions[2].fs_type.should == 'linux-swap(v1)'
73
+ expect(disk).to receive(:run).and_return(double(:output => partitions))
74
+
75
+ expect(disk.partitions[0].id).to eq(1)
76
+ expect(disk.partitions[0].disk).to eq(disk)
77
+ expect(disk.partitions[0].size).to eq(80.5.gigabytes)
78
+ expect(disk.partitions[0].start_sector).to eq(1259.megabytes)
79
+ expect(disk.partitions[0].end_sector).to eq(81.8.gigabytes)
80
+ expect(disk.partitions[0].partition_type).to eq('primary')
81
+ expect(disk.partitions[0].fs_type).to eq('ntfs')
82
+ expect(disk.partitions[1].id).to eq(2)
83
+ expect(disk.partitions[1].disk).to eq(disk)
84
+ expect(disk.partitions[1].size).to eq(80.5.gigabytes)
85
+ expect(disk.partitions[1].start_sector).to eq(81.8.gigabytes)
86
+ expect(disk.partitions[1].end_sector).to eq(162.gigabytes)
87
+ expect(disk.partitions[1].partition_type).to eq('primary')
88
+ expect(disk.partitions[1].fs_type).to eq('ext4')
89
+ expect(disk.partitions[2].id).to eq(3)
90
+ expect(disk.partitions[2].disk).to eq(disk)
91
+ expect(disk.partitions[2].size).to eq(1074.megabytes)
92
+ expect(disk.partitions[2].start_sector).to eq(162.gigabytes)
93
+ expect(disk.partitions[2].end_sector).to eq(163.gigabytes)
94
+ expect(disk.partitions[2].partition_type).to eq('logical')
95
+ expect(disk.partitions[2].fs_type).to eq('linux-swap(v1)')
98
96
  end
99
97
  end
100
98
 
@@ -104,14 +102,14 @@ eos
104
102
  end
105
103
 
106
104
  it "dispatches to create_partition" do
107
- @disk.should_receive(:create_partition).with("primary", "0%", "50%")
105
+ expect(@disk).to receive(:create_partition).with("primary", "0%", "50%")
108
106
  @disk.create_partitions "primary", :start => "0%", :end => "50%"
109
107
  end
110
108
 
111
109
  context "multiple partitions specified" do
112
110
  it "calls create_partition for each partition" do
113
- @disk.should_receive(:create_partition).with("primary", "0%", "49%")
114
- @disk.should_receive(:create_partition).with("primary", "50%", "100%")
111
+ expect(@disk).to receive(:create_partition).with("primary", "0%", "49%")
112
+ expect(@disk).to receive(:create_partition).with("primary", "50%", "100%")
115
113
  @disk.create_partitions("primary", {:start => "0%", :end => "49%"},
116
114
  {:start => "50%", :end => "100%"})
117
115
  end
@@ -134,18 +132,18 @@ eos
134
132
  @disk.instance_variable_set(:@partitions,
135
133
  [LinuxAdmin::Partition.new(:id => 1,
136
134
  :end_sector => 1024)])
137
- @disk.stub(:has_partition_table? => true)
135
+ allow(@disk).to receive_messages(:has_partition_table? => true)
138
136
  end
139
137
 
140
138
  it "uses parted" do
141
139
  params = ['--script', '/dev/hda', 'mkpart', '-a', 'opt', 'primary', 1024, 2048]
142
- @disk.should_receive(:run!).with(@disk.cmd(:parted), :params => { nil => params })
140
+ expect(@disk).to receive(:run!).with(@disk.cmd(:parted), :params => { nil => params })
143
141
  @disk.create_partition 'primary', 1024
144
142
  end
145
143
 
146
144
  it "accepts start/end params" do
147
145
  params = ['--script', '/dev/hda', 'mkpart', '-a', 'opt', 'primary', "0%", "50%"]
148
- @disk.should_receive(:run!).with(@disk.cmd(:parted), :params => { nil => params })
146
+ expect(@disk).to receive(:run!).with(@disk.cmd(:parted), :params => { nil => params })
149
147
  @disk.create_partition 'primary', "0%", "50%"
150
148
  end
151
149
 
@@ -162,34 +160,34 @@ eos
162
160
  end
163
161
 
164
162
  it "returns partition" do
165
- @disk.should_receive(:run!) # stub out call to parted
163
+ expect(@disk).to receive(:run!) # stub out call to parted
166
164
  partition = @disk.create_partition 'primary', 1024
167
- partition.should be_an_instance_of(LinuxAdmin::Partition)
165
+ expect(partition).to be_an_instance_of(LinuxAdmin::Partition)
168
166
  end
169
167
 
170
168
  it "increments partition id" do
171
- @disk.should_receive(:run!) # stub out call to parted
169
+ expect(@disk).to receive(:run!) # stub out call to parted
172
170
  partition = @disk.create_partition 'primary', 1024
173
- partition.id.should == 2
171
+ expect(partition.id).to eq(2)
174
172
  end
175
173
 
176
174
  it "sets partition start to first unused sector on disk" do
177
- @disk.should_receive(:run!) # stub out call to parted
175
+ expect(@disk).to receive(:run!) # stub out call to parted
178
176
  partition = @disk.create_partition 'primary', 1024
179
- partition.start_sector.should == 1024
177
+ expect(partition.start_sector).to eq(1024)
180
178
  end
181
179
 
182
180
  it "stores new partition locally" do
183
- @disk.should_receive(:run!) # stub out call to parted
184
- lambda {
181
+ expect(@disk).to receive(:run!) # stub out call to parted
182
+ expect {
185
183
  @disk.create_partition 'primary', 1024
186
- }.should change{@disk.partitions.size}.by(1)
184
+ }.to change{@disk.partitions.size}.by(1)
187
185
  end
188
186
 
189
187
  it "creates partition table if missing" do
190
- @disk.stub(:has_partition_table? => false)
191
- @disk.should_receive(:create_partition_table)
192
- @disk.should_receive(:run!)
188
+ allow(@disk).to receive_messages(:has_partition_table? => false)
189
+ expect(@disk).to receive(:create_partition_table)
190
+ expect(@disk).to receive(:run!)
193
191
  @disk.create_partition 'primary', 1024
194
192
  end
195
193
  end
@@ -197,39 +195,39 @@ eos
197
195
  describe "#has_partition_table?" do
198
196
  it "positive case" do
199
197
  disk = LinuxAdmin::Disk.new :path => '/dev/hda'
200
- disk.should_receive(:run).and_return(double(:output => "", :exit_status => 0))
201
- disk.should have_partition_table
198
+ expect(disk).to receive(:run).and_return(double(:output => "", :exit_status => 0))
199
+ expect(disk).to have_partition_table
202
200
  end
203
201
 
204
202
  it "negative case" do
205
203
  disk = LinuxAdmin::Disk.new :path => '/dev/hda'
206
204
  output = "\e[?1034h\r\rError: /dev/sdb: unrecognised disk label\n"
207
- disk.should_receive(:run).and_return(double(:output => output, :exit_status => 1))
208
- disk.should_not have_partition_table
205
+ expect(disk).to receive(:run).and_return(double(:output => output, :exit_status => 1))
206
+ expect(disk).not_to have_partition_table
209
207
  end
210
208
  end
211
209
 
212
210
  it "#create_partition_table" do
213
211
  disk = LinuxAdmin::Disk.new :path => '/dev/hda'
214
212
  options = {:params => {nil => %w(--script /dev/hda mklabel msdos)}}
215
- disk.should_receive(:run!).with(disk.cmd(:parted), options)
213
+ expect(disk).to receive(:run!).with(disk.cmd(:parted), options)
216
214
  disk.create_partition_table
217
215
  end
218
216
 
219
217
  describe "#clear!" do
220
218
  it "clears partitions" do
221
219
  disk = LinuxAdmin::Disk.new :path => '/dev/hda'
222
- disk.should_receive(:run).and_return(double(:output => "")) # stub out call to cmds
220
+ expect(disk).to receive(:run).and_return(double(:output => "")) # stub out call to cmds
223
221
  disk.partitions << LinuxAdmin::Partition.new
224
222
 
225
- disk.should_receive(:run!)
223
+ expect(disk).to receive(:run!)
226
224
  disk.clear!
227
- disk.partitions.should be_empty
225
+ expect(disk.partitions).to be_empty
228
226
  end
229
227
 
230
228
  it "uses dd to clear partition table" do
231
229
  disk = LinuxAdmin::Disk.new :path => '/dev/hda'
232
- disk.should_receive(:run!).
230
+ expect(disk).to receive(:run!).
233
231
  with(disk.cmd(:dd),
234
232
  :params => {'if=' => '/dev/zero', 'of=' => '/dev/hda',
235
233
  'bs=' => 512, 'count=' => 1})
@@ -238,8 +236,8 @@ eos
238
236
 
239
237
  it "returns self" do
240
238
  disk = LinuxAdmin::Disk.new :path => '/dev/hda'
241
- disk.stub(:run!) # stub out call to dd
242
- disk.clear!.should == disk
239
+ allow(disk).to receive(:run!) # stub out call to dd
240
+ expect(disk.clear!).to eq(disk)
243
241
  end
244
242
  end
245
243