<commit_before>#
# Cookbook Name:: bcpc
# Recipe:: openstack
#
# Copyright 2013, Bloomberg Finance L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include_recipe "bcpc::default"
include_recipe "bcpc::packages-openstack"

# python-nova is used as the canary package because it's pretty fundamental
min_version = \
  if is_liberty?
    '2:12.0.5'
  elsif is_mitaka?
    '2:13.1.2'
  else
    raise "You are attempting to install an unsupported OpenStack version."
  end

ruby_block 'evaluate-version-eligibility' do
  block do
    minimum_nova_version = Mixlib::ShellOut.new("dpkg --compare-versions $(apt-cache show --no-all-versions python-nova | egrep '^Version:' | awk '{ print $NF }') ge #{min_version}")
    cmd_result = minimum_nova_version.run_command
    fail("You must install OpenStack #{node['bcpc']['openstack_release']} #{min_version} or better. Earlier versions are not supported.") if cmd_result.error?
  end
end

# are we performing an upgrade? (don't check if it's a fresh install)
upgrade_check = Mixlib::ShellOut.new("if dpkg -s python-nova >/dev/null 2>&1; then dpkg --compare-versions $(dpkg -s python-nova | egrep '^Version:' | awk '{ print $NF }') lt $(apt-cache policy python-nova | grep Candidate | awk '{ print $NF }'); else exit 1; fi")
upgrade_check.run_command

file '/usr/local/etc/openstack_upgrade' do
  action :create
  not_if { upgrade_check.error? }
end

%w{ python-novaclient
    python-cinderclient
    python-glanceclient
    python-memcache
    python-keystoneclient
    python-nova-adminclient
    python-heatclient
    python-ceilometerclient
    python-mysqldb
    python-six
    python-ldap
    python-openstackclient<commit_msg>Rework upgrade detection to not happen at recipe compile time<commit_after>#
# Cookbook Name:: bcpc
# Recipe:: openstack
#
# Copyright 2013, <NAME> L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include_recipe "bcpc::default"
include_recipe "bcpc::packages-openstack"

# python-nova is used as the canary package because it's pretty fundamental
min_version = \
  if is_liberty?
    '2:12.0.5'
  elsif is_mitaka?
    '2:13.1.2'
  else
    raise "You are attempting to install an unsupported OpenStack version."
  end

ruby_block 'evaluate-version-eligibility' do
  block do
    minimum_nova_version = Mixlib::ShellOut.new("dpkg --compare-versions $(apt-cache show --no-all-versions python-nova | egrep '^Version:' | awk '{ print $NF }') ge #{min_version}")
    cmd_result = minimum_nova_version.run_command
    fail("You must install OpenStack #{node['bcpc']['openstack_release']} #{min_version} or better. Earlier versions are not supported.") if cmd_result.error?
  end
end

ruby_block 'set-upgrade-flag-file' do
  block do
    upgrade_flag_file = '/usr/local/etc/openstack_upgrade'
    upgrade_check = Mixlib::ShellOut.new("if dpkg -s python-nova >/dev/null 2>&1; then dpkg --compare-versions $(dpkg -s python-nova | egrep '^Version:' | awk '{ print $NF }') lt $(apt-cache policy python-nova | grep Candidate | awk '{ print $NF }'); else exit 2; fi")
    upgrade_check.run_command
    # exit status 1 means comparison failed, exit status 2 means something weird happened
    # (probably shouldn't ever see exit status 2)
    if upgrade_check.error?
      ::File.unlink(upgrade_flag_file) if ::File.exist?(upgrade_flag_file)
    else
      FileUtils.touch(upgrade_flag_file)
    end
  end
end

%w{ python-novaclient
    python-cinderclient
    python-glanceclient
    python-memcache
    python-keystoneclient
    python-nova-adminclient
    python-heatclient
    python-ceilometerclient
    python-mysqldb
    python-six
    python-ldap
    python-openstackclient
{'fraction_non_alphanumeric': 0.10105580693815988, 'fraction_numerical': 0.009696186166774402, 'mean_word_length': 4.051142546245919, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3812729', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1408, 'n_words': 476}