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

        self.stubs.Set(self.share_manager.driver, "create_share",
                       mock.Mock(side_effect=_raise_not_found))
        self.stubs.Set(self.share_manager.driver, "delete_share",
                       mock.Mock(side_effect=_raise_not_found))

        share = self._create_share()
        share_id = share['id']
        self.assertRaises(exception.NotFound, self.share_manager.create_share,
                          self.context, share_id)

        shr = db.share_get(self.context, share_id)
        self.assertEqual(shr['status'], 'error')
        self.assertRaises(exception.NotFound, self.share_manager.delete_share,
                          self.context, share_id)

        shr = db.share_get(self.context, share_id)
        self.assertEqual(shr['status'], 'error_deleting')
        self.share_manager.driver.create_share.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            utils.IsAMatcher(models.Share),
            share_server=None)
        self.share_manager.driver.delete_share.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            utils.IsAMatcher(models.Share),
            share_server=None)
Пример #2
0
    def test_deny_access_access_rule_not_found(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        access = db_utils.create_snapshot_access(
            share_snapshot_id=snapshot['id'])
        wrong_access = {
            'access_type': 'fake_type',
            'access_to': 'fake_IP',
            'share_snapshot_id': 'fake_id'
        }

        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        access_get = self.mock_object(share_api.API, 'snapshot_access_get',
                                      mock.Mock(return_value=wrong_access))

        body = {'deny_access': {'access_id': access.id}}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.deny_access, req, snapshot['id'],
                          body)
        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        access_get.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            body['deny_access']['access_id'])
Пример #3
0
    def test_allow_access(self, ip_address, version):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])

        access = {
            'id': 'fake_id',
            'access_type': 'ip',
            'access_to': ip_address,
            'state': 'new',
        }

        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        allow_access = self.mock_object(share_api.API, 'snapshot_allow_access',
                                        mock.Mock(return_value=access))
        body = {'allow_access': access}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version=version)

        actual = self.controller.allow_access(req, snapshot['id'], body)

        self.assertEqual(access, actual['snapshot_access'])
        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        allow_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot,
            access['access_type'], access['access_to'])
Пример #4
0
    def test_allow_access_exists_exception(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')
        access = {
            'id': 'fake_id',
            'access_type': 'ip',
            'access_to': '1.1.1.1',
            'state': 'new',
        }
        msg = "Share snapshot access exists."

        get = self.mock_object(share_api.API, 'get', mock.Mock(
            return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        allow_access = self.mock_object(
            share_api.API, 'snapshot_allow_access', mock.Mock(
                side_effect=exception.ShareSnapshotAccessExists(msg)))

        body = {'allow_access': access}

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.allow_access, req,
                          snapshot['id'], body)

        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        allow_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot,
            access['access_type'], access['access_to'])
Пример #5
0
    def test_allow_access_share_without_mount_snap_support(self):
        share = db_utils.create_share(mount_snapshot_support=False)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])

        access = {
            'id': 'fake_id',
            'access_type': 'ip',
            'access_to': '1.1.1.1',
            'state': 'new',
        }

        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))

        body = {'allow_access': access}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.allow_access, req,
                          snapshot['id'], body)

        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
Пример #6
0
    def test_infinite_retry(self):
        retry_param = exception.ManilaException

        class FakeTenacityRetry(tenacity.Retrying):
            def __init__(*args, **kwargs):
                pass

        with mock.patch('tenacity.Retrying',
                        autospec=FakeTenacityRetry) as tenacity_retry:

            @utils.retry(retry_param=retry_param,
                         wait_random=True,
                         infinite=True)
            def some_retriable_function():
                pass

            some_retriable_function()

            tenacity_retry.assert_called_once_with(
                sleep=tenacity.nap.sleep,
                before_sleep=mock.ANY,
                after=mock.ANY,
                stop=tenacity.stop.stop_never,
                reraise=True,
                retry=utils.IsAMatcher(tenacity.retry_if_exception_type),
                wait=utils.IsAMatcher(tenacity.wait_random_exponential))
Пример #7
0
    def test_deny_access(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        access = db_utils.create_snapshot_access(
            share_snapshot_id=snapshot['id'])

        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        access_get = self.mock_object(share_api.API, 'snapshot_access_get',
                                      mock.Mock(return_value=access))
        deny_access = self.mock_object(share_api.API, 'snapshot_deny_access')

        body = {'deny_access': {'access_id': access.id}}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        resp = self.controller.deny_access(req, snapshot['id'], body)

        self.assertEqual(202, resp.status_int)
        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        access_get.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            body['deny_access']['access_id'])
        deny_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot, access)
Пример #8
0
    def test_create_share_with_server_created(self):
        """Test share can be created and share server is created."""
        share_net = self._create_share_network()
        share = self._create_share(share_network_id=share_net['id'])
        self._create_share_server(share_network_id=share_net['id'],
                                  host=self.share_manager.host,
                                  state='ERROR')
        share_id = share['id']
        fake_server = {'id': 'fake_srv_id'}
        self.stubs.Set(db, 'share_server_create',
                       mock.Mock(return_value=fake_server))
        self.stubs.Set(self.share_manager, '_setup_server',
                       mock.Mock(return_value=fake_server))

        self.share_manager.create_share(self.context, share_id)

        self.assertEqual(
            share_id,
            db.share_get(context.get_admin_context(), share_id).id)
        shr = db.share_get(self.context, share_id)
        self.assertEqual(shr['status'], 'available')
        self.assertEqual(shr['share_server_id'], 'fake_srv_id')
        db.share_server_create.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), mock.ANY)
        self.share_manager._setup_server.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), fake_server)
Пример #9
0
 def test_create_share_availability_zone(self):
     share_id = 'fake'
     fake_share = {
         'id': share_id,
         'availability_zone': 'fake:fake',
         'size': 1,
     }
     fake_service_1 = {
         'disabled': False, 'host': 'fake_host1',
         'availability_zone': 'fake',
     }
     fake_service_2 = {
         'disabled': False, 'host': 'fake_host2',
         'availability_zone': 'super_fake',
     }
     fake_result = [(fake_service_1, 0), (fake_service_2, 1)]
     fake_request_spec = {
         'share_id': share_id,
         'share_properties': fake_share,
     }
     with mock.patch.object(db, 'service_get_all_share_sorted',
                            mock.Mock(return_value=fake_result)):
         with mock.patch.object(driver, 'share_update_db',
                                mock.Mock(return_value=fake_share)):
             self.driver.schedule_create_share(self.context,
                                               fake_request_spec, {})
             utils.service_is_up.assert_called_once_with(fake_service_1)
             driver.share_update_db.assert_called_once_with(
                 utils.IsAMatcher(context.RequestContext), share_id,
                 fake_service_1['host'])
             db.service_get_all_share_sorted.assert_called_once_with(
                 utils.IsAMatcher(context.RequestContext))
Пример #10
0
    def test_update_access_rules(self, state):

        rules = []
        for i in range(2):
            rules.append({
                'id': 'id-%s' % i,
                'state': state,
                'access_id': 'rule_id%s' % i
            })
        all_rules = copy.deepcopy(rules)
        all_rules.append({
            'id': 'id-3',
            'state': constants.ACCESS_STATE_ERROR,
            'access_id': 'rule_id3'
        })

        snapshot_instance_get = self.mock_object(
            db, 'share_snapshot_instance_get',
            mock.Mock(return_value=self.snapshot_instance))

        snap_get_all_for_snap_instance = self.mock_object(
            db, 'share_snapshot_access_get_all_for_snapshot_instance',
            mock.Mock(return_value=all_rules))

        self.mock_object(db, 'share_snapshot_instance_access_update')
        self.mock_object(self.driver, 'snapshot_update_access')
        self.mock_object(self.snapshot_access, '_check_needs_refresh',
                         mock.Mock(return_value=False))
        self.mock_object(db, 'share_snapshot_instance_access_delete')

        self.snapshot_access.update_access_rules(self.context,
                                                 self.snapshot_instance['id'])

        snapshot_instance_get.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            self.snapshot_instance['id'],
            with_share_data=True)
        snap_get_all_for_snap_instance.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            self.snapshot_instance['id'])
        if state == constants.ACCESS_STATE_QUEUED_TO_APPLY:
            self.driver.snapshot_update_access.assert_called_once_with(
                utils.IsAMatcher(context.RequestContext),
                self.snapshot_instance,
                rules,
                add_rules=rules,
                delete_rules=[],
                share_server=None)
        else:
            self.driver.snapshot_update_access.assert_called_once_with(
                utils.IsAMatcher(context.RequestContext),
                self.snapshot_instance, [],
                add_rules=[],
                delete_rules=rules,
                share_server=None)
Пример #11
0
    def test_init_host_with_no_shares(self):
        self.stubs.Set(self.share_manager.db, 'share_get_all_by_host',
                       mock.Mock(return_value=[]))

        self.share_manager.init_host()

        self.share_manager.db.share_get_all_by_host.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), self.share_manager.host)
        self.share_manager.driver.do_setup.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext))
        self.share_manager.driver.check_for_setup_error.\
            assert_called_once_with()
Пример #12
0
    def test_create_share_with_share_network_server_creation_failed(self):
        fake_share = {'id': 'fake_share_id', 'share_network_id': 'fake_sn_id'}
        fake_server = {'id': 'fake_srv_id'}
        self.stubs.Set(db, 'share_server_create',
                       mock.Mock(return_value=fake_server))
        self.stubs.Set(db, 'share_update', mock.Mock(return_value=fake_share))
        self.stubs.Set(db, 'share_get', mock.Mock(return_value=fake_share))

        def raise_share_server_not_found(*args, **kwargs):
            raise exception.ShareServerNotFound(
                share_server_id=fake_server['id'])

        def raise_manila_exception(*args, **kwargs):
            raise exception.ManilaException()

        self.stubs.Set(db, 'share_server_get_by_host_and_share_net_valid',
                       mock.Mock(side_effect=raise_share_server_not_found))
        self.stubs.Set(self.share_manager, '_setup_server',
                       mock.Mock(side_effect=raise_manila_exception))

        self.assertRaises(
            exception.ManilaException,
            self.share_manager.create_share,
            self.context,
            fake_share['id'],
        )
        db.share_server_get_by_host_and_share_net_valid.\
            assert_called_once_with(
                utils.IsAMatcher(context.RequestContext),
                self.share_manager.host,
                fake_share['share_network_id'],
            )
        db.share_server_create.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), mock.ANY)
        db.share_update.assert_has_calls([
            mock.call(
                utils.IsAMatcher(context.RequestContext),
                fake_share['id'],
                {'share_server_id': fake_server['id']},
            ),
            mock.call(
                utils.IsAMatcher(context.RequestContext),
                fake_share['id'],
                {'status': 'error'},
            )
        ])
        self.share_manager._setup_server.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), fake_server)
Пример #13
0
    def test_delete_share_type_quota(self):
        req = self._get_share_type_request_object('2.39')
        self.mock_object(quota_sets.QUOTAS, 'destroy_all_by_project')
        self.mock_object(quota_sets.QUOTAS, 'destroy_all_by_project_and_user')
        mock_delete_st_quotas = self.mock_object(
            quota_sets.QUOTAS, 'destroy_all_by_project_and_share_type')
        self.mock_object(
            quota_sets.db, 'share_type_get_by_name_or_id',
            mock.Mock(return_value={
                'id': 'fake_st_id',
                'name': 'fake_st_name'
            }))

        result = self.controller.delete(req, self.project_id)

        self.assertEqual(utils.IsAMatcher(webob.response.Response), result)
        self.assertTrue(hasattr(result, 'status_code'))
        self.assertEqual(202, result.status_code)
        mock_delete_st_quotas.assert_called_once_with(
            req.environ['manila.context'], self.project_id, 'fake_st_id')
        quota_sets.QUOTAS.destroy_all_by_project.assert_not_called()
        quota_sets.QUOTAS.destroy_all_by_project_and_user.assert_not_called()
        self.mock_policy_check.assert_called_once_with(
            req.environ['manila.context'], self.resource_name, 'delete')
        quota_sets.db.share_type_get_by_name_or_id.assert_called_once_with(
            req.environ['manila.context'],
            req.environ['QUERY_STRING'].split('=')[-1])
Пример #14
0
    def test_vserver_create_if_not_exists_3(self):
        # server does not exist, lifs ok, one sec service
        network_info = copy.deepcopy(self.network_info)
        network_info['security_services'] = self.network_info[
            'security_services'][0]
        nodes = [
            'fake_node_1',
            'fake_node_2',
        ]
        port = 'fake_port'
        ip1 = network_info['network_allocations'][0]['ip_address']
        ip2 = network_info['network_allocations'][1]['ip_address']
        vserver_name = \
            self.driver.configuration.netapp_vserver_name_template % \
            network_info['server_id']
        self.stubs.Set(self.driver.db, 'share_server_backend_details_set',
                       mock.Mock())
        self.stubs.Set(self.driver, '_vserver_exists',
                       mock.Mock(return_value=False))
        self.stubs.Set(self.driver, '_create_vserver', mock.Mock())
        self.stubs.Set(self.driver, '_get_cluster_nodes',
                       mock.Mock(return_value=nodes))
        self.stubs.Set(self.driver, '_get_node_data_port',
                       mock.Mock(return_value=port))
        self.stubs.Set(self.driver, '_create_lif_if_not_exists', mock.Mock())
        self.stubs.Set(self.driver, '_enable_nfs', mock.Mock())
        self.stubs.Set(self.driver, '_setup_security_services', mock.Mock())

        returned_data = self.driver._vserver_create_if_not_exists(network_info)

        self.assertEqual(returned_data, vserver_name)
        self.driver.db.share_server_backend_details_set.assert_has_calls([
            mock.call(utils.IsAMatcher(context.RequestContext),
                      self.network_info['server_id'],
                      {'vserver_name': vserver_name}),
        ])
        self.driver._vserver_exists.assert_has_calls([mock.call(vserver_name)])
        self.driver._create_vserver.assert_has_calls([mock.call(vserver_name)])
        self.driver._get_cluster_nodes.assert_has_calls([])
        self.driver._get_node_data_port.assert_has_calls([
            mock.call(nodes[0]),
            mock.call(nodes[1]),
        ])
        self.driver._create_lif_if_not_exists.assert_has_calls([
            mock.call(vserver_name,
                      network_info['network_allocations'][0]['id'],
                      network_info['segmentation_id'], nodes[0], port, ip1,
                      '255.255.255.0', mock.ANY),
            mock.call(vserver_name,
                      network_info['network_allocations'][1]['id'],
                      network_info['segmentation_id'], nodes[1], port, ip2,
                      '255.255.255.0', mock.ANY),
        ])
        self.driver._enable_nfs.assert_has_calls([mock.call(mock.ANY)])
        self.driver._setup_security_services.assert_has_calls([
            mock.call(network_info.get('security_services'), mock.ANY,
                      vserver_name),
        ])
Пример #15
0
    def test_init_host(self, status):

        share = db_utils.create_share(task_state=status)

        # mocks
        self.mock_object(db, 'share_get_all', mock.Mock(return_value=[share]))
        self.mock_object(db, 'share_update')

        # run
        self.manager.init_host()

        # asserts
        db.share_get_all.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext))

        db.share_update.assert_called_with(
            utils.IsAMatcher(context.RequestContext), share['id'],
            {'task_state': constants.TASK_STATE_DATA_COPYING_ERROR})
Пример #16
0
    def test_delete_share_if_busy(self):
        """Test snapshot could not be deleted if busy."""
        def _raise_share_snapshot_is_busy(self, *args, **kwargs):
            raise exception.ShareSnapshotIsBusy(snapshot_name='fakename')

        self.stubs.Set(self.share_manager.driver, "delete_snapshot",
                       mock.Mock(side_effect=_raise_share_snapshot_is_busy))
        share = self._create_share(status='ACTIVE')
        snapshot = self._create_snapshot(share_id=share['id'])
        snapshot_id = snapshot['id']

        self.share_manager.delete_snapshot(self.context, snapshot_id)

        snap = db.share_snapshot_get(self.context, snapshot_id)
        self.assertEqual(snap['status'], 'available')
        self.share_manager.driver.delete_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            utils.IsAMatcher(models.ShareSnapshot),
            share_server=None)
Пример #17
0
    def test_update_access_rules_exception(self):

        rules = []
        for i in range(2):
            rules.append({
                'id': 'id-%s' % i,
                'state': constants.ACCESS_STATE_APPLYING,
                'access_id': 'rule_id%s' % i
            })

        snapshot_instance_get = self.mock_object(
            db, 'share_snapshot_instance_get',
            mock.Mock(return_value=self.snapshot_instance))

        snap_get_all_for_snap_instance = self.mock_object(
            db, 'share_snapshot_access_get_all_for_snapshot_instance',
            mock.Mock(return_value=rules))

        self.mock_object(db, 'share_snapshot_instance_access_update')
        self.mock_object(self.driver, 'snapshot_update_access',
                         mock.Mock(side_effect=exception.NotFound))

        self.assertRaises(exception.NotFound,
                          self.snapshot_access.update_access_rules,
                          self.context, self.snapshot_instance['id'])

        snapshot_instance_get.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            self.snapshot_instance['id'],
            with_share_data=True)
        snap_get_all_for_snap_instance.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            self.snapshot_instance['id'])

        self.driver.snapshot_update_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            self.snapshot_instance,
            rules,
            add_rules=rules,
            delete_rules=[],
            share_server=None)
Пример #18
0
    def test_periodic_tasks(self, raise_on_error):
        serv = service.Service(host, binary, topic, CONF.fake_manager)
        self.mock_object(context, 'get_admin_context',
                         mock.Mock(side_effect=context.get_admin_context))
        self.mock_object(serv.manager, 'periodic_tasks')

        serv.periodic_tasks(raise_on_error=raise_on_error)

        context.get_admin_context.assert_called_once_with()
        serv.manager.periodic_tasks.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            raise_on_error=raise_on_error)
Пример #19
0
    def test_create_share_if_two_services_up(self):
        share_id = 'fake'
        fake_share = {'id': share_id, 'size': 1}
        fake_service_1 = {'disabled': False, 'host': 'fake_host1'}
        fake_service_2 = {'disabled': False, 'host': 'fake_host2'}
        fake_result = [(fake_service_1, 2), (fake_service_2, 1)]
        fake_request_spec = {
            'share_id': share_id,
            'share_properties': fake_share,
        }
        self.mock_object(db, 'service_get_all_share_sorted',
                         mock.Mock(return_value=fake_result))
        self.mock_object(base, 'share_update_db',
                         mock.Mock(return_value=db_utils.create_share()))

        self.driver.schedule_create_share(self.context, fake_request_spec, {})
        utils.service_is_up.assert_called_once_with(utils.IsAMatcher(dict))
        db.service_get_all_share_sorted.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext))
        base.share_update_db.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), share_id, 'fake_host1')
Пример #20
0
    def test_update_access_rules_delete_all_rules(self):

        rules = []
        for i in range(2):
            rules.append({
                'id': 'id-%s' % i,
                'state': constants.ACCESS_STATE_QUEUED_TO_DENY,
                'access_id': 'rule_id%s' % i
            })

        snapshot_instance_get = self.mock_object(
            db, 'share_snapshot_instance_get',
            mock.Mock(return_value=self.snapshot_instance))

        snap_get_all_for_snap_instance = self.mock_object(
            db, 'share_snapshot_access_get_all_for_snapshot_instance',
            mock.Mock(side_effect=[rules, []]))

        self.mock_object(db, 'share_snapshot_instance_access_update')
        self.mock_object(self.driver, 'snapshot_update_access')
        self.mock_object(db, 'share_snapshot_instance_access_delete')

        self.snapshot_access.update_access_rules(self.context,
                                                 self.snapshot_instance['id'],
                                                 delete_all_rules=True)

        snapshot_instance_get.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            self.snapshot_instance['id'],
            with_share_data=True)
        snap_get_all_for_snap_instance.assert_called_with(
            utils.IsAMatcher(context.RequestContext),
            self.snapshot_instance['id'])
        self.driver.snapshot_update_access.assert_called_with(
            utils.IsAMatcher(context.RequestContext),
            self.snapshot_instance, [],
            add_rules=[],
            delete_rules=rules,
            share_server=None)
Пример #21
0
    def test_init_host_with_shares_and_rules(self):

        # initialisation of test data
        def raise_share_access_exists(*args, **kwargs):
            raise exception.ShareAccessExists(
                access_type='fake_access_type', access='fake_access')

        shares = [
            {'id': 'fake_id_1', 'status': 'available', },
            {'id': 'fake_id_2', 'status': 'error', 'name': 'fake_name_2'},
            {'id': 'fake_id_3', 'status': 'in-use', 'name': 'fake_name_3'},
        ]
        rules = [
            FakeAccessRule(state='active'),
            FakeAccessRule(state='error'),
        ]
        share_server = 'fake_share_server_type_does_not_matter'
        self.stubs.Set(self.share_manager.db,
                       'share_get_all_by_host',
                       mock.Mock(return_value=shares))
        self.stubs.Set(self.share_manager.driver, 'ensure_share', mock.Mock())
        self.stubs.Set(self.share_manager, '_get_share_server',
                       mock.Mock(return_value=share_server))
        self.stubs.Set(self.share_manager, 'publish_service_capabilities',
                       mock.Mock())
        self.stubs.Set(self.share_manager.db, 'share_access_get_all_for_share',
                       mock.Mock(return_value=rules))
        self.stubs.Set(self.share_manager.driver, 'allow_access',
                       mock.Mock(side_effect=raise_share_access_exists))

        # call of 'init_host' method
        self.share_manager.init_host()

        # verification of call
        self.share_manager.db.share_get_all_by_host.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), self.share_manager.host)
        self.share_manager.driver.do_setup.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext))
        self.share_manager.driver.check_for_setup_error.\
            assert_called_once_with()
        self.share_manager._get_share_server.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), shares[0])
        self.share_manager.driver.ensure_share.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), shares[0],
            share_server=share_server)
        self.share_manager.db.share_access_get_all_for_share.\
            assert_called_once_with(
                utils.IsAMatcher(context.RequestContext), shares[0]['id'])
        self.share_manager.publish_service_capabilities.\
            assert_called_once_with(
                utils.IsAMatcher(context.RequestContext))
        self.share_manager.driver.allow_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), shares[0], rules[0],
            share_server=share_server)
Пример #22
0
    def test_share_create_with_valid_default_share_type(self):
        self.mock_object(share_types, 'get_share_type_by_name',
                         mock.Mock(return_value=self.vt))
        CONF.set_default("default_share_type", self.vt['name'])
        self.mock_object(share_api.API, 'create', self.create_mock)

        body = {"share": copy.deepcopy(self.share)}
        req = fakes.HTTPRequest.blank('/shares')
        res_dict = self.controller.create(req, body)

        expected = self._get_expected_share_detailed_response(self.share)
        share_types.get_share_type_by_name.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), self.vt['name'])
        self.assertEqual(expected, res_dict)
Пример #23
0
 def test_create_share_availability_zone_on_host(self):
     share_id = 'fake'
     fake_share = {
         'id': share_id,
         'availability_zone': 'fake:fake',
         'size': 1,
     }
     fake_request_spec = {
         'share_id': share_id,
         'share_properties': fake_share,
     }
     with mock.patch.object(db, 'service_get_by_args',
                            mock.Mock(return_value='fake_service')):
         with mock.patch.object(driver, 'share_update_db',
                                mock.Mock(return_value=fake_share)):
             self.driver.schedule_create_share(self.admin_context,
                                               fake_request_spec, {})
             utils.service_is_up.assert_called_once_with('fake_service')
             db.service_get_by_args.assert_called_once_with(
                 utils.IsAMatcher(context.RequestContext),
                 'fake', 'manila-share')
             driver.share_update_db.assert_called_once_with(
                 utils.IsAMatcher(context.RequestContext), share_id, 'fake')
Пример #24
0
    def test_create_share_availability_zone_on_host(self):
        share_id = 'fake'
        fake_share = {
            'id': share_id,
            'availability_zone': 'fake:fake',
            'size': 1,
        }
        fake_service = {'disabled': False, 'host': 'fake'}
        fake_request_spec = {
            'share_id': share_id,
            'share_properties': fake_share,
        }
        self.mock_object(db, 'service_get_all_share_sorted',
                         mock.Mock(return_value=[(fake_service, 1)]))
        self.mock_object(base, 'share_update_db',
                         mock.Mock(return_value=db_utils.create_share()))

        self.driver.schedule_create_share(self.admin_context,
                                          fake_request_spec, {})
        utils.service_is_up.assert_called_once_with(fake_service)
        db.service_get_all_share_sorted.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext))
        base.share_update_db.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), share_id, 'fake')
Пример #25
0
 def test_create_share_if_services_not_available(self):
     share_id = 'fake'
     fake_share = {'id': share_id, 'size': 1}
     fake_result = []
     fake_request_spec = {
         'share_id': share_id,
         'share_properties': fake_share,
     }
     with mock.patch.object(db, 'service_get_all_share_sorted',
                            mock.Mock(return_value=fake_result)):
         self.assertRaises(exception.NoValidHost,
                           self.driver.schedule_create_share,
                           self.context, fake_request_spec, {})
         db.service_get_all_share_sorted.assert_called_once_with(
             utils.IsAMatcher(context.RequestContext))
Пример #26
0
    def test_share_server_migration_cancel(self):
        server = db_utils.create_share_server(id='fake_server_id',
                                              status=constants.STATUS_ACTIVE)
        req = self._get_server_migration_request(server['id'])
        context = req.environ['manila.context']

        body = {'migration_cancel': None}

        self.mock_object(db_api, 'share_server_get',
                         mock.Mock(return_value=server))
        self.mock_object(share_api.API, 'share_server_migration_cancel')

        self.controller.share_server_migration_cancel(req, server['id'], body)

        share_api.API.share_server_migration_cancel.assert_called_once_with(
            utils.IsAMatcher(ctx_api.RequestContext), server)
        db_api.share_server_get.assert_called_once_with(context, server['id'])
Пример #27
0
    def test_share_create_with_valid_default_share_type(self):
        self.mock_object(share_types, 'get_share_type_by_name',
                         mock.Mock(return_value=self.vt))
        CONF.set_default("default_share_type", self.vt['name'])
        self.mock_object(share_api.API, 'create', self.create_mock)

        body = {"share": copy.deepcopy(self.share)}
        req = fakes.HTTPRequest.blank('/v1/fake/shares')
        res_dict = self.controller.create(req, body)

        self.mock_policy_check.assert_called_once_with(
            req.environ['manila.context'], self.resource_name, 'create')
        expected = self._get_expected_share_detailed_response(self.share)
        expected['share'].pop('snapshot_support')
        share_types.get_share_type_by_name.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), self.vt['name'])
        self.assertEqual(expected, res_dict)
Пример #28
0
    def test_reset_task_state(self, task_state):
        server = db_utils.create_share_server(
            id='fake_server_id', status=constants.STATUS_ACTIVE)
        req = self._get_server_migration_request(server['id'])

        update = {'task_state': task_state}
        body = {'reset_task_state': update}

        self.mock_object(db_api, 'share_server_update')

        response = self.controller.share_server_reset_task_state(
            req, server['id'], body)

        self.assertEqual(202, response.status_int)

        db_api.share_server_update.assert_called_once_with(utils.IsAMatcher(
            ctx_api.RequestContext), server['id'], update)
Пример #29
0
    def test_delete_user_quota(self):
        project_id = 'foo_project_id'
        self.mock_object(quota_sets.QUOTAS, 'destroy_all_by_project_and_user')
        self.mock_object(quota_sets.QUOTAS, 'destroy_all_by_project')
        req = _get_request(True, True)

        result = self.controller.delete(req, project_id)

        self.assertTrue(utils.IsAMatcher(webob.response.Response) == result)
        self.assertTrue(hasattr(result, 'status_code'))
        self.assertEqual(202, result.status_code)
        (quota_sets.QUOTAS.destroy_all_by_project_and_user.
         assert_called_once_with(req.environ['manila.context'], project_id,
                                 req.environ['manila.context'].user_id))
        self.assertFalse(quota_sets.QUOTAS.destroy_all_by_project.called)
        self.mock_policy_check.assert_called_once_with(
            req.environ['manila.context'], self.resource_name, 'delete')
Пример #30
0
 def test_create_share_if_max_gigabytes_exceeded(self):
     share_id = 'fake'
     fake_share = {'id': share_id, 'size': 10001}
     fake_service_1 = {'disabled': False, 'host': 'fake_host1'}
     fake_service_2 = {'disabled': False, 'host': 'fake_host2'}
     fake_result = [(fake_service_1, 5), (fake_service_2, 7)]
     fake_request_spec = {
         'share_id': share_id,
         'share_properties': fake_share,
     }
     with mock.patch.object(db, 'service_get_all_share_sorted',
                            mock.Mock(return_value=fake_result)):
         self.assertRaises(exception.NoValidHost,
                           self.driver.schedule_create_share,
                           self.context, fake_request_spec, {})
         db.service_get_all_share_sorted.assert_called_once_with(
             utils.IsAMatcher(context.RequestContext))