Ejemplo n.º 1
0
    def _change_data_access_to_instance(self,
                                        instance,
                                        accesses=None,
                                        deny=False):

        self.access_helper.get_and_update_share_instance_access_rules_status(
            self.context,
            status=constants.SHARE_INSTANCE_RULES_SYNCING,
            share_instance_id=instance['id'])

        if deny:
            if accesses is None:
                accesses = []
            else:
                if not isinstance(accesses, list):
                    accesses = [accesses]

            access_filters = {'access_id': [a['id'] for a in accesses]}
            updates = {'state': constants.ACCESS_STATE_QUEUED_TO_DENY}
            self.access_helper.get_and_update_share_instance_access_rules(
                self.context,
                filters=access_filters,
                updates=updates,
                share_instance_id=instance['id'])

        self.share_rpc.update_access(self.context, instance)

        utils.wait_for_access_update(self.context, self.db, instance,
                                     self.wait_access_rules_timeout)
Ejemplo n.º 2
0
    def revert_access_rules(self, share_instances, share_server,
                            dest_host=None):
        shares_instance_ids = []
        for share_instance in share_instances:
            # Cast all rules to 'queued_to_apply' so that they can be
            # re-applied.
            shares_instance_ids.append(share_instance['id'])
            updates = {'state': constants.ACCESS_STATE_QUEUED_TO_APPLY}
            self.access_helper.get_and_update_share_instance_access_rules(
                self.context, updates=updates,
                share_instance_id=share_instance['id'])

        if dest_host:
            rpcapi = share_rpcapi.ShareAPI()
            rpcapi.update_access_for_instances(self.context, dest_host,
                                               shares_instance_ids,
                                               share_server)
        else:
            for share_instance in share_instances:
                self.access_helper.update_access_rules(
                    self.context, share_instance['id'],
                    share_server=share_server)

        for share_instance in share_instances:
            utils.wait_for_access_update(
                self.context, self.db, share_instance,
                self.migration_wait_access_rules_timeout)
Ejemplo n.º 3
0
    def apply_new_access_rules(self, new_share_instance):

        rules = self.db.share_instance_access_copy(
            self.context, self.share['id'], new_share_instance['id'])

        if rules:
            self.api.allow_access_to_instance(self.context, new_share_instance)

            utils.wait_for_access_update(
                self.context, self.db, new_share_instance,
                self.migration_wait_access_rules_timeout)
        else:
            LOG.debug("No access rules to sync to destination share instance.")
Ejemplo n.º 4
0
    def apply_new_access_rules(self, new_share_instance, share_id):

        rules = self.db.share_instance_access_copy(
            self.context, share_id, new_share_instance['id'])

        if rules:
            self.api.allow_access_to_instance(self.context, new_share_instance)

            utils.wait_for_access_update(
                self.context, self.db, new_share_instance,
                self.migration_wait_access_rules_timeout)
        else:
            LOG.debug("No access rules to sync to destination share instance.")
Ejemplo n.º 5
0
    def _change_data_access_to_instance(
            self, instance, access_ref, allow=False):

        self.db.share_instance_update_access_status(
            self.context, instance['id'], constants.STATUS_OUT_OF_SYNC)

        if allow:
            self.share_rpc.allow_access(self.context, instance, access_ref)
        else:
            self.share_rpc.deny_access(self.context, instance, access_ref)

        utils.wait_for_access_update(
            self.context, self.db, instance, self.wait_access_rules_timeout)
Ejemplo n.º 6
0
    def revert_access_rules(self, share_instance, share_server):

        # Cast all rules to 'queued_to_apply' so that they can be re-applied.
        updates = {'state': constants.ACCESS_STATE_QUEUED_TO_APPLY}
        self.access_helper.get_and_update_share_instance_access_rules(
            self.context, updates=updates,
            share_instance_id=share_instance['id'])

        self.access_helper.update_access_rules(
            self.context, share_instance['id'], share_server=share_server)

        utils.wait_for_access_update(
            self.context, self.db, share_instance,
            self.migration_wait_access_rules_timeout)
Ejemplo n.º 7
0
    def revert_access_rules(self, share_instance, share_server):

        # Cast all rules to 'queued_to_apply' so that they can be re-applied.
        updates = {'state': constants.ACCESS_STATE_QUEUED_TO_APPLY}
        self.access_helper.get_and_update_share_instance_access_rules(
            self.context,
            updates=updates,
            share_instance_id=share_instance['id'])

        self.access_helper.update_access_rules(self.context,
                                               share_instance['id'],
                                               share_server=share_server)

        utils.wait_for_access_update(self.context, self.db, share_instance,
                                     self.migration_wait_access_rules_timeout)
Ejemplo n.º 8
0
    def _change_data_access_to_instance(self,
                                        instance,
                                        access_ref,
                                        allow=False):

        self.db.share_instance_update_access_status(
            self.context, instance['id'], constants.STATUS_OUT_OF_SYNC)

        if allow:
            self.share_rpc.allow_access(self.context, instance, access_ref)
        else:
            self.share_rpc.deny_access(self.context, instance, access_ref)

        utils.wait_for_access_update(self.context, self.db, instance,
                                     self.wait_access_rules_timeout)
Ejemplo n.º 9
0
    def apply_new_access_rules(self, new_share_instance):

        self.db.share_instance_access_copy(self.context, self.share['id'],
                                           new_share_instance['id'])

        rules = self.db.share_access_get_all_for_instance(
            self.context, new_share_instance['id'])

        if len(rules) > 0:
            LOG.debug("Restoring all of share %s access rules according to "
                      "DB.", self.share['id'])

            self.api.allow_access_to_instance(self.context, new_share_instance,
                                              rules)
            utils.wait_for_access_update(
                self.context, self.db, new_share_instance,
                self.migration_wait_access_rules_timeout)
Ejemplo n.º 10
0
    def test_wait_for_access_update(self):
        sid = 1
        fake_share_instances = [
            {'id': sid, 'access_rules_status': constants.STATUS_OUT_OF_SYNC},
            {'id': sid, 'access_rules_status': constants.STATUS_ACTIVE},
        ]

        self.mock_object(time, 'sleep')
        self.mock_object(db, 'share_instance_get',
                         mock.Mock(side_effect=fake_share_instances))

        utils.wait_for_access_update(self.context, db,
                                     fake_share_instances[0], 1)

        db.share_instance_get.assert_has_calls(
            [mock.call(mock.ANY, sid), mock.call(mock.ANY, sid)]
        )
        time.sleep.assert_called_once_with(1)
Ejemplo n.º 11
0
    def test_wait_for_access_update(self):
        sid = 1
        fake_share_instances = [
            {'id': sid, 'access_rules_status': constants.STATUS_OUT_OF_SYNC},
            {'id': sid, 'access_rules_status': constants.STATUS_ACTIVE},
        ]

        self.mock_object(time, 'sleep')
        self.mock_object(db, 'share_instance_get',
                         mock.Mock(side_effect=fake_share_instances))

        utils.wait_for_access_update(self.context, db,
                                     fake_share_instances[0], 1)

        db.share_instance_get.assert_has_calls(
            [mock.call(mock.ANY, sid), mock.call(mock.ANY, sid)]
        )
        time.sleep.assert_called_once_with(1)
Ejemplo n.º 12
0
    def _change_data_access_to_instance(self, instance, accesses, deny=False):
        if not isinstance(accesses, list):
            accesses = [accesses]

        self.access_helper.get_and_update_share_instance_access_rules_status(
            self.context, status=constants.SHARE_INSTANCE_RULES_SYNCING,
            share_instance_id=instance['id'])

        if deny:
            access_filters = {'access_id': [a['id'] for a in accesses]}
            updates = {'state': constants.ACCESS_STATE_QUEUED_TO_DENY}
            self.access_helper.get_and_update_share_instance_access_rules(
                self.context, filters=access_filters, updates=updates,
                share_instance_id=instance['id'])

        self.share_rpc.update_access(self.context, instance)

        utils.wait_for_access_update(
            self.context, self.db, instance, self.wait_access_rules_timeout)