Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #887 from markdryan/fix-872
Browse files Browse the repository at this point in the history
ciao-launcher: Always update stats when volumes change
  • Loading branch information
Tim Pepper authored Nov 29, 2016
2 parents c0662b5 + 03f1354 commit cd27b8e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ciao-launcher/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ func (id *instanceData) attachVolumeCommand(cmd *insAttachVolumeCmd) {
attachErr.send(id.ac.conn, id.instance, cmd.volumeUUID)
return
}
d, m, c := id.vm.stats()
id.ovsCh <- &ovsStatsUpdateCmd{id.instance, m, d, c, id.getVolumes()}

glog.Infof("Volume %s attached to instance %s", cmd.volumeUUID, id.instance)
}
Expand All @@ -269,6 +271,8 @@ func (id *instanceData) detachVolumeCommand(cmd *insDetachVolumeCmd) {
detachErr.send(id.ac.conn, cmd.volumeUUID, id.instance)
return
}
d, m, c := id.vm.stats()
id.ovsCh <- &ovsStatsUpdateCmd{id.instance, m, d, c, id.getVolumes()}

glog.Infof("Volume %s detched from instance %s", cmd.volumeUUID, id.instance)
}
Expand Down
51 changes: 49 additions & 2 deletions ciao-launcher/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,57 @@ func (v *instanceTestState) verifyStatsUpdate(t *testing.T, cmd interface{}) {
}
}

func (v *instanceTestState) expectStatsUpdate(t *testing.T, ovsCh <-chan interface{}) bool {
func (v *instanceTestState) getStatsUpdate(t *testing.T, ovsCh <-chan interface{}) *ovsStatsUpdateCmd {
var cmd interface{}
select {
case cmd = <-ovsCh:
case <-time.After(time.Second):
t.Error("Timed out waiting for ovsStatsUpdateCmd")
return false
return nil
}
stats, ok := cmd.(*ovsStatsUpdateCmd)
if !ok {
t.Error("Unexpected Command received on ovsCh")
}
return stats
}

func (v *instanceTestState) expectStatsUpdateWithVolumes(t *testing.T,
ovsCh <-chan interface{}, volumes []string) bool {

stats := v.getStatsUpdate(t, ovsCh)
if stats == nil {
return false
}

if len(volumes) != len(stats.volumes) {
t.Errorf("Unxpected number of volumes. Expected %d found %d",
len(volumes), len(stats.volumes))
}

found := 0
for _, vol := range volumes {
for _, vol2 := range stats.volumes {
if vol2 == vol {
found++
break
}
}
}

if found < len(volumes) {
t.Errorf("Missing volumes. Expected %d found %d", len(volumes), found)
return false
}

return true
}

func (v *instanceTestState) expectStatsUpdate(t *testing.T, ovsCh <-chan interface{}) bool {
stats := v.getStatsUpdate(t, ovsCh)
if stats == nil {
return false
}
if stats.diskUsageMB != v.statsArray[0] || stats.memoryUsageMB != v.statsArray[1] ||
stats.CPUUsage != v.statsArray[2] || stats.instance != v.instance {
t.Error("Incorrect statistics received")
Expand Down Expand Up @@ -935,6 +974,8 @@ func TestAttachVolumeToInstance(t *testing.T) {
t.Error("Timed out waiting for attach volume command result")
}

_ = state.expectStatsUpdateWithVolumes(t, ovsCh, []string{testutil.VolumeUUID})

if !state.deleteInstance(t, ovsCh, cmdCh) {
cleanupShutdownFail(t, cfg.Instance, doneCh, ovsCh, &wg)
}
Expand Down Expand Up @@ -968,6 +1009,8 @@ func TestAttachExistingVolumeToInstance(t *testing.T) {
t.Error("Timed out waiting for attach volume command result")
}

_ = state.expectStatsUpdateWithVolumes(t, ovsCh, []string{testutil.VolumeUUID})

select {
case <-state.errorCh:
t.Error("Initial Volume attach failed")
Expand Down Expand Up @@ -1020,6 +1063,8 @@ func TestDetachVolumeFromInstance(t *testing.T) {
t.Error("Timed out waiting for attach volume command result")
}

_ = state.expectStatsUpdateWithVolumes(t, ovsCh, []string{testutil.VolumeUUID})

select {
case cmdCh <- &insDetachVolumeCmd{testutil.VolumeUUID}:
case <-time.After(time.Second):
Expand All @@ -1033,6 +1078,8 @@ func TestDetachVolumeFromInstance(t *testing.T) {
t.Error("Timed out waiting for attach volume command result")
}

_ = state.expectStatsUpdateWithVolumes(t, ovsCh, []string{})

if !state.deleteInstance(t, ovsCh, cmdCh) {
cleanupShutdownFail(t, cfg.Instance, doneCh, ovsCh, &wg)
}
Expand Down

0 comments on commit cd27b8e

Please sign in to comment.