Skip to content

Commit

Permalink
Merge pull request #49 from sky-uk/fix-allowed-flags
Browse files Browse the repository at this point in the history
Allow generic ipvs scheduler flags
  • Loading branch information
Andrey Sibiryov committed Jan 9, 2018
2 parents 5827cd0 + 03b3abf commit 1255c1b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ var (
schedulerFlags = map[string]int{
"sh-fallback": gnl2go.IP_VS_SVC_F_SCHED_SH_FALLBACK,
"sh-port": gnl2go.IP_VS_SVC_F_SCHED_SH_PORT,
"flag-1": gnl2go.IP_VS_SVC_F_SCHED1,
"flag-2": gnl2go.IP_VS_SVC_F_SCHED2,
"flag-3": gnl2go.IP_VS_SVC_F_SCHED3,
}
ErrIpvsSyscallFailed = errors.New("error while calling into IPVS")
ErrObjectExists = errors.New("specified object already exists")
Expand Down
20 changes: 18 additions & 2 deletions core/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestServiceIsCreated(t *testing.T) {
mockDisco.AssertExpectations(t)
}

func TestServiceIsCreatedWithCustomFlags(t *testing.T) {
func TestServiceIsCreatedWithShFlags(t *testing.T) {
options := &ServiceOptions{Port: 80, Host: "localhost", Protocol: "tcp", Method: "sh", Flags: "sh-port|sh-fallback"}
mockIpvs := &fakeIpvs{}
mockDisco := &fakeDisco{}
Expand Down Expand Up @@ -188,8 +188,24 @@ func TestPulseUpdateRemovesStashWhenDeletedAfterNotification(t *testing.T) {
mockIpvs := &fakeIpvs{}

c := newRoutineContext(backends, mockIpvs)
c.processPulseUpdate(stash, pulse.Update{pulse.ID{VsID: vsID, RsID: rsID}, pulse.Metrics{Status:pulse.StatusRemoved}})
c.processPulseUpdate(stash, pulse.Update{pulse.ID{VsID: vsID, RsID: rsID}, pulse.Metrics{Status: pulse.StatusRemoved}})

assert.Empty(t, stash)
mockIpvs.AssertExpectations(t)
}

func TestServiceIsCreatedWithGenericCustomFlags(t *testing.T) {
options := &ServiceOptions{Port: 80, Host: "localhost", Protocol: "tcp", Method: "sh", Flags: "flag-1|flag-2|flag-3"}
mockIpvs := &fakeIpvs{}
mockDisco := &fakeDisco{}
c := newContext(mockIpvs, mockDisco)

mockIpvs.On("AddServiceWithFlags", "127.0.0.1", uint16(80), uint16(syscall.IPPROTO_TCP), "sh",
gnl2go.U32ToBinFlags(gnl2go.IP_VS_SVC_F_SCHED1 | gnl2go.IP_VS_SVC_F_SCHED2 | gnl2go.IP_VS_SVC_F_SCHED3)).Return(nil)
mockDisco.On("Expose", vsID, "127.0.0.1", uint16(80)).Return(nil)

err := c.createService(vsID, options)
assert.NoError(t, err)
mockIpvs.AssertExpectations(t)
mockDisco.AssertExpectations(t)
}

0 comments on commit 1255c1b

Please sign in to comment.