Example #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)
Example #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]
Example #3
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)
Example #4
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]
Example #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)
Example #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)
Example #7
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')
Example #8
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)
Example #9
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]
Example #10
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]
Example #11
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)
Example #12
0
    def setup_files_dir(self):
        """Move site files to sites/default/files if they are not already.

        This will move the files from their former location, change the file
        path in the database (for all files and the variable itself), then
        create a symlink in their former location.

        """
        file_location = self._get_files_dir()
        if file_location:
            file_path = os.path.join(self.working_dir, file_location)
        else:
            file_path = None
        file_dest = os.path.join(self.working_dir, 'sites/default/files')

        # After moving site to 'default', does 'files' not exist?
        if not os.path.exists(file_dest):
            # Broken symlink at sites/default/files
            if os.path.islink(file_dest):
                local('rm -f %s' % file_dest)
                msg = 'File path was broken symlink. Site files may be missing'
                jenkinstools.junit_fail(msg, 'SetupFilesDir')
                postback.build_warning(msg)
            local('mkdir -p %s' % file_dest)

        # if files are not located in default location, move them there.
        if (file_path) and (file_location != 'sites/default/files'):
            with settings(warn_only=True):
                local('cp -R %s/* %s' % (file_path, file_dest))
            local('rm -rf %s' % file_path)
            path = os.path.split(file_path)
            # Symlink from former location to sites/default/files
            if not os.path.islink(path[0]):
                rel_path = os.path.relpath(file_dest, os.path.split(file_path)[0])
                local('ln -s %s %s' % (rel_path, file_path))

        # Change paths in the files table
        database = '%s_%s' % (self.project, 'dev')

        if self.version == 6:
            file_var = 'file_directory_path'
            file_var_temp = 'file_directory_temp'
            # Change the base path in files table for Drupal 6
            local('mysql -u root %s -e "UPDATE files SET filepath = \
                   REPLACE(filepath,\'%s\',\'%s\');"'% (database,
                                                        file_location,
                                                        'sites/default/files'))
        elif self.version == 7:
            file_var = 'file_public_path'
            file_var_temp = 'file_temporary_path'

        # Change file path drupal variables
        db = dbtools.MySQLConn(database=database,
                               username = self.project,
                               password = self.db_password)
        db.vset(file_var, 'sites/default/files')
        db.vset(file_var_temp, '/tmp')
        db.close()

        # Ignore files directory
        with open(os.path.join(file_dest,'.gitignore'), 'a') as f:
            f.write('*\n')
            f.write('!.gitignore\n')
Example #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)
Example #14
0
    def setup_files_dir(self):
        """Move site files to sites/default/files if they are not already.

        This will move the files from their former location, change the file
        path in the database (for all files and the variable itself), then
        create a symlink in their former location.

        """
        file_location = self._get_files_dir()
        if file_location:
            file_path = os.path.join(self.working_dir, file_location)
        else:
            file_path = None
        file_dest = os.path.join(self.working_dir, 'sites/default/files')

        # After moving site to 'default', does 'files' not exist?
        if not os.path.exists(file_dest):
            # Broken symlink at sites/default/files
            if os.path.islink(file_dest):
                local('rm -f %s' % file_dest)
                msg = 'File path was broken symlink. Site files may be missing'
                jenkinstools.junit_fail(msg, 'SetupFilesDir')
                postback.build_warning(msg)
            local('mkdir -p %s' % file_dest)

        # if files are not located in default location, move them there.
        if (file_path) and (file_location != 'sites/default/files'):
            with settings(warn_only=True):
                local('cp -R %s/* %s' % (file_path, file_dest))
            local('rm -rf %s' % file_path)
            path = os.path.split(file_path)
            # Symlink from former location to sites/default/files
            if not os.path.islink(path[0]):
                rel_path = os.path.relpath(file_dest,
                                           os.path.split(file_path)[0])
                local('ln -s %s %s' % (rel_path, file_path))

        # Change paths in the files table
        database = '%s_%s' % (self.project, 'dev')

        if self.version == 6:
            file_var = 'file_directory_path'
            file_var_temp = 'file_directory_temp'
            # Change the base path in files table for Drupal 6
            local('mysql -u root %s -e "UPDATE files SET filepath = \
                   REPLACE(filepath,\'%s\',\'%s\');"' %
                  (database, file_location, 'sites/default/files'))
        elif self.version == 7:
            file_var = 'file_public_path'
            file_var_temp = 'file_temporary_path'

        # Change file path drupal variables
        db = dbtools.MySQLConn(database=database,
                               username=self.project,
                               password=self.db_password)
        db.vset(file_var, 'sites/default/files')
        db.vset(file_var_temp, '/tmp')
        db.close()

        # Ignore files directory
        with open(os.path.join(file_dest, '.gitignore'), 'a') as f:
            f.write('*\n')
            f.write('!.gitignore\n')