From a12b09b098ea87eec815e166d0e1395f6f47f937 Mon Sep 17 00:00:00 2001 From: shotop Date: Thu, 20 Sep 2018 14:21:40 -0500 Subject: [PATCH] add specs around network restart logic --- .../redhat/cap/change_host_name_test.rb | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb b/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb index 10f43a359..b85802e94 100644 --- a/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb +++ b/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb @@ -39,5 +39,32 @@ describe "VagrantPlugins::GuestRedHat::Cap::ChangeHostName" do cap.change_host_name(machine, name) expect(comm.received_commands.size).to eq(1) end + + context "restarts the network" do + it "uses systemctl and NetworkManager.service" do + comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1) + comm.stub_command("test -f /usr/bin/systemctl && systemctl -q is-active NetworkManager.service", exit_code: 0) + cap.change_host_name(machine, name) + expect(comm.received_commands[1]).to match(/systemctl restart NetworkManager.service/) + end + + it "uses the service command" do + comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1) + comm.stub_command("test -f /usr/bin/systemctl && systemctl -q is-active NetworkManager.service", exit_code: 1) + comm.stub_command("test -f /etc/init.d/network", exit_code: 0) + cap.change_host_name(machine, name) + expect(comm.received_commands[1]).to match(/service network restart/) + end + end + + context "cannot restart the network" do + it "prints cannot restart message" do + comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1) + comm.stub_command("test -f /usr/bin/systemctl && systemctl -q is-active NetworkManager.service", exit_code: 1) + comm.stub_command("test -f /etc/init.d/network", exit_code: 1) + cap.change_host_name(machine, name) + expect(comm.received_commands[1]).to match(/printf "Could not restart the network to set the new hostname!/) + end + end end end