Beispiel #1
0
 def testRun(self):
     p = PlaybookMgr( 'testbook' )
     p.write_inventory( 'testinv', { 'all' : ['localhost'] } )
     f = open( props['emtools.test.sshkeyfile'] )
     keytext = ''.join(f.readlines())
     p.config_ssh( props['emtools.test.user'], keytext )
      
     rc = p.run_module('testinv', 'all', 'setup', sudo=False)
     
     self.assertTrue( rc['contacted'].has_key( 'localhost' ))
     
     rc, results, out, err = p.run_playbook('smokecheck.yml', 'testinv')
     self.assertEquals(rc, 0)
      
     shutil.rmtree( p.get_rootdir() )
Beispiel #2
0
    def run_cmd(self):
        '''
        Prepare and run the ansible playbook command for
        the operation type specified in the constructor
        '''
        self._rundir  = self._cluster.get_vmi()._rundir
        emboxtype = self._cluster.config()['em']['boxtype']
        if not vagboxes.em_support(emboxtype):
            # Don't even try to install if the boxtype does not support an EM
            print 'supported is %s' % vagboxes.list_all(flags=vagboxes.FLAG_EM)
            Log.error("boxtype %s does not support the EM!" % emboxtype)
            return 1
        
        self._pkgtype = vagboxes.get_default_pkgtype(emboxtype)
        vmgr = emvmgr.EMVersionManager()
        (emversion, self._pkgfile) = vmgr.retrieve(self._cluster.config()['em']['version'], self._pkgtype)
        self._pkgname = os.path.split( self._pkgfile )[1]
        
        (ansible_yml,cmdargs) = self._prepare_playbook_install()

        extra_playdir = self._cluster.get_extra_playbook_dir()
        p = PlaybookMgr( os.path.basename(self._rundir), extra_playdir )

        # create ansible inventory file with list of hosts
        emrole = self._cluster.config()['em']['role']
        iplist = [ self._cluster.machine(emrole)['ip'] ]
        ipdict = { 'all' : iplist }
        p.write_inventory( 'emdefault', ipdict )

        # create ansible.cfg file
        self._idbuser = self._cluster.config()['idbuser']
        f = open( common.props['vmi.vagrantvmi.sshkey'] )
        keytext = ''.join(f.readlines())
        p.config_ssh( self._idbuser, keytext )

        # execute playbook thru PlaybookMgr
        Log.info("Running %s EM pkg install playbook; --extra-vars=%s" % (ansible_yml,cmdargs))
        rc, results, out, err = p.run_playbook(ansible_yml, 'emdefault', playbook_args=cmdargs)
        return rc
Beispiel #3
0
def main(argv):
    '''
    main function
    '''
    
    try:                                
        opts, args = getopt.getopt(argv, "hvi", ['json='])
    except getopt.GetoptError:
        usage()
        sys.exit(2)   
    
    # defaults
    use_stdin = False
    json_file = ''
    
    for o,a in opts:
        if o == '-h':
            usage()
            sys.exit(2)
        elif o == '-v':
            print 'runplaybook.py Version: %s' % version
            sys.exit(1)
        elif o == '-i':
            use_stdin = True
        elif o == '--json':
            json_file = a
        else:
            print 'unsupported option: %s' % o
            usage()
            sys.exit(2)
        
    if (use_stdin and json_file) or (not use_stdin and not json_file):
        print 'ERROR: Must specify exactly one of -i or --json'
        usage()
        sys.exit(2)
        
    jsonstr = None
    if use_stdin:
        lines = sys.stdin.readlines()
        jsonstr = ''.join(lines)
    elif json_file:
        f = open( json_file )
        lines = f.readlines()
        jsonstr = ''.join(lines)
    
    
    # debug only
    # print '%s' % req
    try:
        req = playbookreq.PlaybookRequest( jsonstr )

        Log = logutils.getLogger('runplaybook')
        Log.info('request: %s' % req.json_dumps())

        pmgr = PlaybookMgr( req['cluster_name'] )
        rc, results, out, err = pmgr.run_playbook(req['playbook_info']['name'], 'infinidb', req['playbook_info']['hostspec'], playbook_args=req['playbook_info']['extravars'])
        preply_dict = {
            'cluster_name' : req['cluster_name'],
            'playbook_info' : req['playbook_info'],
            'rc' : rc,
            'stdout' : out,
            'stderr' : err,
            'recap_info' : results
        }
        preply = playbookreply.PlaybookReply_from_dict(preply_dict)
        Log.info('reply: %s' % preply.json_dumps())
        print preply
        return rc
        
    except:
        import traceback
        print errormsg.ErrorMsg_from_parms( msg=json.dumps( traceback.format_exc() ) )
        sys.exit(1)
Beispiel #4
0
            cluster_gluster = instance_info[h]['gluster_version']
        instance_info[h]['hadoop_version'] = site_facts['hadoop_version']
        if not cluster_hadoop and instance_info[h]['hadoop_version']:
            cluster_hadoop = instance_info[h]['hadoop_version']
        if not cluster_infinidb and site_facts['infinidb_version']:
            cluster_infinidb = site_facts['infinidb_version']
            infinidb_host = h
        valid_instances = valid_instances + 1

    role_info = {}
    if valid_instances == 0:
        cluster_valid = False
        cluster_reason = 'No reachable hosts'
    elif cluster_infinidb:
        # we found infinidb software.  Run our getinfo playbook to retrieve Calpont.xml
        rc = p.run_playbook('getinfo.yml', 'default')
        if rc == 0:
            # this playbook will write Calpont.xml files to /tmp/<host>-Calpont.xml
            shortname = infinidb_host[0:infinidb_host.find('.')]
            xml = idbxml.IdbXml('/tmp/%s-Calpont.xml' % shortname)

            for r in xml.get_all_roles():
                # eoch role here has role= and ip_address= but we need to put
                # map role to hostname for our reply.
                role = r['role']
                ip = r['ip_address']
                host = ''
                for i in instance_info.iterkeys():
                    if instance_info[i]['ip_address'] == ip:
                        host = i
                if not host:
Beispiel #5
0
    def run_cmd(self):
        '''
        Prepare and run the ansible playbook command for
        the operation type specified in the constructor
        '''
        self._rundir = self._cluster.get_rundir()
        self._pkgdir = self._cluster.get_pkgdir()
        self._pkgfile = self._cluster.get_pkgfile()
        self._idbuser = self._cluster.config()['idbuser']
        eflag = self._cluster.config()['enterprise']
        if eflag:
            self._entflag = "true"
        else:
            self._entflag = "false"
        self._version = self._pkgfilenameparser.get_pkg_version(self._pkgfile)
        self._hadoop = self._cluster.config()['hadoop']
        self._hdfsflag = "false"
        if self._hadoop:
            self._hdfsflag = "true"
        self._upgfile = self._cluster.get_upgfile()
        self._upgversion = None
        if self._upgfile:
            self._upgversion = self._pkgfilenameparser.get_pkg_version(
                self._upgfile)
        m = self._cluster.machine('pm1')
        self._pm1_ip = m['ip']
        self._postconfig_opts = self._cluster.get_postconfig_opts()

        # Add -em to postconfig flags for version 4.6 and up
        if self._optype == 'pkginstall':
            if ConfigSpec._version_greaterthan(self._version, '4.6.0-0'):
                self._postconfig_opts += " -em"
            (ansible_yml, cmdargs) = self._prepare_playbook_pkginstall()
        elif self._optype == 'pkgupgrade':
            if ConfigSpec._version_greaterthan(self._upgversion, '4.6.0-0'):
                self._postconfig_opts += " -em"
            (ansible_yml, cmdargs) = self._prepare_playbook_pkgupgrade()
        elif self._optype == 'bininstall':
            if ConfigSpec._version_greaterthan(self._version, '4.6.0-0'):
                self._postconfig_opts += " -em"
            (ansible_yml, cmdargs) = self._prepare_playbook_bininstall()
        elif self._optype == 'binupgrade':
            if ConfigSpec._version_greaterthan(self._upgversion, '4.6.0-0'):
                self._postconfig_opts += " -em"
            (ansible_yml, cmdargs) = self._prepare_playbook_binupgrade()
        else:
            raise Exception("Unsupported ansible playbook type to run: %s" %
                            self._optype)

        extra_playdir = self._cluster.get_extra_playbook_dir()
        p = PlaybookMgr(os.path.basename(self._rundir), extra_playdir)

        # create ansible inventory file with list of hosts;
        # should already exist for an EM-triggered install.
        full_inv_file = '%s/%s' % (p.get_rootdir(), self._inventory_filename)
        if not os.path.exists(full_inv_file):
            machines = self._cluster.machines()
            iplist = []
            infnodelist = []
            for key in machines:
                m = machines[key]
                iplist.append(m['ip'])

                # if we are using the EM in invm mode we don't want that
                # node to participate in the normal InfiniDB install
                if key != 'em1':
                    #f.write("key: %s.calpont.com; ip: %s\n" % (key,m['ip']))
                    infnodelist.append(m['ip'])

            ipdict = {'all': iplist, 'infinidb_nodes': infnodelist}
            p.write_inventory(self._inventory_filename, ipdict)

        # create ansible.cfg file;
        # should already exist for an EM-triggered install.
        full_ans_file = '%s/%s' % (p.get_rootdir(), 'ansible.cfg')
        if not os.path.exists(full_ans_file):
            keytext = self._cluster.get_sshkey_text()
            p.config_ssh(self._idbuser, keytext)

        # execute playbook thru PlaybookMgr
        self._ansible_file = ansible_yml
        self._extra_vars = cmdargs
        rc, results, out, err = p.run_playbook(ansible_yml,
                                               self._inventory_filename,
                                               playbook_args=cmdargs)

        return rc, results, out, err
Beispiel #6
0
         cluster_gluster = instance_info[h]['gluster_version']
     instance_info[h]['hadoop_version'] = site_facts['hadoop_version']
     if not cluster_hadoop and instance_info[h]['hadoop_version']:
         cluster_hadoop = instance_info[h]['hadoop_version']
     if not cluster_infinidb and site_facts['infinidb_version']:
         cluster_infinidb = site_facts['infinidb_version']
         infinidb_host = h
     valid_instances = valid_instances + 1
     
 role_info = {}
 if valid_instances == 0:
     cluster_valid = False
     cluster_reason = 'No reachable hosts'
 elif cluster_infinidb:
     # we found infinidb software.  Run our getinfo playbook to retrieve Calpont.xml
     rc = p.run_playbook('getinfo.yml', 'default')
     if rc == 0:
         # this playbook will write Calpont.xml files to /tmp/<host>-Calpont.xml
         shortname = infinidb_host[0:infinidb_host.find('.')]
         xml = idbxml.IdbXml( '/tmp/%s-Calpont.xml' % shortname )
         
         for r in xml.get_all_roles():
             # eoch role here has role= and ip_address= but we need to put
             # map role to hostname for our reply.
             role = r['role']
             ip = r['ip_address']
             host = ''
             for i in instance_info.iterkeys():
                 if instance_info[i]['ip_address'] == ip:
                     host = i
             if not host:
Beispiel #7
0
def main(argv):
    '''
    main function
    '''

    try:
        opts, args = getopt.getopt(argv, "hvi", ['json='])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    # defaults
    use_stdin = False
    json_file = ''

    for o, a in opts:
        if o == '-h':
            usage()
            sys.exit(2)
        elif o == '-v':
            print 'runplaybook.py Version: %s' % version
            sys.exit(1)
        elif o == '-i':
            use_stdin = True
        elif o == '--json':
            json_file = a
        else:
            print 'unsupported option: %s' % o
            usage()
            sys.exit(2)

    if (use_stdin and json_file) or (not use_stdin and not json_file):
        print 'ERROR: Must specify exactly one of -i or --json'
        usage()
        sys.exit(2)

    jsonstr = None
    if use_stdin:
        lines = sys.stdin.readlines()
        jsonstr = ''.join(lines)
    elif json_file:
        f = open(json_file)
        lines = f.readlines()
        jsonstr = ''.join(lines)

    # debug only
    # print '%s' % req
    try:
        req = playbookreq.PlaybookRequest(jsonstr)

        Log = logutils.getLogger('runplaybook')
        Log.info('request: %s' % req.json_dumps())

        pmgr = PlaybookMgr(req['cluster_name'])
        rc, results, out, err = pmgr.run_playbook(
            req['playbook_info']['name'],
            'infinidb',
            req['playbook_info']['hostspec'],
            playbook_args=req['playbook_info']['extravars'])
        preply_dict = {
            'cluster_name': req['cluster_name'],
            'playbook_info': req['playbook_info'],
            'rc': rc,
            'stdout': out,
            'stderr': err,
            'recap_info': results
        }
        preply = playbookreply.PlaybookReply_from_dict(preply_dict)
        Log.info('reply: %s' % preply.json_dumps())
        print preply
        return rc

    except:
        import traceback
        print errormsg.ErrorMsg_from_parms(
            msg=json.dumps(traceback.format_exc()))
        sys.exit(1)
Beispiel #8
0
    def run_cmd(self):
        """
        Prepare and run the ansible playbook command for
        the operation type specified in the constructor
        """
        self._rundir = self._cluster.get_rundir()
        self._pkgdir = self._cluster.get_pkgdir()
        self._pkgfile = self._cluster.get_pkgfile()
        self._idbuser = self._cluster.config()["idbuser"]
        eflag = self._cluster.config()["enterprise"]
        if eflag:
            self._entflag = "true"
        else:
            self._entflag = "false"
        self._version = self._pkgfilenameparser.get_pkg_version(self._pkgfile)
        self._hadoop = self._cluster.config()["hadoop"]
        self._hdfsflag = "false"
        if self._hadoop:
            self._hdfsflag = "true"
        self._upgfile = self._cluster.get_upgfile()
        self._upgversion = None
        if self._upgfile:
            self._upgversion = self._pkgfilenameparser.get_pkg_version(self._upgfile)
        m = self._cluster.machine("pm1")
        self._pm1_ip = m["ip"]
        self._postconfig_opts = self._cluster.get_postconfig_opts()

        # Add -em to postconfig flags for version 4.6 and up
        if self._optype == "pkginstall":
            if ConfigSpec._version_greaterthan(self._version, "4.6.0-0"):
                self._postconfig_opts += " -em"
            (ansible_yml, cmdargs) = self._prepare_playbook_pkginstall()
        elif self._optype == "pkgupgrade":
            if ConfigSpec._version_greaterthan(self._upgversion, "4.6.0-0"):
                self._postconfig_opts += " -em"
            (ansible_yml, cmdargs) = self._prepare_playbook_pkgupgrade()
        elif self._optype == "bininstall":
            if ConfigSpec._version_greaterthan(self._version, "4.6.0-0"):
                self._postconfig_opts += " -em"
            (ansible_yml, cmdargs) = self._prepare_playbook_bininstall()
        elif self._optype == "binupgrade":
            if ConfigSpec._version_greaterthan(self._upgversion, "4.6.0-0"):
                self._postconfig_opts += " -em"
            (ansible_yml, cmdargs) = self._prepare_playbook_binupgrade()
        else:
            raise Exception("Unsupported ansible playbook type to run: %s" % self._optype)

        extra_playdir = self._cluster.get_extra_playbook_dir()
        p = PlaybookMgr(os.path.basename(self._rundir), extra_playdir)

        # create ansible inventory file with list of hosts;
        # should already exist for an EM-triggered install.
        full_inv_file = "%s/%s" % (p.get_rootdir(), self._inventory_filename)
        if not os.path.exists(full_inv_file):
            machines = self._cluster.machines()
            iplist = []
            infnodelist = []
            for key in machines:
                m = machines[key]
                iplist.append(m["ip"])

                # if we are using the EM in invm mode we don't want that
                # node to participate in the normal InfiniDB install
                if key != "em1":
                    # f.write("key: %s.calpont.com; ip: %s\n" % (key,m['ip']))
                    infnodelist.append(m["ip"])

            ipdict = {"all": iplist, "infinidb_nodes": infnodelist}
            p.write_inventory(self._inventory_filename, ipdict)

        # create ansible.cfg file;
        # should already exist for an EM-triggered install.
        full_ans_file = "%s/%s" % (p.get_rootdir(), "ansible.cfg")
        if not os.path.exists(full_ans_file):
            keytext = self._cluster.get_sshkey_text()
            p.config_ssh(self._idbuser, keytext)

        # execute playbook thru PlaybookMgr
        self._ansible_file = ansible_yml
        self._extra_vars = cmdargs
        rc, results, out, err = p.run_playbook(ansible_yml, self._inventory_filename, playbook_args=cmdargs)

        return rc, results, out, err