Exemplo n.º 1
0
func newController(conf *controllerConfig) (*controller, error) {
	api, err := api.New()
	if err != nil {
		return nil, err
	}

	c := &controller{
		api:          api,
		omahaHandler: omaha.NewHandler(api),
	}

	if conf.enableSyncer {
		syncerConf := &syncer.Config{
			Api:          api,
			HostPackages: conf.hostCoreosPackages,
			PackagesPath: conf.coreosPackagesPath,
			PackagesURL:  conf.corerollerURL + coreosPkgsRouterPrefix,
		}
		syncer, err := syncer.New(syncerConf)
		if err != nil {
			return nil, err
		}
		c.syncer = syncer
		go syncer.Start()
	}

	return c, nil
}
Exemplo n.º 2
0
func TestAppRegistrationForAppWithChannelAndPackageName(t *testing.T) {
	a, _ := api.New(api.OptionInitDB)
	defer a.Close()
	h := NewHandler(a)

	tAppCoreos, _ := a.GetApp(coreosAppID)
	tPkgCoreos640, _ := a.AddPackage(&api.Package{Type: api.PkgTypeCoreos, URL: "http://sample.url/pkg", Version: "640.0.0", ApplicationID: tAppCoreos.ID})
	tChannel, _ := a.AddChannel(&api.Channel{Name: "mychannel", Color: "white", ApplicationID: tAppCoreos.ID, PackageID: dat.NullStringFrom(tPkgCoreos640.ID)})
	tGroup, _ := a.AddGroup(&api.Group{Name: "Production", ApplicationID: tAppCoreos.ID, ChannelID: dat.NullStringFrom(tChannel.ID), PolicyUpdatesEnabled: true, PolicySafeMode: true, PolicyPeriodInterval: "15 minutes", PolicyMaxUpdatesPerPeriod: 2, PolicyUpdateTimeout: "60 minutes"})

	validUnregisteredIP := "127.0.0.1"
	validUnregisteredMachineID := "65e1266d-6f54-4b87-9080-23b99ca9c12f"
	expectedAppVersion := "640.0.0"
	updateCheck := true
	noEventType := ""
	noEventResult := ""
	completedEventType := "3"
	sucessEventResult := "1"
	eventPreviousVersion := ""
	addPing := true

	omahaResp := doOmahaRequest(t, h, tAppCoreos.ID, expectedAppVersion, validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, addPing, updateCheck, noEventType, noEventResult, eventPreviousVersion)
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaPingResponse(t, omahaResp, tAppCoreos.ID, addPing)
	checkOmahaUpdateResponse(t, omahaResp, expectedAppVersion, "", "", "noupdate")

	omahaResp = doOmahaRequest(t, h, tAppCoreos.ID, expectedAppVersion, validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, addPing, !updateCheck, completedEventType, sucessEventResult, eventPreviousVersion)
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaPingResponse(t, omahaResp, tAppCoreos.ID, addPing)
}
Exemplo n.º 3
0
func TestInvalidRequests(t *testing.T) {
	a, _ := api.New(api.OptionInitDB)
	defer a.Close()
	h := NewHandler(a)

	tTeam, _ := a.AddTeam(&api.Team{Name: "test_team"})
	tApp, _ := a.AddApp(&api.Application{Name: "test_app", Description: "Test app", TeamID: tTeam.ID})
	tPkg, _ := a.AddPackage(&api.Package{Type: api.PkgTypeCoreos, URL: "http://sample.url/pkg", Version: "640.0.0", ApplicationID: tApp.ID})
	tChannel, _ := a.AddChannel(&api.Channel{Name: "test_channel", Color: "blue", ApplicationID: tApp.ID, PackageID: dat.NullStringFrom(tPkg.ID)})
	tGroup, _ := a.AddGroup(&api.Group{Name: "test_group", ApplicationID: tApp.ID, ChannelID: dat.NullStringFrom(tChannel.ID), PolicyUpdatesEnabled: true, PolicySafeMode: true, PolicyPeriodInterval: "15 minutes", PolicyMaxUpdatesPerPeriod: 2, PolicyUpdateTimeout: "60 minutes"})

	validUnregisteredIP := "127.0.0.1"
	validUnregisteredMachineID := "some-id"
	validUnverifiedAppVersion := "100.0.1"
	addPing := false
	updateCheck := true
	noEventType := ""
	noEventResult := ""
	eventPreviousVersion := ""

	omahaResp := doOmahaRequest(t, h, tApp.ID, validUnverifiedAppVersion, validUnregisteredMachineID, "invalid-track", validUnregisteredIP, addPing, updateCheck, noEventType, noEventResult, eventPreviousVersion)
	checkOmahaResponse(t, omahaResp, tApp.ID, "error-instanceRegistrationFailed")

	omahaResp = doOmahaRequest(t, h, tApp.ID, validUnverifiedAppVersion, validUnregisteredMachineID, tGroup.ID, "invalid-ip", addPing, updateCheck, noEventType, noEventResult, eventPreviousVersion)
	checkOmahaResponse(t, omahaResp, tApp.ID, "error-instanceRegistrationFailed")

	omahaResp = doOmahaRequest(t, h, "invalid-app-uuid", validUnverifiedAppVersion, validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, addPing, updateCheck, noEventType, noEventResult, eventPreviousVersion)
	checkOmahaResponse(t, omahaResp, "invalid-app-uuid", "error-instanceRegistrationFailed")

	omahaResp = doOmahaRequest(t, h, tApp.ID, "", validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, addPing, updateCheck, noEventType, noEventResult, eventPreviousVersion)
	checkOmahaResponse(t, omahaResp, tApp.ID, "error-instanceRegistrationFailed")
}
Exemplo n.º 4
0
func TestAppRegistrationForAppWithChannelAndPackageName(t *testing.T) {
	a, _ := api.New(api.OptionInitDB)
	defer a.Close()

	tTeam, _ := a.AddTeam(&api.Team{Name: "test_team"})
	tAppCoreos, _ := a.AddApp(&api.Application{Name: "CoreOS", Description: "Linux containers", TeamID: tTeam.ID})
	tPkgCoreos640, err := a.AddPackage(&api.Package{Type: api.PkgTypeCoreos, URL: "http://sample.url/pkg", Version: "640.0.0", ApplicationID: tAppCoreos.ID})
	tChannel, err := a.AddChannel(&api.Channel{Name: "stable", Color: "white", ApplicationID: tAppCoreos.ID, PackageID: dat.NullStringFrom(tPkgCoreos640.ID)})
	tGroup, err := a.AddGroup(&api.Group{Name: "Production", ApplicationID: tAppCoreos.ID, ChannelID: dat.NullStringFrom(tChannel.ID),
		PolicyUpdatesEnabled: true, PolicySafeMode: true, PolicyPeriodInterval: "15 minutes", PolicyMaxUpdatesPerPeriod: 2, PolicyUpdateTimeout: "60 minutes"})
	assert.NoError(t, err)

	validUnregisteredIP := "127.0.0.1"
	validUnregisteredBootID := "65e1266d-6f54-4b87-9080-23b99ca9c12f"
	expectedAppVersion := "640.0.0"
	updateCheck := true
	noEventType := ""
	noEventResult := ""
	completedEventType := "3"
	sucessEventResult := "1"
	eventPreviousVersion := ""

	omahaResp := doOmahaRequest(t, a, tAppCoreos.ID, expectedAppVersion, validUnregisteredBootID, tGroup.ID, validUnregisteredIP, updateCheck, noEventType, noEventResult, eventPreviousVersion)
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaUpdateResponse(t, omahaResp, expectedAppVersion, "", "", "noupdate")

	omahaResp = doOmahaRequest(t, a, tAppCoreos.ID, expectedAppVersion, validUnregisteredBootID, tGroup.ID, validUnregisteredIP, !updateCheck, completedEventType, sucessEventResult, eventPreviousVersion)
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
}
Exemplo n.º 5
0
func main() {
	env := flag.String("env", "development", "environment")
	port := flag.String("port", "8000", "port")
	dbPath := flag.String("dbPath", "localhost", "path to mongo db")
	loadArticles := flag.Bool("load", false, "path to db")
	maxProcs := flag.Int("maxProcs", runtime.NumCPU(), "number of process")
	cpuProfile := flag.Bool("cpuProfile", false, "enable cpu profiling")
	memProfile := flag.Bool("memProfile", false, "enable memory profiling")
	flag.Parse()

	runtime.GOMAXPROCS(*maxProcs)

	if *cpuProfile {
		f, err := os.Create("mbp.prof")
		if err == nil {
			pprof.StartCPUProfile(f)
			defer pprof.StopCPUProfile()
		}
	}

	if *memProfile {
		f, err := os.Create("mbp.mprof")
		if err == nil {
			pprof.WriteHeapProfile(f)
			f.Close()
		}
	}

	glog.Info(*env, *port, *dbPath)

	dbInstance, err := models.New(*dbPath)
	if err != nil {
		glog.Fatal(err)
	}
	if *loadArticles {
		dbInstance.InitCategories()
		dbInstance.ItemUpdater()
		os.Exit(0)
	}

	go dbInstance.ItemUpdaterCron()

	apiServer, err := api.New(*port, *env, dbInstance)
	if err != nil {
		glog.Fatal(err)
	}

	interrupt := make(chan os.Signal, 1)
	signal.Notify(interrupt, os.Interrupt)

	select {
	case sig := <-interrupt:
		apiServer.Close()
		glog.Infof("Captured %v, exiting...", sig)
	}
}
Exemplo n.º 6
0
func TestAppUpdateForAppWithChannelAndPackageName(t *testing.T) {
	a, _ := api.New(api.OptionInitDB)
	defer a.Close()
	h := NewHandler(a)

	tAppCoreos, _ := a.GetApp(coreosAppID)
	tFilenameCoreos := "coreosupdate.tgz"
	tPkgCoreos640, _ := a.AddPackage(&api.Package{Type: api.PkgTypeCoreos, URL: "http://sample.url/pkg", Filename: dat.NullStringFrom(tFilenameCoreos), Version: "99640.0.0", ApplicationID: tAppCoreos.ID})
	tChannel, _ := a.AddChannel(&api.Channel{Name: "mychannel", Color: "white", ApplicationID: tAppCoreos.ID, PackageID: dat.NullStringFrom(tPkgCoreos640.ID)})
	tGroup, _ := a.AddGroup(&api.Group{Name: "Production", ApplicationID: tAppCoreos.ID, ChannelID: dat.NullStringFrom(tChannel.ID), PolicyUpdatesEnabled: true, PolicySafeMode: true, PolicyPeriodInterval: "15 minutes", PolicyMaxUpdatesPerPeriod: 2, PolicyUpdateTimeout: "60 minutes"})
	coreosAction, _ := a.AddCoreosAction(&api.CoreosAction{Event: "postinstall", Sha256: "fsdkjjfghsdakjfgaksdjfasd", PackageID: tPkgCoreos640.ID})

	validUnregisteredIP := "127.0.0.1"
	validUnregisteredMachineID := "65e1266d-6f54-4b87-9080-23b99ca9c12f"
	oldAppVersion := "610.0.0"
	updateCheck := true
	addPing := true

	omahaResp := doOmahaRequest(t, h, tAppCoreos.ID, oldAppVersion, validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, addPing, updateCheck, "", "", "")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaUpdateResponse(t, omahaResp, tPkgCoreos640.Version, tFilenameCoreos, tPkgCoreos640.URL, "ok")
	checkOmahaPingResponse(t, omahaResp, tAppCoreos.ID, addPing)
	checkOmahaCoreosAction(t, coreosAction, omahaResp.Apps[0].UpdateCheck.Manifest.Actions.Actions[0])

	// Send download started
	omahaResp = doOmahaRequest(t, h, tAppCoreos.ID, oldAppVersion, validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, addPing, !updateCheck, "13", "1", "")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaPingResponse(t, omahaResp, tAppCoreos.ID, addPing)
	checkOmahaNoUpdateResponse(t, omahaResp)

	// Send download finished
	omahaResp = doOmahaRequest(t, h, tAppCoreos.ID, oldAppVersion, validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, addPing, !updateCheck, "14", "1", "")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaPingResponse(t, omahaResp, tAppCoreos.ID, addPing)
	checkOmahaNoUpdateResponse(t, omahaResp)

	// Send complete
	omahaResp = doOmahaRequest(t, h, tAppCoreos.ID, oldAppVersion, validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, addPing, !updateCheck, "3", "1", "")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaPingResponse(t, omahaResp, tAppCoreos.ID, addPing)
	checkOmahaNoUpdateResponse(t, omahaResp)

	// Send rebooted
	omahaResp = doOmahaRequest(t, h, tAppCoreos.ID, tPkgCoreos640.Version, validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, addPing, updateCheck, "3", "2", oldAppVersion)
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaPingResponse(t, omahaResp, tAppCoreos.ID, addPing)
	checkOmahaUpdateResponse(t, omahaResp, tPkgCoreos640.Version, "", "", "noupdate")

	// Expect no update
	omahaResp = doOmahaRequest(t, h, tAppCoreos.ID, tPkgCoreos640.Version, validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, addPing, updateCheck, "", "", "")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaPingResponse(t, omahaResp, tAppCoreos.ID, addPing)
	checkOmahaUpdateResponse(t, omahaResp, tPkgCoreos640.Version, "", "", "noupdate")
}
Exemplo n.º 7
0
func TestAppNoUpdateForAppWithChannelAndPackageName(t *testing.T) {
	a, _ := api.New(api.OptionInitDB)
	defer a.Close()
	h := NewHandler(a)

	tAppCoreos, _ := a.GetApp(coreosAppID)
	tPkgCoreos640, _ := a.AddPackage(&api.Package{Type: api.PkgTypeCoreos, URL: "http://sample.url/pkg", Version: "640.0.0", ApplicationID: tAppCoreos.ID})
	tChannel, _ := a.AddChannel(&api.Channel{Name: "mychannel", Color: "white", ApplicationID: tAppCoreos.ID, PackageID: dat.NullStringFrom(tPkgCoreos640.ID)})
	tGroup, _ := a.AddGroup(&api.Group{Name: "Production", ApplicationID: tAppCoreos.ID, ChannelID: dat.NullStringFrom(tChannel.ID), PolicyUpdatesEnabled: true, PolicySafeMode: true, PolicyPeriodInterval: "15 minutes", PolicyMaxUpdatesPerPeriod: 2, PolicyUpdateTimeout: "60 minutes"})

	validUnregisteredIP := "127.0.0.1"
	validUnregisteredMachineID := "65e1266d-6f54-4b87-9080-23b99ca9c12f"
	expectedAppVersion := "640.0.0"
	updateCheck := true
	addPing := true

	// Now with an error event tag, no updatecheck tag
	omahaResp := doOmahaRequest(t, h, tAppCoreos.ID, expectedAppVersion, validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, !addPing, !updateCheck, "3", "0", "268437959")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaEventResponse(t, omahaResp, tAppCoreos.ID, 1)
	checkOmahaPingResponse(t, omahaResp, tAppCoreos.ID, !addPing)
	checkOmahaNoUpdateResponse(t, omahaResp)

	// Now updatetag, successful event, no previous version
	omahaResp = doOmahaRequest(t, h, tAppCoreos.ID, expectedAppVersion, validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, !addPing, updateCheck, "3", "2", "0.0.0.0")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaEventResponse(t, omahaResp, tAppCoreos.ID, 1)
	checkOmahaPingResponse(t, omahaResp, tAppCoreos.ID, !addPing)
	checkOmahaUpdateResponse(t, omahaResp, expectedAppVersion, "", "", "noupdate")

	// Now updatetag, successful event, no previous version
	omahaResp = doOmahaRequest(t, h, tAppCoreos.ID, expectedAppVersion, validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, addPing, updateCheck, "3", "2", "")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaEventResponse(t, omahaResp, tAppCoreos.ID, 1)
	checkOmahaPingResponse(t, omahaResp, tAppCoreos.ID, addPing)
	checkOmahaUpdateResponse(t, omahaResp, expectedAppVersion, "", "", "noupdate")

	// Now updatetag, successful event, with previous version
	omahaResp = doOmahaRequest(t, h, tAppCoreos.ID, expectedAppVersion, validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, addPing, updateCheck, "3", "2", "614.0.0")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaEventResponse(t, omahaResp, tAppCoreos.ID, 1)
	checkOmahaPingResponse(t, omahaResp, tAppCoreos.ID, addPing)
	checkOmahaUpdateResponse(t, omahaResp, expectedAppVersion, "", "", "noupdate")

	// Now updatetag, successful event, with previous version, greater than current active version
	omahaResp = doOmahaRequest(t, h, tAppCoreos.ID, "666.0.0", validUnregisteredMachineID, tGroup.ID, validUnregisteredIP, addPing, updateCheck, "3", "2", "614.0.0")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaEventResponse(t, omahaResp, tAppCoreos.ID, 1)
	checkOmahaPingResponse(t, omahaResp, tAppCoreos.ID, addPing)
	checkOmahaUpdateResponse(t, omahaResp, expectedAppVersion, "", "", "noupdate")
}
Exemplo n.º 8
0
func TestAppRegistrationForAppWithOtherInfo(t *testing.T) {
	a, _ := api.New(api.OptionInitDB)
	defer a.Close()

	tTeam, _ := a.AddTeam(&api.Team{Name: "test_team"})
	tAppCoreos, _ := a.AddApp(&api.Application{Name: "CoreOS", Description: "Linux containers", TeamID: tTeam.ID})
	tFilenameCoreos := "coreosupdate.tgz"
	tPkgCoreos640, err := a.AddPackage(&api.Package{Type: api.PkgTypeCoreos, URL: "http://sample.url/pkg", Filename: dat.NullStringFrom(tFilenameCoreos), Version: "640.0.0", ApplicationID: tAppCoreos.ID})
	tPkgCoreos653, err := a.AddPackage(&api.Package{Type: api.PkgTypeCoreos, URL: "http://sample.url/pkg", Filename: dat.NullStringFrom(tFilenameCoreos), Version: "653.0.0", ApplicationID: tAppCoreos.ID})
	_, err = a.AddChannel(&api.Channel{Name: "alpha", Color: "green", ApplicationID: tAppCoreos.ID, PackageID: dat.NullStringFrom(tPkgCoreos653.ID)})
	tChannel2, err := a.AddChannel(&api.Channel{Name: "beta", Color: "blue", ApplicationID: tAppCoreos.ID, PackageID: dat.NullStringFrom(tPkgCoreos653.ID)})
	tChannel3, err := a.AddChannel(&api.Channel{Name: "stable", Color: "white", ApplicationID: tAppCoreos.ID, PackageID: dat.NullStringFrom(tPkgCoreos640.ID)})
	tGroup1, err := a.AddGroup(&api.Group{Name: "Production", ApplicationID: tAppCoreos.ID, ChannelID: dat.NullStringFrom(tChannel3.ID),
		PolicyUpdatesEnabled: true, PolicySafeMode: true, PolicyPeriodInterval: "15 minutes", PolicyMaxUpdatesPerPeriod: 2, PolicyUpdateTimeout: "60 minutes"})
	_, err = a.AddGroup(&api.Group{Name: "Qa", ApplicationID: tAppCoreos.ID, ChannelID: dat.NullStringFrom(tChannel2.ID),
		PolicyUpdatesEnabled: true, PolicySafeMode: true, PolicyPeriodInterval: "15 minutes", PolicyMaxUpdatesPerPeriod: 2, PolicyUpdateTimeout: "60 minutes"})
	assert.NoError(t, err)

	tAppAcme, _ := a.AddApp(&api.Application{Name: "Acme", Description: "Container for Application ACME", TeamID: tTeam.ID})
	tFilenameAcme := "acmeupdate.tgz"
	tPkgAcme310, err := a.AddPackage(&api.Package{Type: api.PkgTypeCoreos, URL: "http://sample.url/pkg", Filename: dat.NullStringFrom(tFilenameAcme), Version: "310.0.0", ApplicationID: tAppAcme.ID})
	tPkgAcme333, err := a.AddPackage(&api.Package{Type: api.PkgTypeCoreos, URL: "http://sample.url/pkg", Filename: dat.NullStringFrom(tFilenameAcme), Version: "333.0.0", ApplicationID: tAppAcme.ID})
	tChannel4, err := a.AddChannel(&api.Channel{Name: "latest", Color: "blue", ApplicationID: tAppAcme.ID, PackageID: dat.NullStringFrom(tPkgAcme333.ID)})
	tChannel5, err := a.AddChannel(&api.Channel{Name: "stable", Color: "white", ApplicationID: tAppAcme.ID, PackageID: dat.NullStringFrom(tPkgAcme310.ID)})
	_, err = a.AddGroup(&api.Group{Name: "PROD", ApplicationID: tAppAcme.ID, ChannelID: dat.NullStringFrom(tChannel5.ID),
		PolicyUpdatesEnabled: true, PolicySafeMode: true, PolicyPeriodInterval: "100 millisecond", PolicyMaxUpdatesPerPeriod: 2, PolicyUpdateTimeout: "60 minutes"})
	_, err = a.AddGroup(&api.Group{Name: "QA", ApplicationID: tAppAcme.ID, ChannelID: dat.NullStringFrom(tChannel4.ID),
		PolicyUpdatesEnabled: false, PolicySafeMode: true, PolicyPeriodInterval: "15 minutes", PolicyMaxUpdatesPerPeriod: 2, PolicyUpdateTimeout: "60 minutes"})
	assert.NoError(t, err)

	time.Sleep(10 * time.Millisecond)

	validUnregisteredIP := "127.0.0.1"
	validUnregisteredBootID := "65e1266d-6f54-4b87-9080-23b99ca9c12f"
	expectedAppVersion := "640.0.0"
	updateCheck := true
	noEventType := ""
	noEventResult := ""
	completedEventType := "3"
	sucessEventResult := "1"
	eventPreviousVersion := ""

	omahaResp := doOmahaRequest(t, a, tAppCoreos.ID, expectedAppVersion, validUnregisteredBootID, tGroup1.ID, validUnregisteredIP, updateCheck, noEventType, noEventResult, eventPreviousVersion)
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaUpdateResponse(t, omahaResp, expectedAppVersion, "", "", "noupdate")

	omahaResp = doOmahaRequest(t, a, tAppCoreos.ID, expectedAppVersion, validUnregisteredBootID, tGroup1.ID, validUnregisteredIP, !updateCheck, completedEventType, sucessEventResult, eventPreviousVersion)
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
}
Exemplo n.º 9
0
func TestMain(m *testing.M) {
	os.Setenv("COREROLLER_DB_URL", testsDbURL)

	a, err := api.New(api.OptionInitDB)
	defer a.Close()

	if err != nil {
		log.Println("These tests require PostgreSQL running and a tests database created, please adjust testsDbUrl as needed.")
		log.Println("Default: postgres://[email protected]:5432/coreroller_tests?sslmode=disable")
		log.Println(err)
		os.Exit(1)
	}

	os.Exit(m.Run())
}
Exemplo n.º 10
0
func TestAppUpdateForAppWithChannelAndPackageName(t *testing.T) {
	a, _ := api.New(api.OptionInitDB)
	defer a.Close()

	tTeam, _ := a.AddTeam(&api.Team{Name: "test_team"})
	tAppCoreos, _ := a.AddApp(&api.Application{Name: "CoreOS", Description: "Linux containers", TeamID: tTeam.ID})
	tFilenameCoreos := "coreosupdate.tgz"
	tPkgCoreos640, err := a.AddPackage(&api.Package{Type: api.PkgTypeCoreos, URL: "http://sample.url/pkg", Filename: dat.NullStringFrom(tFilenameCoreos), Version: "640.0.0", ApplicationID: tAppCoreos.ID})
	tChannel, err := a.AddChannel(&api.Channel{Name: "stable", Color: "white", ApplicationID: tAppCoreos.ID, PackageID: dat.NullStringFrom(tPkgCoreos640.ID)})
	tGroup, err := a.AddGroup(&api.Group{Name: "Production", ApplicationID: tAppCoreos.ID, ChannelID: dat.NullStringFrom(tChannel.ID),
		PolicyUpdatesEnabled: true, PolicySafeMode: true, PolicyPeriodInterval: "15 minutes", PolicyMaxUpdatesPerPeriod: 2, PolicyUpdateTimeout: "60 minutes"})
	coreosAction, err := a.AddCoreosAction(&api.CoreosAction{Event: "postinstall", Sha256: "fsdkjjfghsdakjfgaksdjfasd", PackageID: tPkgCoreos640.ID})
	assert.NoError(t, err)

	validUnregisteredIP := "127.0.0.1"
	validUnregisteredBootID := "65e1266d-6f54-4b87-9080-23b99ca9c12f"
	oldAppVersion := "610.0.0"

	omahaResp := doOmahaRequest(t, a, tAppCoreos.ID, oldAppVersion, validUnregisteredBootID, tGroup.ID, validUnregisteredIP, true, "3", "2", oldAppVersion)
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaUpdateResponse(t, omahaResp, tPkgCoreos640.Version, tFilenameCoreos, tPkgCoreos640.URL, "ok")
	checkOmahaCoreosAction(t, coreosAction, omahaResp.Apps[0].UpdateCheck.Manifest.Actions.Actions[0])

	// Expect threshold error
	omahaResp = doOmahaRequest(t, a, tAppCoreos.ID, oldAppVersion, validUnregisteredBootID, tGroup.ID, validUnregisteredIP, true, "", "", "")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "error-maxUpdatesPerPeriodLimitReached")

	// Send download started
	omahaResp = doOmahaRequest(t, a, tAppCoreos.ID, oldAppVersion, validUnregisteredBootID, tGroup.ID, validUnregisteredIP, false, "13", "1", "")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaNoUpdateResponse(t, omahaResp)

	// Send download finished
	omahaResp = doOmahaRequest(t, a, tAppCoreos.ID, oldAppVersion, validUnregisteredBootID, tGroup.ID, validUnregisteredIP, false, "14", "1", "")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaNoUpdateResponse(t, omahaResp)

	// Send complete
	omahaResp = doOmahaRequest(t, a, tAppCoreos.ID, oldAppVersion, validUnregisteredBootID, tGroup.ID, validUnregisteredIP, false, "3", "1", "")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaNoUpdateResponse(t, omahaResp)

	// Send rebooted
	omahaResp = doOmahaRequest(t, a, tAppCoreos.ID, tPkgCoreos640.Version, validUnregisteredBootID, tGroup.ID, validUnregisteredIP, true, "3", "2", oldAppVersion)
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaUpdateResponse(t, omahaResp, tPkgCoreos640.Version, "", "", "noupdate")
}
Exemplo n.º 11
0
func TestAppNoUpdateForAppWithChannelAndPackageName(t *testing.T) {
	a, _ := api.New(api.OptionInitDB)
	defer a.Close()

	tTeam, _ := a.AddTeam(&api.Team{Name: "test_team"})
	tAppCoreos, _ := a.AddApp(&api.Application{Name: "CoreOS", Description: "Linux containers", TeamID: tTeam.ID})
	tPkgCoreos640, err := a.AddPackage(&api.Package{Type: api.PkgTypeCoreos, URL: "http://sample.url/pkg", Version: "640.0.0", ApplicationID: tAppCoreos.ID})
	tChannel, err := a.AddChannel(&api.Channel{Name: "stable", Color: "white", ApplicationID: tAppCoreos.ID, PackageID: dat.NullStringFrom(tPkgCoreos640.ID)})
	tGroup, err := a.AddGroup(&api.Group{Name: "Production", ApplicationID: tAppCoreos.ID, ChannelID: dat.NullStringFrom(tChannel.ID),
		PolicyUpdatesEnabled: true, PolicySafeMode: true, PolicyPeriodInterval: "15 minutes", PolicyMaxUpdatesPerPeriod: 2, PolicyUpdateTimeout: "60 minutes"})
	assert.NoError(t, err)

	validUnregisteredIP := "127.0.0.1"
	validUnregisteredBootID := "65e1266d-6f54-4b87-9080-23b99ca9c12f"
	expectedAppVersion := "640.0.0"

	// Now with an error event tag, no updatecheck tag
	omahaResp := doOmahaRequest(t, a, tAppCoreos.ID, expectedAppVersion, validUnregisteredBootID, tGroup.ID, validUnregisteredIP, false, "3", "0", "268437959")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaEventResponse(t, omahaResp, tAppCoreos.ID, 1)
	checkOmahaNoUpdateResponse(t, omahaResp)

	// Now updatetag, successful event, no previous version
	omahaResp = doOmahaRequest(t, a, tAppCoreos.ID, expectedAppVersion, validUnregisteredBootID, tGroup.ID, validUnregisteredIP, true, "3", "2", "0.0.0.0")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaEventResponse(t, omahaResp, tAppCoreos.ID, 1)
	checkOmahaUpdateResponse(t, omahaResp, expectedAppVersion, "", "", "noupdate")

	// Now updatetag, successful event, no previous version
	omahaResp = doOmahaRequest(t, a, tAppCoreos.ID, expectedAppVersion, validUnregisteredBootID, tGroup.ID, validUnregisteredIP, true, "3", "2", "")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaEventResponse(t, omahaResp, tAppCoreos.ID, 1)
	checkOmahaUpdateResponse(t, omahaResp, expectedAppVersion, "", "", "noupdate")

	// Now updatetag, successful event, with previous version
	omahaResp = doOmahaRequest(t, a, tAppCoreos.ID, expectedAppVersion, validUnregisteredBootID, tGroup.ID, validUnregisteredIP, true, "3", "2", "614.0.0")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaEventResponse(t, omahaResp, tAppCoreos.ID, 1)
	checkOmahaUpdateResponse(t, omahaResp, expectedAppVersion, "", "", "noupdate")

	// Now updatetag, successful event, with previous version, greater than current active version
	omahaResp = doOmahaRequest(t, a, tAppCoreos.ID, "666.0.0", validUnregisteredBootID, tGroup.ID, validUnregisteredIP, true, "3", "2", "614.0.0")
	checkOmahaResponse(t, omahaResp, tAppCoreos.ID, "ok")
	checkOmahaEventResponse(t, omahaResp, tAppCoreos.ID, 1)
	checkOmahaUpdateResponse(t, omahaResp, expectedAppVersion, "", "", "noupdate")
}
Exemplo n.º 12
0
func TestCoreosGroupNamesConversionToIds(t *testing.T) {
	a, _ := api.New(api.OptionInitDB)
	defer a.Close()
	h := NewHandler(a)

	coreosAppIDWithCurlyBraces := "{" + coreosAppID + "}"
	machineID := "65e1266d-6f54-4b87-9080-23b99ca9c12f"
	machineIP := "10.0.0.1"

	omahaResp := doOmahaRequest(t, h, coreosAppID, "2000.0.0", machineID, "invalid-group", machineIP, false, true, "", "", "")
	checkOmahaResponse(t, omahaResp, coreosAppID, "error-instanceRegistrationFailed")

	omahaResp = doOmahaRequest(t, h, coreosAppID, "2000.0.0", machineID, "alpha", machineIP, false, true, "", "", "")
	checkOmahaResponse(t, omahaResp, coreosAppID, "ok")

	omahaResp = doOmahaRequest(t, h, coreosAppIDWithCurlyBraces, "2000.0.0", machineID, "alpha", machineIP, false, true, "", "", "")
	checkOmahaResponse(t, omahaResp, coreosAppIDWithCurlyBraces, "ok")
}
Exemplo n.º 13
0
func newController() (*controller, error) {
	api, err := api.New()
	if err != nil {
		return nil, err
	}

	syncer, err := syncer.New(api)
	if err != nil {
		return nil, err
	}
	go syncer.Start()

	c := &controller{
		api:    api,
		syncer: syncer,
	}
	c.authenticator = auth.NewDigestAuthenticator("coreroller.org", c.getSecret)

	return c, nil
}
Exemplo n.º 14
0
func main() {
	if _, err := api.New(api.OptionInitDB); err != nil {
		log.Fatal(err)
	}
}