Skip to content

Commit

Permalink
Merge pull request #364 from yast/imo-add-info-ayast-probe
Browse files Browse the repository at this point in the history
Add storage information to ayast_probe
  • Loading branch information
imobachgs committed Nov 13, 2017
2 parents b3f9120 + d954ef4 commit a24c156
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 79 deletions.
7 changes: 7 additions & 0 deletions package/autoyast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Nov 7 15:01:35 UTC 2017 - igonzalezsosa@suse.com

- Add storage data to ayast_probe client (bsc#1065668)
- Handle storage proposal exceptions in a proper way
- 4.0.6

-------------------------------------------------------------------
Tue Oct 31 14:13:40 UTC 2017 - igonzalezsosa@suse.com

Expand Down
13 changes: 8 additions & 5 deletions package/autoyast2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: autoyast2
Version: 4.0.5
Version: 4.0.6
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand All @@ -41,8 +41,8 @@ BuildRequires: yast2-services-manager
BuildRequires: yast2-packager
BuildRequires: yast2-update >= 3.3.0
BuildRequires: yast2-slp
# Y2Storage::AutoinstIssues containing section information
BuildRequires: yast2-storage-ng >= 4.0.15
# Y2Storage::AutoinstProfile::SkipListValue#to_hash
BuildRequires: yast2-storage-ng >= 4.0.23

# %%{_unitdir} macro definition is in a separate package since 13.1
%if 0%{?suse_version} >= 1310
Expand All @@ -61,8 +61,8 @@ Requires: yast2-network >= 3.1.145
Requires: yast2-schema
Requires: yast2-transfer >= 2.21.0
Requires: yast2-xml
# Y2Storage::AutoinstIssues containing section information
Requires: yast2-storage-ng >= 4.0.15
# Y2Storage::AutoinstProfile::SkipListValue#to_hash
Requires: yast2-storage-ng >= 4.0.23
Conflicts: yast2-installation < 3.1.166

Provides: yast2-config-autoinst
Expand Down Expand Up @@ -291,6 +291,9 @@ rmdir $RPM_BUILD_ROOT/%{_prefix}/share/doc/packages/autoyast2/html/autoyast
%dir %{yast_libdir}/autoinstall/dialogs
%{yast_libdir}/autoinstall/dialogs/*.rb

%dir %{yast_libdir}/autoinstall/clients
%{yast_libdir}/autoinstall/clients/*.rb

# scripts
%{_prefix}/lib/YaST2/bin/fetch_image.sh
%{_prefix}/lib/YaST2/bin/autoyast-initscripts.sh
Expand Down
6 changes: 5 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ ydialogsdir = @ylibdir@/autoinstall/dialogs
ydialogs_DATA = \
lib/autoinstall/dialogs/question.rb

yclientsdir = @ylibdir@/autoinstall/clients
yclients_DATA = \
lib/autoinstall/clients/ayast_probe.rb

scrconf_DATA = \
scrconf/cfg_autoinstall.scr \
scrconf/autoinstall.scr
Expand Down Expand Up @@ -108,6 +112,6 @@ desktop_DATA = \
fillup_DATA = \
fillup/sysconfig.autoinstall

EXTRA_DIST = $(module_DATA) $(client_DATA) $(ynclude_DATA) $(scrconf_DATA) $(schemafiles_DATA) $(ybin_SCRIPTS) $(desktop_DATA) $(fillup_DATA) $(ylib_DATA) $(ydialogs_DATA)
EXTRA_DIST = $(module_DATA) $(client_DATA) $(ynclude_DATA) $(scrconf_DATA) $(schemafiles_DATA) $(ybin_SCRIPTS) $(desktop_DATA) $(fillup_DATA) $(ylib_DATA) $(ydialogs_DATA) $(yclients_DATA)

include $(top_srcdir)/Makefile.am.common
74 changes: 2 additions & 72 deletions src/clients/ayast_probe.rb
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
139 changes: 139 additions & 0 deletions src/lib/autoinstall/clients/ayast_probe.rb
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
2 changes: 1 addition & 1 deletion src/lib/autoinstall/storage_proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def handle_exception(error)
when Y2Storage::NoDiskSpaceError
issues_list.add(:no_disk_space)
when Y2Storage::Error
issues_list.add(:unknown, error)
issues_list.add(:exception, error)
else
raise error
end
Expand Down
2 changes: 2 additions & 0 deletions test/AutoInstallRules_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
let(:root_path) { File.expand_path('../..', __FILE__) }

describe "#ProbeRules" do
before { subject.main }

it "detect system properties" do
expect(Yast::SCR).to receive(:Read).with(Yast::Path.new(".probe.bios")).and_return([])
expect(Yast::SCR).to receive(:Read).with(Yast::Path.new(".probe.memory")).and_return([])
Expand Down
1 change: 1 addition & 0 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ TESTS = \
lib/pkg_gpg_check_handler_test.rb \
lib/storage_proposal_issues_presenter_test.rb \
lib/storage_proposal_test.rb \
lib/clients/ayast_probe_test.rb \
lib/dialogs/question_test.rb

TEST_EXTENSIONS = .rb
Expand Down
68 changes: 68 additions & 0 deletions test/lib/clients/ayast_probe_test.rb
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
12 changes: 12 additions & 0 deletions test/lib/storage_proposal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@
expect(storage_proposal.proposal).to be(autoinst_proposal)
end
end

context "when the proposal raises and exception" do
before do
allow(autoinst_proposal).to receive(:propose).and_raise(Y2Storage::Error)
end

it "registers an issue" do
issues_list = storage_proposal.issues_list
issue = issues_list.find { |i| i.is_a?(Y2Storage::AutoinstIssues::Exception) }
expect(issue).to_not be_nil
end
end
end

describe "#save" do
Expand Down

0 comments on commit a24c156

Please sign in to comment.