Skip to content

Commit

Permalink
ciao-launcher: Add unit tests for the overseer.
Browse files Browse the repository at this point in the history
This commit adds some unit tests for the overseer go routine.  It
partially implements Issue ciao-project#1.

Signed-off-by: Mark Ryan <[email protected]>
  • Loading branch information
Mark Ryan committed Jun 8, 2016
1 parent 469ca8e commit 0596ad7
Show file tree
Hide file tree
Showing 2 changed files with 830 additions and 11 deletions.
38 changes: 27 additions & 11 deletions ciao-launcher/overseer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ import (
"syscall"
"time"

"gopkg.in/yaml.v2"

"github.com/01org/ciao/payloads"
"github.com/01org/ciao/ssntp"
"github.com/golang/glog"
"gopkg.in/yaml.v2"
)

type ovsAddResult struct {
Expand Down Expand Up @@ -109,6 +110,7 @@ type ovsInstanceState struct {
}

type overseer struct {
instancesDir string
instances map[string]*ovsInstanceState
ovsCh chan interface{}
childDoneCh chan struct{}
Expand All @@ -121,6 +123,10 @@ type overseer struct {
diskSpaceAvailable int
memoryAvailable int
traceFrames *list.List
memInfo string
stat string
loadavg string
statsInterval time.Duration
}

type cnStats struct {
Expand Down Expand Up @@ -233,7 +239,7 @@ func getOnlineCPUs() int {
return cpusOnline
}

func getFSInfo() (total, available int) {
func getFSInfo(instancesDir string) (total, available int) {

total = -1
available = -1
Expand Down Expand Up @@ -458,13 +464,13 @@ func (ovs *overseer) sendTraceReport() {
}
}

func getStats() *cnStats {
func getStats(instancesDir string) *cnStats {
var s cnStats

s.totalMemMB, s.availableMemMB = getMemoryInfo()
s.load = getLoadAvg()
s.cpusOnline = getOnlineCPUs()
s.totalDiskMB, s.availableDiskMB = getFSInfo()
s.totalDiskMB, s.availableDiskMB = getFSInfo(instancesDir)

return &s
}
Expand Down Expand Up @@ -565,7 +571,7 @@ func (ovs *overseer) processStatusCommand(cmd *ovsStatusCmd) {
if !ovs.ac.conn.isConnected() {
return
}
cns := getStats()
cns := getStats(ovs.instancesDir)
ovs.updateAvailableResources(cns)
ovs.sendStatusCommand(cns, ovs.computeStatus())
}
Expand All @@ -575,7 +581,7 @@ func (ovs *overseer) processStatsStatusCommand(cmd *ovsStatsStatusCmd) {
if !ovs.ac.conn.isConnected() {
return
}
cns := getStats()
cns := getStats(ovs.instancesDir)
ovs.updateAvailableResources(cns)
status := ovs.computeStatus()
ovs.sendStatusCommand(cns, status)
Expand Down Expand Up @@ -634,7 +640,7 @@ func (ovs *overseer) processCommand(cmd interface{}) {

func (ovs *overseer) runOverseer() {

statsTimer := time.After(time.Second * statsPeriod)
statsTimer := time.After(ovs.statsInterval)
DONE:
for {
select {
Expand All @@ -645,17 +651,17 @@ DONE:
ovs.processCommand(cmd)
case <-statsTimer:
if !ovs.ac.conn.isConnected() {
statsTimer = time.After(time.Second * statsPeriod)
statsTimer = time.After(ovs.statsInterval)
continue
}

cns := getStats()
cns := getStats(ovs.instancesDir)
ovs.updateAvailableResources(cns)
status := ovs.computeStatus()
ovs.sendStatusCommand(cns, status)
ovs.sendStats(cns, status)
ovs.sendTraceReport()
statsTimer = time.After(time.Second * statsPeriod)
statsTimer = time.After(ovs.statsInterval)
if glog.V(1) {
glog.Infof("Consumed: Disk %d Mem %d CPUs %d",
ovs.diskSpaceAllocated, ovs.memoryAllocated, ovs.vcpusAllocated)
Expand All @@ -671,7 +677,8 @@ DONE:
glog.Info("Overseer exitting")
}

func startOverseer(wg *sync.WaitGroup, ac *agentClient) chan<- interface{} {
func startOverseerFull(instancesDir string, wg *sync.WaitGroup, ac *agentClient, statsInterval time.Duration,
memInfo, stat, loadavg string) chan<- interface{} {

instances := make(map[string]*ovsInstanceState)
ovsCh := make(chan interface{})
Expand Down Expand Up @@ -726,6 +733,7 @@ func startOverseer(wg *sync.WaitGroup, ac *agentClient) chan<- interface{} {
})

ovs := &overseer{
instancesDir: instancesDir,
instances: instances,
ovsCh: ovsCh,
parentWg: wg,
Expand All @@ -736,6 +744,10 @@ func startOverseer(wg *sync.WaitGroup, ac *agentClient) chan<- interface{} {
diskSpaceAllocated: diskSpaceAllocated,
memoryAllocated: memoryAllocated,
traceFrames: list.New(),
statsInterval: statsInterval,
memInfo: memInfo,
stat: stat,
loadavg: loadavg,
}
ovs.parentWg.Add(1)
glog.Info("Starting Overseer")
Expand All @@ -758,3 +770,7 @@ func startOverseer(wg *sync.WaitGroup, ac *agentClient) chan<- interface{} {

return ovsCh
}

func startOverseer(wg *sync.WaitGroup, ac *agentClient) chan<- interface{} {
return startOverseerFull(instancesDir, wg, ac, time.Second*statsPeriod, "/proc/meminfo", "/proc/stat", "/proc/loadavg")
}
Loading

0 comments on commit 0596ad7

Please sign in to comment.