<commit_before>import time

from cassandra import Unauthorized
from ccmlib.common import is_win

from assertions import assert_all, assert_invalid
from dtest import Tester, debug
from tools import require, since


@since('2.2')
class TestAuthUpgrade(Tester):

    def __init__(self, *args, **kwargs):
        # Ignore these log patterns:
        self.ignore_log_patterns = [
            # This one occurs if we do a non-rolling upgrade, the node
            # it's trying to send the migration to hasn't started yet,
            # and when it does, it gets replayed and everything is fine.
            r'Can\'t send migration request: node.*is down',
        ]

        # Force cluster options that are common among versions:
        kwargs['cluster_options'] = {'authenticator': 'PasswordAuthenticator',
                                     'authorizer': 'CassandraAuthorizer'}
        Tester.__init__(self, *args, **kwargs)

    def upgrade_to_22_test(self):
        if is_win():
            # These three occur on older versions of C* on Windows
            self.ignore_log_patterns.append(r'Failed deleting temp components for')
            self.ignore_log_patterns.append(r'Missing component')
            self.ignore_log_patterns.append(r'Exception in thread Thread\[CompactionExecutor')
        self.do_upgrade_with_internal_auth("git:cassandra-2.2")

    # todo: when we branch for 3.0 switch this from trunk to cassandra-3.0
    @since('3.0')
    @require(9704)
    def upgrade_to_30_test(self):
        self.do_upgrade_with_internal_auth("git:trunk")

    def do_upgrade_with_internal_auth(self, target_version):
        """
        Tests upgrade between 2.1->2.2 & 2.1->3.0 as the schema and apis around authn/authz changed

        @jira_ticket CASSANDRA-7653<commit_msg>Exclude 'Unable to delete' on 22 upgrades on Windows<commit_after>import time

from cassandra import Unauthorized
from ccmlib.common import is_win

from assertions import assert_all, assert_invalid
from dtest import Tester, debug
from tools import require, since


@since('2.2')
class TestAuthUpgrade(Tester):

    def __init__(self, *args, **kwargs):
        # Ignore these log patterns:
        self.ignore_log_patterns = [
            # This one occurs if we do a non-rolling upgrade, the node
            # it's trying to send the migration to hasn't started yet,
            # and when it does, it gets replayed and everything is fine.
            r'Can\'t send migration request: node.*is down',
        ]

        # Force cluster options that are common among versions:
        kwargs['cluster_options'] = {'authenticator': 'PasswordAuthenticator',
                                     'authorizer': 'CassandraAuthorizer'}
        Tester.__init__(self, *args, **kwargs)

    def upgrade_to_22_test(self):
        if is_win():
            # These three occur on older versions of C* on Windows
            self.ignore_log_patterns.append(r'Failed deleting temp components for')
            self.ignore_log_patterns.append(r'Missing component')
            self.ignore_log_patterns.append(r'Exception in thread Thread\[CompactionExecutor')
            self.ignore_log_patterns.append(r'Unable to delete')
        self.do_upgrade_with_internal_auth("git:cassandra-2.2")

    # todo: when we branch for 3.0 switch this from trunk to cassandra-3.0
    @since('3.0')
    @require(9704)
    def upgrade_to_30_test(self):
        self.do_upgrade_with_internal_auth("git:trunk")

    def do_upgrade_with_internal_auth(self, target_version):
        """
        Tests upgrade between 2.1->2.2 & 2.1->3.0 as the schema and apis around authn/authz changed

        @jira_ticket CASSANDRA-7653
{'fraction_non_alphanumeric': 0.08610354223433242, 'fraction_numerical': 0.016893732970027248, 'mean_word_length': 2.8642105263157895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5692010', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1034, 'n_words': 314}