From 6181870d318279f9d7ac25011beb1293d3522f6d Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Fri, 8 Apr 2016 15:47:41 -0500 Subject: [PATCH 01/12] checking to see if they belong to the same cloud --- libraries/machine_tag_rl10.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libraries/machine_tag_rl10.rb b/libraries/machine_tag_rl10.rb index d02f4d8..ef1b320 100644 --- a/libraries/machine_tag_rl10.rb +++ b/libraries/machine_tag_rl10.rb @@ -84,11 +84,14 @@ def do_query(query_tags, options = {}) if links links.each do |link| Chef::Log.info "Tagged Resource State:#{api_client.resource(link["href"]).state}" - if api_client.resource(link["href"]).state == 'operational' - resource_tags = api_client.tags.by_resource(resource_hrefs:[link["href"]])#.first.tags - tags_hash[link["href"]]={ - "tags"=> resource_tags.first.tags.map{|tag| tag["name"]} - } + Chef::Log.info "Tagged Resource Cloud:#{api_client.resource(link["href"]).show.cloud.href}" + if api_client.get_instance.show.cloud.href == api_client.resource(link["href"]).show.cloud.href + if api_client.resource(link["href"]).state == 'operational' + resource_tags = api_client.tags.by_resource(resource_hrefs:[link["href"]])#.first.tags + tags_hash[link["href"]]={ + "tags"=> resource_tags.first.tags.map{|tag| tag["name"]} + } + end end end end From 667c0a9256bf2857b88aeb2f4a493dd61b06a956 Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Fri, 8 Apr 2016 15:53:17 -0500 Subject: [PATCH 02/12] fixing issue with tests and incrementing version --- metadata.rb | 2 +- spec/unit_test/machine_tag_rl10_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/metadata.rb b/metadata.rb index 9590b78..547d2a2 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache 2.0' description 'Installs/Configures machine_tag' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '1.2.0' +version '1.2.1' depends 'apt', '~> 2.9.2' depends 'build-essential' diff --git a/spec/unit_test/machine_tag_rl10_spec.rb b/spec/unit_test/machine_tag_rl10_spec.rb index e7b3c69..0ce6abe 100644 --- a/spec/unit_test/machine_tag_rl10_spec.rb +++ b/spec/unit_test/machine_tag_rl10_spec.rb @@ -72,6 +72,8 @@ client = double('RightApi::Client', :log => nil) client.stub(:get_instance).and_return(instance_stub) client.stub_chain(:resource,:state).and_return('operational') + client.stub_chain(:get_instance,:show,:cloud,:href).and_return('/api/clouds/6') + client.stub_chain(:resource,:show,:cloud,:href).and_return('/api/clouds/6') client end From 2cbea8b9f7408fc1847568377879edd5b1ad29b6 Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Mon, 11 Apr 2016 08:54:52 -0500 Subject: [PATCH 03/12] making a split --- libraries/machine_tag_rl10.rb | 5 ++--- spec/unit_test/machine_tag_rl10_spec.rb | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libraries/machine_tag_rl10.rb b/libraries/machine_tag_rl10.rb index ef1b320..3ba931d 100644 --- a/libraries/machine_tag_rl10.rb +++ b/libraries/machine_tag_rl10.rb @@ -83,9 +83,8 @@ def do_query(query_tags, options = {}) links = resources.first.links if links links.each do |link| - Chef::Log.info "Tagged Resource State:#{api_client.resource(link["href"]).state}" - Chef::Log.info "Tagged Resource Cloud:#{api_client.resource(link["href"]).show.cloud.href}" - if api_client.get_instance.show.cloud.href == api_client.resource(link["href"]).show.cloud.href + Chef::Log.info "Tagged Resource Cloud:#{link["href"].split('/')[0..3].join('/')}" + if api_client.get_instance.show.cloud.href == link["href"].split('/')[0..3].join('/') if api_client.resource(link["href"]).state == 'operational' resource_tags = api_client.tags.by_resource(resource_hrefs:[link["href"]])#.first.tags tags_hash[link["href"]]={ diff --git a/spec/unit_test/machine_tag_rl10_spec.rb b/spec/unit_test/machine_tag_rl10_spec.rb index 0ce6abe..fbd3398 100644 --- a/spec/unit_test/machine_tag_rl10_spec.rb +++ b/spec/unit_test/machine_tag_rl10_spec.rb @@ -73,7 +73,6 @@ client.stub(:get_instance).and_return(instance_stub) client.stub_chain(:resource,:state).and_return('operational') client.stub_chain(:get_instance,:show,:cloud,:href).and_return('/api/clouds/6') - client.stub_chain(:resource,:show,:cloud,:href).and_return('/api/clouds/6') client end From 79beeb257adcd0a997d26788e9e500192743027a Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Mon, 11 Apr 2016 11:14:45 -0500 Subject: [PATCH 04/12] fixing test by updating href --- spec/unit_test/machine_tag_rl10_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/unit_test/machine_tag_rl10_spec.rb b/spec/unit_test/machine_tag_rl10_spec.rb index fbd3398..b8336f4 100644 --- a/spec/unit_test/machine_tag_rl10_spec.rb +++ b/spec/unit_test/machine_tag_rl10_spec.rb @@ -82,7 +82,7 @@ let(:resources_stub) { double('resources', - :links=>[{"href"=>"/some_href"}], + :links=>[{"href"=>"/api/clouds/6/instances/1234"}], )} let(:resource_tags_stub) { double('tag_resources', :tags=> rs_raw_output) } @@ -128,10 +128,9 @@ and_return([resources_stub]) client_stub.tags.should_receive(:by_resource). - with(hash_including(resource_hrefs: ["/some_href"])). + with(hash_including(resource_hrefs: ["/api/clouds/6/instances/1234"])). and_return([resource_tags_stub]) - tags = provider.send(:do_query,'database:active=true',{ match_all: false }) tags.should be_a(Array) tags.first.should be_a(MachineTag::Set) From 9acb2250b7e5bc30f1dfa6d612670f0c02ad0061 Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Mon, 11 Apr 2016 11:34:37 -0500 Subject: [PATCH 05/12] failure test --- spec/unit_test/machine_tag_rl10_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/unit_test/machine_tag_rl10_spec.rb b/spec/unit_test/machine_tag_rl10_spec.rb index b8336f4..6621133 100644 --- a/spec/unit_test/machine_tag_rl10_spec.rb +++ b/spec/unit_test/machine_tag_rl10_spec.rb @@ -173,5 +173,15 @@ tags.should == expected_output end + + it "should raise error because of different cloud" do + client_stub.tags.should_receive(:by_tag). + with(hash_including(resource_type: 'instances', tags: ['database:active=true'], match_all: false)). + and_return([resources_stub]) + + client_stub.tags.should_receive(:by_resource). + with(hash_including(resource_hrefs: ["/api/clouds/1/instances/1234"])). + and_raise + end end end From 699b6131be2a87414766e2bd423a422d5a5a9b99 Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Mon, 11 Apr 2016 11:44:38 -0500 Subject: [PATCH 06/12] remove test --- spec/unit_test/machine_tag_rl10_spec.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/spec/unit_test/machine_tag_rl10_spec.rb b/spec/unit_test/machine_tag_rl10_spec.rb index 6621133..b8336f4 100644 --- a/spec/unit_test/machine_tag_rl10_spec.rb +++ b/spec/unit_test/machine_tag_rl10_spec.rb @@ -173,15 +173,5 @@ tags.should == expected_output end - - it "should raise error because of different cloud" do - client_stub.tags.should_receive(:by_tag). - with(hash_including(resource_type: 'instances', tags: ['database:active=true'], match_all: false)). - and_return([resources_stub]) - - client_stub.tags.should_receive(:by_resource). - with(hash_including(resource_hrefs: ["/api/clouds/1/instances/1234"])). - and_raise - end end end From c9c78d21e61a9d6c64af51577afd4a9cb8741fe2 Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Mon, 11 Apr 2016 11:47:01 -0500 Subject: [PATCH 07/12] adding test back in --- spec/unit_test/machine_tag_rl10_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/unit_test/machine_tag_rl10_spec.rb b/spec/unit_test/machine_tag_rl10_spec.rb index b8336f4..6cb2cf3 100644 --- a/spec/unit_test/machine_tag_rl10_spec.rb +++ b/spec/unit_test/machine_tag_rl10_spec.rb @@ -173,5 +173,14 @@ tags.should == expected_output end + it "should raise error because of different cloud" do + client_stub.tags.should_receive(:by_tag). + with(hash_including(resource_type: 'instances', tags: ['database:active=true'], match_all: false)). + and_return([resources_stub]) + + client_stub.tags.should_receive(:by_resource). + with(hash_including(resource_hrefs: ["/api/clouds/1/instances/1234"])). + and_raise + end end end From e1ebae08fe93b6df61f3c97e4c1f5e8411235477 Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Mon, 11 Apr 2016 12:03:07 -0500 Subject: [PATCH 08/12] adding resources_stub_fail --- spec/unit_test/machine_tag_rl10_spec.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spec/unit_test/machine_tag_rl10_spec.rb b/spec/unit_test/machine_tag_rl10_spec.rb index 6cb2cf3..2c256f2 100644 --- a/spec/unit_test/machine_tag_rl10_spec.rb +++ b/spec/unit_test/machine_tag_rl10_spec.rb @@ -85,6 +85,11 @@ :links=>[{"href"=>"/api/clouds/6/instances/1234"}], )} + let(:resource_stub_fail) { + double('resources', + :links=>[{"href"=>"/api/clouds/1/instances/1234"}], + )} + let(:resource_tags_stub) { double('tag_resources', :tags=> rs_raw_output) } before(:each) do @@ -176,11 +181,16 @@ it "should raise error because of different cloud" do client_stub.tags.should_receive(:by_tag). with(hash_including(resource_type: 'instances', tags: ['database:active=true'], match_all: false)). - and_return([resources_stub]) + and_return([resources_stub_fail]) client_stub.tags.should_receive(:by_resource). - with(hash_including(resource_hrefs: ["/api/clouds/1/instances/1234"])). + with(hash_including(resource_hrefs: ["/api/clouds/6/instances/1234"])). and_raise + + tags = provider.send(:do_query,'database:active=true',{ match_all: false }) + tags.should be_a(Array) + tags.first.should be_a(MachineTag::Set) + end end end From fa0abe32e90520551d16f1a98d5c3fa3007a7663 Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Mon, 11 Apr 2016 12:10:33 -0500 Subject: [PATCH 09/12] running new test --- spec/unit_test/machine_tag_rl10_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/unit_test/machine_tag_rl10_spec.rb b/spec/unit_test/machine_tag_rl10_spec.rb index 2c256f2..2de95f9 100644 --- a/spec/unit_test/machine_tag_rl10_spec.rb +++ b/spec/unit_test/machine_tag_rl10_spec.rb @@ -85,7 +85,7 @@ :links=>[{"href"=>"/api/clouds/6/instances/1234"}], )} - let(:resource_stub_fail) { + let(:resources_stub_fail) { double('resources', :links=>[{"href"=>"/api/clouds/1/instances/1234"}], )} @@ -185,11 +185,11 @@ client_stub.tags.should_receive(:by_resource). with(hash_including(resource_hrefs: ["/api/clouds/6/instances/1234"])). - and_raise + and_return([resource_tags_stub]) tags = provider.send(:do_query,'database:active=true',{ match_all: false }) tags.should be_a(Array) - tags.first.should be_a(MachineTag::Set) + tags.should == [] end end From 8cc46fc9514cdaaaffe72b4dbd43fc2b8aaac854 Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Mon, 11 Apr 2016 12:16:58 -0500 Subject: [PATCH 10/12] adding not --- spec/unit_test/machine_tag_rl10_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/unit_test/machine_tag_rl10_spec.rb b/spec/unit_test/machine_tag_rl10_spec.rb index 2de95f9..f8e76af 100644 --- a/spec/unit_test/machine_tag_rl10_spec.rb +++ b/spec/unit_test/machine_tag_rl10_spec.rb @@ -183,9 +183,8 @@ with(hash_including(resource_type: 'instances', tags: ['database:active=true'], match_all: false)). and_return([resources_stub_fail]) - client_stub.tags.should_receive(:by_resource). - with(hash_including(resource_hrefs: ["/api/clouds/6/instances/1234"])). - and_return([resource_tags_stub]) + client_stub.tags.should_not_receive(:by_resource). + with(hash_including(resource_hrefs: ["/api/clouds/6/instances/1234"])) tags = provider.send(:do_query,'database:active=true',{ match_all: false }) tags.should be_a(Array) From dd591d3feea7d5b04114fc7fc8bcea9e6e8e8cc6 Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Mon, 11 Apr 2016 12:28:53 -0500 Subject: [PATCH 11/12] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5017c3b..57655ae 100644 --- a/README.md +++ b/README.md @@ -59,12 +59,17 @@ master.vm.host_name = "master" See `Vagrantfile` for an example. ## RightScale Environment - +### RightLink 6 For using this resource in a *RightScale Environment*, the system must be a RightScale managed VM to have the required access to the [rs_tag utility][rs_tag]. [rs_tag]: http://support.rightscale.com/12-Guides/RightLink/01-RightLink_Overview/RightLink_Command_Line_Utilities#rs_tag +### RightLink 10 +For using this resource in a *RightScale Environment*, the system must be a +RightScale managed VM to have the required access to the right_api_client +with proxy_mode for instance_tokens, the scope is now limited to +operational instances in the same cloud as the VM making the call. # Usage From d045fb564fd4b9c4c80dbb7a941764510dbd1b06 Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Mon, 11 Apr 2016 12:30:29 -0500 Subject: [PATCH 12/12] adding changelog items --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 552f0f4..2f18a0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ machine_tag Cookbook CHANGELOG This file is used to list changes made in each version of the machine_tag cookbook. +v1.2.1 +------ +- Only returns operational instances +- Only returns instances in the same cloud as the machine executing the call. + v1.2.0 ------