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

ciao-launcher: Add more docker unit tests #986

Merged
merged 1 commit into from
Jan 5, 2017
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
3 changes: 3 additions & 0 deletions ciao-launcher/container_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type containerManager interface {
*network.NetworkingConfig, string) (types.ContainerCreateResponse, error)
ContainerRemove(context.Context, types.ContainerRemoveOptions) error
ContainerStart(context.Context, string) error
ContainerInspect(context.Context, string) (types.ContainerJSON, error)
ContainerInspectWithRaw(context.Context, string, bool) (types.ContainerJSON, []byte, error)
ContainerStats(context.Context, string, bool) (io.ReadCloser, error)
ContainerKill(context.Context, string, string) error
ContainerWait(context.Context, string) (int, error)
}
40 changes: 20 additions & 20 deletions ciao-launcher/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ func (d *docker) createImage(bridge string, userData, metaData []byte) error {
err = ioutil.WriteFile(idPath, []byte(resp.ID), 0600)
if err != nil {
glog.Errorf("Unable to store docker container ID %v", err)
_ = dockerDeleteContainer(d.cli, resp.ID, d.cfg.Instance)
return err
}

Expand All @@ -333,6 +334,19 @@ func (d *docker) createImage(bridge string, userData, metaData []byte) error {
return nil
}

func dockerDeleteContainer(cli containerManager, dockerID, instanceUUID string) error {
err := cli.ContainerRemove(context.Background(),
types.ContainerRemoveOptions{
ContainerID: dockerID,
Force: true})
if err != nil {
glog.Warningf("Unable to delete docker instance %s:%s err %v",
instanceUUID, dockerID, err)
}

return err
}

func (d *docker) deleteImage() error {
if d.dockerID == "" {
return nil
Expand All @@ -343,17 +357,7 @@ func (d *docker) deleteImage() error {
return err
}

err = d.cli.ContainerRemove(context.Background(),
types.ContainerRemoveOptions{
ContainerID: d.dockerID,
Force: true})
if err != nil {
glog.Warningf("Unable to delete docker instance %s:%s err %v",
d.cfg.Instance, d.dockerID, err)
return err
}

return nil
return dockerDeleteContainer(d.cli, d.dockerID, d.cfg.Instance)
}

func (d *docker) startVM(vnicName, ipAddress, cephID string) error {
Expand All @@ -378,7 +382,7 @@ func (d *docker) startVM(vnicName, ipAddress, cephID string) error {
return nil
}

func dockerCommandLoop(cli *client.Client, dockerChannel chan interface{}, instance, dockerID string) {
func dockerCommandLoop(cli containerManager, dockerChannel chan interface{}, instance, dockerID string) {
ctx, cancelFunc := context.WithCancel(context.Background())
lostContainerCh := make(chan struct{})
go func() {
Expand Down Expand Up @@ -420,8 +424,9 @@ DONE:
glog.Infof("Docker Instance %s:%s shut down", instance, dockerID)
}

func dockerConnect(dockerChannel chan interface{}, instance, dockerID string, closedCh chan struct{},
connectedCh chan struct{}, wg *sync.WaitGroup, boot bool) {
func dockerConnect(cli containerManager, dockerChannel chan interface{}, instance,
dockerID string, closedCh chan struct{}, connectedCh chan struct{},
wg *sync.WaitGroup, boot bool) {

defer func() {
if closedCh != nil {
Expand All @@ -431,11 +436,6 @@ func dockerConnect(dockerChannel chan interface{}, instance, dockerID string, cl
wg.Done()
}()

cli, err := getDockerClient()
if err != nil {
return
}

// BUG(markus): Need a way to cancel this. Can't do this until we have contexts

con, err := cli.ContainerInspect(context.Background(), dockerID)
Expand Down Expand Up @@ -470,7 +470,7 @@ func (d *docker) monitorVM(closedCh chan struct{}, connectedCh chan struct{},
}
dockerChannel := make(chan interface{})
wg.Add(1)
go dockerConnect(dockerChannel, d.cfg.Instance, d.dockerID, closedCh, connectedCh, wg, boot)
go dockerConnect(d.cli, dockerChannel, d.cfg.Instance, d.dockerID, closedCh, connectedCh, wg, boot)
return dockerChannel
}

Expand Down
Loading