-
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 #364 from yast/imo-add-info-ayast-probe
Add storage information to ayast_probe
- Loading branch information
Showing
10 changed files
with
245 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,2 @@ | ||
# encoding: utf-8 | ||
|
||
# File: clients/ayast_probe.ycp | ||
# Package: Auto-installation | ||
# Author: Uwe Gansert <ug@suse.de> | ||
# Summary: This client is more or less for debugging. | ||
# It dumps interesting autoyast values and is | ||
# not as scaring as reading y2log just for some info | ||
# | ||
# Changes: * initial - just dumps the rule values | ||
# $Id$ | ||
module Yast | ||
class AyastProbeClient < Client | ||
def main | ||
Yast.import "UI" | ||
Yast.import "Stage" | ||
Stage.Set("initial") | ||
Yast.import "AutoInstallRules" | ||
Yast.import "Label" | ||
AutoInstallRules.ProbeRules | ||
|
||
@attrs = | ||
# "NonLinuxPartitions":AutoInstallRules::NonLinuxPartitions, | ||
# "LinuxPartitions":AutoInstallRules::LinuxPartitions, | ||
# "disksize":AutoInstallRules::disksize | ||
{ | ||
"installed_product" => AutoInstallRules.installed_product, | ||
"installed_product_version" => AutoInstallRules.installed_product_version( | ||
), | ||
"hostname" => AutoInstallRules.hostname, | ||
"hostaddress" => AutoInstallRules.hostaddress, | ||
"network" => AutoInstallRules.network, | ||
"domain" => AutoInstallRules.domain, | ||
"arch" => AutoInstallRules.arch, | ||
"karch" => AutoInstallRules.karch, | ||
"product" => AutoInstallRules.product, | ||
"product_vendor" => AutoInstallRules.product_vendor, | ||
"board_vendor" => AutoInstallRules.board_vendor, | ||
"board" => AutoInstallRules.board, | ||
"memsize" => AutoInstallRules.memsize, | ||
"totaldisk" => AutoInstallRules.totaldisk, | ||
"hostid" => AutoInstallRules.hostid, | ||
"mac" => AutoInstallRules.mac, | ||
"linux" => AutoInstallRules.linux, | ||
"others" => AutoInstallRules.others, | ||
"xserver" => AutoInstallRules.xserver | ||
} | ||
@text = "<h3>Keys for rules</h3><table>" | ||
Builtins.foreach(@attrs) do |k, v| | ||
@text = Ops.add( | ||
@text, | ||
Builtins.sformat( | ||
"<tr><td>%1</td><td> = </td><td>%2<br></td></tr>", | ||
k, | ||
v | ||
) | ||
) | ||
end | ||
|
||
UI.OpenDialog( | ||
Opt(:defaultsize), | ||
VBox(RichText(@text), PushButton(Opt(:default), Label.OKButton)) | ||
) | ||
UI.UserInput | ||
UI.CloseDialog | ||
|
||
nil | ||
end | ||
end | ||
end | ||
|
||
Yast::AyastProbeClient.new.main | ||
require "autoinstall/clients/ayast_probe" | ||
Y2Autoinstall::Clients::AyastProbe.new.main |
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,139 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2017] 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. | ||
|
||
Yast.import "UI" | ||
Yast.import "Stage" | ||
Yast.import "AutoInstallRules" | ||
Yast.import "Label" | ||
require "y2storage" | ||
|
||
module Y2Autoinstall | ||
module Clients | ||
class AyastProbe | ||
include Yast::UIShortcuts | ||
|
||
# Client entry point | ||
def main | ||
Yast::Stage.Set("initial") | ||
Yast::AutoInstallRules.ProbeRules | ||
|
||
Yast::UI.OpenDialog( | ||
Opt(:defaultsize), | ||
VBox(RichText(content), PushButton(Opt(:default), Yast::Label.OKButton)) | ||
) | ||
Yast::UI.UserInput | ||
Yast::UI.CloseDialog | ||
|
||
nil | ||
end | ||
|
||
# Content | ||
# | ||
# @return [String] Dialog's content | ||
def content | ||
text = autoinstall_rules_content | ||
text << "<br>" | ||
text << storage_data_content | ||
end | ||
|
||
private | ||
|
||
# Builds a HTML table for a given hash | ||
# | ||
# Keys will be sorted in alphabetical order. | ||
# | ||
# @param rows [Hash<String,String>] Keys/values to show in the table | ||
# @return [String] HTML representation | ||
def table(rows) | ||
content = rows.keys.sort.map do |key| | ||
"<tr><td>#{key}</td><td> = </td><td>#{rows[key]}<br></td></tr>" | ||
end | ||
content.join("\n") | ||
end | ||
|
||
# @return [Array<Symbol>] AutoInstallRules to shown | ||
RULES = [ | ||
:installed_product, | ||
:installed_product_version, | ||
:hostname, | ||
:hostaddress, | ||
:network, | ||
:domain, | ||
:arch, | ||
:karch, | ||
:product, | ||
:product_vendor, | ||
:board, | ||
:memsize, | ||
:totaldisk, | ||
:hostid, | ||
:mac, | ||
:linux, | ||
:others, | ||
:xserver | ||
].freeze | ||
|
||
# Retrieves AutoinstallRules data | ||
# | ||
# @return [Hash<String,String>] | ||
def autoinstall_rules_data | ||
RULES.each_with_object({}) do |rule, hsh| | ||
value = Yast::AutoInstallRules.public_send(rule) | ||
hsh[rule] = value | ||
end | ||
end | ||
|
||
# Returns content for autoinstall rules section | ||
# | ||
# @return [String] Section content | ||
def autoinstall_rules_content | ||
"<h1>Keys for rules</h1>#{table(autoinstall_rules_data)}" | ||
end | ||
|
||
# Retrieves storage data | ||
# | ||
# Only disk devices are considered. | ||
# | ||
# @return [Hash<String,Hash>] Storage data indexed by device kernel name | ||
def storage_data | ||
return @storage_data if @storage_data | ||
devicegraph = Y2Storage::StorageManager.instance.probed | ||
|
||
@storage_data = devicegraph.disk_devices.each_with_object({}) do |device, data| | ||
hsh = Y2Storage::AutoinstProfile::SkipListValue.new(device).to_hash | ||
data[hsh[:device]] = hsh | ||
end | ||
end | ||
|
||
# Returns content for storage data section | ||
# | ||
# @return [String] Section content | ||
def storage_data_content | ||
text = "<h1>Storage Data</h1>" | ||
storage_data.keys.sort.each do |name| | ||
text << "<h2>#{name}</h2>" | ||
text << table(storage_data[name]) | ||
end | ||
text | ||
end | ||
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
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,68 @@ | ||
#!/usr/bin/env rspec | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2017] 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 "../../test_helper" | ||
require "autoinstall/clients/ayast_probe" | ||
|
||
describe Y2Autoinstall::Clients::AyastProbe do | ||
subject(:client) { described_class.new } | ||
|
||
let(:devicegraph) { instance_double(Y2Storage::Devicegraph, disk_devices: disk_devices) } | ||
let(:disk_devices) { [disk] } | ||
let(:disk) { instance_double(Y2Storage::Disk, name: "/dev/sda") } | ||
let(:skip_list_value) do | ||
instance_double( | ||
Y2Storage::AutoinstProfile::SkipListValue, | ||
to_hash: { device: "/dev/sda" } | ||
) | ||
end | ||
|
||
before do | ||
allow(Yast::UI).to receive(:OpenDialog).and_return(true) | ||
allow(Yast::UI).to receive(:CloseDialog).and_return(true) | ||
allow(Y2Storage::StorageManager.instance).to receive(:probed) | ||
.and_return(devicegraph) | ||
allow(Y2Storage::AutoinstProfile::SkipListValue).to receive(:new).with(disk) | ||
.and_return(skip_list_value) | ||
end | ||
|
||
describe "#main" do | ||
let(:installed_product) { "openSUSE Tumbleweed" } | ||
|
||
before do | ||
allow(Yast::AutoInstallRules).to receive(:installed_product) | ||
.and_return(installed_product) | ||
end | ||
|
||
it "includes autoinstall rules information" do | ||
expect(client).to receive(:RichText) | ||
.with(/Keys for rules.*<td>installed_product<\/td><td> = <\/td><td>openSUSE Tumbleweed<br><\/td>/m) | ||
client.main | ||
end | ||
|
||
it "includes storage data" do | ||
expect(client).to receive(:RichText) | ||
.with(/Storage Data.*<h2>\/dev\/sda<\/h2>.*<td>device<\/td><td> = <\/td><td>\/dev\/sda<br><\/td>/m) | ||
client.main | ||
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