Class: Machinery::UpgradeFormatTask

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

Overview

Copyright © 2013-2016 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
63
64
65
66
67
68
69
70
71
72
73
74
75
# 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
      hash = Machinery::Manifest.load(description, store.manifest_path(description)).to_hash
      Machinery.logger.info "Upgrading description '#{description}'"
      Machinery::Ui.print "Reading '#{description}' ... "
      migrated = Machinery::Migration.migrate_description(
        store,
        description,
        force: options[:force]
      )

      if migrated
        migrations_done += 1
        Machinery::Ui.puts "Successfully upgraded from version"\
          " #{hash["meta"]["format_version"]}"\
          " to #{Machinery::SystemDescription::CURRENT_FORMAT_VERSION}."
      end
    rescue StandardError => e
      errors.push("Upgrading description '#{description}' failed:\n#{e}")
      Machinery::Ui.puts "Upgrade failed."
    end
  end

  unless errors.empty?
    Machinery.logger.error errors.join("\n")
    exception = Machinery::Errors::UpgradeFailed.new("\n" + errors.join("\n") +
      Machinery::Ui::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} " \
          "#{Machinery.pluralize(migrations_done, "system description", "system descriptions")}."
      )
    else
      Machinery::Ui.puts "No system descriptions were upgraded."
    end
  end
end