Ejemplo n.º 1
0
    def test_WorkerAdminExceptions(self):
        """ Check that some instantiations of NodeAdmin cause exceptions """

        # no arguments to constructor
        self.assertRaises(Exception, nodeAdmin.NodeAdmin)

        # name given but no CssAccess
        self.assertRaises(Exception, nodeAdmin.NodeAdmin, name="worker")

        # name not given, must have both host and port
        self.assertRaises(Exception, nodeAdmin.NodeAdmin, host="worker")
        self.assertRaises(Exception, nodeAdmin.NodeAdmin, port=5012)

        # instantiate kvI with come initial data
        initData = """\
/\t\\N
/css_meta\t\\N
/css_meta/version\t{version}
/NODES\t\\N
/NODES/worker\t\\N
/NODES/worker/.packed.json\t{{"type": "worker", "host": "localhost", "port": 5012}}
"""
        initData = initData.format(version=css.VERSION)
        css_inst = _makeCss(initData)

        # setup with CSS, this should not throw
        nodeAdmin.NodeAdmin(name="worker", css=css_inst)
Ejemplo n.º 2
0
    def getNodes(self):
        """
        Return tuple with two lists of nodes (NodeAdmin instances) for all
        active nodes. First item in the returned tuple is a list of czar nodes,
        second item is a list of worker nodes.
        """

        mgmt = nodeMgmt.NodeMgmt(self.css, self.wmgrSecretFile)

        czars = []
        workers = []
        try:
            # try get node(s) from CSS
            czars = mgmt.select(css.NODE_STATE_ACTIVE, 'czar')
            workers = mgmt.select(css.NODE_STATE_ACTIVE, 'worker')
        except css.CssError as exc:
            _LOG.error('Failed to get nodes from CSS: %s', exc)

        # add explicit car node if there was no czar in CSS
        if not czars and self.czar:
            host, port = self.czar
            czars.append(
                nodeAdmin.NodeAdmin(host=host,
                                    port=port,
                                    wmgrSecretFile=self.wmgrSecretFile))

        return czars, workers