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 ba107e4 commit eef11ee
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 63 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func NewConfigForTests() *Config {
c.DisableSecurityProviderVerify = true
c.LogFile = "discard"
c.RPCAuthorization = false
c.Choria.FederationCollectives = []string{"alpha", "beta"}

return c
}
Expand Down
2 changes: 1 addition & 1 deletion providers/discovery/external/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (e *External) Discover(ctx context.Context, opts ...DiscoverOption) (n []st
collective: e.fw.Configuration().MainCollective,
timeout: e.timeout,
command: e.fw.Configuration().Choria.ExternalDiscoveryCommand,
federations: e.fw.FederationCollectives(),
federations: e.fw.Configuration().Choria.FederationCollectives,
do: make(map[string]string),
}

Expand Down
28 changes: 8 additions & 20 deletions providers/discovery/external/external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,19 @@ var _ = Describe("External", func() {
})

Describe("Discover", func() {
It("Should request and return discovered nodes", func() {
wd, _ := os.Getwd()
var f *protocol.Filter
BeforeEach(func() {
if runtime.GOOS == "windows" {
Skip("not tested on windows")
}

f := protocol.NewFilter()
f = protocol.NewFilter()
f.AddAgentFilter("rpcutil")
f.AddFactFilter("country", "==", "mt")

wd, _ := os.Getwd()
err := f.AddFactFilter("country", "==", "mt")
Expect(err).ToNot(HaveOccurred())
})
It("Should request and return discovered nodes", func() {
cfg.Choria.ExternalDiscoveryCommand = filepath.Join(wd, "testdata/good.rb")
nodes, err := e.Discover(context.Background(), Filter(f), DiscoveryOptions(map[string]string{"foo": "bar"}))
Expect(err).ToNot(HaveOccurred())
Expand All @@ -82,27 +85,12 @@ var _ = Describe("External", func() {
Skip("not tested on windows")
}

f := protocol.NewFilter()
f.AddAgentFilter("rpcutil")
f.AddFactFilter("country", "==", "mt")

wd, _ := os.Getwd()
cfg.Choria.ExternalDiscoveryCommand = filepath.Join(wd, "testdata/missing.rb")
cmd := filepath.Join(wd, "testdata/good_with_argument.rb") + " discover --test"
nodes, err := e.Discover(context.Background(), Filter(f), DiscoveryOptions(map[string]string{"command": cmd, "foo": "bar"}))
Expect(err).ToNot(HaveOccurred())
Expect(nodes).To(Equal([]string{"one", "two"}))
})

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"}))
})
})
})
})

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

Expand Down
41 changes: 0 additions & 41 deletions providers/discovery/external/testdata/good_with_federations.rb

This file was deleted.

0 comments on commit eef11ee

Please sign in to comment.