guests/alt: Fix flavor and network configure with unit tests
This commit is contained in:
parent
5ff176a82c
commit
015d98e76c
|
@ -3,41 +3,54 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class Flavor
|
||||
def self.flavor(machine)
|
||||
comm = machine.communicate
|
||||
|
||||
# Read the version file
|
||||
if !comm.test("test -f /etc/os-release")
|
||||
if comm.test("test -f /etc/os-release")
|
||||
name = nil
|
||||
machine.communicate.sudo("grep NAME /etc/os-release") do |type, data|
|
||||
comm.sudo("grep NAME /etc/os-release") do |type, data|
|
||||
if type == :stdout
|
||||
name = data.split("=")[1].chomp.to_i
|
||||
name = data.split("=")[1].gsub!(/\A"|"\Z/, '')
|
||||
end
|
||||
end
|
||||
|
||||
if name.nil? and name == "Sisyphus"
|
||||
if !name.nil? and name == "Sisyphus"
|
||||
return :alt
|
||||
end
|
||||
|
||||
version = nil
|
||||
machine.communicate.sudo("grep VERSION_ID /etc/os-release") do |type, data|
|
||||
comm.sudo("grep VERSION_ID /etc/os-release") do |type, data|
|
||||
if type == :stdout
|
||||
version = data.split("=")[1].chomp.to_i
|
||||
verstr = data.split("=")[1]
|
||||
if verstr == "p8"
|
||||
version = 8
|
||||
elsif verstr =~ /^[[\d]]/
|
||||
version = verstr.chomp.to_i
|
||||
subversion = verstr.chomp.split(".")[1].to_i
|
||||
if subversion > 90
|
||||
version += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if version.nil?
|
||||
if version.nil? or version == 0
|
||||
return :alt
|
||||
else
|
||||
return :"alt_#{version}"
|
||||
end
|
||||
else
|
||||
output = ""
|
||||
machine.communicate.sudo("cat /etc/altlinux-release") do |_, data|
|
||||
comm.sudo("cat /etc/altlinux-release") do |_, data|
|
||||
output = data
|
||||
end
|
||||
|
||||
# Detect various flavors we care about
|
||||
if output =~ /(ALT SP|ALT Workstation|ALT Workstation K|ALT Linux starter kit)\s*8( .+)?/i
|
||||
if output =~ /(ALT SP|ALT Education|ALT Workstation|ALT Workstation K|ALT Linux starter kit)\s*8(\.[1-9])?( .+)?/i
|
||||
return :alt_8
|
||||
elsif output =~ /ALT\s*8( .+)?\s.+/i
|
||||
elsif output =~ /ALT\s+8(\.[1-9])?( .+)?\s.+/i
|
||||
return :alt_8
|
||||
elsif output =~ /ALT Linux p8( .+)?/i
|
||||
return :alt_8
|
||||
else
|
||||
return :alt
|
||||
|
|
|
@ -67,13 +67,12 @@ describe "VagrantPlugins::GuestALT::Cap::ConfigureNetworks" do
|
|||
end
|
||||
|
||||
context "with nm_controlled option omitted" do
|
||||
it "downs networks manually, creates ifaces, starts networks manually and restart NetworksManager" do
|
||||
it "downs networks via nmcli, creates ifaces and restart NetworksManager" do
|
||||
cap.configure_networks(machine, [network_1, network_2])
|
||||
expect(comm.received_commands[0]).to match(/ifdown/)
|
||||
expect(comm.received_commands[0]).to match(/nmcli.*disconnect/)
|
||||
expect(comm.received_commands[0]).to match(/mkdir.*\/etc\/net\/ifaces/)
|
||||
expect(comm.received_commands[0]).to match(/ifup/)
|
||||
expect(comm.received_commands[0]).to match(/NetworkManager/)
|
||||
expect(comm.received_commands[0]).to_not match(/nmcli/)
|
||||
expect(comm.received_commands[0]).to_not match(/ifdown|ifup/)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -21,22 +21,51 @@ describe "VagrantPlugins::GuestALT::Cap::Flavor" do
|
|||
describe ".flavor" do
|
||||
let(:cap) { caps.get(:flavor) }
|
||||
|
||||
{
|
||||
"ALT Education 8.1" => :alt,
|
||||
"ALT Workstation 8.1" => :alt,
|
||||
"ALT Workstation K 8.1 (Centaurea Ruthenica)" => :alt,
|
||||
"ALT Linux p8 (Hypericum)" => :alt,
|
||||
"ALT Sisyphus (unstable) (sisyphus)" => :alt,
|
||||
context "without /etc/os-release file" do
|
||||
{
|
||||
"ALT 8.1 Server" => :alt_8,
|
||||
"ALT Education 8.1" => :alt_8,
|
||||
"ALT Workstation 8.1" => :alt_8,
|
||||
"ALT Workstation K 8.1 (Centaurea Ruthenica)" => :alt_8,
|
||||
"ALT Linux p8 (Hypericum)" => :alt_8,
|
||||
|
||||
"ALT Linux 6.0.1 Spt (separator)" => :alt,
|
||||
"ALT Linux 7.0.5 School Master" => :alt,
|
||||
"ALT starter kit (Hypericum)" => :alt,
|
||||
"ALT Sisyphus (unstable) (sisyphus)" => :alt,
|
||||
"ALT Linux Sisyphus (unstable)" => :alt,
|
||||
"ALT Linux 6.0.1 Spt (separator)" => :alt,
|
||||
"ALT Linux 7.0.5 School Master" => :alt,
|
||||
"ALT starter kit (Hypericum)" => :alt,
|
||||
|
||||
"ALT" => :alt,
|
||||
}.each do |str, expected|
|
||||
it "returns #{expected} for #{str}" do
|
||||
comm.stub_command("cat /etc/altlinux-release", stdout: str)
|
||||
expect(cap.flavor(machine)).to be(expected)
|
||||
"ALT" => :alt,
|
||||
"Simply" => :alt,
|
||||
}.each do |str, expected|
|
||||
it "returns #{expected} for #{str} in /etc/altlinux-release" do
|
||||
comm.stub_command("test -f /etc/os-release", exit_code: 1)
|
||||
comm.stub_command("cat /etc/altlinux-release", stdout: str)
|
||||
expect(cap.flavor(machine)).to be(expected)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with /etc/os-release file" do
|
||||
{
|
||||
[ "NAME=\"Sisyphus\"", "VERSION_ID=20161130" ] => :alt,
|
||||
|
||||
[ "NAME=\"ALT Education\"", "VERSION_ID=8.1" ] => :alt_8,
|
||||
[ "NAME=\"ALT Server\"", "VERSION_ID=8.1" ] => :alt_8,
|
||||
[ "NAME=\"ALT SPServer\"", "VERSION_ID=8.0" ] => :alt_8,
|
||||
[ "NAME=\"starter kit\"", "VERSION_ID=p8" ] => :alt_8,
|
||||
[ "NAME=\"ALT Linux\"", "VERSION_ID=8.0.0" ] => :alt_8,
|
||||
[ "NAME=\"Simply Linux\"", "VERSION_ID=7.95.0" ] => :alt_8,
|
||||
|
||||
[ "NAME=\"ALT Linux\"", "VERSION_ID=7.0.5" ] => :alt_7,
|
||||
[ "NAME=\"School Junior\"", "VERSION_ID=7.0.5" ] => :alt_7,
|
||||
}.each do |strs, expected|
|
||||
it "returns #{expected} for #{strs[0]} and #{strs[1]} in /etc/os-release" do
|
||||
comm.stub_command("test -f /etc/os-release", exit_code: 0)
|
||||
comm.stub_command("grep NAME /etc/os-release", stdout: strs[0])
|
||||
comm.stub_command("grep VERSION_ID /etc/os-release", stdout: strs[1])
|
||||
expect(cap.flavor(machine)).to be(expected)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue