From e045823ae8cf006402bed86c84fda50818e4ed41 Mon Sep 17 00:00:00 2001 From: Nicolas Bock Date: Wed, 23 Nov 2016 12:14:49 -0700 Subject: [PATCH] provisioner: Add autoyast self update option AutoYaST can update itself before installing the OS. This patch enables this feature and adds a field to the provisioner barclamp so that a repository URL can be set by the user. The special token `` resolves to the IP:port of the admin node. An empty URL defaults to the SUSE customer center (scc.suse.com). --- .../provisioner/recipes/update_nodes.rb | 15 +++++++++++++++ .../templates/default/autoyast.xml.erb | 17 +++++++++++++++++ .../migrate/provisioner/103_self_update.rb | 15 +++++++++++++++ .../data_bags/crowbar/template-provisioner.json | 8 +++++++- .../crowbar/template-provisioner.schema | 4 +++- .../provisioner/_edit_attributes.html.haml | 5 +++++ .../config/locales/provisioner/en.yml | 5 +++++ 7 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 chef/data_bags/crowbar/migrate/provisioner/103_self_update.rb diff --git a/chef/cookbooks/provisioner/recipes/update_nodes.rb b/chef/cookbooks/provisioner/recipes/update_nodes.rb index 32868fd976..40b1b7f9b5 100644 --- a/chef/cookbooks/provisioner/recipes/update_nodes.rb +++ b/chef/cookbooks/provisioner/recipes/update_nodes.rb @@ -301,6 +301,18 @@ def find_node_boot_mac_addresses(node, admin_data_net) end when /^(open)?suse/ + expanded_self_update_url = node[:provisioner][:suse][:autoyast][:self_update_url].gsub( + "", "#{admin_ip}:#{web_port}" + ) + do_self_update = node[:provisioner][:suse][:autoyast][:do_self_update] + if do_self_update && !expanded_self_update_url.empty? + do_self_update = system("wget --quiet --spider " + + expanded_self_update_url.gsub("$arch", "#{arch}")) + unless do_self_update + Chef::Log.warn("AutoYaST self-update URL #{expanded_self_update_url} does not exist") + end + end + append << "install=#{install_url} autoyast=#{node_url}/autoyast.xml" if node[:provisioner][:use_serial_console] append << "textmode=1" @@ -308,6 +320,7 @@ def find_node_boot_mac_addresses(node, admin_data_net) append << "ifcfg=dhcp4 netwait=60" append << "squash=0" # workaround bsc#962397 append << "autoupgrade=1" if mnode[:state] == "os-upgrading" + append << "self_update" if do_self_update target_platform_distro = os.gsub(/-.*$/, "") target_platform_version = os.gsub(/^.*-/, "") @@ -350,6 +363,8 @@ def find_node_boot_mac_addresses(node, admin_data_net) web_port: web_port, packages: packages, repos: repos, + do_self_update: do_self_update, + self_update_url: expanded_self_update_url, rootpw_hash: node[:provisioner][:root_password_hash] || "", timezone: timezone, boot_device: boot_device, diff --git a/chef/cookbooks/provisioner/templates/default/autoyast.xml.erb b/chef/cookbooks/provisioner/templates/default/autoyast.xml.erb index 6260811dd2..6bd2a62c9f 100644 --- a/chef/cookbooks/provisioner/templates/default/autoyast.xml.erb +++ b/chef/cookbooks/provisioner/templates/default/autoyast.xml.erb @@ -26,7 +26,24 @@ true + <% if @do_self_update %> + + <%= @self_update_url %> + + <% end -%> + + + true + true + 10 + + + true + true + 10 + + <% @repos.keys.sort.each do |name| %> diff --git a/chef/data_bags/crowbar/migrate/provisioner/103_self_update.rb b/chef/data_bags/crowbar/migrate/provisioner/103_self_update.rb new file mode 100644 index 0000000000..6d67c1c54f --- /dev/null +++ b/chef/data_bags/crowbar/migrate/provisioner/103_self_update.rb @@ -0,0 +1,15 @@ +def upgrade(ta, td, a, d) + a["suse"] = {} unless a.key?("suse") + a["suse"]["autoyast"] = {} unless a["suse"].key?("autoyast") + a["suse"]["autoyast"]["do_self_update"] = ta["suse"]["autoyast"]["do_self_update"] + a["suse"]["autoyast"]["self_update_url"] = ta["suse"]["autoyast"]["self_update_url"] + return a, d +end + +def downgrade(ta, td, a, d) + delete a["suse"]["autoyast"]["do_self_update"] + delete a["suse"]["autoyast"]["self_update_url"] + delete a["suse"]["autoyast"] if a["suse"]["autoyast"].empty? + delete a["suse"] if a["suse"].empty? + return a, d +end diff --git a/chef/data_bags/crowbar/template-provisioner.json b/chef/data_bags/crowbar/template-provisioner.json index 2729588d9f..55c2aad59e 100644 --- a/chef/data_bags/crowbar/template-provisioner.json +++ b/chef/data_bags/crowbar/template-provisioner.json @@ -158,6 +158,12 @@ } } }, + "suse": { + "autoyast": { + "do_self_update": false, + "self_update_url": "http:///suse-12.2/$arch/repos/installer-update" + } + }, "keep_existing_hostname": false, "timezone": "UTC", "web_port": 8091, @@ -200,7 +206,7 @@ "provisioner": { "crowbar-revision": 0, "crowbar-applied": false, - "schema-revision": 102, + "schema-revision": 103, "element_states": { "provisioner-server": [ "readying", "ready", "applying" ], "provisioner-base": [ "hardware-installing", "readying", "ready", "applying" ] diff --git a/chef/data_bags/crowbar/template-provisioner.schema b/chef/data_bags/crowbar/template-provisioner.schema index 49b96ccc8a..b7660faf67 100644 --- a/chef/data_bags/crowbar/template-provisioner.schema +++ b/chef/data_bags/crowbar/template-provisioner.schema @@ -61,7 +61,9 @@ "type": "map", "required": false, "mapping": { - "ssh_password": { "type": "str", "required": false } + "ssh_password": { "type": "str", "required": false }, + "do_self_update": { "type": "bool", "required": true }, + "self_update_url": { "type": "str", "required": true } } } } diff --git a/crowbar_framework/app/views/barclamp/provisioner/_edit_attributes.html.haml b/crowbar_framework/app/views/barclamp/provisioner/_edit_attributes.html.haml index 01e43e4218..bf22b9aa87 100644 --- a/crowbar_framework/app/views/barclamp/provisioner/_edit_attributes.html.haml +++ b/crowbar_framework/app/views/barclamp/provisioner/_edit_attributes.html.haml @@ -7,6 +7,11 @@ %span.help-block = t(".access_keys_hint") + = boolean_field %w(suse autoyast do_self_update) + = string_field %w(suse autoyast self_update_url) + %span.help-block + = t(".suse.autoyast.self_update_url_hint") + = string_field :shell_prompt %span.help-block = t(".shell_prompt_hint") diff --git a/crowbar_framework/config/locales/provisioner/en.yml b/crowbar_framework/config/locales/provisioner/en.yml index 7708da5404..b3a283e295 100644 --- a/crowbar_framework/config/locales/provisioner/en.yml +++ b/crowbar_framework/config/locales/provisioner/en.yml @@ -21,6 +21,11 @@ en: edit_attributes: access_keys: 'Additional SSH keys' access_keys_hint: 'Each SSH key must be on its own line' + suse: + autoyast: + do_self_update: 'Update AutoYaST before installing node' + self_update_url: 'AutoYaST Self-update URL' + self_update_url_hint: 'The alias can be used to specify the admin server. An empty URL implies scc.suse.com.' shell_prompt: 'Custom Shell Prompt' shell_prompt_hint: 'You can use the placeholders USER, ALIAS, HOST, FQDN, CWD and SUFFIX to customize the shell prompt on all nodes. Add a \n for a new line within the prompt.' serial_console: 'Serial Console'