def analyze_failed_registration_nodes():
    """ If we can just retry the archive, but we can only do that if the
    ORIGINAL node hasn't changed.
    """
    # Get the registrations that are messed up
    failed_registration_nodes = find_failed_registrations()

    # Build up a list of dictionaries with info about these failed nodes
    failed_registration_info = []
    for broken_registration in failed_registration_nodes:
        unacceptable_node_logs_after_date = list(
            broken_registration.registered_from.get_aggregate_logs_queryset(Auth(broken_registration.registered_from.creator))
            .filter(date__gt=broken_registration.registered_date)
            .exclude(action__in=fa.LOG_WHITELIST)
            .exclude(action__in=fa.LOG_GREYLIST)
            .values_list('action', flat=True)
        )

        # Does it have any addons?
        addon_list = [
            addon for addon in ADDONS_REQUESTED
            if broken_registration.registered_from.has_addon(addon)
            and addon not in {'osfstorage', 'wiki'}
        ]
        has_addons = bool(addon_list)

        # Any registrations succeeded after the stuck one?
        # Not sure why broken_registration.registered_from.registrations was always 0 locally...
        succeeded_registrations_after_failed = []
        for other_reg in Registration.find(
            Q('registered_from', 'eq', broken_registration.registered_from) &
            Q('registered_date', 'gt', broken_registration.registered_date)
        ):
            if other_reg.sanction:
                if other_reg.sanction.is_approved:
                    succeeded_registrations_after_failed.append(other_reg._id)
            else:
                succeeded_registrations_after_failed.append(other_reg._id)

        can_be_reset = fa.verify(broken_registration)
        logger.info('Found broken registration {}'.format(broken_registration._id))
        failed_registration_info.append(
            {
                'registration': broken_registration._id,
                'registered_date': broken_registration.registered_date,
                'original_node': broken_registration.registered_from._id,
                'logs_on_original_after_registration_date': unacceptable_node_logs_after_date,
                'has_addons': has_addons,
                'addon_list': addon_list,
                'succeeded_registrations_after_failed': succeeded_registrations_after_failed,
                'can_be_reset': can_be_reset,
                'registered_from_public': broken_registration.registered_from.is_public,
            }
        )

    return failed_registration_info
    def test_register_draft_without_embargo_creates_registration_approval(self, mock_enqueue):
        res = self.app.post(
            self.project.api_url_for('register_draft_registration', draft_id=self.draft._id),
            self.valid_make_public_payload,
            content_type='application/json',
            auth=self.user.auth
        )
        assert_equal(res.status_code, 202)

        registration = Registration.find().order_by('-registered_date').first()
        assert_not_equal(registration.registration_approval, None)
Example #3
0
    def test_register_draft_without_embargo_creates_registration_approval(self, mock_enqueue):
        res = self.app.post(
            self.project.api_url_for('register_draft_registration', draft_id=self.draft._id),
            self.valid_make_public_payload,
            content_type='application/json',
            auth=self.user.auth
        )
        assert_equal(res.status_code, 202)

        registration = Registration.find().order_by('-registered_date').first()
        assert_not_equal(registration.registration_approval, None)
Example #4
0
    def test_register_draft_registration_with_embargo_is_not_public(self, mock_enqueue):
        res = self.app.post_json(
            self.node.api_url_for('register_draft_registration', draft_id=self.draft._id),
            self.embargo_payload,
            auth=self.user.auth
        )

        assert_equal(res.status_code, http.ACCEPTED)

        registration = Registration.find().order_by('-registered_date').first()

        assert_false(registration.is_public)
        assert_true(registration.is_pending_embargo)
        assert_is_not_none(registration.embargo)
Example #5
0
    def test_POST_register_embargo_is_not_public(self, mock_enqueue):
        res = self.app.post(self.project.api_url_for(
            'register_draft_registration', draft_id=self.draft._id),
                            self.valid_embargo_payload,
                            content_type='application/json',
                            auth=self.user.auth)

        assert_equal(res.status_code, 202)

        registration = Registration.find().sort('-registered_date').first()

        assert_false(registration.is_public)
        assert_true(registration.is_pending_embargo_for_existing_registration)
        assert_is_not_none(registration.embargo)
Example #6
0
    def test_register_draft_registration_with_embargo_is_not_public(
            self, mock_enqueue):
        res = self.app.post_json(self.node.api_url_for(
            'register_draft_registration', draft_id=self.draft._id),
                                 self.embargo_payload,
                                 auth=self.user.auth)

        assert_equal(res.status_code, http.ACCEPTED)

        registration = Registration.find().order_by('-registered_date').first()

        assert_false(registration.is_public)
        assert_true(registration.is_pending_embargo)
        assert_is_not_none(registration.embargo)
Example #7
0
    def test_POST_register_embargo_is_not_public(self, mock_enqueue):
        res = self.app.post(
            self.project.api_url_for('register_draft_registration', draft_id=self.draft._id),
            self.valid_embargo_payload,
            content_type='application/json',
            auth=self.user.auth
        )

        assert_equal(res.status_code, 202)

        registration = Registration.find().order_by('-registered_date').first()

        assert_false(registration.is_public)
        assert_true(registration.is_pending_embargo_for_existing_registration)
        assert_is_not_none(registration.embargo)
Example #8
0
 def get_default_queryset(self):
     return Registration.find(self.base_node_query)
Example #9
0
 def get_default_queryset(self):
     return Registration.find(self.base_node_query)
Example #10
0
def analyze_failed_registration_nodes():
    """ If we can just retry the archive, but we can only do that if the
    ORIGINAL node hasn't changed.
    """
    # Get the registrations that are messed up
    failed_registration_nodes = find_failed_registrations()

    # Build up a list of dictionaries with info about these failed nodes
    failed_registration_info = []
    for broken_registration in failed_registration_nodes:
        node_logs_after_date = list(
            broken_registration.registered_from.get_aggregate_logs_queryset(
                Auth(broken_registration.registered_from.creator)).filter(
                    date__gt=broken_registration.registered_date).exclude(
                        action__in=LOG_WHITELIST).values_list('action',
                                                              flat=True))

        # Does it have any addons?
        addon_list = [
            addon for addon in ADDONS_REQUESTED
            if broken_registration.registered_from.has_addon(addon)
            and addon not in {'osfstorage', 'wiki'}
        ]
        has_addons = True if len(addon_list) > 0 else False

        # Any registrations succeeded after the stuck one?
        # Not sure why broken_registration.registered_from.registrations was always 0 locally...
        succeeded_registrations_after_failed = []
        for other_reg in Registration.find(
                Q('registered_from', 'eq', broken_registration.registered_from)
                & Q('registered_date', 'gt',
                    broken_registration.registered_date)):
            if other_reg.sanction:
                if other_reg.sanction.is_approved:
                    succeeded_registrations_after_failed.append(other_reg._id)
            else:
                succeeded_registrations_after_failed.append(other_reg._id)

        can_be_reset = len(node_logs_after_date) == 0 and not has_addons
        logger.info('Found broken registration {}'.format(
            broken_registration._id))
        failed_registration_info.append({
            'registration':
            broken_registration._id,
            'registered_date':
            broken_registration.registered_date,
            'original_node':
            broken_registration.registered_from._id,
            'logs_on_original_after_registration_date':
            node_logs_after_date,
            'has_addons':
            has_addons,
            'addon_list':
            addon_list,
            'succeeded_registrations_after_failed':
            succeeded_registrations_after_failed,
            'can_be_reset':
            can_be_reset,
            'registered_from_public':
            broken_registration.registered_from.is_public,
        })

    return failed_registration_info