From a7f09f010c6d6e5bacba3ee95a2b35ccec1e4e36 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Mon, 22 Jul 2019 16:05:48 +0200 Subject: [PATCH] alpine: Convert nfs_client capability to seperate commands The workaround for the broken repository should be safe to be removed, since the last affected Alpine version (<=3.3) EOL'd in November of 2017. The remaining important commands can be split out into seperate calls of sudo(), which removes the need for manual exit-code checking (since it aborts by itself when a command fails) and makes the code easier to handle in general. --- plugins/guests/alpine/cap/nfs_client.rb | 40 ++---------------- .../guests/alpine/cap/nfs_client_test.rb | 42 +++---------------- 2 files changed, 9 insertions(+), 73 deletions(-) diff --git a/plugins/guests/alpine/cap/nfs_client.rb b/plugins/guests/alpine/cap/nfs_client.rb index f9f065db2..b9d803134 100644 --- a/plugins/guests/alpine/cap/nfs_client.rb +++ b/plugins/guests/alpine/cap/nfs_client.rb @@ -3,42 +3,10 @@ module VagrantPlugins module Cap class NFSClient def self.nfs_client_install(machine) - comm = machine.communicate - comm.sudo <<-EOS.gsub(/^\s+\|\s?/, '') - | # work around defunct repository in configuration - | # box: maier/apline-3.3 - | repo_file="/etc/apk/repositories" - | if [ $(grep -c "repos.dfw.lax-noc.com" $repo_file) -ne 0 ]; then - | repo_file_bak="${repo_file}.orig" - | echo "updating repositories" - | cp $repo_file $repo_file_bak - | sed -e 's/repos.dfw.lax-noc.com/dl-cdn.alpinelinux.org/' $repo_file_bak > $repo_file - | fi - | - | echo "updating repository indices" - | apk update - | if [ $? -ne 0 ]; then - | exit 1 - | fi - | - | echo "installing nfs-utils" - | apk add --upgrade nfs-utils - | if [ $? -ne 0 ]; then - | exit 1 - | fi - | - | echo "installing rpc.statd" - | rc-update add rpc.statd - | if [ $? -ne 0 ]; then - | exit 1 - | fi - | - | echo "starting rpc.statd service" - | rc-service rpc.statd start - | if [ $? -ne 0 ]; then - | exit 1 - | fi - EOS + machine.communicate.sudo('apk update') + machine.communicate.sudo('apk add --upgrade nfs-utils') + machine.communicate.sudo('rc-update add rpc.statd') + machine.communicate.sudo('rc-service rpc.statd start') end end end diff --git a/test/unit/plugins/guests/alpine/cap/nfs_client_test.rb b/test/unit/plugins/guests/alpine/cap/nfs_client_test.rb index 11a03ed9b..9273707c3 100644 --- a/test/unit/plugins/guests/alpine/cap/nfs_client_test.rb +++ b/test/unit/plugins/guests/alpine/cap/nfs_client_test.rb @@ -17,43 +17,11 @@ describe 'VagrantPlugins::GuestAlpine::Cap::NFSClient' do end it 'should install nfs client' do - x = <<-EOS.gsub(/^\s+\|\s?/, '') - | # work around defunct repository in configuration - | # box: maier/apline-3.3 - | repo_file="/etc/apk/repositories" - | if [ $(grep -c "repos.dfw.lax-noc.com" $repo_file) -ne 0 ]; then - | repo_file_bak="${repo_file}.orig" - | echo "updating repositories" - | cp $repo_file $repo_file_bak - | sed -e 's/repos.dfw.lax-noc.com/dl-cdn.alpinelinux.org/' $repo_file_bak > $repo_file - | fi - | - | echo "updating repository indices" - | apk update - | if [ $? -ne 0 ]; then - | exit 1 - | fi - | - | echo "installing nfs-utils" - | apk add --upgrade nfs-utils - | if [ $? -ne 0 ]; then - | exit 1 - | fi - | - | echo "installing rpc.statd" - | rc-update add rpc.statd - | if [ $? -ne 0 ]; then - | exit 1 - | fi - | - | echo "starting rpc.statd service" - | rc-service rpc.statd start - | if [ $? -ne 0 ]; then - | exit 1 - | fi - EOS - expect(communicator).to receive(:sudo).with(x) - allow_message_expectations_on_nil described_class.nfs_client_install(machine) + + expect(communicator.received_commands[0]).to match(/apk update/) + expect(communicator.received_commands[1]).to match(/apk add --upgrade nfs-utils/) + expect(communicator.received_commands[2]).to match(/rc-update add rpc.statd/) + expect(communicator.received_commands[3]).to match(/rc-service rpc.statd start/) end end