• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / d-installer / 4512499803

pending completion
4512499803

Pull #501

github

Unknown Committer
Unknown Commit Message
Pull Request #501: [web] Add DASD UI - first version

462 of 863 branches covered (53.53%)

Branch coverage included in aggregate %.

64 of 235 new or added lines in 9 files covered. (27.23%)

14 existing lines in 1 file now uncovered.

4668 of 6129 relevant lines covered (76.16%)

10.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.1
/service/lib/dinstaller/dbus/storage/dasds_format_job.rb
1
# frozen_string_literal: true
2

3
# Copyright (c) [2023] SUSE LLC
4
#
5
# All Rights Reserved.
6
#
7
# This program is free software; you can redistribute it and/or modify it
8
# under the terms of version 2 of the GNU General Public License as published
9
# by the Free Software Foundation.
10
#
11
# This program is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14
# more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with this program; if not, contact SUSE LLC.
18
#
19
# To contact SUSE LLC about this file by physical or electronic mail, you may
20
# find current contact information at www.suse.com.
21

22
require "dbus"
1✔
23
require "dinstaller/dbus/base_object"
1✔
24

25
module DInstaller
1✔
26
  module DBus
1✔
27
    module Storage
1✔
28
      # Class representing the process of formatting a set of DASDs
29
      class DasdsFormatJob < BaseObject
1✔
30
        # Internal class to make easier to index the status information both by DASD id and by job
31
        # path, although in fact both are fully stable during the whole execution of the installer.
32
        #
33
        # This class helps to refresh the relationship between the DASD and its path every time a
34
        # status update is sent from the backend, although as already mentioned that wouldn't be
35
        # needed with the current implementation of the DASDs tree, since it keeps that relationship
36
        # stable.
37
        class DasdFormatInfo
1✔
38
          # @return [String] channel id of the DASD
39
          attr_accessor :id
1✔
40

41
          # @return [String] path of the DASD in the D-Bus tree
42
          attr_accessor :path
1✔
43

44
          # @return [Integer] total number of cylinders reported by the format operation
45
          attr_accessor :cylinders
1✔
46

47
          # @return [Integer] number of cylinders already processed by the format operation
48
          attr_accessor :progress
1✔
49

50
          # @return [Boolean] whether the disk is already fully formatted
51
          attr_accessor :done
1✔
52

53
          # Constructor
54
          #
55
          # @param status [Y2S390::FormatStatus]
56
          # @param dasds_tree [DasdsTree]
57
          def initialize(status, dasds_tree)
1✔
58
            @id = status.dasd.id
2✔
59
            @cylinders = status.cylinders
2✔
60
            @progress = status.progress
2✔
61
            @done = status.done?
2✔
62

63
            dbus_dasd = dasds_tree.find { |d| d.id == @id }
5✔
64
            if dbus_dasd
2✔
65
              @path = dbus_dasd.path
2✔
66
            else
67
              logger.warning "DASD is not longer in the D-BUS tree: #{status.inspect}"
×
68
            end
69
          end
70

71
          # Progress representation as expected by the D-Bus API (property Summary and signal
72
          # SummaryUpdated)
73
          def to_dbus
1✔
74
            [cylinders, progress, done]
2✔
75
          end
76
        end
77

78
        JOB_INTERFACE = "org.opensuse.DInstaller.Storage1.Job"
1✔
79
        private_constant :JOB_INTERFACE
1✔
80

81
        dbus_interface JOB_INTERFACE do
1✔
82
          dbus_reader(:running, "b")
1✔
83
          dbus_reader(:exit_code, "u")
1✔
84
          dbus_signal(:Finished, "exit_code:u")
1✔
85
        end
86

87
        DASD_FORMAT_INTERFACE = "org.opensuse.DInstaller.Storage1.DASD.Format"
1✔
88
        private_constant :DASD_FORMAT_INTERFACE
1✔
89

90
        dbus_interface DASD_FORMAT_INTERFACE do
1✔
91
          dbus_reader(:summary, "a{s(uub)}")
1✔
92
        end
93

94
        # @return [Boolean]
95
        attr_reader :running
1✔
96

97
        # @return [Integer] zero if still running
98
        attr_reader :exit_code
1✔
99

100
        # @return [Array<Y2390::Dasd>]
101
        attr_reader :dasds
1✔
102

103
        # Constructor
104
        #
105
        # @param initial [Array<Y2S390::FormatStatus>] initial status report from the format process
106
        # @param dasds_tree [DasdsTree] see #dasds_tree
107
        # @param path [DBus::ObjectPath] path in which the Job object is exported
108
        # @param logger [Logger, nil]
109
        def initialize(initial, dasds_tree, path, logger: nil)
1✔
110
          super(path, logger: logger)
1✔
111

112
          @exit_code = 0
1✔
113
          @running = true
1✔
114
          @dasds_tree = dasds_tree
1✔
115
          @infos = {}
1✔
116
          update_info(initial)
1✔
117
        end
118

119
        # Current status, in the format described by the D-Bus API
120
        def summary
1✔
121
          result = {}
1✔
122
          @infos.each_value { |i| result[i.path] = i.to_dbus if i.path }
3✔
123
          result
1✔
124
        end
125

126
        # Marks the job as finished
127
        #
128
        # @note A Finished and a PropertiesChanged signals are always emitted.
129
        #
130
        # @param exit_code [Integer]
131
        def finish_format(exit_code)
1✔
132
          @running = false
×
133
          @exit_code = exit_code
×
134
          Finished(exit_code)
×
NEW
135
          dbus_properties_changed(JOB_INTERFACE, interfaces_and_properties[JOB_INTERFACE], [])
×
136
        end
137

138
        # Updates the internal status information
139
        #
140
        # @note A SummaryUpdated signal is always emitted
141
        #
142
        # @param statuses [Array<Y2S390::FormatStatus] latest status update from the format process
143
        def update_format(statuses)
1✔
144
          return if statuses.empty?
×
145

146
          update_info(statuses)
×
147
          dbus_properties_changed(DASD_FORMAT_INTERFACE, { "Summary" => summary }, [])
×
148
        end
149

150
      private
1✔
151

152
        # @return [DasdsTree] D-Bus representation of the DASDs
153
        attr_reader :dasds_tree
1✔
154

155
        # @param statuses [Array<Y2S390::FormatStatus] latest status update from the format process
156
        def update_info(statuses)
1✔
157
          statuses.each do |status|
1✔
158
            info = DasdFormatInfo.new(status, dasds_tree)
2✔
159
            @infos[info.id] = info
2✔
160
          end
161
        end
162
      end
163
    end
164
  end
165
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc