-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #581 from yast/wsl_product_selection
YAML products reader
- Loading branch information
Showing
9 changed files
with
203 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright (c) [2022] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "yaml" | ||
require "yast" | ||
|
||
module Registration | ||
Yast.import "Arch" | ||
|
||
# Reads products defined by YAML file | ||
# | ||
# Added for SLED registration on a WSL SLES image (jsc#PED-1380). | ||
class YamlProductsReader | ||
attr_reader :path | ||
|
||
def initialize(path = DEFAULT_PATH) | ||
@path = path | ||
end | ||
|
||
# @return [Array<Hash>] | ||
def read | ||
return [] unless yaml_exist? | ||
|
||
YAML.load_file(path).map { |p| transform(p) } | ||
end | ||
|
||
private | ||
|
||
DEFAULT_PATH = "/etc/YaST2/products.yaml".freeze | ||
private_constant :DEFAULT_PATH | ||
|
||
# check if yaml products are defined at all | ||
def yaml_exist? | ||
::File.exist?(path) | ||
end | ||
|
||
# For all values: | ||
# - converts them to String (to allow writing "15.4" as 15.4) | ||
# - replaces $arch substring with the current architecture | ||
# And also: | ||
# - replaces version with version_version as registration expects | ||
# - adds arch key if not defined | ||
# - converts value of default key to boolean | ||
# | ||
# @param product [Hash] | ||
# @return [Hash] A new transformed hash | ||
def transform(product) | ||
arch = Yast::Arch.rpm_arch | ||
|
||
res = product.map do |key, val| | ||
val_s = val.to_s | ||
val_s.gsub!("$arch", arch) | ||
[key, val_s] | ||
end.to_h | ||
res["version_version"] ||= res["version"] | ||
res["arch"] ||= arch | ||
res["default"] = res["default"]&.casecmp?("true") ? true : false | ||
|
||
res | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# TODO: references for this file, | ||
# describe what it is | ||
# https://jira.suse.com/browse/PED-1380 | ||
- display_name: "SUSE Linux Enterprise Desktop 15 SP4" | ||
name: "SLED" | ||
register_target: "sle-15-$arch" | ||
version: "15.4" | ||
- display_name: "SUSE Linux Enterprise Server 15 SP4" | ||
name: "SLES" | ||
register_target: "sle-15-$arch" | ||
version: "15.4" | ||
default: True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright (c) [2022] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require_relative "../spec_helper" | ||
require "registration/yaml_products_reader" | ||
|
||
describe Registration::YamlProductsReader do | ||
subject { described_class.new(File.expand_path("#{__dir__}/../fixtures/wsl_products.yml")) } | ||
|
||
describe "#read" do | ||
it "reads content of yaml file" do | ||
expect(subject.read.first["name"]).to eq "SLED" | ||
end | ||
|
||
it "adds arch key if not defined" do | ||
expect(subject.read.first["arch"]).to eq Yast::Arch.rpm_arch | ||
end | ||
|
||
it "converts version to version_version" do | ||
expect(subject.read.first["version_version"]).to eq "15.4" | ||
end | ||
|
||
it "expands properly arch variable" do | ||
expect(subject.read.first["register_target"]).to eq "sle-15-#{Yast::Arch.rpm_arch}" | ||
end | ||
|
||
it "converts default to boolean" do | ||
products = subject.read | ||
expect(products[0]["default"]).to eq(false) | ||
expect(products[1]["default"]).to eq(true) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters