Example #1
0
func createEnvISO(env *cpi.AgentEnv, runner cmd.Runner) (path string, err error) {
	json, err := json.Marshal(env)
	if err != nil {
		return
	}
	envDir, err := ioutil.TempDir("", "agent-iso-dir")
	if err != nil {
		return
	}
	// Name of the environment JSON file should be "env" to fit ISO 9660 8.3 filename scheme
	envFile, err := os.Create(p.Join(envDir, "env"))
	if err != nil {
		return
	}
	_, err = envFile.Write(json)
	if err != nil {
		return
	}
	err = envFile.Close()
	if err != nil {
		return
	}

	envISO, err := ioutil.TempFile("", "agent-env-iso")
	if err != nil {
		return
	}
	envISO.Close()
	output, err := runner.Run("mkisofs", "-o", envISO.Name(), envFile.Name())
	if err != nil {
		out := string(output[:])
		return "", errors.New(fmt.Sprintf("Failed to generate ISO for agent settings: %v\n%s", err, out))
	}
	// Cleanup temp dir but ignore the error. Failure to delete a temp file is not
	// worth worrying about.
	_ = os.RemoveAll(envDir)
	return envISO.Name(), nil
}
Example #2
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/vmware/bosh-photon-cpi/cmd"
	"github.com/vmware/bosh-photon-cpi/cpi"
	"github.com/vmware/bosh-photon-cpi/logger"
	. "github.com/vmware/bosh-photon-cpi/mocks"
	ec "github.com/vmware/photon-controller-go-sdk/photon"
	"net/http"
	"net/http/httptest"
	"os"
)

var _ = Describe("AgentEnv", func() {
	var (
		ctx    *cpi.Context
		env    *cpi.AgentEnv
		runner cmd.Runner
		server *httptest.Server
	)

	BeforeEach(func() {
		server = NewMockServer()
		runner = cmd.NewRunner()
		httpClient := &http.Client{Transport: DefaultMockTransport}
		ctx = &cpi.Context{
			Client: ec.NewTestClient(server.URL, "", nil, httpClient),
			Config: &cpi.Config{
				Photon: &cpi.PhotonConfig{
					Target:    server.URL,
					ProjectID: "fake-project-id",
				},
				Agent: &cpi.AgentConfig{Mbus: "fake-mbus", NTP: []string{"fake-ntp"}},