Skip to content

Commit

Permalink
agent: publish unit state regardless of hash
Browse files Browse the repository at this point in the history
When starting up, the Agent may already have some Jobs loaded. In this
case, the UnitStatePublisher will not have a cached hash for the
corresponding Unit. The UnitStatePublisher must publish state regardless
of the UnitHash being absent.
  • Loading branch information
bcwaldon committed Jul 28, 2014
1 parent d555d28 commit 11949e0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
9 changes: 6 additions & 3 deletions agent/unit_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ func (p *UnitStatePublisher) publishOne(name string, us *unit.UnitState) {
// 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?
if len(us.UnitHash) == 0 {
log.Errorf("Refusing to push UnitState(%s), no UnitHash: %#v", name, us)
} else if len(us.MachineID) == 0 {

// 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 {
log.Errorf("Refusing to push UnitState(%s), no MachineID: %#v", name, us)
} else {
log.V(1).Infof("Pushing UnitState(%s) to Registry: %#v", name, us)
Expand Down
13 changes: 7 additions & 6 deletions registry/unit_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,22 @@ func unitStateToModel(us *unit.UnitState) *unitStateModel {
return nil
}

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

usm := unitStateModel{
LoadState: us.LoadState,
ActiveState: us.ActiveState,
SubState: us.SubState,
UnitHash: us.UnitHash,
}

if us.MachineID != "" {
usm.MachineState = &machine.MachineState{ID: us.MachineID}
}

// Refuse to create a UnitState without a Hash
if len(us.UnitHash) == 0 {
return nil
}
usm.UnitHash = us.UnitHash

return &usm
}
20 changes: 11 additions & 9 deletions registry/unit_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ func TestSaveUnitState(t *testing.T) {
mID := "mymachine"
us := unit.NewUnitState("abc", "def", "ghi", mID)

// saving unit state with no hash should fail (nil action)
r.SaveUnitState(j, us)
if len(e.sets) != 0 || e.deletes != nil {
t.Fatalf("SaveUnitState on UnitState with no hash acted unexpectedly!")
t.Logf("sets: %#v", e.sets)
t.Logf("deletes: %#v", e.deletes)
}
// 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)
//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!")
//}

us.UnitHash = "quickbrownfox"
r.SaveUnitState(j, us)
Expand Down Expand Up @@ -139,9 +140,10 @@ func TestUnitStateToModel(t *testing.T) {
want: nil,
},
{
// No unit states without hashes
// Unit state with no hash and no machineID is OK
// See https://github.com/coreos/fleet/issues/720
in: &unit.UnitState{"foo", "bar", "baz", "", ""},
want: nil,
want: &unitStateModel{"foo", "bar", "baz", nil, ""},
},
{
// Unit state with hash but no machineID is OK
Expand Down

0 comments on commit 11949e0

Please sign in to comment.