func removeLeftovers() { testInfraDir := path.Join(apis.DefaultAnvilFolder, DefaultTestinfraSubfolder) files, err := ioutil.ReadDir(testInfraDir) if err != nil { apis.Logf("Error while cleaning left over files: %v", err) return } for _, file := range files { if strings.Contains(file.Name(), sshConfigPrexix) { path := path.Join(apis.DefaultAnvilFolder, DefaultTestinfraSubfolder, file.Name()) err := os.Remove(path) if err != nil { apis.Logf("Can't remove %s: %v", path, err) } } } }
func executeTestinfraFile(testFileName string, inst apis.Instance) ([]byte, error) { params := make([]string, 0, 10) params = append(params, "--color=yes") params = append(params, "--sudo") connParams, err := generateConnectionParams(inst) if err != nil { return nil, err } params = append(params, connParams...) params = append(params, testFileName) testinfraCmd := exec.Command("testinfra", params...) outBuffer := bytes.NewBuffer(make([]byte, 16032)) multiWriter := io.MultiWriter(outBuffer) testinfraCmd.Stdout = multiWriter testinfraCmd.Stderr = multiWriter err = testinfraCmd.Start() if err != nil { apis.Logf("Error in starting testinfra: %v", err) return nil, err } err = testinfraCmd.Wait() removeLeftovers() return outBuffer.Bytes(), err }