Make options 'exists-action' and 'is-public' configurable

Currently options 'is-public' and 'exists-action' are hardcoded in
murano_appllication provider. It can lead some problems, during
uploading and updating action, so it make sense to make them
configurable.

Related-Bug: #1624723

Change-Id: I061cb64856e14d326dfa30851e427088e60f0a48
This commit is contained in:
Denis Egorenko 2016-09-20 13:50:53 +03:00
parent a3cd7ef663
commit 02f15492a0
7 changed files with 94 additions and 14 deletions

View File

@ -29,10 +29,20 @@ Puppet::Type.type(:murano_application).provide(
unless resource[:category].nil?
opts.push('-c').push(resource[:category])
end
opts.push('--is-public').push('--exists-action').push('u')
opts.push('--is-public') if resource[:public]
auth_murano('package-import', opts)
end
def flush
if [:present, :latest].include?(resource[:ensure])
unless resource[:exists_action] == 's'
opts = [ resource[:package_path] ]
opts.push('-c').push(resource[:category]) unless resource[:category].nil?
opts.push('--is-public') if resource[:public]
opts.push('--exists-action').push(resource[:exists_action])
auth_murano('package-import', opts)
end
end
end
end

View File

@ -9,6 +9,16 @@
# Path to package file
# Required
#
# [*exists_action*]
# Default action when a package
# already exists
# Optional
#
# [*public*]
# Make the package available for users
# from other tenants
# Optional
#
# [*category*]
# Category for the new application
# Optional
@ -44,6 +54,24 @@ Puppet::Type.newtype(:murano_application) do
newvalues(/\S+/)
end
newproperty(:exists_action) do
desc 'Default action when a package already exists'
defaultto('s')
validate do |value|
allowed_actions = ['s', 'a', 'u']
raise ArgumentError, 'Unknown action is set' unless allowed_actions.include?(value)
end
end
newproperty(:public) do
desc 'Make the package available for users from other tenants'
defaultto('true')
newvalues(/(t|T)rue/, /(f|F)alse/, true, false)
munge do |value|
value.to_s.downcase.to_sym
end
end
newproperty(:category) do
desc 'Package category'
validate do |value|
@ -57,4 +85,4 @@ Puppet::Type.newtype(:murano_application) do
raise ArgumentError, 'Name and package path must be set' unless self[:name] and self[:package_path]
end
end
end

View File

@ -16,17 +16,32 @@
# (Optional) Application category
# Defaults to 'undef'
#
# [*exists_action*]
# (Optional) Default action when a package
# already exists: s - skip, a - abort,
# u - update.
# Defaults to 's'
#
# [*public*]
# (Optional) Make the package available for users
# from other tenants
# Defaults to true
#
define murano::application (
$package_ensure = 'present',
$package_name = $title,
$package_category = undef,
$exists_action = 's',
$public = true,
) {
$package_path="/var/cache/murano/meta/${package_name}.zip"
murano_application { $package_name:
ensure => $package_ensure,
package_path => $package_path,
category => $package_category,
ensure => $package_ensure,
package_path => $package_path,
exists_action => $exists_action,
public => $public,
category => $package_category,
}
}

View File

@ -0,0 +1,8 @@
---
fixes:
- Murano application provider has problem with
updating murano package importing, when new version
is released. That was because of incorrect handling of
'exists-action' option. Now, it has been moved into
separate property, that will allow properly handle update
if needed.

View File

@ -6,14 +6,18 @@ describe 'murano::application' do
describe 'with default parameters' do
it { is_expected.to contain_murano_application('io.murano').with(
:ensure => 'present',
:package_path => '/var/cache/murano/meta/io.murano.zip'
:ensure => 'present',
:package_path => '/var/cache/murano/meta/io.murano.zip',
:public => true,
:exists_action => 's'
)}
end
describe 'with package_category override' do
let :params do {
:package_category => 'library'
:package_category => 'library',
:public => false,
:exists_action => 'u'
}
end
@ -21,6 +25,8 @@ describe 'murano::application' do
:ensure => 'present',
:package_path => '/var/cache/murano/meta/io.murano.zip',
:category => 'library',
:public => false,
:exists_action => 'u'
)}
end

View File

@ -8,9 +8,11 @@ describe provider_class do
let :app_attrs do
{
:name => 'io.murano',
:package_path => '/tmp/io.murano.zip',
:ensure => 'present',
:name => 'io.murano',
:package_path => '/tmp/io.murano.zip',
:ensure => 'present',
:public => true,
:exists_action => 'u',
}
end
@ -42,12 +44,20 @@ describe provider_class do
describe '#create' do
it 'should create application' do
provider.expects(:auth_murano).with("package-import", ['/tmp/io.murano.zip', '--is-public', '--exists-action', 'u'] )
provider.expects(:auth_murano).with("package-import", ['/tmp/io.murano.zip', '--is-public'] )
.returns('')
provider.create
end
end
describe '#flush' do
it 'should flush application' do
provider.expects(:auth_murano).with("package-import", ['/tmp/io.murano.zip', '--is-public', '--exists-action', 'u'] )
.returns('')
provider.flush
end
end
describe '#destroy' do
it 'should destroy application' do
resource[:ensure] = :absent

View File

@ -22,4 +22,7 @@ describe 'Puppet::Type.type(:murano_application)' do
Puppet::Type.type(:murano_application).new(:name => 'io.murano', :package_path => '/tmp/io.zip', :category => 'library')
end
it 'should reject wrong exists action' do
expect { Puppet::Type.type(:murano_application).new(:name => 'io.murano', :package_path => '/tmp/io.zip', :category => 'library', :exists_action => 'e') }.to raise_error(Puppet::Error, /Unknown action is set/)
end
end