Пример #1
0
    def test_add_prereqs(self):
        # Reset
        ctx = sm.ServiceContext(INFILENAME)
        svc = filter(lambda x: x.name == "HMaster", ctx.services)[0]
        newPr = sm.Prereq("Andy", "TheCommand")
        svc.prereqs = [newPr]
        ctx.commit(OUTFILENAME)
        ctx = sm.ServiceContext(OUTFILENAME)
        svc = filter(lambda x: x.name == "HMaster", ctx.services)[0]
        self.assertEqual(len(svc.prereqs), 1)
        self.assertEqual(svc.prereqs[0].name, "Andy")
        self.assertEqual(svc.prereqs[0].script, "TheCommand")

        # Add one
        svc.prereqs.append(sm.Prereq("Bob", "ThatCommand"))
        ctx.commit(OUTFILENAME)
        ctx = sm.ServiceContext(OUTFILENAME)
        svc = filter(lambda x: x.name == "HMaster", ctx.services)[0]
        sortedPrereqs = sorted(svc.prereqs, key=lambda k: k.name)
        self.assertEqual(len(svc.prereqs), 2)
        self.assertEqual(sortedPrereqs[0].name, "Andy")
        self.assertEqual(sortedPrereqs[0].script, "TheCommand")
        self.assertEqual(sortedPrereqs[1].name, "Bob")
        self.assertEqual(sortedPrereqs[1].script, "ThatCommand")
Пример #2
0
    def test_modify_prereqs(self):
        # Modify
        ctx = sm.ServiceContext(INFILENAME)
        svc = filter(lambda x: x.name == "HMaster", ctx.services)[0]
        newPr = sm.Prereq("Andy", "TheCommand")
        svc.prereqs = [newPr]
        ctx.commit(OUTFILENAME)
        ctx = sm.ServiceContext(OUTFILENAME)
        svc = filter(lambda x: x.name == "HMaster", ctx.services)[0]
        svc.prereqs[0].name = "Alice"
        ctx.commit(OUTFILENAME)
        ctx = sm.ServiceContext(OUTFILENAME)
        svc = filter(lambda x: x.name == "HMaster", ctx.services)[0]
        self.assertEqual(len(svc.prereqs), 1)
        self.assertEqual(svc.prereqs[0].name, "Alice")
        self.assertEqual(svc.prereqs[0].script, "TheCommand")

        # Delete
        svc.prereqs = []
        ctx.commit(OUTFILENAME)
        ctx = sm.ServiceContext(OUTFILENAME)
        svc = filter(lambda x: x.name == "HMaster", ctx.services)[0]
        self.assertEqual(svc.prereqs, [])
Пример #3
0
    def cutover(self, dmd):
        try:
            ctx = sm.ServiceContext()
        except sm.ServiceMigrationError:
            log.info("Couldn't generate service context, skipping.")
            return

        # Find the services to edit.
        # For "lite" services, there is a single opentsdb service and, it should
        # not be edited. For "full" services, the opentsdb service is an organizer
        # with reader and writer subservices. The reader services should be
        # edited.
        opentsdbs = [i for i in ctx.services if i.name == 'opentsdb' ]
        readers = [i for i in ctx.services if i.name == 'reader' and
                ctx.getServiceParent(i) in opentsdbs]

        changed = False

        for reader in readers:
            reader.prereqs = [sm.Prereq(name='HBase Regionservers up', script='{{with $rss := (child (child (parent (parent .)) "HBase") "RegionServer").Instances }}wget -q -O- http://localhost:61000/status/cluster | grep \'{{$rss}} live servers\'{{end}}'), sm.Prereq(name='HBase tables exist', script='wget -q -O- http://localhost:61000 | [[ $(grep -c -E -o \"\\b${CONTROLPLANE_TENANT_ID}-tsdb(-|\\s|$)\") == 4 ]]')]
            changed = True

        if changed:
            ctx.commit()
Пример #4
0
    def cutover(self, dmd):
        try:
            ctx = sm.ServiceContext()
        except sm.ServiceMigrationError:
            log.info("Couldn't generate service context, skipping.")
            return

        changed = False

        # If the service lacks Solr, add it now.
        solr = filter(lambda s: s.name == "Solr", ctx.services)
        log.info("Found %i services named 'Solr'." % len(solr))
        if not solr:
            imageid = os.environ['SERVICED_SERVICE_IMAGE']
            log.info("No Solr found; creating new service.")
            new_solr = default_solr_service(imageid)
            infrastructure = ctx.findServices('^[^/]+/Infrastructure$')[0]
            ctx.deployService(json.dumps(new_solr), infrastructure)
            changed = True

        # Remove the zencatalogservice-uri global conf option from the top service
        zenoss = ctx.getTopService()
        global_conf = zenoss.context
        if global_conf and "global.conf.zencatalogservice-uri" in global_conf:
            del global_conf["global.conf.zencatalogservice-uri"]
            changed = True

        # Now healthchecks
        solr_answering_healthcheck = HealthCheck(
            name="solr_answering",
            interval=10.0,
            script=
            "curl -A 'Solr answering healthcheck' -s http://localhost:8983/solr/zenoss_model/admin/ping?wt=json | grep -q '\"status\":\"OK\"'"
        )

        for svc in ctx.services:
            # Remove zencatalogservice, if it still exists
            if svc.name == "zencatalogservice":
                svcid = svc._Service__data['ID']
                # ZEN-28127: during unittests, ctx is an instance of
                # FakeServiceContext which is set to None.
                if ctx._client is not None:
                    ctx._client.deleteService(svcid)
                ctx.services.remove(svc)
                changed = True
                continue
            # Remove zencatalogservice response prereq and add solr one
            for pr in svc.prereqs[:]:
                if pr.name == "zencatalogservice response":
                    svc.prereqs.remove(pr)
                    svc.prereqs.append(
                        sm.Prereq(
                            name='Solr answering',
                            script=
                            """curl -A 'Solr answering prereq' -s http://localhost:8983/solr/zenoss_model/admin/ping?wt=json | grep -q '\"status\":\"OK\"'"""
                        ))
                    changed = True
            # If we've got a solr_answering health check, we can stop.
            # Otherwise, remove catalogservice health checks and add Solr ones
            if filter(lambda c: c.name == 'solr_answering', svc.healthChecks):
                continue
            for hc in svc.healthChecks:
                if hc.name == "catalogservice_answering":
                    svc.healthChecks.remove(hc)
                    changed = True

            # Get rid of erroneous "solr" endpoints that some older migrations added and the "zodb_zencatalogservice" endpoint import that zenimpactstate may have
            eps_to_remove = filter(
                lambda ep: ep.purpose == 'import' and
                (ep.application == 'solr' or ep.application ==
                 'zodb_zencatalogservice'), svc.endpoints)

            for ep in eps_to_remove:
                changed = True
                svc.endpoints.remove(ep)

            for ep in svc.endpoints:
                if ep.purpose == 'import' and ep.application == 'zodb_.*':
                    svc.healthChecks.append(solr_answering_healthcheck)
                    changed = True
                    break

        filterName = 'solr'
        filename = 'Products/ZenModel/migrate/data/%s-6.0.0.conf' % filterName
        with open(zenPath(filename)) as filterFile:
            try:
                filterDef = filterFile.read()
            except Exception as e:
                log.error("Error reading {0} logfilter file: {1}".format(
                    filename, e))
                return
            log.info("Updating log filter named {0}".format(filterName))
            changed = True
            ctx.addLogFilter(filterName, filterDef)

        if changed:
            ctx.commit()