Skip to content

Commit

Permalink
Merge pull request #201 from imobach/fix-install-rules-sle-12-sp1
Browse files Browse the repository at this point in the history
Fix install rules SLE 12 SP1
  • Loading branch information
imobachgs committed Mar 15, 2016
2 parents 4eca998 + 21fa54a commit ff69a3d
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 173 deletions.
7 changes: 7 additions & 0 deletions package/autoyast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Mar 10 08:33:33 UTC 2016 - igonzalezsosa@suse.com

- Evaluate the correct domain, network, product and product version
when applying rules (bnc#963137).
- 3.1.101.15

-------------------------------------------------------------------
Wed Feb 24 16:36:20 UTC 2016 - igonzalezsosa@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/autoyast2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: autoyast2
Version: 3.1.101.14
Version: 3.1.101.15
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
148 changes: 71 additions & 77 deletions src/modules/AutoInstallRules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ module Yast
class AutoInstallRulesClass < Module
include Yast::Logger

# FIXME: why this values?
DEFAULT_IP = "192.168.1.1"
DEFAULT_NETWORK = "192.168.1.0"

def main
Yast.import "UI"
textdomain "autoinst"
Expand All @@ -33,6 +37,8 @@ def main
Yast.import "URL"
Yast.import "IP"
Yast.import "Product"
Yast.import "Hostname"
Yast.import "OSRelease"

Yast.include self, "autoinstall/io.rb"

Expand Down Expand Up @@ -145,31 +151,39 @@ def getMAC
if Stage.initial
cmd = 'ip link show | grep link/ether | head -1 | sed -e "s:^.*link/ether.::" -e "s: .*::"'
ret = SCR.Execute(path(".target.bash_output"), cmd )
Builtins.y2milestone("mac Addr ret:%1", ret)
tmpmac = ret.fetch("stdout","")
Builtins.y2milestone("mac Addr ret:%1", ret)
tmpmac = ret.fetch("stdout","")
end
Builtins.y2milestone("mac Addr tmp:%1", tmpmac)
cleanmac = Builtins.deletechars(tmpmac != nil ? tmpmac : "", ":\n")
Builtins.y2milestone("mac Addr mac:%1", cleanmac)
cleanmac
end

# Return the network part of the hostaddress
#
# Unless is called during initial stage (Stage.initial),
# it always returns DEFAULT_NETWORK.
#
# @example
# AutoInstallRules.getNetwork #=> "192.168.122.0"
#
# @return [String] Network part of the hostaddress
#
# @see hostaddress
# @see get_network_from_wicked
def getNetwork
Stage.initial ? get_network_from_wicked : DEFAULT_NETWORK
end

# Return host id (hex ip )
#
# Unless is called during initial stage (Stage.initial),
# it always returns DEFAULT_IP.
#
# @return [String] host ID
def getHostid
if Stage.initial
wicked_ret = SCR.Execute(path(".target.bash_output"), "/usr/sbin/wicked show --verbose all|grep pref-src")
if wicked_ret["exit"] == 0
stdout = wicked_ret["stdout"].split
@hostaddress = stdout[stdout.index("pref-src")+1]
else
log.warn "Cannot evaluate IP address with wicked: #{wicked_ret["stderr"]}"
@hostaddress = nil
end
else
@hostaddress = "192.168.1.1" # FIXME
end
@hostaddress = Stage.initial ? get_ip_from_wicked : DEFAULT_IP
IP.ToHex(@hostaddress)
end

Expand Down Expand Up @@ -293,9 +307,9 @@ def ProbeRules
Ops.set(@ATTR, "hostid", @hostid)

Ops.set(@ATTR, "hostname", getHostname)
@domain = Convert.to_string(SCR.Read(path(".etc.install_inf.Domain")))
@domain = Hostname.CurrentDomain
Ops.set(@ATTR, "domain", @domain)
@network = Convert.to_string(SCR.Read(path(".etc.install_inf.Network")))
@network = getNetwork
Ops.set(@ATTR, "network", @network)
@haspcmcia = Convert.to_string(
SCR.Read(path(".etc.install_inf.HasPCMCIA"))
Expand All @@ -314,19 +328,13 @@ def ProbeRules

Builtins.y2milestone("Other linux parts: %1", @LinuxPartitions)

distro_str = SCR.Read(path(".content.DISTRO"))
log.info "DISTRO: #{distro_str}"

distro = distro_map(distro_str) || {}
cpe = cpeid_map(distro["cpeid"]) || {}

@installed_product = distro["name"] || ""
@installed_product_version = cpe["version"] || ""
@installed_product = Yast::OSRelease.ReleaseInformation
@installed_product_version = Yast::OSRelease.ReleaseVersion
Ops.set(@ATTR, "installed_product", @installed_product)
Ops.set(@ATTR, "installed_product_version", @installed_product_version)

log.info "Installing #{@installed_product.inspect}, " \
"version: #{@installed_product_version.inspect}"
log.info "Installing #{@installed_product}, " \
"version: #{@installed_product_version}"
log.info "ATTR=#{@ATTR}"

nil
Expand Down Expand Up @@ -461,16 +469,16 @@ def Read
AutoInstallRules.ProbeRules if !rulelist.empty?
Builtins.foreach(rulelist) do |ruleset|
Builtins.y2milestone("Ruleset: %1", ruleset)
rls = ruleset.keys
if( rls.include?("result"))
rls.reject! {|r| r=="result"}
rls.push("result")
end
rls = ruleset.keys
if( rls.include?("result"))
rls.reject! {|r| r=="result"}
rls.push("result")
end
op = Ops.get_string(ruleset, "operator", "and")
rls.reject! {|r| r=="op"}
Builtins.y2milestone("Orderes Rules: %1", rls)
Builtins.y2milestone("Orderes Rules: %1", rls)
Builtins.foreach(rls) do |rule|
ruledef = ruleset.fetch( rule, {} )
ruledef = ruleset.fetch( rule, {} )
Builtins.y2milestone("Rule: %1", rule)
Builtins.y2milestone("Ruledef: %1", ruledef)
match = Ops.get_string(ruledef, "match", "undefined")
Expand Down Expand Up @@ -1160,54 +1168,40 @@ def AutoInstallRules
publish :function => :CreateFile, :type => "void (string)"
publish :function => :AutoInstallRules, :type => "void ()"

private

# TODO FIXME: share these functions (move to yast2?)

# Split CPE ID and distro label (separated by comma)
# @param distro [String] "DISTRO" value from content file
# @return [Hash<String,String>,nil] parsed value, map:
# {"name" => <string>, "cpeid" => <string> }
# or nil if the input value is invalid
def distro_map(distro)
if !distro
log.warn "Received nil distro value"
return nil
end

# split at the first comma, resulting in 2 parts at max.
cpeid, name = distro.split(",", 2)
private

if !name
log.warn "Cannot parse DISTRO value: #{distro}"
return nil
# Return the IP through wicked
#
# @return [String] IP address
def get_ip_from_wicked
wicked_ret = SCR.Execute(path(".target.bash_output"), "/usr/sbin/wicked show --verbose all")
log.info("Wicked show: #{wicked_ret}")

# Regexp to match the network address.
regexp = / pref-src ([\h:\.]+)/
if ret = wicked_ret["stdout"][regexp, 1]
ret
else
log.warn "Cannot evaluate IP address with wicked: #{wicked_ret["stderr"]}"
nil
end

{"cpeid" => cpeid, "name" => name}
end

# parse CPE ID in URI syntax
# @see http://csrc.nist.gov/publications/nistir/ir7695/NISTIR-7695-CPE-Naming.pdf
# @param cpeid [String] e.g. "cpe:/o:suse:sles:12"
# @return [Hash<String,String>] parsed values, the keys are "part", "vendor", "product",
# "version", "update", "edition", "lang", nil is returned for missing values
def cpeid_map(cpeid)
return nil unless cpeid && cpeid.start_with?("cpe:/")

# remove the "cpe:/" prefix
raw_cpe = cpeid.sub(/^cpe:\//, "")

parts = raw_cpe.split(":")

{
"part" => parts[0],
"vendor" => parts[1],
"product" => parts[2],
"version" => parts[3],
"update" => parts[4],
"edition" => parts[5],
"lang" => parts[6]
}
# Return the network address through wicked
#
# @return [String] Network IP address
def get_network_from_wicked
wicked_ret = SCR.Execute(path(".target.bash_output"),
"/usr/sbin/wicked show --verbose all")

# Regexp to match the network address.
regexp = / ([\h:\.]+)\/\d+ dev.+pref-src #{hostaddress}/
if ret = wicked_ret["stdout"][regexp, 1]
ret
else
log.warn "Cannot find network address through wicked: #{wicked_ret}"
nil
end
end
end

Expand Down
Loading

0 comments on commit ff69a3d

Please sign in to comment.