-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#10 jmsqueue in puppet_x and tests for create and destroy
- Loading branch information
Kozakowski Karol
committed
Jan 22, 2016
1 parent
1eb9009
commit 1e8c1dd
Showing
4 changed files
with
219 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# A module for Jmsqueue | ||
module Puppet_X::Coi::Jboss::Provider::Jmsqueue | ||
def create | ||
if runasdomain? | ||
profile = "--profile=#{@resource[:profile]}" | ||
else | ||
profile = '' | ||
end | ||
entries = @resource[:entries].join '", "' | ||
if not entries.empty? | ||
entries = '["%s"]' % entries | ||
else | ||
raise "Array of entries can not be empty" | ||
end | ||
durable = @resource[:durable].to_bool | ||
extcmd = "/extension=org.jboss.as.messaging" | ||
if not execute("#{extcmd}:read-resource()")[:result] | ||
bringUp "Extension - messaging", "#{extcmd}:add()" | ||
end | ||
syscmd = compilecmd "/subsystem=messaging" | ||
if not execute("#{syscmd}:read-resource()")[:result] | ||
bringUp "Subsystem - messaging", "#{syscmd}:add()" | ||
end | ||
hornetcmd = compilecmd "/subsystem=messaging/hornetq-server=default" | ||
if not execute("#{hornetcmd}:read-resource()")[:result] | ||
bringUp "Default HornetQ", "#{hornetcmd}:add()" | ||
end | ||
cmd = "jms-queue #{profile} add --queue-address=#{@resource[:name]} --entries=#{entries} --durable=\"#{durable.to_s}\"" | ||
bringUp "JMS Queue", cmd | ||
end | ||
|
||
def destroy | ||
if runasdomain? | ||
profile = "--profile=#{@resource[:profile]}" | ||
else | ||
profile = '' | ||
end | ||
cmd = "jms-queue #{profile} remove --queue-address=#{@resource[:name]}" | ||
bringDown "JMS Queue", cmd | ||
end | ||
|
||
# | ||
def exists? | ||
$data = nil | ||
cmd = compilecmd "/subsystem=messaging/hornetq-server=default/jms-queue=#{@resource[:name]}:read-resource()" | ||
res = executeAndGet cmd | ||
|
||
if not res[:result] | ||
Puppet.debug "JMS Queue do not exists" | ||
return false | ||
end | ||
$data = res[:data] | ||
return true | ||
end | ||
|
||
def durable | ||
trace 'durable' | ||
Puppet.debug "Durable given: #{@resource[:durable].inspect}" | ||
$data['durable'].to_bool.to_s | ||
end | ||
|
||
def durable= value | ||
trace 'durable= %s' % value.to_s | ||
setattr 'durable', ('"%s"' % value.to_bool) | ||
end | ||
|
||
def entries | ||
trace 'entries' | ||
$data['entries'] | ||
end | ||
|
||
def entries= value | ||
trace 'entries= %s' % value.inspect | ||
entries = value.join '", "' | ||
if not entries.empty? | ||
entries = '["%s"]' % entries | ||
else | ||
raise "Array of entries can not be empty" | ||
end | ||
setattr 'entries', entries | ||
end | ||
|
||
private | ||
|
||
def setattr name, value | ||
setattribute_raw "/subsystem=messaging/hornetq-server=default/jms-queue=#{@resource[:name]}", name, value | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
require "spec_helper" | ||
|
||
context "mocking default values" do | ||
|
||
let(:mock_values) do | ||
{ | ||
:product => 'jboss-eap', | ||
:version => '6.4.0.GA', | ||
:controller => '127.0.0.1:9999', | ||
} | ||
end | ||
|
||
before :each do | ||
Puppet_X::Coi::Jboss::Configuration.reset_config(mock_values) | ||
end | ||
|
||
after :each do | ||
Puppet_X::Coi::Jboss::Configuration.reset_config | ||
end | ||
|
||
describe 'Puppet::Type::Confignode::ProviderJbosscli' do | ||
|
||
let(:described_class) do | ||
Puppet::Type.type(:jboss_jmsqueue).provider(:jbosscli) | ||
end | ||
let(:sample_repl) do | ||
{ | ||
:name => 'app-mails', | ||
:durable => true, | ||
:ensure => 'present', | ||
:entries => [ | ||
'queue/app-mails', | ||
'java:jboss/exported/jms/queue/app-mails', | ||
], | ||
:profile => 'full-ha' | ||
} | ||
end | ||
|
||
let(:extended_repl) do | ||
{} | ||
end | ||
|
||
let(:resource) do | ||
raw = sample_repl.merge(extended_repl) | ||
raw[:provider] = described_class.name | ||
|
||
Puppet::Type.type(:jboss_jmsqueue).new(raw) | ||
end | ||
|
||
let(:provider) do | ||
resource.provider | ||
end | ||
|
||
before :each do | ||
allow(provider.class).to receive(:suitable?).and_return(true) | ||
end | ||
|
||
describe '#create wth runasdomain? => true' do | ||
before :each do | ||
|
||
|
||
bringUpName = 'Extension - messaging' | ||
bringUpNameSubsytem = 'Subsystem - messaging' | ||
profile = resource[:profile] | ||
cmd = "/extension=org.jboss.as.messaging:add()" | ||
cmd2 = | ||
execCMD = '/extension=org.jboss.as.messaging:read-resource()' | ||
execCMD_expected_output = { | ||
:result => false, | ||
} | ||
execCMD2 = '/extension=org.jboss.as.messaging:add()' | ||
|
||
# line 4 | ||
expect(provider).to receive(:runasdomain?).and_return(true) | ||
|
||
# line 17 | ||
expect(provider).to receive(:execute).with(execCMD).and_return(execCMD_expected_output) | ||
|
||
# line 18 | ||
expect(provider).to receive(:bringUp).with(bringUpName, execCMD2).and_return(true) | ||
|
||
# line 20 | ||
cmdCompile = '/subsystem=messaging' | ||
compiledCMDSubsystem = '/profile/full-ha/subsystem=messaging' | ||
expect(provider).to receive(:compilecmd).with(cmdCompile).and_return(compiledCMDSubsystem) | ||
|
||
# line 21 | ||
execCMDSubsystem = "#{compiledCMDSubsystem}:read-resource()" | ||
expect(provider).to receive(:execute).with(execCMDSubsystem).and_return(execCMD_expected_output) | ||
|
||
# line 22 | ||
cmdSubsystem = "#{compiledCMDSubsystem}:add()" | ||
expect(provider).to receive(:bringUp).with(bringUpNameSubsytem, cmdSubsystem).and_return(true) | ||
|
||
# line 24 | ||
hornetCMD = '/subsystem=messaging/hornetq-server=default' | ||
compiledHornetCMD = "/profile/full-ha/#{hornetCMD}" | ||
execHornetCMD = "#{compiledHornetCMD}:read-resource()" | ||
hornetBringUpName = 'Default HornetQ' | ||
horneBringUpCMD = "#{compiledHornetCMD}:add()" | ||
|
||
expect(provider).to receive(:compilecmd).with(hornetCMD).and_return(compiledHornetCMD) | ||
expect(provider).to receive(:execute).with(execHornetCMD).and_return(execCMD_expected_output) | ||
expect(provider).to receive(:bringUp).with(hornetBringUpName, horneBringUpCMD).and_return(true) | ||
|
||
# line 28 | ||
finalCMD = "jms-queue --profile=full-ha add --queue-address=#{resource[:name]} --entries=#{resource[:entries]} --durable=\"#{resource[:durable].to_s}\"" | ||
finalBringUpName = 'JMS Queue' | ||
expect(provider).to receive(:bringUp).with(finalBringUpName, finalCMD).and_return(true) | ||
|
||
end | ||
|
||
subject { provider.create } | ||
it {expect(subject).to eq(true)} | ||
end | ||
|
||
describe '#destroy' do | ||
before :each do | ||
expect(provider).to receive(:runasdomain?).and_return(true) | ||
cmd = "jms-queue --profile=#{resource[:profile]} remove --queue-address=#{resource[:name]}" | ||
bringDownName = 'JMS Queue' | ||
expect(provider).to receive(:bringDown).with(bringDownName, cmd).and_return(true) | ||
end | ||
|
||
subject { provider.destroy } | ||
it { expect(subject).to eq(true) } | ||
end | ||
end | ||
end |