diff --git a/src/bosh-director/lib/bosh/director/deployment_plan/instance.rb b/src/bosh-director/lib/bosh/director/deployment_plan/instance.rb index 7ee5502fea..3b1635779d 100644 --- a/src/bosh-director/lib/bosh/director/deployment_plan/instance.rb +++ b/src/bosh-director/lib/bosh/director/deployment_plan/instance.rb @@ -148,6 +148,13 @@ def bind_existing_instance_model(existing_instance_model) @model = existing_instance_model @desired_variable_set = @deployment_model.last_successful_variable_set || @deployment_model.current_variable_set @previous_variable_set = existing_instance_model.variable_set + templates_archive = existing_instance_model.latest_rendered_templates_archive + if templates_archive + self.rendered_templates_archive = Core::Templates::RenderedTemplatesArchive.new( + templates_archive.blobstore_id, + templates_archive.sha1, + ) + end end def bind_existing_reservations(reservations) diff --git a/src/bosh-director/lib/bosh/director/rendered_templates_persister.rb b/src/bosh-director/lib/bosh/director/rendered_templates_persister.rb index 9b713228f1..47adf5713e 100644 --- a/src/bosh-director/lib/bosh/director/rendered_templates_persister.rb +++ b/src/bosh-director/lib/bosh/director/rendered_templates_persister.rb @@ -81,6 +81,10 @@ def send_templates_to_agent(instance_plan) rendered_templates_archive = instance_plan.rendered_templates.persist_through_agent(instance.agent_client) + instance.model.add_rendered_templates_archive(rendered_templates_archive.spec.merge({ + content_sha1: instance.configuration_hash, + created_at: Time.now, + })) instance.rendered_templates_archive = rendered_templates_archive end end diff --git a/src/bosh-director/spec/unit/deployment_plan/instance_spec.rb b/src/bosh-director/spec/unit/deployment_plan/instance_spec.rb index 0d92a6ef5b..6fb22e921c 100644 --- a/src/bosh-director/spec/unit/deployment_plan/instance_spec.rb +++ b/src/bosh-director/spec/unit/deployment_plan/instance_spec.rb @@ -96,6 +96,17 @@ module Bosh::Director::DeploymentPlan expect(instance.previous_variable_set).to eq(variable_set_model) end end + + context 'if there is an existing rendered_templates_archive for the model' do + let!(:rendered_templates_archive) { FactoryBot.create(:models_rendered_templates_archive, instance: instance_model) } + + it 'configures the instance to have the same rendered_templates_archive as the existing model' do + instance.bind_existing_instance_model(instance_model) + + expect(instance.rendered_templates_archive.sha1).to eq(rendered_templates_archive.sha1) + expect(instance.rendered_templates_archive.blobstore_id).to eq(rendered_templates_archive.blobstore_id) + end + end end describe '#bind_new_instance_model' do diff --git a/src/bosh-director/spec/unit/rendered_templates_persister_spec.rb b/src/bosh-director/spec/unit/rendered_templates_persister_spec.rb index 86a43736c7..b55d1db4a4 100644 --- a/src/bosh-director/spec/unit/rendered_templates_persister_spec.rb +++ b/src/bosh-director/spec/unit/rendered_templates_persister_spec.rb @@ -10,7 +10,10 @@ module Bosh::Director let(:instance_plan) { instance_double('Bosh::Director::DeploymentPlan::InstancePlan') } let(:instance) { instance_double('Bosh::Director::DeploymentPlan::Instance') } - let(:rendered_templates_archive) { instance_double('Bosh::Director::Core::Templates::RenderedTemplatesArchive') } + let(:blobstore_id) { 'generated-blobstore-id' } + let(:sha1) { 'generated-sha1' } + let(:configuration_hash) { 'configuraiton-hash' } + let(:rendered_templates_archive) { Bosh::Director::Core::Templates::RenderedTemplatesArchive.new(blobstore_id, sha1) } let(:rendered_job_instance) { instance_double('Bosh::Director::Core::Templates::RenderedJobInstance') } @@ -32,6 +35,8 @@ module Bosh::Director allow(instance).to receive(:rendered_templates_archive=) allow(instance).to receive(:agent_client).and_return(agent_client) + allow(instance).to receive(:model).and_return(FactoryBot.create(:models_instance)) + allow(instance).to receive(:configuration_hash).and_return(configuration_hash) allow(SecureRandom).to receive(:uuid).and_return(blobstore_id) end @@ -55,7 +60,7 @@ module Bosh::Director it 'should deliver the templates through NATS' do allow(Base64).to receive(:encode64).with(template_contents).and_return(mock_base64_contents) - expect(rendered_job_instance).to receive(:persist_through_agent).with(agent_client) + expect(rendered_job_instance).to receive(:persist_through_agent).with(agent_client).and_return(rendered_templates_archive) persister.persist(instance_plan) end @@ -67,6 +72,18 @@ module Bosh::Director persister.persist(instance_plan) end + it 'persists the rendered_templates_archive for the instance model' do + allow(rendered_job_instance).to receive(:persist_through_agent).with(agent_client).and_return(rendered_templates_archive) + + persister.persist(instance_plan) + + rendered_templates_archive = instance.model.latest_rendered_templates_archive + expect(rendered_templates_archive).to be + expect(rendered_templates_archive.content_sha1).to eq(configuration_hash) + expect(rendered_templates_archive.sha1).to eq(sha1) + expect(rendered_templates_archive.blobstore_id).to eq(blobstore_id) + end + context 'when persist through agent fails with AgentUnsupportedAction error' do it 'should delegate to persist_to_blobstore' do allow(rendered_job_instance).to receive(:persist_through_agent)