Esempio n. 1
0
func doOmahaRequest(t *testing.T, h *Handler, appID, appVersion, appMachineID, appTrack, ip string, addPing, updateCheck bool, eventType, eventResult, eventPreviousVersion string) *omahaSpec.Response {
	omahaReq := omahaSpec.NewRequest(reqVersion, reqPlatform, reqSp, reqArch)
	app := omahaReq.AddApp(appID, appVersion)
	app.MachineID = appMachineID
	app.Track = appTrack
	if updateCheck {
		app.AddUpdateCheck()
	}
	if eventType != "" {
		e := app.AddEvent()
		e.Type = eventType
		e.Result = eventResult
		e.PreviousVersion = eventPreviousVersion
	}
	if addPing {
		app.AddPing()
	}

	omahaReqXML, err := xml.Marshal(omahaReq)
	assert.NoError(t, err)

	omahaRespXML := new(bytes.Buffer)
	h.Handle(bytes.NewReader(omahaReqXML), omahaRespXML, ip)

	var omahaResp *omahaSpec.Response
	err = xml.NewDecoder(omahaRespXML).Decode(&omahaResp)
	assert.NoError(t, err)

	return omahaResp
}
Esempio n. 2
0
func doOmahaRequest(t *testing.T, a *api.API, appID, appVersion, appMachineID, appTrack, ip string, updateCheck bool, eventType, eventResult, eventPreviousVersion string) *omahaSpec.Response {
	omahaReq := omahaSpec.NewRequest(reqVersion, reqPlatform, reqSp, reqArch)
	app := omahaReq.AddApp(appID, appVersion)
	app.MachineID = appMachineID
	app.Track = appTrack
	if updateCheck {
		app.AddUpdateCheck()
	}
	if eventType != "" {
		e := app.AddEvent()
		e.Type = eventType
		e.Result = eventResult
		e.PreviousVersion = eventPreviousVersion
	}
	fakeBodyReader, fakeBodyWriter := io.Pipe()
	go xml.NewEncoder(fakeBodyWriter).Encode(omahaReq)

	encodeToXMLAndPrint(omahaReq, showRequest)

	omahaResponseReader, omahaResponseWriter := io.Pipe()
	go HandleRequest(a, fakeBodyReader, omahaResponseWriter, ip)

	var omahaResp *omahaSpec.Response
	xml.NewDecoder(omahaResponseReader).Decode(&omahaResp)

	encodeToXMLAndPrint(omahaResp, showResponse)

	return omahaResp
}
Esempio n. 3
0
// doOmahaRequest sends an Omaha request checking if there is an update for a
// specific CoreOS channel, returning the update check to the caller.
func (s *Syncer) doOmahaRequest(channel, currentVersion string) (*omaha.UpdateCheck, error) {
	req := omaha.NewRequest("Chateau", "CoreOS", currentVersion+"_x86_64", "")
	req.Version = "CoreOSUpdateEngine-0.1.0.0"
	req.UpdaterVersion = "CoreOSUpdateEngine-0.1.0.0"
	req.InstallSource = "scheduler"
	req.IsMachine = "1"
	app := req.AddApp(coreosAppID, currentVersion)
	app.AddUpdateCheck()
	app.MachineID = s.machinesIDs[channel]
	app.BootId = s.bootIDs[channel]
	app.Track = channel

	payload, err := xml.Marshal(req)
	if err != nil {
		logger.Error("checkForUpdates, marshalling request xml", "error", err)
		return nil, err
	}
	logger.Debug("doOmahaRequest", "request", string(payload))

	resp, err := s.httpClient.Post(coreosUpdatesURL, "text/xml", bytes.NewReader(payload))
	if err != nil {
		logger.Error("checkForUpdates, posting omaha response", "error", err)
		return nil, err
	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		logger.Error("checkForUpdates, reading omaha response", "error", err)
		return nil, err

	}
	logger.Debug("doOmahaRequest", "response", string(body))

	oresp := &omaha.Response{}
	err = xml.Unmarshal(body, oresp)
	if err != nil {
		logger.Error("checkForUpdates, unmarshalling omaha response", "error", err)
		return nil, err
	}

	return oresp.Apps[0].UpdateCheck, nil
}