guests/redhat: Configure NFS in one command
Previously this was very complicated trying to flip between Ruby and bash. This commit uses a single bash command that decides between yum and dnf in the script itself.
This commit is contained in:
parent
e09d342284
commit
3098c13869
|
@ -3,32 +3,20 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class NFSClient
|
||||
def self.nfs_client_install(machine)
|
||||
if VagrantPlugins::GuestRedHat::Plugin.dnf?(machine)
|
||||
machine.communicate.sudo("dnf -y install nfs-utils nfs-utils-lib")
|
||||
else
|
||||
machine.communicate.sudo("yum -y install nfs-utils nfs-utils-lib")
|
||||
end
|
||||
restart_nfs(machine)
|
||||
end
|
||||
machine.communicate.sudo <<-EOH.gsub(/^ {12}/, '')
|
||||
if command -v dnf; then
|
||||
dnf -y install nfs-utils nfs-utils-lib portmap
|
||||
else
|
||||
yum -y install nfs-utils nfs-utils-lib portmap
|
||||
fi
|
||||
|
||||
def self.nfs_client_installed(machine)
|
||||
installed = machine.communicate.test("test -x /sbin/mount.nfs")
|
||||
restart_nfs(machine) if installed
|
||||
installed
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def self.systemd?(machine)
|
||||
machine.communicate.test("test $(ps -o comm= 1) == 'systemd'")
|
||||
end
|
||||
|
||||
def self.restart_nfs(machine)
|
||||
if systemd?(machine)
|
||||
machine.communicate.sudo("/bin/systemctl restart rpcbind nfs")
|
||||
else
|
||||
machine.communicate.sudo("/etc/init.d/rpcbind restart; /etc/init.d/nfs restart")
|
||||
end
|
||||
if test $(ps -o comm= 1) == 'systemd'; then
|
||||
/bin/systemctl restart rpcbind nfs
|
||||
else
|
||||
/etc/init.d/rpcbind restart
|
||||
/etc/init.d/nfs restart
|
||||
fi
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
require_relative "../../../../base"
|
||||
|
||||
describe "VagrantPlugins::GuestRedHat::Cap:NFSClient" do
|
||||
let(:caps) do
|
||||
VagrantPlugins::GuestRedHat::Plugin
|
||||
.components
|
||||
.guest_capabilities[:redhat]
|
||||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
end
|
||||
|
||||
after do
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".nfs_client_install" do
|
||||
let(:cap) { caps.get(:nfs_client_install) }
|
||||
|
||||
it "installs rsync" do
|
||||
cap.nfs_client_install(machine)
|
||||
expect(comm.received_commands[0]).to match(/install nfs-utils nfs-utils-lib portmap/)
|
||||
expect(comm.received_commands[0]).to match(/\/bin\/systemctl restart rpcbind nfs/)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue