Пример #1
0
    def test_allow_deny_access_error(self):
        """Test access rules to share can be created and deleted with error."""
        def _fake_allow_access(self, *args, **kwargs):
            raise exception.NotFound()

        def _fake_deny_access(self, *args, **kwargs):
            raise exception.NotFound()

        self.stubs.Set(FakeShareDriver, "allow_access", _fake_allow_access)
        self.stubs.Set(FakeShareDriver, "deny_access", _fake_deny_access)

        share = self._create_share()
        share_id = share['id']
        access = self._create_access(share_id=share_id)
        access_id = access['id']

        self.assertRaises(exception.NotFound, self.share_manager.allow_access,
                          self.context, access_id)

        acs = db.share_access_get(self.context, access_id)
        self.assertEqual(acs['state'], 'error')

        self.assertRaises(exception.NotFound, self.share_manager.deny_access,
                          self.context, access_id)

        acs = db.share_access_get(self.context, access_id)
        self.assertEqual(acs['state'], 'error')
Пример #2
0
    def test_allow_deny_access_error(self):
        """Test access rules to share can be created and deleted with error."""

        def _fake_allow_access(self, *args, **kwargs):
            raise exception.NotFound()

        def _fake_deny_access(self, *args, **kwargs):
            raise exception.NotFound()

        self.stubs.Set(FakeShareDriver, "allow_access", _fake_allow_access)
        self.stubs.Set(FakeShareDriver, "deny_access", _fake_deny_access)

        share = self._create_share()
        share_id = share['id']
        access = self._create_access(share_id=share_id)
        access_id = access['id']

        self.assertRaises(exception.NotFound,
                          self.share_manager.allow_access,
                          self.context,
                          access_id)

        acs = db.share_access_get(self.context, access_id)
        self.assertEqual(acs['state'], 'error')

        self.assertRaises(exception.NotFound,
                          self.share_manager.deny_access,
                          self.context,
                          access_id)

        acs = db.share_access_get(self.context, access_id)
        self.assertEqual(acs['state'], 'error')
Пример #3
0
 def test_access_get(self):
     self.mox.StubOutWithMock(share_api.policy, 'check_policy')
     share_api.policy.check_policy(self.context, 'share', 'access_get')
     self.mox.StubOutWithMock(db_driver, 'share_access_get')
     db_driver.share_access_get(self.context, 'fakeid').AndReturn('fake')
     self.mox.ReplayAll()
     rule = self.api.access_get(self.context, 'fakeid')
     self.assertEqual(rule, 'fake')
Пример #4
0
 def test_access_get(self):
     self.mox.StubOutWithMock(share_api.policy, "check_policy")
     share_api.policy.check_policy(self.context, "share", "access_get")
     self.mox.StubOutWithMock(db_driver, "share_access_get")
     db_driver.share_access_get(self.context, "fakeid").AndReturn("fake")
     self.mox.ReplayAll()
     rule = self.api.access_get(self.context, "fakeid")
     self.assertEqual(rule, "fake")
Пример #5
0
    def test_allow_deny_access(self):
        """Test access rules to share can be created and deleted."""

        share = self._create_share()
        share_id = share['id']
        access = self._create_access(share_id=share_id)
        access_id = access['id']
        self.share.allow_access(self.context, access_id)
        self.assertEqual('active', db.share_access_get(self.context,
                                                       access_id).state)

        self.share.deny_access(self.context, access_id)
        acs = db.share_access_get(
            context.get_admin_context(read_deleted='yes'),
            access_id)
        self.assertEquals(acs['state'], 'deleted')
        self.assertRaises(exception.NotFound,
                          db.share_access_get,
                          self.context,
                          access_id)
Пример #6
0
    def test_allow_deny_access(self):
        """Test access rules to share can be created and deleted."""
        share = self._create_share()
        share_id = share['id']
        access = self._create_access(share_id=share_id)
        access_id = access['id']
        self.share_manager.allow_access(self.context, access_id)
        self.assertEqual('active',
                         db.share_access_get(self.context, access_id).state)

        self.share_manager.deny_access(self.context, access_id)
        self.assertRaises(exception.NotFound, db.share_access_get,
                          self.context, access_id)
Пример #7
0
    def test_allow_deny_access(self):
        """Test access rules to share can be created and deleted."""
        share = self._create_share()
        share_id = share['id']
        access = self._create_access(share_id=share_id)
        access_id = access['id']
        self.share_manager.allow_access(self.context, access_id)
        self.assertEqual('active', db.share_access_get(self.context,
                                                       access_id).state)

        self.share_manager.deny_access(self.context, access_id)
        self.assertRaises(exception.NotFound,
                          db.share_access_get,
                          self.context,
                          access_id)
Пример #8
0
    def test__update_access_rules_recursive_driver_exception(self, drv_exc):
        other = access.ShareInstanceAccess(db, None)
        share = db_utils.create_share(
            status=constants.STATUS_AVAILABLE,
            access_rules_status=constants.SHARE_INSTANCE_RULES_SYNCING)
        share_instance_id = share['instance']['id']
        rule_4 = []
        get_and_update_count = [1]
        drv_count = [1]

        def _get_and_update_side_effect(*args, **kwargs):
            # The third call to this method needs to create a new access rule
            mtd = other.get_and_update_share_instance_access_rules
            if get_and_update_count[0] == 3:
                rule_4.append(
                    db_utils.create_access(
                        state=constants.ACCESS_STATE_QUEUED_TO_APPLY,
                        share_id=share['id']))
            get_and_update_count[0] += 1
            return mtd(*args, **kwargs)

        def _driver_side_effect(*args, **kwargs):
            if drv_exc and drv_count[0] == 2:
                raise exception.ManilaException('fake')
            drv_count[0] += 1

        rule_kwargs = {'share_id': share['id'], 'access_level': 'rw'}
        rule_1 = db_utils.create_access(state=constants.ACCESS_STATE_APPLYING,
                                        **rule_kwargs)
        rule_2 = db_utils.create_access(state=constants.ACCESS_STATE_ACTIVE,
                                        **rule_kwargs)
        rule_3 = db_utils.create_access(state=constants.ACCESS_STATE_DENYING,
                                        **rule_kwargs)

        self.mock_object(self.access_helper,
                         'get_and_update_share_instance_access_rules',
                         mock.Mock(side_effect=_get_and_update_side_effect))
        self.mock_object(self.access_helper.driver, 'update_access',
                         mock.Mock(side_effect=_driver_side_effect))

        if drv_exc:
            self.assertRaises(exception.ManilaException,
                              self.access_helper._update_access_rules,
                              self.context, share_instance_id)
        else:
            retval = self.access_helper._update_access_rules(self.context,
                                                             share_instance_id)
            self.assertIsNone(retval)

        expected_filters_1 = {
            'state': (constants.ACCESS_STATE_APPLYING,
                      constants.ACCESS_STATE_ACTIVE,
                      constants.ACCESS_STATE_DENYING),
        }
        conditionally_change_2 = {
            constants.ACCESS_STATE_APPLYING: constants.ACCESS_STATE_ACTIVE,
        }
        expected_filters_3 = {
            'state': (constants.ACCESS_STATE_QUEUED_TO_APPLY,
                      constants.ACCESS_STATE_QUEUED_TO_DENY),
        }
        expected_conditionally_change_3 = {
            constants.ACCESS_STATE_QUEUED_TO_APPLY:
                constants.ACCESS_STATE_APPLYING,
            constants.ACCESS_STATE_QUEUED_TO_DENY:
                constants.ACCESS_STATE_DENYING,
        }
        expected_conditionally_change_4 = {
            constants.ACCESS_STATE_APPLYING: constants.ACCESS_STATE_ERROR,
            constants.ACCESS_STATE_DENYING: constants.ACCESS_STATE_ERROR,
        }
        expected_get_and_update_calls = [
            mock.call(self.context, filters=expected_filters_1,
                      share_instance_id=share_instance_id),
            mock.call(self.context, share_instance_id=share_instance_id,
                      conditionally_change=conditionally_change_2),
            mock.call(self.context, filters=expected_filters_3,
                      share_instance_id=share_instance_id,
                      conditionally_change=expected_conditionally_change_3),
            mock.call(self.context, filters=expected_filters_1,
                      share_instance_id=share_instance_id),
        ]

        if drv_exc:
            expected_get_and_update_calls.append(
                mock.call(
                    self.context, share_instance_id=share_instance_id,
                    conditionally_change=expected_conditionally_change_4))
        else:
            expected_get_and_update_calls.append(
                mock.call(self.context, share_instance_id=share_instance_id,
                          conditionally_change=conditionally_change_2))

        # Verify rule changes:
        # 'denying' rule must not exist
        self.assertRaises(exception.NotFound,
                          db.share_access_get,
                          self.context, rule_3['id'])
        # 'applying' rule must be set to 'active'
        rules_that_must_be_active = (rule_1, rule_2)
        if not drv_exc:
            rules_that_must_be_active += (rule_4[0], )
        for rule in rules_that_must_be_active:
            rule = db.share_access_get(self.context, rule['id'])
        self.assertEqual(constants.ACCESS_STATE_ACTIVE,
                         rule['state'])
        # access_rules_status must be as expected
        expected_access_rules_status = (
            constants.SHARE_INSTANCE_RULES_ERROR if drv_exc
            else constants.STATUS_ACTIVE)
        share_instance = db.share_instance_get(self.context, share_instance_id)
        self.assertEqual(
            expected_access_rules_status,
            share_instance['access_rules_status'])
Пример #9
0
    def test__update_access_rules_recursive_driver_exception(self, drv_exc):
        other = access.ShareInstanceAccess(db, None)
        share = db_utils.create_share(
            status=constants.STATUS_AVAILABLE,
            access_rules_status=constants.SHARE_INSTANCE_RULES_SYNCING)
        share_instance_id = share['instance']['id']
        rule_4 = []
        get_and_update_count = [1]
        drv_count = [1]

        def _get_and_update_side_effect(*args, **kwargs):
            # The third call to this method needs to create a new access rule
            mtd = other.get_and_update_share_instance_access_rules
            if get_and_update_count[0] == 3:
                rule_4.append(
                    db_utils.create_access(
                        state=constants.ACCESS_STATE_QUEUED_TO_APPLY,
                        share_id=share['id']))
            get_and_update_count[0] += 1
            return mtd(*args, **kwargs)

        def _driver_side_effect(*args, **kwargs):
            if drv_exc and drv_count[0] == 2:
                raise exception.ManilaException('fake')
            drv_count[0] += 1

        rule_kwargs = {'share_id': share['id'], 'access_level': 'rw'}
        rule_1 = db_utils.create_access(state=constants.ACCESS_STATE_APPLYING,
                                        **rule_kwargs)
        rule_2 = db_utils.create_access(state=constants.ACCESS_STATE_ACTIVE,
                                        **rule_kwargs)
        rule_3 = db_utils.create_access(state=constants.ACCESS_STATE_DENYING,
                                        **rule_kwargs)

        self.mock_object(self.access_helper,
                         'get_and_update_share_instance_access_rules',
                         mock.Mock(side_effect=_get_and_update_side_effect))
        self.mock_object(self.access_helper.driver, 'update_access',
                         mock.Mock(side_effect=_driver_side_effect))

        if drv_exc:
            self.assertRaises(exception.ManilaException,
                              self.access_helper._update_access_rules,
                              self.context, share_instance_id)
        else:
            retval = self.access_helper._update_access_rules(
                self.context, share_instance_id)
            self.assertIsNone(retval)

        expected_filters_1 = {
            'state':
            (constants.ACCESS_STATE_APPLYING, constants.ACCESS_STATE_ACTIVE,
             constants.ACCESS_STATE_DENYING),
        }
        conditionally_change_2 = {
            constants.ACCESS_STATE_APPLYING: constants.ACCESS_STATE_ACTIVE,
        }
        expected_filters_3 = {
            'state': (constants.ACCESS_STATE_QUEUED_TO_APPLY,
                      constants.ACCESS_STATE_QUEUED_TO_DENY),
        }
        expected_conditionally_change_3 = {
            constants.ACCESS_STATE_QUEUED_TO_APPLY:
            constants.ACCESS_STATE_APPLYING,
            constants.ACCESS_STATE_QUEUED_TO_DENY:
            constants.ACCESS_STATE_DENYING,
        }
        expected_conditionally_change_4 = {
            constants.ACCESS_STATE_APPLYING: constants.ACCESS_STATE_ERROR,
            constants.ACCESS_STATE_DENYING: constants.ACCESS_STATE_ERROR,
        }
        expected_get_and_update_calls = [
            mock.call(self.context,
                      filters=expected_filters_1,
                      share_instance_id=share_instance_id),
            mock.call(self.context,
                      share_instance_id=share_instance_id,
                      conditionally_change=conditionally_change_2),
            mock.call(self.context,
                      filters=expected_filters_3,
                      share_instance_id=share_instance_id,
                      conditionally_change=expected_conditionally_change_3),
            mock.call(self.context,
                      filters=expected_filters_1,
                      share_instance_id=share_instance_id),
        ]

        if drv_exc:
            expected_get_and_update_calls.append(
                mock.call(
                    self.context,
                    share_instance_id=share_instance_id,
                    conditionally_change=expected_conditionally_change_4))
        else:
            expected_get_and_update_calls.append(
                mock.call(self.context,
                          share_instance_id=share_instance_id,
                          conditionally_change=conditionally_change_2))

        # Verify rule changes:
        # 'denying' rule must not exist
        self.assertRaises(exception.NotFound, db.share_access_get,
                          self.context, rule_3['id'])
        # 'applying' rule must be set to 'active'
        rules_that_must_be_active = (rule_1, rule_2)
        if not drv_exc:
            rules_that_must_be_active += (rule_4[0], )
        for rule in rules_that_must_be_active:
            rule = db.share_access_get(self.context, rule['id'])
        self.assertEqual(constants.ACCESS_STATE_ACTIVE, rule['state'])
        # access_rules_status must be as expected
        expected_access_rules_status = (constants.SHARE_INSTANCE_RULES_ERROR if
                                        drv_exc else constants.STATUS_ACTIVE)
        share_instance = db.share_instance_get(self.context, share_instance_id)
        self.assertEqual(expected_access_rules_status,
                         share_instance['access_rules_status'])