Class: UpgradeFormatTask

Inherits:
Object
  • Object
show all
Defined in:
lib/upgrade_format_task.rb

Overview

Copyright © 2013-2015 SUSE LLC

This program is free software; you can redistribute it and/or modify it under the terms of version 3 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 about this file by physical or electronic mail, you may find current contact information at www.suse.com

Instance Method Summary collapse

Instance Method Details

#upgrade(store, name, options = {}) ⇒ Object



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
# File 'lib/upgrade_format_task.rb', line 19

def upgrade(store, name, options = {})
  if !options[:all] && !store.list.include?(name)
    raise Machinery::Errors::SystemDescriptionNotFound.new(
      "System description \"#{name}\" does not exist."
    )
  end

  if options[:all]
    descriptions = store.list
  else
    descriptions = [name]
  end

  errors = []
  migrations_done = 0

  descriptions.each do |description|
    begin
      Machinery.logger.info "Upgrading description \"#{description}\""
      Machinery::Ui.puts "Upgrading description \"#{description}\""
      migrated = Migration.migrate_description(store, description, force: options[:force])
      migrations_done += 1 if migrated
    rescue StandardError => e
      errors.push("Upgrading description \"#{description}\" failed:\n#{e}")
    end
  end

  if !errors.empty?
    Machinery.logger.error errors.join("\n")
    exception = Machinery::Errors::UpgradeFailed.new(errors.join("\n") +
      Hint.to_string(:upgrade_format_force, name: name || "--all"))
    raise exception
  end

  if options[:all]
    if migrations_done > 0
      Machinery::Ui.puts "Upgraded #{migrations_done} system descriptions successfully."
    else
      Machinery::Ui.puts "No system descriptions were upgraded."
    end
  elsif migrations_done > 0
    Machinery::Ui.puts "System description \"#{name}\" successfully upgraded."
  end
end