Skip to content

Commit

Permalink
Merge 27977ec into 8f2c3ba
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Dec 3, 2018
2 parents 8f2c3ba + 27977ec commit 65f1aca
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package/autoyast2.spec
Expand Up @@ -68,7 +68,7 @@ Requires: yast2-ntp-client >= 4.0.1
# Moving security module to first installation stage
Requires: yast2-security >= 4.1.1
Requires: yast2-network >= 3.1.145
Requires: yast2-schema
Requires: yast2-schema >= 4.0.6
Requires: yast2-transfer >= 2.21.0
Requires: yast2-xml
# AutoinstIssues::NoProposal
Expand Down
22 changes: 21 additions & 1 deletion src/clients/inst_autoconfigure.rb
Expand Up @@ -87,6 +87,26 @@ def main
unknown_sections = Y2ModuleConfig.unhandled_profile_sections - unsupported_sections
if unknown_sections.any?
log.error "Could not process these unknown profile sections: #{unknown_sections}"
needed_packages = Y2ModuleConfig.required_packages(unknown_sections)
unless needed_packages.empty?
schema_package_list = needed_packages.map do |section, packages|
case packages.size
when 0
package_description = _("No needed package found.")
when 1
# TRANSLATOR: %s is the package name
package_description = _("Needed package: %s") % packages.first
else
# TRANSLATOR: %s is the list of package names
package_description = _("Needed packages: %s") % packages.join(",")
end

"<#{section}/> - #{package_description}"
end
else
schema_package_list = unknown_sections.map{|section| "<#{section}/>"}
end

Report.LongWarning(
# TRANSLATORS: Error message, %s is replaced by newline-separated
# list of unknown sections of the profile
Expand All @@ -98,7 +118,7 @@ def main
"all the needed YaST packages in the <software/> section " \
"as required for functionality provided by additional modules."
) %
unknown_sections.map{|section| "&lt;#{section}/&gt;"}.join("<br>")
schema_package_list.join("<br>")
)
end

Expand Down
65 changes: 59 additions & 6 deletions src/modules/Y2ModuleConfig.rb
Expand Up @@ -15,6 +15,8 @@ class Y2ModuleConfigClass < Module
RESOURCE_NAME_MERGE_KEYS = "X-SuSE-YaST-AutoInstMerge"
RESOURCE_ALIASES_NAME_KEY = "X-SuSE-YaST-AutoInstResourceAliases"
MODES = %w(all configure write)
YAST_SCHEMA_DIR = "/usr/share/YaST2/schema/autoyast/rng/*.rng"
SCHEMA_PACKAGE_FILE = "/usr/share/YaST2/schema/autoyast/rnc/includes.rnc"

include Yast::Logger

Expand All @@ -28,6 +30,7 @@ def main
Yast.import "Desktop"
Yast.import "Wizard"
Yast.import "Directory"
Yast.import "PackageSystem"

# include "autoinstall/io.ycp";

Expand Down Expand Up @@ -67,7 +70,6 @@ def ReadMenuEntries(modes)
Desktop.Read(_Values)
configurations = deep_copy(Desktop.Modules)

#y2debug("%1", configurations );
groups = deep_copy(Desktop.Groups)

confs = {}
Expand Down Expand Up @@ -116,7 +118,6 @@ def SortGroups(_GroupMap, _GroupList)
# @return [void]
def CreateGroupTree(_Groups)
_Groups = deep_copy(_Groups)
#y2debug("Groups: %1", Groups);

grouplist = []
grouplist = SortGroups(_Groups, Builtins.maplist(_Groups) do |rawname, group|
Expand All @@ -128,8 +129,6 @@ def CreateGroupTree(_Groups)
_MeunTreeEntry = { "entry" => name, "title" => title }
@MenuTreeData = Builtins.add(@MenuTreeData, _MeunTreeEntry)
end

#y2debug("data: %1", MenuTreeData);
nil
end

Expand Down Expand Up @@ -158,8 +157,6 @@ def ConstructMenu
@MenuTreeData = Builtins.add(@MenuTreeData, menu_entry)
end
end
# y2debug("MenuTreeData: %1", MenuTreeData );

nil
end

Expand Down Expand Up @@ -418,6 +415,41 @@ def resource_aliases_map
end
end

# Returns required package names for the given AutoYaST sections.
#
# @param sections [Array<String>] Section names
# @return [Hash<String, Array<String>>] Required packages of a section.
def required_packages(sections)
package_names = {}
log.info "Evaluating needed packages for handling AY-sections #{sections}"
if PackageSystem.Installed("yast2-schema") &&
PackageSystem.Installed("grep")
sections.each do |section|
# Evaluate which *rng file belongs to the given section
package_names[section] = []
ret = SCR.Execute(path(".target.bash_output"),
"/usr/bin/grep -l \"<define name=\\\"#{section}\\\">\" #{YAST_SCHEMA_DIR}")
if ret["exit"] == 0
ret["stdout"].split.uniq.each do |rng_file|
# Evalute package name to which this rng file belongs to.
package = package_name_of_schema(File.basename(rng_file, ".rng"))
if package
package_names[section] << package unless PackageSystem.Installed(package)
else
log.info("No package belongs to #{rng_file}.")
end
end
else
log.info("Cannot evaluate needed packages for AY section: #{section}")
end
end
else
log.info("Cannot evaluate needed packages for installation " \
"due missing environment.")
end
return package_names
end

publish :variable => :GroupMap, :type => "map <string, map>"
publish :variable => :ModuleMap, :type => "map <string, map>"
publish :variable => :MenuTreeData, :type => "list <map>"
Expand All @@ -426,8 +458,29 @@ def resource_aliases_map
publish :function => :getResourceData, :type => "any (map, string)"
publish :function => :Deps, :type => "list <map> ()"
publish :function => :SetDesktopIcon, :type => "boolean (string)"
publish :function => :required_packages, :type => "map <string, list> (list <string>)"
publish :function => :unhandled_profile_sections, :type => "list <string> ()"
publish :function => :unsupported_profile_sections, :type => "list <string> ()"

private

# Returns package name of a given schema.
# This information is stored in /usr/share/YaST2/schema/autoyast/rnc/includes.rnc
# which will be provided by the yast2-schema package.
#
# @param schema <String> schema name like firewall, firstboot, ...
# @return <String> package name or nil
def package_name_of_schema(schema)
if !@schema_package
@schema_package = {}
File::readlines(SCHEMA_PACKAGE_FILE).each do |line|
line_split = line.split
next if line.split.size < 4 # Old version of yast2-schema
@schema_package[File.basename(line_split[1].delete("\'"), ".rnc")] = line.split.last
end
end
@schema_package[schema]
end
end

Y2ModuleConfig = Y2ModuleConfigClass.new
Expand Down
53 changes: 53 additions & 0 deletions test/Y2ModuleConfig_test.rb
Expand Up @@ -135,4 +135,57 @@
end
end
end

describe "#required_packages" do
context "packages needed for the check are not installed" do
it "returns an empty hash" do
allow(Yast::PackageSystem).to receive(:Installed).with("yast2-schema").and_return false
expect(subject.required_packages([])).to eq({})
end
end

context "all packages needed for the check are installed" do
before do
allow(Yast::PackageSystem).to receive(:Installed).with("yast2-schema").and_return true
allow(Yast::PackageSystem).to receive(:Installed).with("grep").and_return true
end

context "no rng file found for the given AY section" do
it "returns a hash with an empty package array" do
expect(Yast::SCR).to receive(:Execute).with(Yast::Path.new(".target.bash_output"),
"/usr/bin/grep -l \"<define name=\\\"not-found\\\">\" /usr/share/YaST2/schema/autoyast/rng/*.rng").
and_return({"exit"=>1, "stderr"=>"", "stdout"=>""})
expect(subject.required_packages(["not-found"])).to eq({"not-found"=>[]})
end
end

context "rng file found for the given AY section" do
before do
allow(Yast::SCR).to receive(:Execute).with(Yast::Path.new(".target.bash_output"),
"/usr/bin/grep -l \"<define name=\\\"firstboot\\\">\" /usr/share/YaST2/schema/autoyast/rng/*.rng").
and_return ( {"exit"=>0, "stderr"=>"",
"stdout"=>"/usr/share/YaST2/schema/autoyast/rng/firstboot.rng\n"} )
allow(File).to receive(:readlines).with("/usr/share/YaST2/schema/autoyast/rnc/includes.rnc").
and_return(["include 'firstboot.rnc' # yast2-firstboot\n", "include 'pxe.rnc' # autoyast2\n"])
end

context "regarding rnc files does not belong to any package" do
it "returns a hash with an empty package array" do
expect(Yast::SCR).to receive(:Execute).with(Yast::Path.new(".target.bash_output"),
"/usr/bin/grep -l \"<define name=\\\"fake\\\">\" /usr/share/YaST2/schema/autoyast/rng/*.rng").
and_return ( {"exit"=>0, "stderr"=>"",
"stdout"=>"/usr/share/YaST2/schema/autoyast/rng/fake.rng\n"} )
expect(subject.required_packages(["fake"])).to eq({"fake"=>[]})
end
end

context "regarding rnc files belongs to a package" do
it "returns a hash with needed package list" do
expect(Yast::PackageSystem).to receive(:Installed).with("yast2-firstboot").and_return false
expect(subject.required_packages(["firstboot"])).to eq({"firstboot"=>["yast2-firstboot"]})
end
end
end
end
end
end

0 comments on commit 65f1aca

Please sign in to comment.