예제 #1
0
    def testAttach(self):        
        #print '++++++++++ DEBUG: starting testAttach'
        mgr = ClusterMgr()
        
        c = mgr.alloc_new('testAttach',self._defcfg,'vagrant')
        c1 = mgr.attach( 'testAttach' )
        self.assertEquals( c1.id() , c.id() )

        with self.assertRaisesRegexp(Exception,"Error attaching to cluster.*"):        
            c2 = mgr.attach( 'no-cluster' )
                
        mgr.destroy(c)
예제 #2
0
class ClusterCmd(object):
    def __init__(self):
        self._mgr = ClusterMgr()

    def main(self, argv=None):
        if not argv:
            argv = sys.argv

        try:
            opts, args = getopt.getopt(argv[1:], "u", [])
        except getopt.GetoptError as err:
            # print help information and exit:
            print str(err)  # will print something like "option -a not recognized"
            self.usage()
            sys.exit(2)

        for o, a in opts:
            if o == "-u":
                import autooam.test.test_common

                # reinitialize this to pickup debug db
                self._mgr = ClusterMgr()
            else:
                assert False, "unhandled option"

        cmdaction = {
            "list": self.listclusters,
            "start": self.start,
            "poweron": self.poweron,
            "poweroff": self.poweroff,
            "pause": self.pause,
            "resume": self.resume,
            "destroy": self.destroy,
            "shell": self.shell,
            "show": self.show,
            "forceclean": self.forceclean,
            "run": self.run,
            "attach": self.attach,
        }

        if len(args) < 1 or not cmdaction.has_key(args[0]):
            self.usage()

        return cmdaction[args[0]](args[1:])

    def usage(self):
        print """usage: clustercmd [-u] command [command options] ...
        
            -u  : enable unit-test mode
            
        Supported command options:
            list
                : list all clusters
            start cluster
                : start the cluster with name <cluster>
            poweron cluster
                : powers on the cluster with name <cluster>
            poweroff cluster
                : powers off the cluster with name <cluster>
            pause cluster
                : pauses the cluster with name <cluster>
            resume cluster
                : resumes the cluster with name <cluster>
            destroy <regex>
                : destroy any clusters with name  or ID matching <regex>
            shell cluster node cmd
                : run 'cmd' on node 'node' in the named cluster
            show cluster
                : show details for the cluster with name <cluster>            
            forceclean cluster
                : destroy and clean cluster, even if in inconsistent state
            run cluster test
                : run the test suite named 'test' on <cluster>            
            attach cluster emhost emport
                : attempt an attach from EM server <emhost>:<emport> to <cluster>            
        """
        sys.exit(1)

    def listclusters(self, args):
        print "Clusters: (name, id)"
        for c in self._mgr.list_clusters():
            sync = "ok"
            try:
                cluster = self._mgr.attach(c[0])
                sync = "ok,%s" % cluster.status()
            except Exception, err:
                sync = "invalid (%s),n/a" % err
            print "\t(%s,%s,%s)" % (c[0], c[1], sync)
        return 0