New message about repository check fail
Done: - change message about error; - add into mcollective log info about perfomed command; - add tests. Change-Id: I0c0c9b67157879e05fd4c43f67477d8de3b8f549 Related-Bug: #1471085
This commit is contained in:
parent
34e0493afa
commit
745fea3968
|
@ -125,14 +125,22 @@ module Astute
|
|||
|
||||
def self.check_repositories_with_setup(ctx, nodes)
|
||||
uids = nodes.map { |node| node['uid'].to_s }
|
||||
net_probe = MClient.new(ctx, "net_probe", uids)
|
||||
net_probe = MClient.new(ctx, "net_probe", uids, check_result=false)
|
||||
|
||||
data = {}
|
||||
nodes.each do |node|
|
||||
data[node['uid'].to_s] = node
|
||||
end
|
||||
data = nodes.inject({}) { |h, node| h.merge({node['uid'].to_s => node}) }
|
||||
|
||||
result = net_probe.check_repositories_with_setup(:data => data)
|
||||
bad_nodes = nodes.map { |n| n['uid'] } - result.map { |n| n.results[:sender] }
|
||||
|
||||
if bad_nodes.present?
|
||||
error_msg = "Astute could not get result from nodes #{bad_nodes}. " \
|
||||
"Please check mcollective log on problem nodes " \
|
||||
"for more details. Hint: try to execute check manually " \
|
||||
"using command from mcollective log on nodes, also " \
|
||||
"check nodes availability using command `mco ping` " \
|
||||
"on master node."
|
||||
raise MClientTimeout, error_msg
|
||||
end
|
||||
|
||||
{'nodes' => flatten_response(result), 'status'=> 'ready'}
|
||||
end
|
||||
|
|
|
@ -84,6 +84,7 @@ module MCollective
|
|||
-a #{config['addr']} \
|
||||
--vlan #{config['vlan']} \
|
||||
'#{config['urls'].join("' '")}'"
|
||||
Log.debug("about to execute: #{cmd}")
|
||||
|
||||
reply[:status] = run(cmd, :stdout => :out, :stderr => :err)
|
||||
reply[:out] = reply[:out] && reply[:out].length >= 2 ? JSON.parse(reply[:out]) : ""
|
||||
|
|
|
@ -211,7 +211,6 @@ describe Astute::Network do
|
|||
uids = ["1", "2"]
|
||||
res = Astute::Network.check_vlans_by_traffic("1", uids, data)
|
||||
res.should eql(correct_res)
|
||||
|
||||
end
|
||||
|
||||
it "returns tags sent only by some nodes"do
|
||||
|
@ -229,4 +228,85 @@ describe Astute::Network do
|
|||
|
||||
end
|
||||
|
||||
describe ".check_repositories_with_setup" do
|
||||
let(:nodes) do
|
||||
[
|
||||
{
|
||||
"iface"=>"eth1",
|
||||
"uid"=>"1",
|
||||
"vlan"=>0,
|
||||
"gateway"=>"10.109.1.1",
|
||||
"addr"=>"10.109.1.4/24",
|
||||
"urls"=>[
|
||||
"http://10.109.0.2:8080/2014.2.2-7.0/centos/auxiliary",
|
||||
"http://10.109.0.2:8080/2014.2.2-7.0/centos/x86_64"]
|
||||
},
|
||||
{
|
||||
"iface"=>"eth1",
|
||||
"uid"=>"4",
|
||||
"vlan"=>0,
|
||||
"gateway"=>"10.109.1.1",
|
||||
"addr"=>"10.109.1.4/24",
|
||||
"urls"=>[
|
||||
"http://10.109.0.2:8080/2014.2.2-7.0/centos/auxiliary",
|
||||
"http://10.109.0.2:8080/2014.2.2-7.0/centos/x86_64"]
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
let(:mclient) do
|
||||
mclient = mock_rpcclient
|
||||
Astute::MClient.any_instance.stubs(:rpcclient).returns(mclient)
|
||||
Astute::MClient.any_instance.stubs(:log_result).returns(mclient)
|
||||
Astute::MClient.any_instance.stubs(:check_results_with_retries).returns(mclient)
|
||||
mclient
|
||||
end
|
||||
|
||||
def build_mcresult(status=0, out="", err="", sender="1")
|
||||
rs = {:sender => sender, :data => {
|
||||
:status => status,
|
||||
:out => out,
|
||||
:err => err
|
||||
}}
|
||||
mcresult_mock = mock_mc_result(rs)
|
||||
mock_result = mock
|
||||
mock_result.stubs(:results).returns(rs)
|
||||
mock_result.stubs(:each).returns(mcresult_mock)
|
||||
mock_result
|
||||
end
|
||||
|
||||
it "should check repositories with setup" do
|
||||
mclient.expects(:check_repositories_with_setup)
|
||||
.with({:data => {"1" => nodes.first, "4" => nodes.last}})
|
||||
.returns([
|
||||
build_mcresult(status=0),
|
||||
build_mcresult(status=0, out="", err="", sender="4")]
|
||||
)
|
||||
|
||||
res = Astute::Network.check_repositories_with_setup(
|
||||
Astute::Context.new('task_uuid', reporter),
|
||||
nodes)
|
||||
|
||||
res.should eql({
|
||||
"status"=>"ready",
|
||||
"nodes"=>[
|
||||
{:out=>"", :err=>"", :status=>0, :uid=>"1"},
|
||||
{:out=>"", :err=>"", :status=>0, :uid=>"4"}]
|
||||
})
|
||||
end
|
||||
|
||||
it "should show error if repositories with setup do not return answer" do
|
||||
mclient.expects(:check_repositories_with_setup)
|
||||
.with({:data => {"1" => nodes.first, "4" => nodes.last}})
|
||||
.returns([
|
||||
build_mcresult(status=0)]
|
||||
)
|
||||
|
||||
expect{Astute::Network.check_repositories_with_setup(
|
||||
Astute::Context.new('task_uuid', reporter),
|
||||
nodes)}.to raise_error(Astute::MClientTimeout, /check mcollective log/)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue