예제 #1
0
    def _get_drupal_version_info(self):
        """Determine the platform, version, and revision of the imported site.
        Returns tuple of major_version (6 or 7) and the nearest git revision.

        """
        version = drupaltools.get_drupal_version(self.working_dir)
        if not version:
            err = 'Error: This does not appear to be a Drupal 6 site.'
            jenkinstools.junit_fail(err, 'DrupalVersion')
            postback.build_error(err)
        else:
            jenkinstools.junit_pass('Drupal version %s found.' % (version),
                                   'DrupalVersion')

        platform = drupaltools.get_drupal_platform(self.working_dir)

        major_version = int(version[0:1])
        if major_version == 6:
            if platform == 'DRUPAL':
                revision = 'DRUPAL-%s' % version
            elif platform == 'PRESSFLOW' or platform == 'PANTHEON':
                revision = self._get_pressflow_revision(6)
        elif major_version == 7:
            #TODO: Temporary until D7 git setup is finalized.
            if platform == 'DRUPAL':
                # TODO: replace - with . in tags once git repo is finalized.
                revision = version.replace('-','.') # temp hack
            elif platform == 'PRESSFLOW' or platform == 'PANTHEON':
                revision = self._get_pressflow_revision(7)
        return (major_version, revision)
예제 #2
0
    def _get_site_name(self):
        """Return the name of the site to be imported.

        A valid site is any directory under sites/ that contains a settings.php

        """
        root = os.path.join(self.working_dir, 'sites')
        sites =[s for s in os.listdir(root) \
                        if os.path.isdir(os.path.join(root,s)) and (
                           'settings.php' in os.listdir(os.path.join(root,s)))]

        # Unless only one site is found, post error and exit.  
        site_count = len(sites)
        if site_count > 1:
            err = 'Multiple settings.php files were found:\n' + \
                  '\n'.join(sites)
            jenkinstools.junit_fail(err, 'SiteCount')
            postback.build_error(err)
        elif site_count == 0:
            err = 'Error: No settings.php files were found.'
            jenkinstools.junit_fail(err, 'SiteCount')
            postback.build_error(err)
        else:
            jenkinstools.junit_pass('Site found.', 'SiteCount')
            return sites[0]
예제 #3
0
    def _get_site_name(self):
        """Return the name of the site to be imported.

        A valid site is any directory under sites/ that contains a settings.php

        """
        root = os.path.join(self.working_dir, 'sites')
        sites =[s for s in os.listdir(root) \
                        if os.path.isdir(os.path.join(root,s)) and (
                           'settings.php' in os.listdir(os.path.join(root,s)))]

        # Unless only one site is found, post error and exit.
        site_count = len(sites)
        if site_count > 1:
            err = 'Multiple settings.php files were found:\n' + \
                  '\n'.join(sites)
            jenkinstools.junit_fail(err, 'SiteCount')
            postback.build_error(err)
        elif site_count == 0:
            err = 'Error: No settings.php files were found.'
            jenkinstools.junit_fail(err, 'SiteCount')
            postback.build_error(err)
        else:
            jenkinstools.junit_pass('Site found.', 'SiteCount')
            return sites[0]
예제 #4
0
    def _get_drupal_version_info(self):
        """Determine the platform, version, and revision of the imported site.
        Returns tuple of major_version (6 or 7) and the nearest git revision.

        """
        version = drupaltools.get_drupal_version(self.working_dir)
        if not version:
            err = 'Error: This does not appear to be a Drupal 6 site.'
            jenkinstools.junit_fail(err, 'DrupalVersion')
            postback.build_error(err)
        else:
            jenkinstools.junit_pass('Drupal version %s found.' % (version),
                                    'DrupalVersion')

        platform = drupaltools.get_drupal_platform(self.working_dir)

        major_version = int(version[0:1])
        if major_version == 6:
            if platform == 'DRUPAL':
                revision = 'DRUPAL-%s' % version
            elif platform == 'PRESSFLOW' or platform == 'PANTHEON':
                revision = self._get_pressflow_revision(6)
        elif major_version == 7:
            #TODO: Temporary until D7 git setup is finalized.
            if platform == 'DRUPAL':
                # TODO: replace - with . in tags once git repo is finalized.
                revision = version.replace('-', '.')  # temp hack
            elif platform == 'PRESSFLOW' or platform == 'PANTHEON':
                revision = self._get_pressflow_revision(7)
        return (major_version, revision)
예제 #5
0
def get_drupal_root(base):
    """Return the location of drupal root within 'base' dir tree.

    """
    for root, dirs, files in os.walk(base, topdown=True):
        if ('index.php' in files) and ('sites' in dirs):
            jenkinstools.junit_pass('Drupal root found.', 'DrupalRoot')
            return root
    err = 'Cannot locate drupal install in archive.'
    jenkinstools.junit_fail(err, 'DrupalRoot')
    postback.build_error(err)
예제 #6
0
def get_drupal_root(base):
    """Return the location of drupal root within 'base' dir tree.

    """
    for root, dirs, files in os.walk(base, topdown=True):
        if ('index.php' in files) and ('sites' in dirs):
            jenkinstools.junit_pass('Drupal root found.', 'DrupalRoot')
            return root
    err = 'Cannot locate drupal install in archive.'
    jenkinstools.junit_fail(err, 'DrupalRoot')
    postback.build_error(err)
예제 #7
0
def drupal_update_status(project):
    """Return drupal/pantheon update status for each environment.

    """
    try:
        status = drupaltools.get_drupal_update_status(project)
    except:
        jenkinstools.junit_error(traceback.format_exc(), 'UpdateStatus')
        raise
    else:
        jenkinstools.junit_pass('%s' % status, 'UpdateStatus')
        postback.write_build_data('drupal_core_status', {'status': status})
예제 #8
0
def git_repo_status(project):
    """Post back to Atlas with the status of the project Repo.

    """
    try:
        repo = gittools.GitRepo(project)
        status = repo.get_repo_status()
    except:
        jenkinstools.junit_error(traceback.format_exc(), 'GitRepoStatus')
        raise
    else:
        jenkinstools.junit_pass('%s' % status, 'GitRepoStatus')
        postback.write_build_data('git_repo_status', {'status': status})
예제 #9
0
 def drupal_updatedb(self):
     alias = '@%s_%s' % (self.project, self.project_env)
     with settings(warn_only=True):
         result = local('drush %s -by updb' % alias)
     json_out = pantheon.parse_drush_output(result)
     msgs = '\n'.join(['[%s] %s' % (o['type'], o['message'])
                     for o in json_out['log']])
     if (result.failed):
         jenkinstools.junit_fail(msgs, 'UpdateDB')
         postback.build_warning("Warning: UpdateDB encountered an error.")
         print("\n=== UpdateDB Debug Output ===\n%s\n" % msgs)
     else:
         jenkinstools.junit_pass(msgs, 'UpdateDB')
예제 #10
0
    def _get_archive_type(self):
        """Return the generic type of archive (tar/zip).

        """
        if tarfile.is_tarfile(self.path):
            jenkinstools.junit_pass('Tar found.','ArchiveType')
            return 'tar'
        elif zipfile.is_zipfile(self.path):
            jenkinstools.junit_pass('Zip found.','ArchiveType')
            return 'zip'
        else:
            err = 'Error: Not a valid tar/zip archive.'
            jenkinstools.junit_fail(err,'ArchiveType')
            postback.build_error(err)
예제 #11
0
    def _get_database_dump(self):
        """Return the filename of the database dump.

        This will look for *.mysql or *.sql files in the root drupal directory.
        If more than one dump is found, the build will exit with an error.

        """
        sql_dump = [dump for dump in os.listdir(self.working_dir) \
                    if os.path.splitext(dump)[1] in ['.sql', '.mysql']]
        count = len(sql_dump)
        if count == 0:
            err = 'No database dump files were found (*.mysql or *.sql)'
            jenkinstools.junit_fail(err, 'MYSQLCount')
            postback.build_error(err)
        elif count > 1:
            err = 'Multiple database dump files were found:\n' + \
                  '\n'.join(sql_dump)
            jenkinstools.junit_fail(err, 'MYSQLCount')
            postback.build_error(err)
        else:
            jenkinstools.junit_pass('MYSQL Dump found at %s' % 
                                   (sql_dump[0]), 'MYSQLCount')
            return sql_dump[0]
예제 #12
0
    def _get_database_dump(self):
        """Return the filename of the database dump.

        This will look for *.mysql or *.sql files in the root drupal directory.
        If more than one dump is found, the build will exit with an error.

        """
        sql_dump = [dump for dump in os.listdir(self.working_dir) \
                    if os.path.splitext(dump)[1] in ['.sql', '.mysql']]
        count = len(sql_dump)
        if count == 0:
            err = 'No database dump files were found (*.mysql or *.sql)'
            jenkinstools.junit_fail(err, 'MYSQLCount')
            postback.build_error(err)
        elif count > 1:
            err = 'Multiple database dump files were found:\n' + \
                  '\n'.join(sql_dump)
            jenkinstools.junit_fail(err, 'MYSQLCount')
            postback.build_error(err)
        else:
            jenkinstools.junit_pass('MYSQL Dump found at %s' % (sql_dump[0]),
                                    'MYSQLCount')
            return sql_dump[0]
예제 #13
0
    def enable_pantheon_settings(self):
        """Enable required modules, and set Pantheon defaults.

        """
        if self.version == 6:
            required_modules = ['apachesolr',
                                'apachesolr_search',
                                'cookie_cache_bypass',
                                'locale',
                                'syslog',
                                'varnish']
        elif self.version == 7:
            required_modules = ['apachesolr',
                                'apachesolr_search']

        # Enable modules.
        with settings(hide('warnings'), warn_only=True):
            for module in required_modules:
                result = local('drush -y @working_dir en %s' % module)
                if result.failed:
                    # If importing vanilla drupal, this module wont exist.
                    if module != 'cookie_cache_bypass':
                        message = 'Could not enable %s module.' % module
                        jenkinstools.junit_fail('%s\n%s' % 
                                               (message, result.stderr), 
                                               'EnableModules', module)
                        postback.build_warning(message)
                        print message
                        print '\n%s module could not be enabled. ' % module + \
                              'Error Message:'
                        print '\n%s' % result.stderr
                else:
                    jenkinstools.junit_pass('%s enabled.' % module, 
                                           'EnableModules', module)

        if self.version == 6:
            drupal_vars = {
                'apachesolr_search_make_default': 1,
                'apachesolr_search_spellcheck': 1,
                'cache': '3',
                'block_cache': '1',
                'page_cache_max_age': '900',
                'page_compression': '0',
                'preprocess_js': '1',
                'preprocess_css': '1'}

        elif self.version == 7:
            drupal_vars = {
                'cache': 1,
                'block_cache': 1,
                'cache_lifetime': "0",
                'page_cache_maximum_age': "900",
                'page_compression': 0,
                'preprocess_css': 1,
                'preprocess_js': 1,
                'search_active_modules': {
                    'apachesolr_search':'apachesolr_search',
                    'user': '******',
                    'node': 0},
                'search_default_module': 'apachesolr_search'}

        # Set variables.
        database = '%s_dev' % self.project
        db = dbtools.MySQLConn(database=database,
                               username = self.project,
                               password = self.db_password)
        for key, value in drupal_vars.iteritems():
            db.vset(key, value)

        # apachesolr module for drupal 7 stores config in db.
        if self.version == 7:
            db.execute('TRUNCATE apachesolr_server')
            for env in self.environments:
                config = self.config['environments']['env']['solr'];
                db.execute('INSERT INTO apachesolr_server ' + \
                    '(host, port, server_id, name, path) VALUES ' + \
                    '("%s", "%s", ' + \
                      '"%s", "Pantheon %s", "/%s")' % \
                      (config['solr_host'], config['solr_port'], \
                      config['apachesolr_default_server'], env, \
                      config['solr_path']))
        db.close()

        # D7: apachesolr config link will not display until cache cleared?
        with settings(warn_only=True):
            local('drush @working_dir -y cc all')

       # Remove temporary working_dir drush alias.
        alias_file = '/opt/drush/aliases/working_dir.alias.drushrc.php'
        if os.path.exists(alias_file):
            local('rm -f %s' % alias_file)
예제 #14
0
    def enable_pantheon_settings(self):
        """Enable required modules, and set Pantheon defaults.

        """
        if self.version == 6:
            required_modules = [
                'apachesolr', 'apachesolr_search', 'cookie_cache_bypass',
                'locale', 'syslog', 'varnish'
            ]
        elif self.version == 7:
            required_modules = ['apachesolr', 'apachesolr_search']

        # Enable modules.
        with settings(hide('warnings'), warn_only=True):
            for module in required_modules:
                result = local('drush -y @working_dir en %s' % module)
                if result.failed:
                    # If importing vanilla drupal, this module wont exist.
                    if module != 'cookie_cache_bypass':
                        message = 'Could not enable %s module.' % module
                        jenkinstools.junit_fail(
                            '%s\n%s' % (message, result.stderr),
                            'EnableModules', module)
                        postback.build_warning(message)
                        print message
                        print '\n%s module could not be enabled. ' % module + \
                              'Error Message:'
                        print '\n%s' % result.stderr
                else:
                    jenkinstools.junit_pass('%s enabled.' % module,
                                            'EnableModules', module)

        if self.version == 6:
            drupal_vars = {
                'apachesolr_search_make_default': 1,
                'apachesolr_search_spellcheck': 1,
                'cache': '3',
                'block_cache': '1',
                'page_cache_max_age': '900',
                'page_compression': '0',
                'preprocess_js': '1',
                'preprocess_css': '1'
            }

        elif self.version == 7:
            drupal_vars = {
                'cache': 1,
                'block_cache': 1,
                'cache_lifetime': "0",
                'page_cache_maximum_age': "900",
                'page_compression': 0,
                'preprocess_css': 1,
                'preprocess_js': 1,
                'search_active_modules': {
                    'apachesolr_search': 'apachesolr_search',
                    'user': '******',
                    'node': 0
                },
                'search_default_module': 'apachesolr_search'
            }

        # Set variables.
        database = '%s_dev' % self.project
        db = dbtools.MySQLConn(database=database,
                               username=self.project,
                               password=self.db_password)
        for key, value in drupal_vars.iteritems():
            db.vset(key, value)

        # apachesolr module for drupal 7 stores config in db.
        if self.version == 7:
            db.execute('TRUNCATE apachesolr_server')
            for env in self.environments:
                config = self.config['environments']['env']['solr']
                db.execute('INSERT INTO apachesolr_server ' + \
                    '(host, port, server_id, name, path) VALUES ' + \
                    '("%s", "%s", ' + \
                      '"%s", "Pantheon %s", "/%s")' % \
                      (config['solr_host'], config['solr_port'], \
                      config['apachesolr_default_server'], env, \
                      config['solr_path']))
        db.close()

        # D7: apachesolr config link will not display until cache cleared?
        with settings(warn_only=True):
            local('drush @working_dir -y cc all')

    # Remove temporary working_dir drush alias.
        alias_file = '/opt/drush/aliases/working_dir.alias.drushrc.php'
        if os.path.exists(alias_file):
            local('rm -f %s' % alias_file)