Skip to content

Commit

Permalink
Merge dc7a730 into e012414
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiamarchi committed Jul 26, 2018
2 parents e012414 + dc7a730 commit 0aaa224
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ log level (for instance `VAGRANT_LOG=debug`). If you want only OpenStack provide
logs use the variable `VAGRANT_OPENSTACK_LOG`. if both variables are set, `VAGRANT_LOG`
takes precedence.

### Version checker

Each time Vagrant OpenStack Provider runs it checks the installed plugin version and
print a warning on stderr if the plugin is not up-to-date.

If for any reason you need to disable this check, set the environment variable
`VAGRANT_OPENSTACK_VERSION_CKECK` to value `DISABLED` prior to run vagrant.

### CentOS/RHEL/Fedora (sudo: sorry, you must have a tty to run sudo)

Expand Down
32 changes: 25 additions & 7 deletions source/lib/vagrant-openstack-provider/version_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,39 @@ class VersionChecker
#
attr_accessor :status

#
# boolean attribute to disbale version checker
#
attr_accessor :check_enabled

def initialize
@status = nil
@check_enabled = true

check = ENV['VAGRANT_OPENSTACK_VERSION_CKECK']
@check_enabled = false if check && check.upcase == 'DISABLED'
end

#
# Check the latest version from rubygem and set the status
#
def check
return :latest unless @check_enabled
return @status unless @status.nil?
latest = Gem.latest_spec_for('vagrant-openstack-provider').version.version

begin
latest = Gem.latest_spec_for('vagrant-openstack-provider').version.version
rescue
# If for any reason the version of the latest pulished
# version can't be found we don't fail in any way
return :latest
end

current = VagrantPlugins::Openstack::VERSION

unless current =~ VERSION_PATTERN
@status = :unstable
print I18n.t('vagrant_openstack.version_unstable')
print_message I18n.t('vagrant_openstack.version_unstable')
return
end

Expand All @@ -47,19 +65,19 @@ def check

if i_current > i_latest
@status = :unstable
print I18n.t('vagrant_openstack.version_unstable')
print_message I18n.t('vagrant_openstack.version_unstable')
return
end

@status = :outdated
print I18n.t('vagrant_openstack.version_outdated', latest: latest, current: current)
print_message I18n.t('vagrant_openstack.version_outdated', latest: latest, current: current)
end

private

def print(message)
puts message.yellow
puts ''
def print_message(message)
$stderr.puts message.yellow
$stderr.puts ''
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
def assert_version_is(expected_status, latest, current)
stub_const('VagrantPlugins::Openstack::VERSION', current)
version.stub(:version) { latest }
@checker.stub(:print)
expect(@checker).to receive(:print) unless expected_status == :latest
@checker.stub(:print_message)
expect(@checker).to receive(:print_message) unless expected_status == :latest
@checker.check
expect(@checker.status).to eq(expected_status)
end
Expand Down

0 comments on commit 0aaa224

Please sign in to comment.