From d7c67c2c12d81bd9909edf7b9d25ac263df92119 Mon Sep 17 00:00:00 2001 From: Vincent Roseberry Date: Thu, 26 Apr 2018 22:39:51 +0000 Subject: [PATCH] Magic Modules changes. --- .../gcompute_target_http_proxy/google.rb | 13 +++++- lib/puppet/type/gcompute_target_http_proxy.rb | 6 +++ ...compute_target_http_proxy_provider_spec.rb | 46 +++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/gcompute_target_http_proxy/google.rb b/lib/puppet/provider/gcompute_target_http_proxy/google.rb index 71ba2c41..9c8c8441 100644 --- a/lib/puppet/provider/gcompute_target_http_proxy/google.rb +++ b/lib/puppet/provider/gcompute_target_http_proxy/google.rb @@ -34,6 +34,7 @@ require 'google/compute/property/time' require 'google/compute/property/urlmap_selflink' require 'google/hash_utils' +require 'google/object_store' require 'puppet' Puppet::Type.type(:gcompute_target_http_proxy).provide(:google) do @@ -56,11 +57,13 @@ def self.prefetch(resources) fetch = fetch_resource(resource, self_link(resource), 'compute#targetHttpProxy') resource.provider = present(name, fetch) unless fetch.nil? + Google::ObjectStore.instance.add(:gcompute_target_http_proxy, resource) end end def self.present(name, fetch) result = new({ title: name, ensure: :present }.merge(fetch_to_hash(fetch))) + result.instance_variable_set(:@fetched, fetch) result end @@ -89,7 +92,7 @@ def create fetch_auth(@resource), 'application/json', resource_to_request) - wait_for_operation create_req.send, @resource + @fetched = wait_for_operation create_req.send, @resource @property_hash[:ensure] = :present end @@ -110,7 +113,7 @@ def flush fetch_auth(@resource), 'application/json', resource_to_request) - wait_for_operation update_req.send, @resource + @fetched = wait_for_operation update_req.send, @resource end def dirty(field, from, to) @@ -121,6 +124,12 @@ def dirty(field, from, to) } end + def exports + { + self_link: @fetched['selfLink'] + } + end + private def self.resource_to_hash(resource) diff --git a/lib/puppet/type/gcompute_target_http_proxy.rb b/lib/puppet/type/gcompute_target_http_proxy.rb index 1cca62c0..7cec3c48 100644 --- a/lib/puppet/type/gcompute_target_http_proxy.rb +++ b/lib/puppet/type/gcompute_target_http_proxy.rb @@ -29,6 +29,7 @@ require 'google/compute/property/string' require 'google/compute/property/time' require 'google/compute/property/urlmap_selflink' +require 'google/object_store' require 'puppet' Puppet::Type.newtype(:gcompute_target_http_proxy) do @@ -88,4 +89,9 @@ newproperty(:url_map, parent: Google::Compute::Property::UrlMapSelfLinkRef) do desc 'A reference to UrlMap resource' end + + # Returns all properties that a provider can export to other resources + def exports + provider.exports + end end diff --git a/spec/gcompute_target_http_proxy_provider_spec.rb b/spec/gcompute_target_http_proxy_provider_spec.rb index 82e70fb4..83f6dff8 100644 --- a/spec/gcompute_target_http_proxy_provider_spec.rb +++ b/spec/gcompute_target_http_proxy_provider_spec.rb @@ -791,6 +791,26 @@ end end + context '#exports' do + context 'exports all properties' do + let(:resource1) { create_type 1 } + before do + prefetch_url_map + expect_network_get_success 1 + described_class.prefetch(title0: resource1) + end + + subject { resource1.exports } + + let(:expected_results) do + { + self_link: 'selflink(resource(target_http_proxy,0))' + } + end + it { is_expected.to eq(expected_results) } + end + end + private def expect_network_get_success(id, data = {}) @@ -1006,6 +1026,32 @@ def debug_network(message) if ENV['RSPEC_DEBUG'] || ENV['RSPEC_HTTP_VERBOSE'] end + # Creates and prefetch type so exports can be resolved without network access. + def prefetch_url_map + expect_network_get_success_url_map 1 + + resource = Puppet::Type.type(:gcompute_url_map).new( + project: 'test project#0 data', + name: 'test name#0 data' + ) + + Puppet::Type.type(:gcompute_url_map).provider(:google) + .prefetch(resource: resource) + end + + # Creates and prefetch type so exports can be resolved without network access. + def prefetch_backend_service + expect_network_get_success_backend_service 1 + + resource = Puppet::Type.type(:gcompute_backend_service).new( + project: 'test project#0 data', + name: 'test name#0 data' + ) + + Puppet::Type.type(:gcompute_backend_service).provider(:google) + .prefetch(resource: resource) + end + def expand_variables_url_map(template, data, ext_dat = {}) Puppet::Type.type(:gcompute_url_map).provider(:google) .expand_variables(template, data, ext_dat)