From 6911474b191f67ff4edf61f698c6e95a2248fc57 Mon Sep 17 00:00:00 2001 From: zhangyangyang Date: Sat, 7 Oct 2017 16:47:15 +0800 Subject: [PATCH] Remove some useless method These methods are deprecated. They are for old nova cli auth. Change-Id: I3065864458827d4c1c3c81688502d1057124322a --- lib/puppet/provider/nova.rb | 49 --------------------------------- spec/unit/provider/nova_spec.rb | 28 ------------------- 2 files changed, 77 deletions(-) diff --git a/lib/puppet/provider/nova.rb b/lib/puppet/provider/nova.rb index 08f9099ff..6754c51d7 100644 --- a/lib/puppet/provider/nova.rb +++ b/lib/puppet/provider/nova.rb @@ -60,21 +60,6 @@ class Puppet::Provider::Nova < Puppet::Provider::Openstack '/etc/nova/nova.conf' end - # deprecated: method for old nova cli auth - def self.withenv(hash, &block) - saved = ENV.to_hash - hash.each do |name, val| - ENV[name.to_s] = val - end - - yield - ensure - ENV.clear - saved.each do |name, val| - ENV[name] = val - end - end - def self.nova_conf return @nova_conf if @nova_conf @nova_conf = Puppet::Util::IniConfig::File.new @@ -128,40 +113,6 @@ class Puppet::Provider::Nova < Puppet::Provider::Openstack @auth_endpoint ||= get_auth_endpoint end - # deprecated: method for old nova cli auth - def self.auth_nova(*args) - q = nova_credentials - authenv = { - :OS_AUTH_URL => self.auth_endpoint, - :OS_USERNAME => q['username'], - :OS_PROJECT_NAME => q['project_name'], - :OS_PASSWORD => q['password'] - } - if q.key?('region_name') - authenv[:OS_REGION_NAME] = q['region_name'] - end - begin - withenv authenv do - nova(args) - end - rescue Exception => e - if (e.message =~ /\[Errno 111\] Connection refused/) or - (e.message =~ /\(HTTP 400\)/) - sleep 10 - withenv authenv do - nova(args) - end - else - raise(e) - end - end - end - - # deprecated: method for old nova cli auth - def auth_nova(*args) - self.class.auth_nova(args) - end - def self.reset @nova_conf = nil @nova_credentials = nil diff --git a/spec/unit/provider/nova_spec.rb b/spec/unit/provider/nova_spec.rb index 9e16d516a..d370576cb 100644 --- a/spec/unit/provider/nova_spec.rb +++ b/spec/unit/provider/nova_spec.rb @@ -65,34 +65,6 @@ describe Puppet::Provider::Nova do end - describe 'when invoking the nova cli' do - - it 'should set auth credentials in the environment' do - authenv = { - :OS_AUTH_URL => auth_endpoint, - :OS_USERNAME => credential_hash['username'], - :OS_PROJECT_NAME => credential_hash['project_name'], - :OS_PASSWORD => credential_hash['password'], - :OS_REGION_NAME => credential_hash['region_name'], - } - klass.expects(:get_nova_credentials).with().returns(credential_hash) - klass.expects(:withenv).with(authenv) - klass.auth_nova('test_retries') - end - - ['[Errno 111] Connection refused', - '(HTTP 400)'].reverse.each do |valid_message| - it "should retry when nova cli returns with error #{valid_message}" do - klass.expects(:get_nova_credentials).with().returns({}) - klass.expects(:sleep).with(10).returns(nil) - klass.expects(:nova).twice.with(['test_retries']).raises( - Exception, valid_message).then.returns('') - klass.auth_nova('test_retries') - end - end - - end - describe 'when parse a string line' do it 'should return the same string' do res = klass.str2hash("zone1")