Skip to content
This repository has been archived by the owner on Nov 28, 2018. It is now read-only.

(#13429) refactor puppetral agent for telly compatibility #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion agent/puppetca/agent/puppetca.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def startup_hook
signed = paths_for_cert(certname)[:signed]
csr = paths_for_cert(certname)[:request]

msg = []
msg = new_msg_array

if has_cert?(certname)
File.unlink(signed)
Expand Down Expand Up @@ -105,6 +105,13 @@ def paths_for_cert(certname)
{:signed => "#{@cadir}/signed/#{certname}.pem",
:request => "#{@cadir}/requests/#{certname}.pem"}
end

# This is only here to simplify testing, so that we can simulate
# various lengths of the msg queue
def new_msg_array()
[]
end
private :new_msg_array
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion agent/puppetca/spec/puppetca_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@
end

it "should return the message if there are no certs but msg.size is not 0" do
@msg_array = []

@agent.expects(:paths_for_cert).with("certname").twice.returns({:signed => "signed", :request => "request"})
@agent.expects(:has_cert?).with("certname").returns(false)
@agent.expects(:cert_waiting?).with("certname").returns(false)
Array.any_instance.expects(:size).returns(1)
@agent.expects(:new_msg_array).returns(@msg_array)
@msg_array.expects(:size).returns(1)
result = @agent.call(:clean, :certname => "certname")
result.should be_successful
result.should have_data_items(:msg => "")
Expand Down
6 changes: 6 additions & 0 deletions agent/puppetral/agent/puppetral.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'puppet'
require 'puppet/face/resource'

module MCollective
module Agent
Expand All @@ -17,6 +18,11 @@ module Agent
# You can use puppetral to declare instances of any sensible Puppet type,
# as long as you supply all of the attributes that the type requires.
class Puppetral<RPC::Agent
def initialize
super
Puppet.initialize_settings
end

metadata :name => "Resource Abstraction Layer Agent",
:description => "View and edit resources with Puppet's resource abstraction layer",
:author => "R.I.Pienaar <[email protected]>, Max Martin <[email protected]>",
Expand Down
18 changes: 18 additions & 0 deletions agent/puppetral/spec/puppetral_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
#!/usr/bin/env rspec
require 'spec_helper'
require 'tmpdir'

describe "puppetral agent" do
before :all do
agent_file = File.join([File.dirname(__FILE__), "../agent/puppetral.rb"])
@agent = MCollective::Test::LocalAgentTest.new("puppetral", :agent_file => agent_file).plugin
end

# Not entirely thrilled with this; these tests end up causing puppet to actually
# write some files in vardir, so we need to make sure that vardir is a real
# directory that we can write to. In an ideal world, I'd prefer that external
# tools need not be quite so familiar with puppet's internal state and settings
# implementations in order to run tests. However, the current behavior of
# puppet in "test" mode is to use "/dev/null" for all of the state / config
# directories so that we will detect tests that attempt to write to them and
# fail, since most spec tests should not be doing so. --cprice 2012-04-24
before :each do
@vardir = Dir.mktmpdir
Puppet[:vardir] = @vardir
end

after :each do
FileUtils.rm_rf(@vardir) if File.directory?(@vardir)
end

describe "#find" do
it "should retrieve information about the type and title passed" do
result = @agent.call(:find, :type => 'User', :title => 'bob')
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'rspec/mocks'
require 'mocha'
require 'tempfile'
require 'puppet_spec_helper'

RSpec.configure do |config|
config.mock_with :mocha
Expand Down