-
Notifications
You must be signed in to change notification settings - Fork 19
/
migration_repos_workflow.rb
262 lines (231 loc) · 8.34 KB
/
migration_repos_workflow.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
require "yast"
require "registration/registration"
require "registration/registration_ui"
require "registration/sw_mgmt"
require "registration/ui/migration_selection_dialog"
module Registration
module UI
# This class handles workflow for adding migration services
class MigrationReposWorkflow
include Yast::Logger
include Yast::I18n
include Yast::UIShortcuts
Yast.import "Report"
Yast.import "Sequencer"
# run workflow for adding the migration services
def self.run
workflow = MigrationReposWorkflow.new
workflow.run
end
# the constructor
def initialize
textdomain "registration"
url = UrlHelpers.registration_url
self.registration = Registration.new(url)
self.registration_ui = RegistrationUI.new(registration)
self.registered_services = []
self.error = false
end
# The repositories migration workflow is:
#
# - find all installed products
# - ask the registration server for the available product migrations
# - user selects the migration target
# - the registered products are upgraded and new services/repositories
# are added to the system
# - return the migration summary to the caller
# @return [Hash] the result is a Hash with migration repositores details
# or error details
#
# @example Migration to the new services succeeded
# {
# # service details
# registered_services: [
# { name: "SUSE_Linux_Enterprise_Server_12_SP1_12.1_x86_64",
# url: "https://scc.suse.com/...",
# product: {
# name: "SLES",
# friendly_name: "SUSE Linux Enterprise Server 12 SP1 12.1 x86_64",
# version: "12.1",
# arch: "x86_64",
# release_type: nil },
# repositories: [{
# # the data returned from Pkg.SourceGeneralData() + the source ID
# "alias" => "SUSE_Linux_Enterprise_Server_12_SP1_12.1_x86_64:" \
# "SLES12-SP1-Pool",
# "autorefresh" => false,
# "base_urls" => ["https://updates.suse.com/..."],
# "enabled" => true,
# "is_update_repo" => false,
# "keeppackages" => false,
# "mirror_list" => "",
# "name" => "SLES12-SP1-Pool",
# "priority" => 99,
# "product_dir" => "",
# "service" => "SUSE_Linux_Enterprise_Server_12_SP1_12.1_x86_64",
# "type" => "YUM",
# "url" => "https://updates.suse.com/...",
# "SrcId" => 3
# }]
# }
# ],
# # user requests manual repository adjustment
# manual_repo_selection: false
# }
#
# @example User aborted the migration
# {
# aborted: true
# }
#
# @example An error occured during registeration of migration products
# {
# error: true,
# # (translated) error description
# error_msg: _("Error in ...")
# }
#
def run
aliases = {
"find_products" => [->() { find_products }, true],
"load_migration_products" => [->() { load_migration_products }, true],
"select_migration_products" => ->() { select_migration_products },
"register_migration_products" => ->() { register_migration_products }
}
sequence = {
"ws_start" => "find_products",
"find_products" => {
abort: :abort,
cancel: :cancel,
next: "load_migration_products"
},
"load_migration_products" => {
abort: :abort,
cancel: :cancel,
next: "select_migration_products"
},
"select_migration_products" => {
abort: :abort,
cancel: :cancel,
next: "register_migration_products"
},
"register_migration_products" => {
cancel: :cancel,
abort: :abort,
next: :next
}
}
log.info "Starting migration repositories sequence"
begin
ui = Yast::Sequencer.Run(aliases, sequence)
log.info "User input: #{ui}"
self.aborted = !error && (ui == :abort || ui == :cancel)
rescue => e
log.error "Caught error: #{e.class}: #{e.message.inspect}, #{e.backtrace}"
set_error(e.message)
end
ret = client_result
log.info "Client result: #{ret}"
ret
end
private
attr_accessor :result, :products, :migrations, :registration,
:registration_ui, :selected_migrations, :registered_services,
:manual_repo_selection, :aborted, :error, :error_msg
# find all installed products
# @return [Symbol] workflow symbol (:next or :abort)
def find_products
if !SwMgmt.init
set_error(Yast::Pkg.LastError)
return :abort
end
# load the resolvables from the repositories
Yast::Pkg.SourceLoad
self.products = ::Registration::SwMgmt.installed_products.map do |product|
::Registration::SwMgmt.remote_product(product)
end
if products.empty?
# TRANSLATORS: Error message
set_error(_("No installed product found."))
return :abort
end
:next
end
# load migration products for the installed products from the registration server
# @return [Symbol] workflow symbol (:next or :abort)
def load_migration_products
self.migrations = registration_ui.migration_products(products)
if migrations.empty?
# TRANSLATORS: Error message
set_error(_("No migration product found."))
return :abort
end
:next
end
# run the migration target selection dialog
# @return [Symbol] workflow symbol (:next or :abort)
def select_migration_products
dialog = MigrationSelectionDialog.new(migrations)
ret = dialog.run
if ret == :next
self.selected_migrations = dialog.selected_migrations
self.manual_repo_selection = dialog.manual_repo_selection
end
log.info "Selected migrations: #{selected_migrations}"
ret
end
# upgrade the services to the new version
# @return [Symbol] workflow symbol (:next)
def register_migration_products
Yast::Popup.Feedback(RegistrationUI::CONTACTING_MESSAGE,
# TRANSLATORS: Progress label
_("Registering Migration Products...")) do
selected_migrations.each do |migration|
migration.each do |product|
log.info "Registering migration product #{product}"
registered_services << registration.upgrade_product(product)
end
end
end
log.info "Registered services: #{registered_services}"
:next
end
# format the client response
# @return [Hash] client response
# @see #run for examples
def client_result
# abort result
return { aborted: true } if aborted
# error result
if error
return {
error: true,
error_msg: error_msg
}
end
# success
{
registered_services: registered_services.map do |service|
{
name: service.name,
url: service.url,
product: {
name: service.product.identifier,
friendly_name: service.product.friendly_name,
version: service.product.version,
arch: service.product.arch,
release_type: service.product.release_type
},
repositories: SwMgmt.service_repos(service)
}
end,
manual_repo_selection: manual_repo_selection
}
end
def set_error(msg)
self.error = true
self.error_msg = msg
end
end
end
end