Skip to content

Commit

Permalink
(choria-io#2169) Pass choria federations to external discovery agent
Browse files Browse the repository at this point in the history
  • Loading branch information
vjanelle committed May 2, 2024
1 parent 9cd9601 commit ba107e4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions inter/imocks/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func NewFrameworkForTests(ctrl *gomock.Controller, logWriter io.Writer, opts ...
fw.EXPECT().Configuration().Return(mopts.cfg).AnyTimes()
fw.EXPECT().Logger(gomock.AssignableToTypeOf("")).Return(logrus.NewEntry(logger)).AnyTimes()
fw.EXPECT().NewRequestID().Return(util.RandomHexString(), nil).AnyTimes()
fw.EXPECT().FederationCollectives().Return([]string{}).AnyTimes()
fw.EXPECT().HasCollective(gomock.AssignableToTypeOf("")).DoAndReturn(func(c string) bool {
for _, collective := range fw.Configuration().Collectives {
if c == collective {
Expand Down
5 changes: 5 additions & 0 deletions providers/discovery/external/external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,15 @@ var _ = Describe("External", func() {
Context("Should pass CHORIA_FED_COLLECTIVE when the value is set", func() {
BeforeEach(func() {
cfg.Choria.FederationCollectives = []string{"alpha", "beta"}
fw.EXPECT().FederationCollectives().Return([]string{"alpha", "beta"}).AnyTimes()
})
It("Should contain the list of collectives", func() {
Expect(cfg.Choria.FederationCollectives).To(ContainElements([]string{"alpha", "beta"}))
})
})
})
})

func RunExternalCommands() {

}
1 change: 1 addition & 0 deletions providers/discovery/external/testdata/good.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def write_output(output)
"identity" => []
},
"collective" => "ginkgo",
"federations" => [],
"timeout" => 2,
}

Expand Down
41 changes: 41 additions & 0 deletions providers/discovery/external/testdata/good_with_federations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env ruby

require "json"
require "pp"

def write_output(output)
File.open(ENV["CHORIA_EXTERNAL_REPLY"], "w") {|f|
f.puts(output.to_json)
}
exit
end

if ENV["CHORIA_EXTERNAL_PROTOCOL"] != "io.choria.choria.discovery.v1.external_request"
write_output({"error" => "invalid protocol"})
exit
end

request = JSON.parse(File.read(ENV["CHORIA_EXTERNAL_REQUEST"]))
expected = {
"$schema" => "https://choria.io/schemas/choria/discovery/v1/external_request.json",
"options" => {
"foo" => "bar"
},
"protocol" => "io.choria.choria.discovery.v1.external_request",
"filter" => {
"fact" => [{"fact" => "country", "operator"=>"==","value"=>"mt"}],
"cf_class"=>[],
"agent" => ["rpcutil"],
"compound" => [],
"identity" => []
},
"collective" => "ginkgo",
"federations" => ["alpha", "beta"]
"timeout" => 2,
}
if request != expected
write_output({"error" => "invalid filter received: "+request.pretty_inspect})
else
write_output({"protocol" => "io.choria.choria.discovery.v1.external_reply", "nodes" => ["one","two"]})
end

0 comments on commit ba107e4

Please sign in to comment.