8000 agent: reenable check for nil hash in unit state publisher by dongsupark · Pull Request #1639 · coreos/fleet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

agent: reenable check for nil hash in unit state publisher #1639

Merged
merged 2 commits into from
Jul 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions agent/unit_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,9 @@ func newPublisher(reg registry.Registry, ttl time.Duration) publishFunc {
// Sanity check - don't want to publish incomplete UnitStates
// TODO(jonboulle): consider teasing apart a separate UnitState-like struct
// so we can rely on a UnitState always being fully hydrated?

// See https://github.com/coreos/fleet/issues/720
//if len(us.UnitHash) == 0 {
// log.Errorf("Refusing to push UnitState(%s), no UnitHash: %#v", name, us)

if len(us.MachineID) == 0 {
if len(us.UnitHash) == 0 {
log.Errorf("Refusing to push UnitState(%s), no UnitHash: %#v", name, us)
} else if len(us.MachineID) == 0 {
log.Errorf("Refusing to push UnitState(%s), no MachineID: %#v", name, us)
} else {
log.Debugf("Pushing UnitState(%s) to Registry: %#v", name, us)
Expand Down
4 changes: 4 additions & 0 deletions agent/unit_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,15 @@ func TestDefaultPublisher(t *testing.T) {
UnitName: "foo.service",
ActiveState: "active",
MachineID: "xyz",
UnitHash: "quickbrownfox",
},
nil,
[]*unit.UnitState{
&unit.UnitState{
UnitName: "foo.service",
ActiveState: "active",
MachineID: "xyz",
UnitHash: "quickbrownfox",
},
},
},
Expand All @@ -243,6 +245,7 @@ func TestDefaultPublisher(t *testing.T) {
&unit.UnitState{
UnitName: "foo.service",
ActiveState: "active",
UnitHash: "quickbrownfox",
},
nil,
[]*unit.UnitState{},
Expand All @@ -255,6 +258,7 @@ func TestDefaultPublisher(t *testing.T) {
unit.UnitState{
UnitName: "foo.service",
ActiveState: "active",
UnitHash: "quickbrownfox",
},
},
[]*unit.UnitState{},
Expand Down
7 changes: 3 additions & 4 deletions registry/unit_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,9 @@ func unitStateToModel(us *unit.UnitState) *unitStateModel {
}

// Refuse to create a UnitState without a Hash
// See https://github.com/coreos/fleet/issues/720
//if len(us.UnitHash) == 0 {
// return nil
//}
if len(us.UnitHash) == 0 {
return nil
}

usm := unitStateModel{
LoadState: us.LoadState,
Expand Down
26 changes: 9 additions & 17 deletions registry/unit_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,13 @@ func TestSaveUnitState(t *testing.T) {
t.Fatalf("SaveUnitState of nil state should fail but acted unexpectedly!")
}

// Saving unit state with no hash should succeed for now, but should fail
// in the future. See https://github.com/coreos/fleet/issues/720.
//r.SaveUnitState(j, us, time.Second)
//if len(e.sets) != 1 || e.deletes == nil {
// t.Logf("sets: %#v", e.sets)
// t.Logf("deletes: %#v", e.deletes)
// t.Fatalf("SaveUnitState on UnitState with no hash acted unexpectedly!")
A5A1 //}
// Saving unit state with no hash should should fail.
r.SaveUnitState(j, us, time.Second)
if len(e.sets) != 0 || e.deletes != nil {
t.Logf("sets: %#v", e.sets)
t.Logf("deletes: %#v", e.deletes)
t.Fatalf("SaveUnitState on UnitState with no hash acted unexpectedly!")
}

us.UnitHash = "quickbrownfox"
r.SaveUnitState(j, us, time.Second)
Expand Down Expand Up @@ -195,8 +194,7 @@ func TestUnitStateToModel(t *testing.T) {
want: nil,
},
{
// Unit state with no hash and no machineID is OK
// See https://github.com/coreos/fleet/issues/720
// Unit state with no hash and no machineID is not OK
in: &unit.UnitState{
LoadState: "foo",
ActiveState: "bar",
Expand All @@ -205,13 +203,7 @@ func TestUnitStateToModel(t *testing.T) {
UnitHash: "",
UnitName: "name",
},
want: &unitStateModel{
LoadState: "foo",
ActiveState: "bar",
SubState: "baz",
MachineState: nil,
UnitHash: "",
},
want: nil,
},
{
// Unit state with hash but no machineID is OK
Expand Down
0