From 4d816f4d270a069d9dceb400883991d6d74a4255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Thu, 18 Jan 2024 14:51:39 +0000 Subject: [PATCH 1/3] [service] Add D-Bus method --- .../bus/org.opensuse.Agama.Software1.bus.xml | 4 +++ doc/dbus/org.opensuse.Agama.Software1.doc.xml | 10 ++++++ service/lib/agama/dbus/clients/software.rb | 15 ++++++-- service/lib/agama/dbus/software/manager.rb | 6 +++- service/lib/agama/software/manager.rb | 13 +++++-- .../test/agama/dbus/clients/software_test.rb | 26 +++++++++++++- .../test/agama/dbus/software/manager_test.rb | 12 ++++++- service/test/agama/software/manager_test.rb | 34 ++++++++++++++++++- 8 files changed, 111 insertions(+), 9 deletions(-) diff --git a/doc/dbus/bus/org.opensuse.Agama.Software1.bus.xml b/doc/dbus/bus/org.opensuse.Agama.Software1.bus.xml index 525ce9d6fb..b2c21475f8 100644 --- a/doc/dbus/bus/org.opensuse.Agama.Software1.bus.xml +++ b/doc/dbus/bus/org.opensuse.Agama.Software1.bus.xml @@ -53,6 +53,10 @@ + + + + diff --git a/doc/dbus/org.opensuse.Agama.Software1.doc.xml b/doc/dbus/org.opensuse.Agama.Software1.doc.xml index ed2dca4c0f..0080f876ff 100644 --- a/doc/dbus/org.opensuse.Agama.Software1.doc.xml +++ b/doc/dbus/org.opensuse.Agama.Software1.doc.xml @@ -75,6 +75,16 @@ + + + + + + diff --git a/service/lib/agama/dbus/clients/software.rb b/service/lib/agama/dbus/clients/software.rb index 9ff10a4fc6..b271e3be2e 100644 --- a/service/lib/agama/dbus/clients/software.rb +++ b/service/lib/agama/dbus/clients/software.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright (c) [2022-2023] SUSE LLC +# Copyright (c) [2022-2024] SUSE LLC # # All Rights Reserved. # @@ -114,13 +114,22 @@ def provisions_selected?(tags) dbus_object.ProvisionsSelected(tags) end - # Determines whether a package with the given name is installed + # Determines whether a package is installed. # - # @param name [String] Package name + # @param name [String] Package name. + # @return [Boolean] def package_installed?(name) dbus_object.IsPackageInstalled(name) end + # Determines whether a package is available. + # + # @param name [String] Package name. + # @return [Boolean] + def package_available?(name) + dbus_object.IsPackageAvailable(name) + end + # Add the given list of resolvables to the packages proposal # # @param unique_id [String] Unique identifier for the resolvables list diff --git a/service/lib/agama/dbus/software/manager.rb b/service/lib/agama/dbus/software/manager.rb index 9ca3ea8eb2..6fec2df0f4 100644 --- a/service/lib/agama/dbus/software/manager.rb +++ b/service/lib/agama/dbus/software/manager.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright (c) [2022-2023] SUSE LLC +# Copyright (c) [2022-2024] SUSE LLC # # All Rights Reserved. # @@ -99,6 +99,10 @@ def issues backend.package_installed?(name) end + dbus_method :IsPackageAvailable, "in name:s, out result:b" do |name| + backend.package_available?(name) + end + dbus_method(:UsedDiskSpace, "out SpaceSize:s") { backend.used_disk_space } dbus_method(:Probe) { probe } diff --git a/service/lib/agama/software/manager.rb b/service/lib/agama/software/manager.rb index c3f83ff969..a6ebf38ff2 100644 --- a/service/lib/agama/software/manager.rb +++ b/service/lib/agama/software/manager.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright (c) [2021-2023] SUSE LLC +# Copyright (c) [2021-2024] SUSE LLC # # All Rights Reserved. # @@ -279,7 +279,7 @@ def on_selected_patterns_change(&block) @selected_patterns_change_callbacks << block end - # Determines whether a package is installed + # Determines whether a package is installed in the target system. # # @param name [String] Package name # @return [Boolean] true if it is installed; false otherwise @@ -287,6 +287,15 @@ def package_installed?(name) on_target { Yast::Package.Installed(name, target: :system) } end + # Determines whether a package is available. + # + # @param name [String] Package name + # @return [Boolean] + def package_available?(name) + # Beware: apart from true and false, Available can return nil if things go wrong. + on_local { !!Yast::Package.Available(name) } + end + # Counts how much disk space installation will use. # @return [String] # @note Reimplementation of Yast::Package.CountSizeToBeInstalled diff --git a/service/test/agama/dbus/clients/software_test.rb b/service/test/agama/dbus/clients/software_test.rb index c379920f5e..6f2fe0b161 100644 --- a/service/test/agama/dbus/clients/software_test.rb +++ b/service/test/agama/dbus/clients/software_test.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright (c) [2022-2023] SUSE LLC +# Copyright (c) [2022-2024] SUSE LLC # # All Rights Reserved. # @@ -164,6 +164,30 @@ end end + describe "#package_available?" do + let(:dbus_object) do + double(::DBus::ProxyObject, introspect: nil, IsPackageAvailable: available) + end + + let(:package) { "NetworkManager" } + + context "when the package is available" do + let(:available) { true } + + it "returns true" do + expect(subject.package_available?(package)).to eq(true) + end + end + + context "when the package is available" do + let(:available) { false } + + it "returns false" do + expect(subject.package_available?(package)).to eq(false) + end + end + end + describe "#on_product_selected" do before do allow(dbus_product).to receive(:path).and_return("/org/opensuse/Agama/Test") diff --git a/service/test/agama/dbus/software/manager_test.rb b/service/test/agama/dbus/software/manager_test.rb index ead7fcdc49..b6c1816ca7 100644 --- a/service/test/agama/dbus/software/manager_test.rb +++ b/service/test/agama/dbus/software/manager_test.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright (c) [2022-2023] SUSE LLC +# Copyright (c) [2022-2024] SUSE LLC # # All Rights Reserved. # @@ -135,4 +135,14 @@ expect(installed).to eq(true) end end + + describe "D-Bus IsPackageAvailable" do + it "returns whether the package is available or not" do + expect(backend).to receive(:package_available?).with("NetworkManager").and_return(true) + available = subject.public_send( + "org.opensuse.Agama.Software1%%IsPackageAvailable", "NetworkManager" + ) + expect(available).to eq(true) + end + end end diff --git a/service/test/agama/software/manager_test.rb b/service/test/agama/software/manager_test.rb index c25e15f4b9..d338bc880f 100644 --- a/service/test/agama/software/manager_test.rb +++ b/service/test/agama/software/manager_test.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright (c) [2022-2023] SUSE LLC +# Copyright (c) [2022-2024] SUSE LLC # # All Rights Reserved. # @@ -406,6 +406,38 @@ end end + describe "#package_available?" do + before do + allow(Yast::Package).to receive(:Available).with(package).and_return(available) + end + + let(:package) { "NetworkManager" } + + context "when the package is available" do + let(:available) { true } + + it "returns true" do + expect(subject.package_available?(package)).to eq(true) + end + end + + context "when the package is not available" do + let(:available) { false } + + it "returns false" do + expect(subject.package_available?(package)).to eq(false) + end + end + + context "when there is an error checking its availability" do + let(:available) { nil } + + it "returns false" do + expect(subject.package_available?(package)).to eq(false) + end + end + end + describe "#product_issues" do before do allow_any_instance_of(Agama::Software::ProductBuilder) From 993b30eb1a4544daa122bc8d12a5bb090f888e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Thu, 18 Jan 2024 14:54:54 +0000 Subject: [PATCH 2/3] [service] Call to Software service to check availability --- service/lib/agama/dbus/y2dir/README.md | 29 ++++++++++++++- .../dbus/y2dir/manager/modules/Package.rb | 35 +++++++++---------- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/service/lib/agama/dbus/y2dir/README.md b/service/lib/agama/dbus/y2dir/README.md index d11a3167c8..7febb8ce64 100644 --- a/service/lib/agama/dbus/y2dir/README.md +++ b/service/lib/agama/dbus/y2dir/README.md @@ -1 +1,28 @@ -Override directory to redirect some yast modules to use D-Bus methods. It is just temporary workaround for POC. +This directory contains some redefinitions of YaST modules in order to call to D-Bus methods instead +of executing the actual code of the module. + +# Why is this needed? + +Agama relies on YaST code and YaST usually works as a single process. By contrast, Agama works as a +set of different processes (software service, storage service, etc), and each service runs its own +YaST instance. + +Having different YaST instances implies that the information is scattered in different processes. +For example, only the YaST instance in the software service has the information about the software +configuration. This means that other YaST instances need to ask to the software YaST instance for +the information. + +# How to communicate among YaST instances + +A YaST instance can get information from other instance by doing a D-Bus call to the service running +such an instance. For example, the YaST instance in the storage service has to call to the D-Bus API +of the software service instead of directly calling to the software module code. To achieve that, +the storage service replaces the implementation of the YaST software module by its own +implementation which uses D-Bus calls. + +# How to replace a YaST module + +The code replacement of the YaST modules is done by means of the *Y2DIR* mechanism of YaST. When a +service is started (check *agamactl* script), the YaST modules redefined by the service (under +*lib/agama/dbus/y2dir/*) are added to the *Y2DIR* environment variable. YaST takes precedence of the +paths at *Y2DIR*, so these files will be loaded instead of the files originally delivered by YaST. diff --git a/service/lib/agama/dbus/y2dir/manager/modules/Package.rb b/service/lib/agama/dbus/y2dir/manager/modules/Package.rb index ec74593cc7..dd43a9573e 100644 --- a/service/lib/agama/dbus/y2dir/manager/modules/Package.rb +++ b/service/lib/agama/dbus/y2dir/manager/modules/Package.rb @@ -1,4 +1,4 @@ -# Copyright (c) [2022] SUSE LLC +# Copyright (c) [2022-2024] SUSE LLC # # All Rights Reserved. # @@ -22,36 +22,35 @@ # :nodoc: module Yast - # Replacement for the Yast::Package module - # - # @see https://github.com/yast/yast-yast2/blob/b8cd178b7f341f6e3438782cb703f4a3ab0529ed/library/packages/src/modules/Package.rb + # Replacement for the Yast::Package module. class PackageClass < Module def main puts "Loading mocked module #{__FILE__}" @client = Agama::DBus::Clients::Software.new end - # Determines whether the package is available + # Determines whether a package is available. # - # @see https://github.com/yast/yast-yast2/blob/b8cd178b7f341f6e3438782cb703f4a3ab0529ed/library/packages/src/modules/Package.rb#L72 - # @todo Perform a real D-Bus call. - def Available(_package_name) - true + # @param name [String] Package name. + # @return [Boolean] + def Available(name) + client.package_available?(name) end - # Determines whether the package is available + # Determines whether a set of packages is available. # - # @todo Perform a real D-Bus call. - def AvailableAll(_package_names) - true + # @param names [Array] Names of the packages. + # @return [Boolean] + def AvailableAll(names) + names.all? { |name| client.package_available?(name) } end - # Determines whether the package is available + # Determines whether a package is installed in the target system. # - # @see https://github.com/yast/yast-yast2/blob/b8cd178b7f341f6e3438782cb703f4a3ab0529ed/library/packages/src/modules/Package.rb#L121 - # @todo Perform a real D-Bus call. - def Installed(package_name, target: nil) - client.package_installed?(package_name) + # @param name [String] Package name. + # @return [Boolean] + def Installed(name, target: nil) + client.package_installed?(name) end private From f827b72d27698b757ec55b266a53c87f9c0baf5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Thu, 18 Jan 2024 14:57:09 +0000 Subject: [PATCH 3/3] [service] Changelog --- service/package/rubygem-agama.changes | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/service/package/rubygem-agama.changes b/service/package/rubygem-agama.changes index 065179651c..686902495f 100644 --- a/service/package/rubygem-agama.changes +++ b/service/package/rubygem-agama.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Thu Jan 18 14:55:36 UTC 2024 - José Iván López González + +- Add support to check availability of a package + (gh#openSUSE/agama#1004). + ------------------------------------------------------------------- Thu Jan 18 08:35:01 UTC 2024 - Ancor Gonzalez Sosa