diff --git a/chef/cookbooks/omnibus_updater/.gitignore b/chef/cookbooks/omnibus_updater/.gitignore index 7beac451c..d14fc3c00 100644 --- a/chef/cookbooks/omnibus_updater/.gitignore +++ b/chef/cookbooks/omnibus_updater/.gitignore @@ -1,5 +1,7 @@ -.bundle -.cache -.kitchen +.* +!.gitignore +!.kitchen.yml bin Gemfile.lock +Cheffile.lock +tmp* \ No newline at end of file diff --git a/chef/cookbooks/omnibus_updater/.kitchen.yml b/chef/cookbooks/omnibus_updater/.kitchen.yml new file mode 100644 index 000000000..fbc6fb993 --- /dev/null +++ b/chef/cookbooks/omnibus_updater/.kitchen.yml @@ -0,0 +1,28 @@ +--- +driver_plugin: vagrant +platforms: +- name: ubuntu-12.04 + driver_config: + box: opscode-ubuntu-12.04 + box_url: https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-ubuntu-12.04.box +- name: ubuntu-10.04 + driver_config: + box: opscode-ubuntu-10.04 + box_url: https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-ubuntu-10.04.box +- name: centos-6.4 + driver_config: + box: opscode-centos-6.4 + box_url: https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-centos-6.3.box +- name: centos-5.8 + driver_config: + box: opscode-centos-5.8 + box_url: https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-centos-5.8.box +suites: +- name: default + run_list: + - recipe[omnibus_updater_test::default] + - recipe[minitest-handler] +- name: upgrade + run_list: + - recipe[omnibus_updater_test::version_upgrade] + - recipe[minitest-handler] diff --git a/chef/cookbooks/omnibus_updater/CHANGELOG.md b/chef/cookbooks/omnibus_updater/CHANGELOG.md index 108284ac3..0f1a522be 100644 --- a/chef/cookbooks/omnibus_updater/CHANGELOG.md +++ b/chef/cookbooks/omnibus_updater/CHANGELOG.md @@ -1,3 +1,17 @@ +v0.2.4 +====== +* Only download omnibus package if version difference detected (#20 #22 #23) +* Provide attribute for always downloading package even if version matches + +v0.2.3 +====== +* Use chef internals for interactions with omnitruck to provide proper proxy support (#19) + +v0.2.0 +====== +* Use omnitruck client for url generation for package fetching +* Use `prerelease` in favor of `allow_release_clients` + v0.1.2 ====== * Fix regression on debian package path construction (thanks [ashmere](https://github.com/ashmere)) diff --git a/chef/cookbooks/omnibus_updater/Cheffile b/chef/cookbooks/omnibus_updater/Cheffile new file mode 100644 index 000000000..c9538720d --- /dev/null +++ b/chef/cookbooks/omnibus_updater/Cheffile @@ -0,0 +1,4 @@ +site 'http://community.opscode.com/api/v1' + +cookbook 'omnibus_updater', path: './' +cookbook 'omnibus_updater_test', path: './test/kitchen/cookbooks/omnibus_updater_test' \ No newline at end of file diff --git a/chef/cookbooks/omnibus_updater/Gemfile b/chef/cookbooks/omnibus_updater/Gemfile index f0f457b38..f948d094e 100644 --- a/chef/cookbooks/omnibus_updater/Gemfile +++ b/chef/cookbooks/omnibus_updater/Gemfile @@ -1,3 +1,3 @@ source :rubygems -gem 'test-kitchen' +gem 'vagabond' diff --git a/chef/cookbooks/omnibus_updater/README.md b/chef/cookbooks/omnibus_updater/README.md index 79cf2c4a9..6c5636423 100644 --- a/chef/cookbooks/omnibus_updater/README.md +++ b/chef/cookbooks/omnibus_updater/README.md @@ -14,13 +14,13 @@ be installed on the node: `knife node run_list add recipe[omnibus_updater]` -In your role you'll likely want to set the version (it defaults -to the 0.10.10 version of Chef): +In your role you'll likely want to set the version. It defaults +to nothing, and will install the latest.. ``` override_attributes( :omnibus_updater => { - :version => '10.16.2' + :version => '11.4.0' } ) ``` @@ -35,37 +35,30 @@ override_attributes( } ) ``` ---- - -If you are using a Chef version earlier than 10.12.0 you may want -to take a look at the chef_gem cookbook to ensure gems are going -where expected. - ---- - -The default recipe will install the omnibus package based -on system information but you can override that by using -the `install_via` attribute which accepts: deb, rpm or script. Features ======== -Auto version expansion ----------------------- +Latest Version +-------------- -Versions for the omnibus installer are defined as: x.y.z-n If the `:version` attribute only provides -x.y.z the `n` value will be automatically filled in with the latest available version. +Force installation of the latest version regardless of value stored in version +attribute by setting the `force_latest` attribute. -Auto version searching ----------------------- +Chef Killing +------------ -Using the `:version_search` attribute, the latest stable version of the omnibus installer will -be installed automatically as they become available. +By default the omnibus updater will kill the chef instance by raising and exception. +You can turn this off using the `kill_chef_on_upgrade` attribute. It is not +recommended to turn this off. Internal chef libraries may change, move, or no +longer exist. The currently running instance can encounter unexpected states because +of this. To prevent this, the updater will attempt to kill the Chef instance so +that it can be restarted in a normal state. -Release clients ---------------- +Prerelease +-------- -Release clients can be installed via the auto-installation using `:allow_release_clients` attribute. +Prereleases can be installed via the auto-installation using `prerelease` attribute. Disable ------- @@ -79,4 +72,4 @@ Infos * Repo: https://github.com/hw-cookbooks/omnibus_updater * IRC: Freenode @ #heavywater - +* Cookbook: http://ckbk.it/omnibus_updater \ No newline at end of file diff --git a/chef/cookbooks/omnibus_updater/attributes/default.rb b/chef/cookbooks/omnibus_updater/attributes/default.rb index c1ba25b19..c51027e36 100644 --- a/chef/cookbooks/omnibus_updater/attributes/default.rb +++ b/chef/cookbooks/omnibus_updater/attributes/default.rb @@ -1,8 +1,9 @@ -default[:omnibus_updater][:version] = '10.18.2' -default[:omnibus_updater][:version_search] = false -default[:omnibus_updater][:base_uri] = 'http://opscode-omnibus-packages.s3.amazonaws.com' +default[:omnibus_updater][:version] = nil +default[:omnibus_updater][:force_latest] = false default[:omnibus_updater][:cache_dir] = '/opt' default[:omnibus_updater][:cache_omnibus_installer] = false default[:omnibus_updater][:remove_chef_system_gem] = false -default[:omnibus_updater][:allow_release_clients] = false +default[:omnibus_updater][:prerelease] = false default[:omnibus_updater][:disabled] = false +default[:omnibus_updater][:kill_chef_on_upgrade] = true +default[:omnibus_updater][:always_download] = false diff --git a/chef/cookbooks/omnibus_updater/libraries/omnitrucker.rb b/chef/cookbooks/omnibus_updater/libraries/omnitrucker.rb new file mode 100644 index 000000000..da15a99d1 --- /dev/null +++ b/chef/cookbooks/omnibus_updater/libraries/omnitrucker.rb @@ -0,0 +1,64 @@ +module OmnibusTrucker + class << self + URL_MAP = { + :p => :platform, :pv => :platform_version, :m => :machine, + :v => :version, :prerelease => :prerelease, + :nightlies => :nightlies + } + + def build_url(*opts) + args = node = nil + opts.each do |o| + if(o.kind_of?(Hash)) + args = o + elsif(o.kind_of?(Chef::Node)) + node = o + else + raise ArgumentError.new "Provided argument is not allowed: #{o.class}" + end + end + args ||= {} + if(node) + args = collect_attributes(node).merge(args) + end + url = args[:url] || "http://www.opscode.com/chef/download#{'-server' if args[:server]}" + u_args = URL_MAP.map do |u_k, a_k| + "#{u_k}=#{args[a_k]}" unless args[a_k].nil? + end.compact + "#{url}?#{u_args.join('&')}" + end + + def collect_attributes(node, args={}) + set = Hash[*( + [:platform_family, :platform, :platform_version].map do |k| + [k, args[k] || node[k]] + end.flatten.compact + )] + unless(@attrs) + if(set[:platform_family] == 'rhel') + @attrs = {:platform => 'el', :platform_version => set[:platform_version].to_i} + else + @attrs = {:platform => set[:platform], :platform_version => set[:platform_version]} + end + @attrs[:machine] = args[:machine] || node[:kernel][:machine] + end + @attrs + end + + def url(url_or_node, node = nil) + if(url_or_node.is_a?(Chef::Node)) + url = build_url(url_or_node) + node = url_or_node + else + url = url_or_node + raise "Node instance is required for Omnitruck.url!" unless node + end + request = Chef::REST::RESTRequest.new(:head, URI.parse(url), nil) + result = request.call + if(result.kind_of?(Net::HTTPRedirection)) + result['location'] + end + end + + end +end diff --git a/chef/cookbooks/omnibus_updater/metadata.json b/chef/cookbooks/omnibus_updater/metadata.json deleted file mode 100644 index baeedf894..000000000 --- a/chef/cookbooks/omnibus_updater/metadata.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "omnibus_updater", - "description": "Chef omnibus package updater and installer", - "long_description": "OmnibusUpdater\n==============\n\nUpdate your omnibus! This cookbook can install the omnibus\nChef package into your system if you are currently running\nvia gem install, and it can keep your omnibus install up\nto date.\n\nUsage\n=====\n\nAdd the recipe to your run list and specify what version should\nbe installed on the node:\n\n`knife node run_list add recipe[omnibus_updater]`\n\nIn your role you'll likely want to set the version (it defaults\nto the 0.10.10 version of Chef):\n\n```\noverride_attributes(\n :omnibus_updater => {\n :version => '10.16.2'\n }\n)\n```\n\nIt can also uninstall Chef from the system Ruby installation\nif you tell it to:\n\n```\noverride_attributes(\n :omnibus_updater => {\n :remove_chef_system_gem => true\n }\n)\n```\n---\n\nIf you are using a Chef version earlier than 10.12.0 you may want\nto take a look at the chef_gem cookbook to ensure gems are going\nwhere expected.\n\n---\n\nThe default recipe will install the omnibus package based\non system information but you can override that by using\nthe `install_via` attribute which accepts: deb, rpm or script.\n\nFeatures\n========\n\nAuto version expansion\n----------------------\n\nVersions for the omnibus installer are defined as: x.y.z-n If the `:version` attribute only provides\nx.y.z the `n` value will be automatically filled in with the latest available version.\n\nAuto version searching\n----------------------\n\nUsing the `:version_search` attribute, the latest stable version of the omnibus installer will\nbe installed automatically as they become available.\n\nRelease clients\n---------------\n\nRelease clients can be installed via the auto-installation using `:allow_release_clients` attribute.\n\nDisable\n-------\n\nIf you want to disable the updater you can set the `disabled`\nattribute to true. This might be useful if the cookbook is added\nto a role but should then be skipped for example on a Chef server.\n\nInfos\n=====\n\n* Repo: https://github.com/hw-cookbooks/omnibus_updater\n* IRC: Freenode @ #heavywater\n\n", - "maintainer": "Chris Roberts", - "maintainer_email": "chrisroberts.code@gmail.com", - "license": "Apache 2.0", - "platforms": { - }, - "dependencies": { - }, - "recommendations": { - }, - "suggestions": { - }, - "conflicting": { - }, - "providing": { - }, - "replacing": { - }, - "attributes": { - }, - "groupings": { - }, - "recipes": { - }, - "version": "0.1.2" -} \ No newline at end of file diff --git a/chef/cookbooks/omnibus_updater/metadata.rb b/chef/cookbooks/omnibus_updater/metadata.rb index f4746acfc..8333fb9c5 100644 --- a/chef/cookbooks/omnibus_updater/metadata.rb +++ b/chef/cookbooks/omnibus_updater/metadata.rb @@ -1,7 +1,8 @@ +name "omnibus_updater" maintainer "Chris Roberts" maintainer_email "chrisroberts.code@gmail.com" license "Apache 2.0" description "Chef omnibus package updater and installer" long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "0.1.2" +version "0.2.4" diff --git a/chef/cookbooks/omnibus_updater/recipes/deb_downloader.rb b/chef/cookbooks/omnibus_updater/recipes/deb_downloader.rb deleted file mode 100644 index abb6e5f34..000000000 --- a/chef/cookbooks/omnibus_updater/recipes/deb_downloader.rb +++ /dev/null @@ -1,18 +0,0 @@ -# NOTE: This recipe is here for others that just want the -# package, not the actual installation (lxc for example) - -include_recipe 'omnibus_updater::set_remote_path' - -remote_file "chef omnibus_package_downloader[#{File.basename(node[:omnibus_updater][:full_uri])}]" do - path File.join(node[:omnibus_updater][:cache_dir], File.basename(node[:omnibus_updater][:full_uri])) - source node[:omnibus_updater][:full_uri] - backup false - only_if do - node[:omnibus_updater][:cache_omnibus_installer] && - !File.exists?( - File.join(node[:omnibus_updater][:cache_dir], File.basename(node[:omnibus_updater][:full_uri])) - ) - end -end - -include_recipe 'omnibus_updater::old_package_cleaner' diff --git a/chef/cookbooks/omnibus_updater/recipes/deb_package.rb b/chef/cookbooks/omnibus_updater/recipes/deb_package.rb deleted file mode 100644 index 172556da5..000000000 --- a/chef/cookbooks/omnibus_updater/recipes/deb_package.rb +++ /dev/null @@ -1,30 +0,0 @@ -include_recipe 'omnibus_updater::set_remote_path' - -remote_file "chef omnibus_package[#{File.basename(node[:omnibus_updater][:full_uri])}]" do - path File.join(node[:omnibus_updater][:cache_dir], File.basename(node[:omnibus_updater][:full_uri])) - source node[:omnibus_updater][:full_uri] - backup false - not_if do - File.exists?( - File.join(node[:omnibus_updater][:cache_dir], File.basename(node[:omnibus_updater][:full_uri])) - ) || ( - Chef::VERSION.to_s.scan(/\d+\.\d+\.\d+/) == node[:omnibus_updater][:full_version].scan(/\d+\.\d+\.\d+/) && OmnibusChecker.is_omnibus? - ) - end - notifies :create, 'ruby_block[Omnibus Chef install notifier]', :delayed -end - -ruby_block 'Omnibus Chef install notifier' do - block do - true - end - action :nothing - notifies :run, "execute[chef omnibus_install[#{node[:omnibus_updater][:full_version]}]]", :delayed -end - -execute "chef omnibus_install[#{node[:omnibus_updater][:full_version]}]" do - command "dpkg -i #{File.join(node[:omnibus_updater][:cache_dir], File.basename(node[:omnibus_updater][:full_uri]))}" - action :nothing -end - -include_recipe 'omnibus_updater::old_package_cleaner' diff --git a/chef/cookbooks/omnibus_updater/recipes/default.rb b/chef/cookbooks/omnibus_updater/recipes/default.rb index 337578d96..ab71128ef 100644 --- a/chef/cookbooks/omnibus_updater/recipes/default.rb +++ b/chef/cookbooks/omnibus_updater/recipes/default.rb @@ -1,25 +1,10 @@ -if node[:omnibus_updater][:disabled] +if(node[:omnibus_updater][:disabled]) Chef::Log.warn 'Omnibus updater disabled via `disabled` attribute' -elsif node[:omnibus_updater][:install_via] - case node[:omnibus_updater][:install_via] - when 'deb' - include_recipe 'omnibus_updater::deb_package' - when 'rpm' - include_recipe 'omnibus_updater::rpm_package' - when 'script' - include_recipe 'omnibus_updater::script' - else - raise "Unknown omnibus update method requested: #{node[:omnibus_updater][:install_via]}" - end else - case node.platform_family - when 'debian' - include_recipe 'omnibus_updater::deb_package' - when 'fedora', 'rhel' - include_recipe 'omnibus_updater::rpm_package' - else - include_recipe 'omnibus_updater::script' - end + include_recipe 'omnibus_updater::downloader' + include_recipe 'omnibus_updater::installer' end -include_recipe 'omnibus_updater::remove_chef_system_gem' if node[:omnibus_updater][:remove_chef_system_gem] +if(node[:omnibus_updater][:remove_chef_system_gem]) + include_recipe 'omnibus_updater::remove_chef_system_gem' +end diff --git a/chef/cookbooks/omnibus_updater/recipes/downloader.rb b/chef/cookbooks/omnibus_updater/recipes/downloader.rb new file mode 100644 index 000000000..17948a504 --- /dev/null +++ b/chef/cookbooks/omnibus_updater/recipes/downloader.rb @@ -0,0 +1,36 @@ +# NOTE: This recipe is here for others that just want the +# package, not the actual installation (lxc for example) + +if(node[:omnibus_updater][:direct_url]) + remote_path = node[:omnibus_updater][:direct_url] +else + version = node[:omnibus_updater][:version] || '' + remote_path = OmnibusTrucker.url( + OmnibusTrucker.build_url(node, + :version => node[:omnibus_updater][:force_latest] ? nil : version.sub(/\-.+$/, ''), + :prerelease => node[:omnibus_updater][:preview] + ), node + ) +end + +if(remote_path) + node.set[:omnibus_updater][:full_url] = remote_path + Chef::Log.info "Omnibus Updater remote path: #{remote_path}" + + remote_file "omnibus_remote[#{File.basename(remote_path)}]" do + path File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path)) + source remote_path + backup false + action :create_if_missing + only_if do + unless(version = node[:omnibus_updater][:version]) + version = node[:omnibus_updater][:full_url].scan(%r{chef_(\d+\.\d+.\d+)}).flatten.first + end + node[:omnibus_updater][:always_download] || Chef::VERSION != version.to_s.sub(/\-.+$/, '') + end + end +else + Chef::Log.warn 'Failed to retrieve omnibus download URL' +end + +include_recipe 'omnibus_updater::old_package_cleaner' diff --git a/chef/cookbooks/omnibus_updater/recipes/installer.rb b/chef/cookbooks/omnibus_updater/recipes/installer.rb new file mode 100644 index 000000000..ee99670b6 --- /dev/null +++ b/chef/cookbooks/omnibus_updater/recipes/installer.rb @@ -0,0 +1,36 @@ +include_recipe 'omnibus_updater' +remote_path = node[:omnibus_updater][:full_url].to_s + +ruby_block 'Omnibus Chef install notifier' do + block{ true } + action :nothing + subscribes :create, "remote_file[omnibus_remote[#{File.basename(remote_path)}]]", :immediately + notifies :run, "execute[omnibus_install[#{File.basename(remote_path)}]]", :delayed +end + +execute "omnibus_install[#{File.basename(remote_path)}]" do + case File.extname(remote_path) + when '.deb' + command "dpkg -i #{File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))}" + when '.rpm' + command "rpm -Uvh #{File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))}" + when '.sh' + command "/bin/sh #{File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))}" + else + raise "Unknown package type encountered for install: #{File.extname(remote_path)}" + end + action :nothing + notifies :create, 'ruby_block[omnibus chef killer]', :immediately +end + +ruby_block 'omnibus chef killer' do + block do + raise 'New omnibus chef version installed. Killing Chef run!' + end + action :nothing + only_if do + node[:omnibus_updater][:kill_chef_on_upgrade] + end +end + +include_recipe 'omnibus_updater::old_package_cleaner' diff --git a/chef/cookbooks/omnibus_updater/recipes/old_package_cleaner.rb b/chef/cookbooks/omnibus_updater/recipes/old_package_cleaner.rb index 156cd4fa5..51edb2eb8 100644 --- a/chef/cookbooks/omnibus_updater/recipes/old_package_cleaner.rb +++ b/chef/cookbooks/omnibus_updater/recipes/old_package_cleaner.rb @@ -1,7 +1,7 @@ old_pkgs = if(::File.exist?(node[:omnibus_updater][:cache_dir])) Dir.glob(File.join(node[:omnibus_updater][:cache_dir], 'chef*')).find_all do |file| - !file.include?(node[:omnibus_updater][:version]) && !file.scan(/\.(rpm|deb)$/).empty? + !file.include?(node[:omnibus_updater][:version].to_s) && !file.scan(/\.(rpm|deb)$/).empty? end else [] diff --git a/chef/cookbooks/omnibus_updater/recipes/rpm_package.rb b/chef/cookbooks/omnibus_updater/recipes/rpm_package.rb deleted file mode 100644 index 7d26dd3d3..000000000 --- a/chef/cookbooks/omnibus_updater/recipes/rpm_package.rb +++ /dev/null @@ -1,30 +0,0 @@ -include_recipe 'omnibus_updater::set_remote_path' - -remote_file "chef omnibus_package[#{File.basename(node[:omnibus_updater][:full_uri])}]" do - path File.join(node[:omnibus_updater][:cache_dir], File.basename(node[:omnibus_updater][:full_uri])) - source node[:omnibus_updater][:full_uri] - backup false - not_if do - File.exists?( - File.join(node[:omnibus_updater][:cache_dir], File.basename(node[:omnibus_updater][:full_uri])) - ) || ( - Chef::VERSION.to_s.scan(/\d+\.\d+\.\d+/) == node[:omnibus_updater][:full_version].scan(/\d+\.\d+\.\d+/) && OmnibusChecker.is_omnibus? - ) - end - notifies :create, 'ruby_block[Omnibus Chef install notifier]', :delayed -end - -ruby_block 'Omnibus Chef install notifier' do - block do - true - end - action :nothing - notifies :run, "execute[chef omnibus_install[#{node[:omnibus_updater][:full_version]}]]", :delayed -end - -execute "chef omnibus_install[#{node[:omnibus_updater][:full_version]}]" do - command "rpm -Uvh #{File.join(node[:omnibus_updater][:cache_dir], File.basename(node[:omnibus_updater][:full_uri]))}" - action :nothing -end - -include_recipe 'omnibus_updater::old_package_cleaner' diff --git a/chef/cookbooks/omnibus_updater/recipes/script.rb b/chef/cookbooks/omnibus_updater/recipes/script.rb deleted file mode 100644 index 0a8c1282a..000000000 --- a/chef/cookbooks/omnibus_updater/recipes/script.rb +++ /dev/null @@ -1,38 +0,0 @@ -include_recipe 'omnibus_updater::set_remote_path' - -remote_file "chef omnibus_script[#{File.basename(node[:omnibus_updater][:full_uri])}]" do - path File.join(node[:omnibus_updater][:cache_dir], File.basename(node[:omnibus_updater][:full_uri])) - source node[:omnibus_updater][:full_uri] - backup false - not_if do - File.exists?( - File.join(node[:omnibus_updater][:cache_dir], File.basename(node[:omnibus_updater][:full_uri])) - ) || ( - Chef::VERSION.to_s.scan(/\d+\.\d+\.\d+/) == node[:omnibus_updater][:full_version].scan(/\d+\.\d+\.\d+/) && OmnibusChecker.is_omnibus? - ) - end -end - -# NOTE: We do not use notifications to trigger the install -# since they are broken with remote_file in 0.10.10 -execute "chef omnibus_install[#{node[:omnibus_updater][:full_version]}]" do - command "bash #{File.join(node[:omnibus_updater][:cache_dir], File.basename(node[:omnibus_updater][:full_uri]))}" - only_if do - (File.exists?( - File.join(node[:omnibus_updater][:cache_dir], File.basename(node[:omnibus_updater][:full_uri])) - ) && - Chef::VERSION.to_s.scan(/\d+\.\d+\.\d+/) != node[:omnibus_updater][:full_version].scan(/\d+\.\d+\.\d+/)) || - !OmnibusChecker.is_omnibus? - end -end - -ruby_block "omnibus_updater[remove old install scripts]" do - block do - Dir.glob(File.join(node[:omnibus_updater][:cache_dir], 'chef*.sh')).each do |file| - unless(file.include?(node[:omnibus_updater][:version])) - Chef::Log.info "Deleting stale omnibus script: #{file}" - File.delete(file) - end - end - end -end diff --git a/chef/cookbooks/omnibus_updater/recipes/set_remote_path.rb b/chef/cookbooks/omnibus_updater/recipes/set_remote_path.rb deleted file mode 100644 index 64d737011..000000000 --- a/chef/cookbooks/omnibus_updater/recipes/set_remote_path.rb +++ /dev/null @@ -1,139 +0,0 @@ -# RULES - -if(node[:omnibus_updater][:version].nil? && !node[:omnibus_updater][:version_search]) - raise "Omnibus Updater cannot determine version installation request. Please set version of enable version search" -end - -if(node[:omnibus_updater][:version_search]) - Chef::Log.warn "Omnibus Updater is set to automatically upgrade via search!" - if(node[:omnibus_updater][:allow_release_clients]) - Chef::Log.warn "Omnibus Updater will allow installation of release clients found via search!" - end -end - -if(!node[:omnibus_updater][:version].to_s.include?('-') || node[:omnibus_updater][:version_search]) - require 'open-uri' - require 'rexml/document' - pkgs_doc = REXML::Document.new(open(node[:omnibus_updater][:base_uri])) - pkgs_avail = pkgs_doc.elements.to_a('//Contents//Key').map(&:text).find_all do |f| - (f.include?('.rpm') || f.include?('.deb')) && f.include?('chef') && - !f.include?('server') && (node[:omnibus_updater][:allow_release_clients] || !f.include?('.rc')) && - !f.scan(/\d+\.\d+\.\d+-\d+\./).empty? - end - unless(node[:omnibus_updater][:version_search]) - searched_ver = pkgs_avail.find_all{|x| x.include?(node[:omnibus_updater][:version]) }.sort.last - unless(searched_ver) - raise "Omnibus Updater failed to find a valid version string. Base version requested: #{node[:omnibus_updater][:version]}" - else - node.set[:omnibus_updater][:full_version] = searched_ver.scan(/\d+\.\d+\.\d+-\d+/).first - node.set[:omnibus_updater][:version] = node[:omnibus_updater][:full_version].sub(/-\d+$/,'') - end - end -else - node.set[:omnibus_updater][:full_version] = node[:omnibus_updater][:version] -end - -platform_name = node.platform -platform_majorversion = "" -kernel_name = node.kernel.machine -case node.platform_family -when 'debian' - if(node.platform == 'ubuntu') - platform_version = case node.platform_version - when '10.10', '10.04' - platform_majorversion << '10.04' - '10.04' - when '12.10', '12.04', '11.10', '11.04' - platform_majorversion << '11.04' - '11.04' - else - raise 'Unsupported ubuntu version for deb packaged omnibus' - end - else - platform_version = case pv = node.platform_version.split('.').first - when '6', '5' - platform_majorversion << '6' - '6.0.5' - else - platform_majorversion << pv - pv - end - end -when 'fedora', 'rhel' - platform_version = node.platform_version.split('.').first - platform_name = 'el' - platform_majorversion << platform_version -else - platform_version = node.platform_version -end - -if(node[:omnibus_updater][:install_via]) - install_via = node[:omnibus_updater][:install_via] -else - install_via = case node.platform_family - when 'debian' - 'deb' - when 'fedora', 'rhel', 'centos' - 'rpm' - else - raise 'Unsupported omnibus install method requested' - end -end -case install_via -when 'deb' - if(pkgs_avail) - path_name = pkgs_avail.find_all{ |path| - ver = node[:omnibus_updater][:version] || '.' - path.include?('.deb') && path.include?(platform_name) && - path.include?(platform_version) && path.include?(node.kernel.machine) && - path.include?(ver) - }.sort.last - else - kernel_name = "" - file_name = "chef_#{node[:omnibus_updater][:full_version]}.#{platform_name}.#{platform_version}_" - if(node.kernel.machine.include?('64')) - file_name << 'amd64' - kernel_name << 'x86_64' - else - file_name << 'i386' - kernel_name << 'i686' - end - file_name << '.deb' - end -when 'rpm' - if(pkgs_avail) - path_name = pkgs_avail.find_all{ |path| - ver = node[:omnibus_updater][:version] || '.' - path.include?('.rpm') && path.include?(platform_name) && - path.include?(platform_version) && path.include?(node.kernel.machine) && - path.include?(ver) - }.sort.last - else - file_name = "chef-#{node[:omnibus_updater][:full_version]}.#{platform_name}#{platform_version}.#{node.kernel.machine}.rpm" - end -else - raise 'Unsupported install via provided' -end - -remote_omnibus_file = if(path_name) - File.join(node[:omnibus_updater][:base_uri], path_name) - else - File.join( - node[:omnibus_updater][:base_uri], - platform_name, - platform_majorversion, - kernel_name, - file_name - ) - end - -unless(remote_omnibus_file == node[:omnibus_updater][:full_uri]) - node.override[:omnibus_updater][:full_uri] = remote_omnibus_file - Chef::Log.info "Omnibus remote file location: #{remote_omnibus_file}" -end - -unless(node[:omnibus_updater][:full_version]) - node.set[:omnibus_updater][:version] = remote_omnibus_file.scan(%r{chef[_-](\d+.\d+.\d+-\d+)}).flatten.first - node.set[:omnibus_updater][:full_version] = node[:omnibus_updater][:version] -end - diff --git a/chef/cookbooks/omnibus_updater/test/kitchen/Kitchenfile b/chef/cookbooks/omnibus_updater/test/kitchen/Kitchenfile new file mode 100644 index 000000000..86a12c63e --- /dev/null +++ b/chef/cookbooks/omnibus_updater/test/kitchen/Kitchenfile @@ -0,0 +1,6 @@ +cookbook "omnibus_updater" do + configuration "default" + configuration "version_upgrade" + configuration "search" + lint false +end diff --git a/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/files/default/tests/minitest/default_test.rb b/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/files/default/tests/minitest/default_test.rb new file mode 100644 index 000000000..f93cfa43a --- /dev/null +++ b/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/files/default/tests/minitest/default_test.rb @@ -0,0 +1,14 @@ +require 'minitest/spec' +require 'open-uri' + +describe_recipe 'omnibus_updater_test::default' do + include MiniTest::Chef::Assertions + + it "sets remote package location" do + assert(node[:omnibus_updater][:full_url], "Failed to set URI for omnibus package") + end + + it "does not download the package to the node" do + file("/opt/#{File.basename(node[:omnibus_updater][:full_url])}").wont_exist + end +end diff --git a/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/files/default/tests/minitest/version_upgrade_test.rb b/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/files/default/tests/minitest/version_upgrade_test.rb new file mode 100644 index 000000000..b9a53de18 --- /dev/null +++ b/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/files/default/tests/minitest/version_upgrade_test.rb @@ -0,0 +1,23 @@ +require 'minitest/spec' +require 'rexml/document' +require 'open-uri' + +describe_recipe 'omnibus_updater_test::version_upgrade' do + include MiniTest::Chef::Assertions + + it "sets remote package location" do + assert(node[:omnibus_updater][:full_url], "Failed to set URI for omnibus package") + end + + it "downloads the package to the node" do + file("/opt/#{File.basename(node[:omnibus_updater][:full_url])}").must_exist + end + + it "installs the proper version into the node" do + assert_equal( + node[:omnibus_updater][:version].scan(/^\d+\.\d+\.\d+/).first, + `chef-client --version`.strip.scan(/\d+\.\d+\.\d+/).first, + "Installed chef version does not match version requested" + ) + end +end diff --git a/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/metadata.rb b/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/metadata.rb new file mode 100644 index 000000000..6be474e15 --- /dev/null +++ b/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/metadata.rb @@ -0,0 +1,4 @@ +name 'omnibus_updater_test' +version '0.0.1' +depends "omnibus_updater" +depends "minitest-handler" diff --git a/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/recipes/default.rb b/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/recipes/default.rb new file mode 100644 index 000000000..9717f06c9 --- /dev/null +++ b/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/recipes/default.rb @@ -0,0 +1,3 @@ +node.set[:omnibus_updater][:kill_chef_on_upgrade] = false +node.set[:omnibus_updater][:version] = false +include_recipe "omnibus_updater" diff --git a/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/recipes/version_upgrade.rb b/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/recipes/version_upgrade.rb new file mode 100644 index 000000000..bfb2a6e78 --- /dev/null +++ b/chef/cookbooks/omnibus_updater/test/kitchen/cookbooks/omnibus_updater_test/recipes/version_upgrade.rb @@ -0,0 +1,3 @@ +node.set[:omnibus_updater][:version] = '11.2.0' +node.set[:omnibus_updater][:kill_chef_on_upgrade] = false +include_recipe "omnibus_updater"