/
migration_repos_workflow.rb
317 lines (270 loc) · 10.4 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# ------------------------------------------------------------------------------
# Copyright (c) 2015 SUSE LLC
#
# 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.
#
# ------------------------------------------------------------------------------
#
require "yast"
require "registration/registration"
require "registration/registration_ui"
require "registration/migration_repositories"
require "registration/sw_mgmt"
require "registration/ui/migration_selection_dialog"
require "registration/ui/migration_repos_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
# @return [Symbol] the UI symbol
def self.run
workflow = MigrationReposWorkflow.new
workflow.run
end
# the constructor
def initialize
textdomain "registration"
# a dummy message which will be used later, just make sure we have it
# before the translation deadline...
# TRANSLATORS: popup question, confirm installing the available
# updates now
_("Online updates are available for installation.\n" \
"It is recommended to install all updates before proceeding.\n\n" \
"Would you like to install the updates now?")
url = UrlHelpers.registration_url
self.registration = Registration.new(url)
self.registration_ui = RegistrationUI.new(registration)
self.registered_services = []
end
# The repositories migration workflow is:
#
# - find all installed products
# - query registered addons from the server
# - ask the registration server for the available product migrations
# (for both installed and registered products)
# - user selects the migration target
# - the registered products are upgraded and new services/repositories
# are added to the system
# - (optionally) user manually selects the migration repositories
# - user is asked to install also the latest updates (or to migrate to the GA version)
# - "Update from ALL" is set in libzypp (uses all enabled repositories)
# - (optional step) user can manually set the migration repositories,
# the selected repositories are enabled or disabled
# - return the user input symbol (:next or :abort) to the caller
# @return [Symbol] the UI symbol
#
def run
log.info "Starting migration repositories sequence"
ret = nil
begin
ret = run_sequence
rescue => e
log.error "Caught error: #{e.class}: #{e.message.inspect}, #{e.backtrace}"
# TRANSLATORS: error message, %s are details
Yast::Report.Error(_("Internal error: %s") % e.message)
ret = :abort
end
ret
end
private
attr_accessor :products, :migrations, :registration,
:registration_ui, :selected_migration, :registered_services,
:manual_repo_selection
WORKFLOW_SEQUENCE = {
"ws_start" => "find_products",
"find_products" => {
abort: :abort,
cancel: :abort,
next: "load_migration_products"
},
"load_migration_products" => {
abort: :abort,
cancel: :abort,
next: "select_migration_products"
},
"select_migration_products" => {
abort: :abort,
cancel: :abort,
next: "register_migration_products"
},
"register_migration_products" => {
abort: :abort,
cancel: :abort,
next: "activate_migration_repos"
},
"activate_migration_repos" => {
abort: :abort,
cancel: :abort,
repo_selection: "select_migration_repos",
next: "store_repos_state"
},
"select_migration_repos" => {
abort: :abort,
cancel: :abort,
next: "store_repos_state"
},
"store_repos_state" => {
next: :next
}
}
# run the workflow
# @return [Symbol] the UI symbol
def run_sequence
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 }, true],
"activate_migration_repos" => [->() { activate_migration_repos }, true],
"select_migration_repos" => ->() { select_migration_repos },
"store_repos_state" => ->() { store_repos_state }
}
ui = Yast::Sequencer.Run(aliases, WORKFLOW_SEQUENCE)
log.info "User input: #{ui}"
ui
end
# find all installed products
# @return [Symbol] workflow symbol (:next or :abort)
def find_products
log.info "Loading installed products"
SwMgmt.init(true)
self.products = ::Registration::SwMgmt.installed_products.map do |product|
::Registration::SwMgmt.remote_product(product)
end
if products.empty?
# TRANSLATORS: Error message
Yast::Report.Error(_("No installed product found."))
return :abort
end
merge_registered_addons
log.info "Products to migrate: #{products}"
:next
end
def merge_registered_addons
# load the extensions to merge the registered but not installed extensions
Addon.find_all(registration)
addons = Addon.registered_not_installed.map(&:to_h).map do |addon|
SwMgmt.remote_product(addon)
end
products.concat(addons)
end
# load migration products for the installed products from the registration server
# @return [Symbol] workflow symbol (:next or :abort)
def load_migration_products
log.info "Loading migration products from server"
self.migrations = registration_ui.migration_products(products)
if migrations.empty?
# TRANSLATORS: Error message
Yast::Report.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
log.info "Displaying migration target selection dialog"
dialog = MigrationSelectionDialog.new(migrations, products_to_migrate)
ret = dialog.run
if ret == :next
self.selected_migration = dialog.selected_migration
self.manual_repo_selection = dialog.manual_repo_selection
log.info "Selected migration: #{selected_migration}"
end
ret
end
# collect products to migrate
# @return [Array<Hash>] installed or registered products
def products_to_migrate
installed_products = SwMgmt.installed_products
log.info "installed_products: #{installed_products}"
registered_products = Addon.registered_not_installed.map do |addon|
ret = addon.to_h
ret["display_name"] = addon.friendly_name
ret
end
installed_products.concat(registered_products)
end
# upgrade the services to the new version
# @return [Symbol] workflow symbol (:next)
def register_migration_products
migration_progress
begin
log.info "Registering the migration target products"
Yast::Popup.Feedback(RegistrationUI::CONTACTING_MESSAGE,
# TRANSLATORS: Progress label
_("Registering Migration Products...")) do
if !selected_migration.all? { |product| register_migration_product(product) }
return :abort
end
end
ensure
Yast::Wizard.EnableNextButton
Yast::Wizard.EnableBackButton
end
# synchronize the changes done by modifying the services,
# reinitialize the repositories and reload the available packages
Yast::Pkg.SourceFinishAll
Yast::Pkg.TargetFinish
SwMgmt.init(true)
log.info "Registered services: #{registered_services}"
:next
end
# just set an empty Wizard dialog to replace the current one after
# pressing "Next"
def migration_progress
Yast::Wizard.SetContents(
_("Registration"),
# TRANSLATORS: progress message
Label(_("Preparing Migration Repositories...")),
"",
false,
false
)
end
# register a migration product
# @return [Boolean] true on success
def register_migration_product(product)
log.info "Registering migration product #{product}"
ConnectHelpers.catch_registration_errors do
registered_services << registration.upgrade_product(product)
end
end
# activate the added migration repos (set the DUP property)
# @return [Symbol] the UI symbol (:abort, :next or :repo_selection)
def activate_migration_repos
log.info "Activating the migration repositories"
migration_repos = ::Registration::MigrationRepositories.new
registered_services.each do |service|
migration_repos.services << service
end
if migration_repos.service_with_update_repo?
migration_repos.install_updates = registration_ui.install_updates?
end
migration_repos.activate_services
manual_repo_selection ? :repo_selection : :next
end
# run the manual migration repository selection dialog
# @return [Symbol] the UI symbol (:abort, :next)
def select_migration_repos
UI::MigrationReposSelectionDialog.run
end
def store_repos_state
RepoStateStorage.instance.write
:next
end
end
end
end