func (s *serviceSuite) TestIsServiceInstalledWhenNotInstalled(c *gc.C) { mongo.PatchService(s.PatchValue, svctesting.NewFakeServiceData()) isInstalled, err := mongo.IsServiceInstalled("some-namespace") c.Assert(err, jc.ErrorIsNil) c.Assert(isInstalled, jc.IsFalse) }
func (s *serviceSuite) TestIsServiceInstalledWhenInstalled(c *gc.C) { svcName := mongo.ServiceName svcData := svctesting.NewFakeServiceData(svcName) mongo.PatchService(s.PatchValue, svcData) isInstalled, err := mongo.IsServiceInstalled() c.Assert(err, jc.ErrorIsNil) c.Assert(isInstalled, jc.IsTrue) }
// ensureMongoServer ensures that mongo is installed and running, // and ready for opening a state connection. func (a *MachineAgent) ensureMongoServer(agentConfig agent.Config) (err error) { a.mongoInitMutex.Lock() defer a.mongoInitMutex.Unlock() if a.mongoInitialized { logger.Debugf("mongo is already initialized") return nil } defer func() { if err == nil { a.mongoInitialized = true } }() mongoInstalled, err := mongo.IsServiceInstalled() if err != nil { return errors.Annotate(err, "error while checking if mongodb service is installed") } if !mongoInstalled { // EnsureMongoServer installs/upgrades the init config as necessary. ensureServerParams, err := cmdutil.NewEnsureServerParams(agentConfig) if err != nil { return err } if err := cmdutil.EnsureMongoServer(ensureServerParams); err != nil { return err } } logger.Debugf("mongodb service is installed") // Mongo is installed, record the version. err = a.ChangeConfig(func(config agent.ConfigSetter) error { config.SetMongoVersion(mongo.InstalledVersion()) return nil }) if err != nil { return errors.Annotate(err, "cannot set mongo version") } return nil }