Fix broken 'ansible_install' methods signature
- By the way: Trim the generate 'pip install' command in Ansible::Cap::Guest::Pip::pip_install - GH-11048: Fix same regression for FreeBSD and SuSE guests. - GH-6633: Add RSpec examples to cover ansible_local 'cap' code. Note: RedHat/Fedora guests are not covered yet by unit tests.
This commit is contained in:
parent
113a0a7aaa
commit
a2b87eace4
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
module FreeBSD
|
||||
module AnsibleInstall
|
||||
|
||||
def self.ansible_install(machine, install_mode, ansible_version, pip_args)
|
||||
def self.ansible_install(machine, install_mode, ansible_version, pip_args, pip_install_cmd = "")
|
||||
if install_mode != :default
|
||||
raise Ansible::Errors::AnsiblePipInstallIsNotSupported
|
||||
else
|
||||
|
|
|
@ -16,8 +16,12 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
args_array = [pip_args, upgrade_arg, "#{package}#{version_arg}"]
|
||||
args_array.reject! { |a| a.nil? || a.empty? }
|
||||
|
||||
machine.communicate.sudo "pip install #{args_array.join(' ')}"
|
||||
pip_install = "pip install"
|
||||
pip_install += " #{args_array.join(' ')}" unless args_array.empty?
|
||||
|
||||
machine.communicate.sudo pip_install
|
||||
end
|
||||
|
||||
def self.get_pip(machine, pip_install_cmd=DEFAULT_PIP_INSTALL_CMD)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
require_relative "../../../errors"
|
||||
|
||||
module VagrantPlugins
|
||||
module Ansible
|
||||
|
@ -6,7 +7,7 @@ module VagrantPlugins
|
|||
module SUSE
|
||||
module AnsibleInstall
|
||||
|
||||
def self.ansible_install(machine, install_mode, ansible_version, pip_args)
|
||||
def self.ansible_install(machine, install_mode, ansible_version, pip_args, pip_install_cmd = "")
|
||||
if install_mode != :default
|
||||
raise Ansible::Errors::AnsiblePipInstallIsNotSupported
|
||||
else
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
require_relative "../../../../../../base"
|
||||
require_relative "../shared/pip_ansible_install_examples"
|
||||
|
||||
|
||||
require Vagrant.source_root.join("plugins/provisioners/ansible/cap/guest/arch/ansible_install")
|
||||
|
||||
|
||||
describe VagrantPlugins::Ansible::Cap::Guest::Arch::AnsibleInstall do
|
||||
include_context "unit"
|
||||
|
||||
subject { VagrantPlugins::Ansible::Cap::Guest::Arch::AnsibleInstall }
|
||||
|
||||
let(:iso_env) do
|
||||
# We have to create a Vagrantfile so there is a root path
|
||||
env = isolated_environment
|
||||
env.vagrantfile("")
|
||||
env.create_vagrant_env
|
||||
end
|
||||
|
||||
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
|
||||
let(:communicator) { double("comm") }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(communicator)
|
||||
allow(communicator).to receive(:execute).and_return(true)
|
||||
end
|
||||
|
||||
describe "#pip_setup" do
|
||||
it "install required Arch packages and call Cap::Guest::Pip::get_pip" do
|
||||
pip_install_cmd = "foo"
|
||||
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("pacman -Syy --noconfirm")
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("pacman -S --noconfirm base-devel curl git")
|
||||
expect(VagrantPlugins::Ansible::Cap::Guest::Pip).to receive(:get_pip).once.ordered.
|
||||
with(machine, pip_install_cmd)
|
||||
|
||||
subject.pip_setup(machine, pip_install_cmd)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#ansible_install" do
|
||||
|
||||
it_behaves_like "Ansible setup via pip"
|
||||
|
||||
describe "when install_mode is :default (or unknown)" do
|
||||
it "installs ansible with 'pacman' package manager" do
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("pacman -Syy --noconfirm")
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("pacman -S --noconfirm ansible")
|
||||
|
||||
subject.ansible_install(machine, :default, "", "", "")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,50 @@
|
|||
require_relative "../../../../../../base"
|
||||
require_relative "../shared/pip_ansible_install_examples"
|
||||
|
||||
|
||||
require Vagrant.source_root.join("plugins/provisioners/ansible/cap/guest/debian/ansible_install")
|
||||
|
||||
|
||||
describe VagrantPlugins::Ansible::Cap::Guest::Debian::AnsibleInstall do
|
||||
include_context "unit"
|
||||
|
||||
subject { VagrantPlugins::Ansible::Cap::Guest::Debian::AnsibleInstall }
|
||||
|
||||
let(:iso_env) do
|
||||
# We have to create a Vagrantfile so there is a root path
|
||||
env = isolated_environment
|
||||
env.vagrantfile("")
|
||||
env.create_vagrant_env
|
||||
end
|
||||
|
||||
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
|
||||
let(:communicator) { double("comm") }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(communicator)
|
||||
allow(communicator).to receive(:execute).and_return(true)
|
||||
end
|
||||
|
||||
describe "#ansible_install" do
|
||||
|
||||
it_behaves_like "Ansible setup via pip on Debian-based systems"
|
||||
|
||||
describe "when install_mode is :default (or unknown)" do
|
||||
it "installs ansible with apt package manager" do
|
||||
install_backports_if_wheezy_release = <<INLINE_CRIPT
|
||||
CODENAME=`lsb_release -cs`
|
||||
if [ x$CODENAME == 'xwheezy' ]; then
|
||||
echo 'deb http://http.debian.net/debian wheezy-backports main' > /etc/apt/sources.list.d/wheezy-backports.list
|
||||
fi
|
||||
INLINE_CRIPT
|
||||
|
||||
expect(communicator).to receive(:sudo).once.ordered.with(install_backports_if_wheezy_release)
|
||||
expect(communicator).to receive(:sudo).once.ordered.with("apt-get update -y -qq")
|
||||
expect(communicator).to receive(:sudo).once.ordered.with("apt-get install -y -qq ansible")
|
||||
|
||||
subject.ansible_install(machine, :default, "", "", "")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,41 @@
|
|||
require_relative "../../../../../../base"
|
||||
require_relative "../shared/pip_ansible_install_examples"
|
||||
|
||||
|
||||
require Vagrant.source_root.join("plugins/provisioners/ansible/cap/guest/freebsd/ansible_install")
|
||||
|
||||
|
||||
describe VagrantPlugins::Ansible::Cap::Guest::FreeBSD::AnsibleInstall do
|
||||
include_context "unit"
|
||||
|
||||
subject { VagrantPlugins::Ansible::Cap::Guest::FreeBSD::AnsibleInstall }
|
||||
|
||||
let(:iso_env) do
|
||||
# We have to create a Vagrantfile so there is a root path
|
||||
env = isolated_environment
|
||||
env.vagrantfile("")
|
||||
env.create_vagrant_env
|
||||
end
|
||||
|
||||
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
|
||||
let(:communicator) { double("comm") }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(communicator)
|
||||
allow(communicator).to receive(:execute).and_return(true)
|
||||
end
|
||||
|
||||
describe "#ansible_install" do
|
||||
|
||||
it_behaves_like "Ansible setup via pip is not implemented"
|
||||
|
||||
describe "when install_mode is :default (or unknown)" do
|
||||
it "installs ansible with 'pkg' package manager" do
|
||||
expect(communicator).to receive(:sudo).with("yes | pkg install ansible")
|
||||
|
||||
subject.ansible_install(machine, :default, "", "", "")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,68 @@
|
|||
|
||||
shared_examples_for "Ansible setup via pip" do
|
||||
|
||||
describe "when install_mode is :pip" do
|
||||
it "installs pip and calls Cap::Guest::Pip::pip_install" do
|
||||
expect(communicator).to receive(:sudo).at_least(1).times.ordered
|
||||
expect(VagrantPlugins::Ansible::Cap::Guest::Pip).to receive(:pip_install).once.ordered.
|
||||
with(machine, "ansible", anything, anything, true)
|
||||
|
||||
subject.ansible_install(machine, :pip, "", "", "")
|
||||
end
|
||||
end
|
||||
|
||||
describe "when install_mode is :pip_args_only" do
|
||||
it "installs pip and calls Cap::Guest::Pip::pip_install with 'pip_args' parameter" do
|
||||
pip_args = "-r /vagrant/requirements.txt"
|
||||
|
||||
expect(communicator).to receive(:sudo).at_least(1).times.ordered
|
||||
expect(VagrantPlugins::Ansible::Cap::Guest::Pip).to receive(:pip_install).with(machine, "", "", pip_args, false).ordered
|
||||
|
||||
subject.ansible_install(machine, :pip_args_only, "", pip_args, "")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
shared_examples_for "Ansible setup via pip on Debian-based systems" do
|
||||
|
||||
describe "installs required Debian packages and..." do
|
||||
pip_install_cmd = "foo"
|
||||
|
||||
it "calls Cap::Guest::Pip::get_pip with 'pip' install_mode" do
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("apt-get update -y -qq")
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("apt-get install -y -qq build-essential curl git libssl-dev libffi-dev python-dev")
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("pip install --upgrade ansible")
|
||||
|
||||
subject.ansible_install(machine, :pip, "", "", pip_install_cmd)
|
||||
end
|
||||
|
||||
it "calls Cap::Guest::Pip::get_pip with 'pip_args_only' install_mode" do
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("apt-get update -y -qq")
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("apt-get install -y -qq build-essential curl git libssl-dev libffi-dev python-dev")
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("pip install")
|
||||
|
||||
subject.ansible_install(machine, :pip_args_only, "", "", pip_install_cmd)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it_behaves_like "Ansible setup via pip"
|
||||
|
||||
end
|
||||
|
||||
shared_examples_for "Ansible setup via pip is not implemented" do
|
||||
|
||||
describe "when install_mode is different from :default" do
|
||||
it "raises an AnsiblePipInstallIsNotSupported error" do
|
||||
expect { subject.ansible_install(machine, :ansible_the_hardway, "", "", "") }.to raise_error(VagrantPlugins::Ansible::Errors::AnsiblePipInstallIsNotSupported)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,41 @@
|
|||
require_relative "../../../../../../base"
|
||||
require_relative "../shared/pip_ansible_install_examples"
|
||||
|
||||
|
||||
require Vagrant.source_root.join("plugins/provisioners/ansible/cap/guest/suse/ansible_install")
|
||||
|
||||
|
||||
describe VagrantPlugins::Ansible::Cap::Guest::SUSE::AnsibleInstall do
|
||||
include_context "unit"
|
||||
|
||||
subject { VagrantPlugins::Ansible::Cap::Guest::SUSE::AnsibleInstall }
|
||||
|
||||
let(:iso_env) do
|
||||
# We have to create a Vagrantfile so there is a root path
|
||||
env = isolated_environment
|
||||
env.vagrantfile("")
|
||||
env.create_vagrant_env
|
||||
end
|
||||
|
||||
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
|
||||
let(:communicator) { double("comm") }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(communicator)
|
||||
allow(communicator).to receive(:execute).and_return(true)
|
||||
end
|
||||
|
||||
describe "#ansible_install" do
|
||||
|
||||
it_behaves_like "Ansible setup via pip is not implemented"
|
||||
|
||||
describe "when install_mode is :default (or unknown)" do
|
||||
it "installs ansible with 'zypper' package manager" do
|
||||
expect(communicator).to receive(:sudo).with("zypper --non-interactive --quiet install ansible")
|
||||
|
||||
subject.ansible_install(machine, :default, "", "", "")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,76 @@
|
|||
require_relative "../../../../../../base"
|
||||
require_relative "../shared/pip_ansible_install_examples"
|
||||
|
||||
|
||||
require Vagrant.source_root.join("plugins/provisioners/ansible/cap/guest/ubuntu/ansible_install")
|
||||
|
||||
|
||||
describe VagrantPlugins::Ansible::Cap::Guest::Ubuntu::AnsibleInstall do
|
||||
include_context "unit"
|
||||
|
||||
subject { VagrantPlugins::Ansible::Cap::Guest::Ubuntu::AnsibleInstall }
|
||||
|
||||
let(:iso_env) do
|
||||
# We have to create a Vagrantfile so there is a root path
|
||||
env = isolated_environment
|
||||
env.vagrantfile("")
|
||||
env.create_vagrant_env
|
||||
end
|
||||
|
||||
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
|
||||
let(:communicator) { double("comm") }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(communicator)
|
||||
allow(communicator).to receive(:execute).and_return(true)
|
||||
end
|
||||
|
||||
describe "#ansible_install" do
|
||||
|
||||
it_behaves_like "Ansible setup via pip on Debian-based systems"
|
||||
|
||||
describe "when install_mode is :default (or unknown)" do
|
||||
describe "#ansible_apt_install" do
|
||||
describe "installs ansible from ansible/ansible PPA repository" do
|
||||
|
||||
check_if_add_apt_repository_is_present="test -x \"$(which add-apt-repository)\""
|
||||
|
||||
it "first installs 'software-properties-common' package if add-apt-repository is not already present" do
|
||||
allow(communicator).to receive(:test).
|
||||
with(check_if_add_apt_repository_is_present).and_return(false)
|
||||
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("""
|
||||
apt-get update -y -qq && \
|
||||
apt-get install -y -qq software-properties-common
|
||||
""")
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("""
|
||||
add-apt-repository ppa:ansible/ansible -y && \
|
||||
apt-get update -y -qq && \
|
||||
apt-get install -y -qq ansible
|
||||
""")
|
||||
|
||||
subject.ansible_install(machine, :default, "", "", "")
|
||||
end
|
||||
|
||||
it "adds 'ppa:ansible/ansible' and install 'ansible' package" do
|
||||
allow(communicator).to receive(:test).
|
||||
with(check_if_add_apt_repository_is_present).and_return(true)
|
||||
|
||||
expect(communicator).to receive(:sudo).
|
||||
with("""
|
||||
add-apt-repository ppa:ansible/ansible -y && \
|
||||
apt-get update -y -qq && \
|
||||
apt-get install -y -qq ansible
|
||||
""")
|
||||
|
||||
subject.ansible_install(machine, :default, "", "", "")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue