Skip to content

Commit

Permalink
Merge pull request #52 from bdunne/fstab_doesnt_exist_on_rhel_containers
Browse files Browse the repository at this point in the history
Skip editing /etc/fstab if it doesn't exist
  • Loading branch information
Fryguy authored Aug 23, 2017
2 parents a1533a9 + 1b1c48c commit fefd0c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions db/migrate/20170512233333_drop_miq_server_rhn_mirror.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def up
require 'fileutils'
require 'linux_admin'

LinuxAdmin::FSTab.instance.entries.delete_if { |e| e.mount_point == "/repo" }
LinuxAdmin::FSTab.instance.write!
if File.exist?("/etc/fstab")
LinuxAdmin::FSTab.instance.entries.delete_if { |e| e.mount_point == "/repo" }
LinuxAdmin::FSTab.instance.write!
end

FileUtils.rm_f("/etc/httpd/conf.d/manageiq-https-mirror.conf")
FileUtils.rm_f("/etc/yum.repos.d/manageiq-mirror.repo")
Expand Down
16 changes: 16 additions & 0 deletions spec/migrations/20170512233333_drop_miq_server_rhn_mirror_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_migration
require 'linux_admin'

describe DropMiqServerRhnMirror do
let(:server_role_stub) { migration_stub(:ServerRole) }
Expand Down Expand Up @@ -43,6 +44,7 @@
expect(File).to receive(:exist?).with('/var/www/miq/vmdb').and_return(true)

mock_fstab_lines = ["/dev/sda / xfs defaults 0 0", "/dev/sdb /repo xfs defaults 0 0"]
expect(File).to receive(:exist?).with("/etc/fstab").and_return(true)
expect(File).to receive(:read).with("/etc/fstab").and_return(mock_fstab_lines.join("\n"))
expect(File).to receive(:write).with("/etc/fstab", "/dev/sda / xfs defaults 0 0 \n")

Expand All @@ -52,5 +54,19 @@

migrate
end

it "doesn't fail if /etc/fstab doesn't exist" do
expect(Rails.env).to receive(:production?).and_return(true)
expect(File).to receive(:exist?).with('/var/www/miq/vmdb').and_return(true)

expect(File).to receive(:exist?).with("/etc/fstab").and_return(false)
expect(LinuxAdmin::FSTab.instance).not_to receive(:write!)

expect(FileUtils).to receive(:rm_f).with("/etc/httpd/conf.d/manageiq-https-mirror.conf")
expect(FileUtils).to receive(:rm_f).with("/etc/yum.repos.d/manageiq-mirror.repo")
expect(FileUtils).to receive(:rm_rf).with([])

migrate
end
end
end

0 comments on commit fefd0c9

Please sign in to comment.