Exemplo n.º 1
0
def main():
    """
    main method
    parses arguments and constructs Manager object and performs actions
    """
    logger = fancylogger.getLogger()
    options = get_options()
    logger.debug("arguments parsed, starting manager")
    manager = Manager(options)

    #print status
    if manager.status:
        print "Status:\n %s" % manager.status

    #actually do requested commands
    out = manager.doit()
    #parse and display the output
    errors = []
    if out:
        for i in out:  # this is an array of nodes and their  output,err
            if len(i[1]) > 0:  # only print if something to show
                print "%s:" % i[0]  # first element is the node
                for j in i[1]:  # second element is an array of [outputs of commands,errors]
                    print "    output: %s" % str(j[1][0])
                    if j[1][1]:
                        print "    error:  %s" % str(j[1][1])
                        errors.append(i[0])

    # print all nodes with errors out on the end
    if len(errors) > 0:
        print "ERRORS occured in: \n ", ",".join([str(x) for x in errors])
Exemplo n.º 2
0
    def testdoitOutput(self):
        """Test the consistency of the output of manager.doit"""
        opts = Options()  # default options object
        opts.cluster = TEST_CLUSTER
        opts.quattor_nodes = True
        opts.ledon = True
        manager = Manager(opts)
        manager.nodes = CompositeNode(timeout=1)
        # create a fake node
        testnode = TestNode('node111', 'localhost', None)
        # overwrite it's testcommand to be sure it times out
        testnode.ledoncommand = Command('sleep 3', timeout=1)
        manager.nodes.add(testnode)

        # make sure this works for multiple nodes
        testnode2 = TestNode('node112', 'localhost', None)
        # overwrite it's testcommand to be sure it times out
        testnode2.ledoncommand = Command('sleep 3', timeout=1)
        manager.nodes.add(testnode2)
        # parse actions again so they get applied on the new node
        manager.parseActions()
        out = manager.doit()
        # make sure this output is of a format we can handle
        errors = []
        for i in out:
            if len(i) > 1 and len(i[1]) > 0:
                for j in i[1]:  # second element is an array of [outputs of commands,errors]
                    self.assertEquals(j[1][0], None)
                    if j[1][1]:
                        self.assertEquals(j[1][1], 'command timed out')
                        errors.append(i[0])

        # actuall node should be in output, not just the name, because this is also used for printstatussee
        self.assertTrue(testnode in errors)
        self.assertTrue(testnode2 in errors)
Exemplo n.º 3
0
    def testManagerCreatorActionOptions(self):
        """
        test the manager constructor
        """
#        debug = True cluster = None chassis = None down = False all = False
#        idle = False offline = False node = ""
        opts = Options()  # default options object
        opts.cluster = TEST_CLUSTER
        opts.quattor = True
        opts.all = True
        opts.forced = True
        opts.state = True
        manager = Manager(opts)
        manager.doit()
        opts.non_threaded = True
        manager = Manager(opts)
        opts.non_threaded = False
        manager = Manager(opts)
        manager.doit()

        opts.non_threaded = False
        opts.poweron = True
        Manager(opts).doit()

        opts.postpoweron = True
        Manager(opts)  # should create a manager

        opts.postpoweron = False
        opts.hardreboot = True
        Manager(opts)

        opts.hardreboot = False
        opts.softreboot = True
        Manager(opts)

        opts.all = False
        opts.worker = True
        opts.forced = False

        opts.pbsmomstatus = True
        Manager(opts).doit()

        opts.pbsmomrestart = True
        Manager(opts)  # should create a manager

        opts.pbsmomstop = True
        Manager(opts)  # should create a manager

        opts.pbsmomcleanup = True
        Manager(opts)  # should create a manager

        opts.runcmd = "echo hello"
        Manager(opts).doit()  # should create a manager
Exemplo n.º 4
0
    def testManagerhasSpecials(self):
        """
        test on inclusion of special nodes
        """
        opts = Options()
        opts.cluster = TEST_CLUSTER

        manager = Manager(opts)
        self.assertFalse(manager.hasSpecials())
        opts.worker = True
        manager = Manager(opts)
        self.assertFalse(manager.hasSpecials())
        opts.all_nodes = True
        manager = Manager(opts)
        self.assertTrue(manager.hasSpecials())  # should have special nodes with force (the master)

        opts = Options()
        opts.cluster = TEST_CLUSTER
        opts.master = "master1"
        self.assertTrue(Manager(opts).hasSpecials())  # should create a manager
Exemplo n.º 5
0
    def testManagerhasSpecials(self):
        """
        test on inclusion of special nodes
        """
        opts = Options()
        opts.cluster = 'cubone'

        manager = Manager(opts)
        self.assertFalse(manager.hasSpecials())
        opts.worker = True
        #self.assertRaises(Exception, Manager, opts)
        manager = Manager(opts)
        self.assertFalse(manager.hasSpecials())
        opts.all_nodes = True
        manager = Manager(opts)
        self.assertTrue(manager.hasSpecials())  # should have special nodes with force (the master)

        opts = Options()
        opts.cluster = 'cubone'
        opts.master = "master7"
        self.assertTrue(Manager(opts).hasSpecials())  # should create a manager