Use post in mcollective facter updater
This commit is contained in:
parent
ead633567b
commit
5e5d0131e0
@ -22,38 +22,13 @@ action "get", :description => "fetches a value from a file" do
|
||||
:display_as => "Value"
|
||||
end
|
||||
|
||||
action "put", :description => "Value to add to file" do
|
||||
action "post", :description => "Create new attributes file" do
|
||||
display :failed
|
||||
|
||||
input :key,
|
||||
:prompt => "Key",
|
||||
:description => "Key you want to set in the file",
|
||||
:type => :string,
|
||||
:validation => '^[a-zA-Z0-9_]+$',
|
||||
:optional => false,
|
||||
:maxlength => 90
|
||||
|
||||
input :value,
|
||||
:prompt => "Value",
|
||||
:description => "Value you want to set in the file",
|
||||
:type => :string,
|
||||
:validation => '^[a-zA-Z0-9_]+$',
|
||||
:optional => false,
|
||||
:maxlength => 90
|
||||
|
||||
output :msg,
|
||||
:description => "Status",
|
||||
:display_as => "Status"
|
||||
end
|
||||
|
||||
action "delete", :description => "Delete a key/value pair if it exists" do
|
||||
display :failed
|
||||
|
||||
input :key,
|
||||
:prompt => "Key",
|
||||
:description => "Key you want to change in the file",
|
||||
:type => :string,
|
||||
:validation => '^[a-zA-Z0-9_]+$',
|
||||
:type => :hash,
|
||||
:optional => false,
|
||||
:maxlength => 90
|
||||
|
||||
|
@ -35,7 +35,6 @@ module MCollective
|
||||
end
|
||||
|
||||
def write_facts(fname, facts)
|
||||
|
||||
if not File.exists?(File.dirname(fname))
|
||||
Dir.mkdir(File.dirname(fname))
|
||||
end
|
||||
@ -54,39 +53,22 @@ module MCollective
|
||||
|
||||
action "get" do
|
||||
validate :key, String
|
||||
|
||||
kv_map = parse_facts(nailyfile)
|
||||
if kv_map[request[:key]] != nil
|
||||
reply[:value] = kv_map[request[:key]]
|
||||
end
|
||||
end
|
||||
|
||||
action "put" do
|
||||
validate :key, String
|
||||
validate :value, String
|
||||
action "post" do
|
||||
validate :value, Hash
|
||||
|
||||
kv_map = parse_facts(nailyfile)
|
||||
kv_map.update({request[:key] => request[:value]})
|
||||
kv_map = request[:value]
|
||||
|
||||
if write_facts(nailyfile, kv_map)
|
||||
reply[:msg] = "Settings Updated!"
|
||||
else
|
||||
reply.fail! "Could not write file!"
|
||||
end
|
||||
|
||||
end
|
||||
action "delete" do
|
||||
validate :key, String
|
||||
|
||||
kv_map = parse_facts(nailyfile)
|
||||
kv_map.delete(request[:key])
|
||||
|
||||
if write_facts(nailyfile,kv_map)
|
||||
reply[:msg] = "Setting deleted!"
|
||||
else
|
||||
reply.fail! "Could not write file!"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -9,6 +9,9 @@ if File.exist?("/etc/naily.facts")
|
||||
Facter.add(var) do
|
||||
setcode { val }
|
||||
end
|
||||
Facter.add("myrole") do
|
||||
setcode {'a' => {'b' => {'c' => 'd'}}}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -16,17 +16,20 @@ describe "MCollective" do
|
||||
end
|
||||
|
||||
it "it should update facts file with new key-value and could get it back" do
|
||||
value_to_send = rand(2**30).to_s
|
||||
data_to_send = {"anykey" => rand(2**30).to_s, "other" => "static"}
|
||||
node = "admin"
|
||||
mc = rpcclient("nailyfact")
|
||||
mc.progress = false
|
||||
mc.discover(:nodes => [node])
|
||||
stats = mc.put(:key => "role", :value => value_to_send)
|
||||
stats.should have(1).items
|
||||
stats[0].results[:statuscode].should eql(0)
|
||||
stats = mc.get(:key => "role")
|
||||
stats = mc.post(:value => data_to_send)
|
||||
check_mcollective_result(stats)
|
||||
stats[0].results[:data][:value].should eql(value_to_send)
|
||||
|
||||
stats = mc.get(:key => "anykey")
|
||||
check_mcollective_result(stats)
|
||||
stats[0].results[:data][:value].should eql(data_to_send['anykey'])
|
||||
stats = mc.get(:key => "other")
|
||||
check_mcollective_result(stats)
|
||||
stats[0].results[:data][:value].should eql(data_to_send['other'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user