Example #1
0
 def test_deny_access_no_host(self):
     share = fake_share('fakeid', host=None)
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, 'deny_access')
     self.mox.ReplayAll()
     self.assertRaises(exception.InvalidShare, self.api.deny_access,
                       self.context, share, 'fakeacc')
Example #2
0
 def test_deny_access_status_not_available(self):
     share = fake_share('fakeid', status='error')
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, 'deny_access')
     self.mox.ReplayAll()
     self.assertRaises(exception.InvalidShare, self.api.deny_access,
                       self.context, share, 'fakeacc')
Example #3
0
 def test_get_all_admin_all_tenants(self):
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, 'get_all')
     self.mox.StubOutWithMock(db_driver, 'share_get_all')
     db_driver.share_get_all(self.context)
     self.mox.ReplayAll()
     self.api.get_all(self.context, search_opts={'all_tenants': 1})
Example #4
0
    def test_create_snapshot(self):
        date = datetime.datetime(1, 1, 1, 1, 1, 1)
        timeutils.set_time_override(override_time=date)
        share = fake_share('fakeid',
                           status='available')
        snapshot = fake_snapshot('fakesnapshotid',
                                 share_id=share['id'],
                                 status='creating')
        fake_name = 'fakename'
        fake_desc = 'fakedesc'
        options = {'share_id': share['id'],
                   'user_id': self.context.user_id,
                   'project_id': self.context.project_id,
                   'status': "creating",
                   'progress': '0%',
                   'share_size': share['size'],
                   'size': 1,
                   'display_name': fake_name,
                   'display_description': fake_desc,
                   'share_proto': share['share_proto'],
                   'export_location': share['export_location']}

        self.mox.StubOutWithMock(share_api, 'check_policy')
        share_api.check_policy(self.context, 'create_snapshot', share)
        self.mox.StubOutWithMock(quota.QUOTAS, 'reserve')
        quota.QUOTAS.reserve(self.context, snapshots=1, gigabytes=1).\
            AndReturn('reservation')
        self.mox.StubOutWithMock(db_driver, 'share_snapshot_create')
        db_driver.share_snapshot_create(self.context,
                                        options).AndReturn(snapshot)
        self.mox.StubOutWithMock(quota.QUOTAS, 'commit')
        quota.QUOTAS.commit(self.context, 'reservation')
        self.share_rpcapi.create_snapshot(self.context, share, snapshot)
        self.mox.ReplayAll()
        self.api.create_snapshot(self.context, share, fake_name, fake_desc)
Example #5
0
 def test_deny_access_not_active_not_error(self):
     share = fake_share('fakeid', status='available')
     access = fake_access('fakaccid', state='fakenew')
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, 'deny_access')
     self.mox.ReplayAll()
     self.assertRaises(exception.InvalidShareAccess, self.api.deny_access,
                       self.context, share, access)
Example #6
0
 def test_access_get(self):
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, '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')
Example #7
0
 def test_get_all_not_admin(self):
     ctx = context.RequestContext('fakeuid', 'fakepid', id_admin=False)
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(ctx, 'get_all')
     self.mox.StubOutWithMock(db_driver, 'share_get_all_by_project')
     db_driver.share_get_all_by_project(ctx, 'fakepid')
     self.mox.ReplayAll()
     self.api.get_all(ctx)
Example #8
0
 def test_get(self):
     self.mox.StubOutWithMock(db_driver, 'share_get')
     db_driver.share_get(self.context, 'fakeid').AndReturn('fakeshare')
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, 'get', 'fakeshare')
     self.mox.ReplayAll()
     result = self.api.get(self.context, 'fakeid')
     self.assertEqual(result, 'fakeshare')
Example #9
0
 def test_create_snapshot_if_share_not_available(self):
     share = fake_share('fakeid',
                        status='error')
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, 'create_snapshot', share)
     self.mox.ReplayAll()
     self.assertRaises(exception.InvalidShare, self.api.create_snapshot,
                       self.context, share, 'fakename', 'fakedesc')
Example #10
0
 def test_delete_snapshot_wrong_status(self):
     snapshot = fake_snapshot('fakesnapshotid', share_id='fakeshareid',
                              status='creating')
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, 'delete_snapshot', snapshot)
     self.mox.ReplayAll()
     self.assertRaises(exception.InvalidShareSnapshot,
                       self.api.delete_snapshot, self.context, snapshot)
Example #11
0
 def test_deny_access_error(self):
     share = fake_share('fakeid', status='available')
     access = fake_access('fakaccid', state='fakeerror')
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, 'deny_access')
     self.mox.StubOutWithMock(db_driver, 'share_access_delete')
     db_driver.share_access_delete(self.context, access['id'])
     self.mox.ReplayAll()
     self.api.deny_access(self.context, share, access)
Example #12
0
 def test_get_snapshot(self):
     fake_get_snap = {'fake_key': 'fake_val'}
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, 'get_snapshot')
     self.mox.StubOutWithMock(db_driver, 'share_snapshot_get')
     db_driver.share_snapshot_get(self.context,
                                  'fakeid').AndReturn(fake_get_snap)
     self.mox.ReplayAll()
     rule = self.api.get_snapshot(self.context, 'fakeid')
     self.assertEqual(rule, fake_get_snap)
Example #13
0
 def test_deny_access_active(self):
     share = fake_share('fakeid', status='available')
     access = fake_access('fakaccid', state='fakeactive')
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, 'deny_access')
     self.mox.StubOutWithMock(db_driver, 'share_access_update')
     db_driver.share_access_update(self.context, access['id'],
                                   {'state': 'fakedeleting'})
     self.share_rpcapi.deny_access(self.context, share, access)
     self.mox.ReplayAll()
     self.api.deny_access(self.context, share, access)
Example #14
0
 def test_get_all_not_admin_search_opts(self):
     search_opts = {'size': 'fakesize'}
     fake_objs = [{'name': 'fakename1'}, search_opts]
     ctx = context.RequestContext('fakeuid', 'fakepid', id_admin=False)
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(ctx, 'get_all')
     self.mox.StubOutWithMock(db_driver, 'share_get_all_by_project')
     db_driver.share_get_all_by_project(ctx,
                                        'fakepid').AndReturn(fake_objs)
     self.mox.ReplayAll()
     result = self.api.get_all(ctx, search_opts)
     self.assertEqual([search_opts], result)
Example #15
0
 def test_allow_access(self):
     share = fake_share('fakeid', status='available')
     values = {'share_id': share['id'],
               'access_type': 'fakeacctype',
               'access_to': 'fakeaccto'}
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, 'allow_access')
     self.mox.StubOutWithMock(db_driver, 'share_access_create')
     db_driver.share_access_create(self.context, values).\
         AndReturn('fakeacc')
     self.share_rpcapi.allow_access(self.context, share, 'fakeacc')
     self.mox.ReplayAll()
     access = self.api.allow_access(self.context, share, 'fakeacctype',
                                    'fakeaccto')
     self.assertEqual(access, 'fakeacc')
Example #16
0
 def test_access_get_all(self):
     share = fake_share('fakeid')
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, 'access_get_all')
     self.mox.StubOutWithMock(db_driver, 'share_access_get_all_for_share')
     db_driver.share_access_get_all_for_share(self.context, 'fakeid').\
         AndReturn([fake_access('fakeacc0id', state='fakenew'),
                    fake_access('fakeacc1id', state='fakeerror')])
     self.mox.ReplayAll()
     rules = self.api.access_get_all(self.context, share)
     self.assertEqual(rules, [{'id': 'fakeacc0id',
                               'access_type': 'fakeacctype',
                               'access_to': 'fakeaccto',
                               'state': 'fakenew'},
                              {'id': 'fakeacc1id',
                               'access_type': 'fakeacctype',
                               'access_to': 'fakeaccto',
                               'state': 'fakeerror'}])
Example #17
0
 def test_delete_snapshot(self):
     date = datetime.datetime(1, 1, 1, 1, 1, 1)
     timeutils.set_time_override(override_time=date)
     share = fake_share('fakeid')
     snapshot = fake_snapshot('fakesnapshotid', share_id=share['id'],
                              status='available')
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, 'delete_snapshot', snapshot)
     self.mox.StubOutWithMock(db_driver, 'share_snapshot_update')
     db_driver.share_snapshot_update(self.context, snapshot['id'],
                                     {'status': 'deleting'})
     self.mox.StubOutWithMock(db_driver, 'share_get')
     db_driver.share_get(self.context,
                         snapshot['share_id']).AndReturn(share)
     self.share_rpcapi.delete_snapshot(self.context, snapshot,
                                       share['host'])
     self.mox.ReplayAll()
     self.api.delete_snapshot(self.context, snapshot)