From b9bda186d49b8e5192e9576e7bfeeacdf4a590c7 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 26 Oct 2018 12:14:32 +0100 Subject: [PATCH] Add `undeploy_first` parameter to `wildfly_deployment` Instead of using `cli.update_deploy`, when setting this parameter to `true`, the deployment is undeployed, before being redeployed. --- .../provider/wildfly_deployment/http_api.rb | 7 ++- lib/puppet/type/wildfly_deployment.rb | 8 +++- manifests/deployment.pp | 19 ++++---- spec/types/wildfly_deployment_spec.rb | 4 +- .../wildfly_deployment/http_api_spec.rb | 45 +++++++++++++++++++ 5 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 spec/unit/puppet/provider/wildfly_deployment/http_api_spec.rb diff --git a/lib/puppet/provider/wildfly_deployment/http_api.rb b/lib/puppet/provider/wildfly_deployment/http_api.rb index f0b6503a..6b2799e6 100644 --- a/lib/puppet/provider/wildfly_deployment/http_api.rb +++ b/lib/puppet/provider/wildfly_deployment/http_api.rb @@ -24,7 +24,12 @@ def content def content=(value) debug "Updating deploy #{@resource[:name]} with content from #{@resource[:source]}" - cli.update_deploy(@resource[:name], @resource[:source], @resource[:server_group], @resource[:operation_headers]) + if @resource[:undeploy_first] + destroy + create + else + cli.update_deploy(@resource[:name], @resource[:source], @resource[:server_group], @resource[:operation_headers]) + end end def server_group_address diff --git a/lib/puppet/type/wildfly_deployment.rb b/lib/puppet/type/wildfly_deployment.rb index 73f2759f..abd81717 100644 --- a/lib/puppet/type/wildfly_deployment.rb +++ b/lib/puppet/type/wildfly_deployment.rb @@ -1,4 +1,5 @@ require 'digest' +require 'puppet/parameter/boolean' Puppet::Type.newtype(:wildfly_deployment) do desc 'Manages JBoss deployment' @@ -39,7 +40,7 @@ end newparam(:timeout) do - desc 'Operation timeout. Defaults to 120' + desc 'Operation timeout. Defaults to 300' defaultto 300 munge(&:to_i) @@ -54,6 +55,11 @@ end end + newparam(:undeploy_first, :boolean => true, :parent => Puppet::Parameter::Boolean) do + desc 'Whether to perform an undeploy before redeploying' + defaultto :false # rubocop:disable Lint/BooleanSymbol + end + newproperty(:content) do desc 'SHA1 of deployed content' defaultto '' diff --git a/manifests/deployment.pp b/manifests/deployment.pp index e35495b7..35a36139 100644 --- a/manifests/deployment.pp +++ b/manifests/deployment.pp @@ -11,16 +11,18 @@ # @param password The password for Wildfly's management user. # @param host The IP address or FQDN of the JBoss Management service. # @param port The port of the JBoss Management service. +# @param undeploy_first Instead of 'updating' a deployment, should the existing deployment be undeployed and then redeployed? define wildfly::deployment( Variant[Pattern[/^file:\/\//], Pattern[/^puppet:\/\//], Stdlib::Httpsurl, Stdlib::Httpurl] $source, - Enum[present, absent] $ensure = present, - Optional[Integer] $timeout = undef, - Optional[String] $server_group = undef, - $operation_headers = {}, - String $username = $wildfly::mgmt_user['username'], - String $password = $wildfly::mgmt_user['password'], - String $host = $wildfly::properties['jboss.bind.address.management'], - String $port = $wildfly::properties['jboss.management.http.port'], + Enum[present, absent] $ensure = present, + Optional[Integer] $timeout = undef, + Optional[String] $server_group = undef, + $operation_headers = {}, + String $username = $wildfly::mgmt_user['username'], + String $password = $wildfly::mgmt_user['password'], + String $host = $wildfly::properties['jboss.bind.address.management'], + String $port = $wildfly::properties['jboss.management.http.port'], + Optional[Boolean] $undeploy_first = undef, ) { $file_name = basename($source) @@ -42,6 +44,7 @@ timeout => $timeout, source => "${wildfly::deploy_cache_dir}/${file_name}", operation_headers => $operation_headers, + undeploy_first => $undeploy_first, require => [Service['wildfly'], File["${wildfly::deploy_cache_dir}/${file_name}"]], } diff --git a/spec/types/wildfly_deployment_spec.rb b/spec/types/wildfly_deployment_spec.rb index ef7b3296..1f2362c1 100644 --- a/spec/types/wildfly_deployment_spec.rb +++ b/spec/types/wildfly_deployment_spec.rb @@ -8,10 +8,10 @@ end it 'has expected parameters' do - expect(deployment.parameters).to include(:name, :source, :server_group, :username, :password, :host, :port, :timeout, :operation_headers) + expect(deployment.parameters).to include(:name, :source, :server_group, :username, :password, :host, :port, :timeout, :operation_headers, :undeploy_first) end - describe 'when testing wheter content checksum is in sync' do + describe 'when testing whether content checksum is in sync' do let(:resource) { described_class.new(:name => 'app.ear') } it 'is if deployed content SHA1 checksum matches source checksum' do diff --git a/spec/unit/puppet/provider/wildfly_deployment/http_api_spec.rb b/spec/unit/puppet/provider/wildfly_deployment/http_api_spec.rb new file mode 100644 index 00000000..f8ae53fd --- /dev/null +++ b/spec/unit/puppet/provider/wildfly_deployment/http_api_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +provider_class = Puppet::Type.type(:wildfly_deployment).provider(:http_api) + +describe provider_class do + let :resource do + Puppet::Type.type(:wildfly_deployment).new( + :name => 'test.ear', + :source => '/tmp/test.ear', + :operation_headers => {}, + :provider => :http_api) + end + + let :provider do + resource.provider + end + + describe 'content=' do + describe 'undeploy_first' do + context 'by default' do + it 'undeploy_first is false' do + expect(resource[:undeploy_first]).to be(false) + end + it 'calls `update_deploy`' do + expect(provider).not_to receive(:destroy) + expect(provider).not_to receive(:create) + + cli = double + allow(provider).to receive(:cli).and_return(cli) + + expect(provider.cli).to receive(:update_deploy).with('test.ear', '/tmp/test.ear', nil, {}) + provider.content = 'unused' + end + end + context 'when undeploy_first => true' do + it 'calls `destroy` followed by `create`' do + resource[:undeploy_first] = true + expect(provider).to receive(:destroy).ordered + expect(provider).to receive(:create).ordered + provider.content = 'unused' + end + end + end + end +end