DataTransferSessionTest.cpp 52.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/******************************************************************************
 *
 * This file is part of the Castor project.
 * See http://castor.web.cern.ch/castor
 *
 * Copyright (C) 2003  CERN
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * 
 *
 * @author Castor Dev team, castor-dev@cern.ch
 *****************************************************************************/

24
25
26
27
#define __STDC_CONSTANT_MACROS // For using stdint macros (stdint is included
// by inttypes.h, so we shoot first)
#include <stdint.h>
#include <inttypes.h>
28
#include <gtest/gtest.h>
29

30
#include "castor/legacymsg/RmcProxyDummy.hpp"
31
#include "castor/log/StringLogger.hpp"
32
33
34
#include "castor/mediachanger/MediaChangerFacade.hpp"
#include "castor/mediachanger/MmcProxyDummy.hpp"
#include "castor/messages/AcsProxyDummy.hpp"
35
#include "castor/messages/TapeserverProxyDummy.hpp"
36
#include "castor/server/ProcessCapDummy.hpp"
37
#include "castor/server/Threading.hpp"
38
#include "castor/tape/tapeserver/daemon/DataTransferSession.hpp"
39
#include "castor/tape/tapeserver/daemon/VolumeInfo.hpp"
40
41
#include "castor/tape/tapeserver/system/Wrapper.hpp"
#include "castor/tape/tapeserver/file/File.hpp"
42
#include "castor/tape/tapeserver/drive/FakeDrive.hpp"
43
44
#include "common/exception/Exception.hpp"
#include "common/Utils.hpp"
45
#include "Ctape.h"
46
#include "scheduler/Scheduler.hpp"
47
#include "smc_struct.h"
48
49
#include "nameserver/mockNS/MockNameServer.hpp"
#include "remotens/MockRemoteNS.hpp"
50
#include "remotens/MockRemoteFullFS.hpp"
51
#include "scheduler/DummyScheduler.hpp"
52
#include "scheduler/OStoreDB/OStoreDBFactory.hpp"
53
#include "scheduler/MountType.hpp"
54
55
56
57
#include "nameserver/NameServer.hpp"
#include "scheduler/testingMocks/MockRetrieveMount.hpp"
#include "scheduler/testingMocks/MockArchiveJob.hpp"
#include "scheduler/testingMocks/MockArchiveMount.hpp"
58

59
#include <dirent.h>
60
#include <fcntl.h>
61
#include <stdexcept>
Eric Cano's avatar
Eric Cano committed
62
63
64
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
65
66
#include <unistd.h>
#include <zlib.h>
Eric Cano's avatar
Eric Cano committed
67

68
using namespace castor::tape::tapeserver;
69
using namespace castor::tape::tapeserver::daemon;
70
71
namespace unitTest {

72
73
class castor_tape_tapeserver_daemon_DataTransferSessionTest: public
  ::testing::Test {
74
75
76
protected:

  void SetUp() {
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    strncpy(m_tmpDir, "/tmp/DataTransferSessionTestXXXXXX", sizeof(m_tmpDir));
    if(!mkdtemp(m_tmpDir)) {
      const std::string errMsg = cta::Utils::errnoToString(errno);
      std::ostringstream msg;
      msg << "Failed to create directory with template"
        " /tmp/DataTransferSessionTestXXXXXX: " << errMsg;
      bzero(m_tmpDir, sizeof(m_tmpDir));
      throw cta::exception::Exception(msg.str());
    }

    struct stat statBuf;
    bzero(&statBuf, sizeof(statBuf));
    if(stat(m_tmpDir, &statBuf)) {
      const std::string errMsg = cta::Utils::errnoToString(errno);
      std::ostringstream msg;
      msg << "Failed to stat directory " << m_tmpDir << ": " << errMsg;
      throw cta::exception::Exception(msg.str());
    }

    std::ostringstream cmd;
    cmd << "touch " << m_tmpDir << "/hello";
    system(cmd.str().c_str());
99
100
101
  }

  void TearDown() {
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
    // If Setup() created a temporary directory
    if(m_tmpDir) {

      // Openn the directory
      std::unique_ptr<DIR, std::function<int(DIR*)>>
        dir(opendir(m_tmpDir), closedir);
      if(NULL == dir.get()) {
        const std::string errMsg = cta::Utils::errnoToString(errno);
        std::ostringstream msg;
        msg << "Failed to open directory " << m_tmpDir << ": " << errMsg;
        throw cta::exception::Exception(msg.str());
      }

      // Delete each of the files within the directory
      struct dirent *entry = NULL;
      while((entry = readdir(dir.get()))) {
        const std::string entryName(entry->d_name);
        if(entryName != "." && entryName != "..") {
          const std::string entryPath = std::string(m_tmpDir) + "/" + entryName;
          if(unlink(entryPath.c_str())) {
            const std::string errMsg = cta::Utils::errnoToString(errno);
            std::ostringstream msg;
            msg << "Failed to unlink " << entryPath;
            throw cta::exception::Exception(msg.str());
          }
        }
      }

      // Delete the now empty directory
      if(rmdir(m_tmpDir)) {
        const std::string errMsg = cta::Utils::errnoToString(errno);
        std::ostringstream msg;
        msg << "Failed to delete directory " << m_tmpDir << ": " << errMsg;
        throw cta::exception::Exception(msg.str());
      }
    }
138
  }
139

140
141
142
143
144
145
146
  /**
   * Temporary directory created with mkdtemp that will be used to contain the
   * destination remote files of the tests that need to create them.
   *
   * Please note that a new temporary directory is created and deleted for each
   * test by the Setup() and TearDown() methods.
   */
147
  char m_tmpDir[100];
148
149
};

150
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionGooddayRecall) {
Eric Cano's avatar
Eric Cano committed
151
152
153
  // 0) Prepare the logger for everyone
  castor::log::StringLogger logger("tapeServerUnitTest");
  
154
  // 1) prepare the fake scheduler
155
  std::string vid = "V12345";
156
157
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

158
159
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
160
161
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
162
  mockSys.fake.setupForVirtualDriveSLC6();
163
164
165
  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete 
166
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive;
167
168
169
170

  // 4) Create the scheduler
  cta::MockNameServer ns;
  cta::MockRemoteNS rns;
171
  cta::OStoreDBWrapper<cta::objectstore::BackendVFS> db("Unittest");
172
173
174
175
176
177
178
179
  cta::Scheduler scheduler(ns, db, rns);

  // Always use the same requester
  const cta::SecurityIdentity requester;

  // List to remember the path of each remote file so that the existance of the
  // files can be tested for at the end of the test
  std::list<std::string> remoteFilePaths;
180
  
181
182
183
184
185
186
187
188
189
190
191
192
  // 5) Create the tapepool, library and tape for the scheduler.
  // Make mounts immediate.
  ASSERT_NO_THROW(scheduler.createAdminUserWithoutAuthorizingRequester(requester, requester.getUser(), ""));
  ASSERT_NO_THROW(scheduler.createAdminHostWithoutAuthorizingRequester(requester, requester.getHost(), ""));
  ASSERT_NO_THROW(scheduler.createTapePool(requester, "TapePool", 1, ""));
  cta::MountCriteria immediateMount;
  immediateMount.maxAge = 0;
  immediateMount.maxBytesQueued = 1;
  immediateMount.maxFilesQueued = 1;
  immediateMount.quota = 10;
  ASSERT_NO_THROW(scheduler.setTapePoolMountCriteria("TapePool", cta::MountCriteriaByDirection(immediateMount, immediateMount)));                   
  ASSERT_NO_THROW(scheduler.createLogicalLibrary(requester, "T10KD6", ""));
193
  ASSERT_NO_THROW(scheduler.createTape(requester, "V12345", "T10KD6", "TapePool", 10*1000*1000, ""));
194
  
195
  // 5) Prepare files for reading by writing them to the mock system
196
197
198
  {
    // Label the tape
    castor::tape::tapeFile::LabelSession ls(*mockSys.fake.m_pathToDrive["/dev/nst0"], 
199
        "V12345");
200
201
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    // And write to it
202
    castor::tape::tapeserver::daemon::VolumeInfo volInfo;
203
    volInfo.vid="V12345";
204
    castor::tape::tapeFile::WriteSession ws(*mockSys.fake.m_pathToDrive["/dev/nst0"],
205
       volInfo , 0, true);
206
207
208

    // Write a few files on the virtual tape and modify the archive name space
    // so that it is in sync
209
210
211
    uint8_t data[1000];
    castor::tape::SCSI::Structures::zeroStruct(&data);
    for (int fseq=1; fseq <= 10 ; fseq ++) {
212
213
      // Create a path to a remote destination file
      std::ostringstream remoteFilePath;
214
      remoteFilePath << "file://" << m_tmpDir << "/test" << fseq;
215
216
      remoteFilePaths.push_back(remoteFilePath.str());

217
      // Create an archive file entry in the archive namespace
218
219
220
221
      std::ostringstream archiveFilePath;
      archiveFilePath << "/test" << fseq;
      const mode_t archiveFileMode = 0655;
      const uint64_t archiveFileSize = 256*1024;
222
      ASSERT_NO_THROW(ns.createFile(
223
224
225
        requester,
        archiveFilePath.str(),
        archiveFileMode,
226
        archiveFileSize));
227
      std::unique_ptr<cta::ArchiveFileStatus> status = ns.statFile(requester, archiveFilePath.str());
228
      
229
      // Write the file to tape
230
231
232
233
234
      cta::MockRetrieveMount mrm;
      cta::MockNameServer mns;
      cta::MockArchiveMount mam(mns);
      std::unique_ptr<cta::RetrieveJob> ftr(new cta::MockRetrieveJob(mrm));
      std::unique_ptr<cta::ArchiveJob> ftm(new cta::MockArchiveJob(mam, mns));
235
      ftr->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
236
      ftm->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
237
238
      ftr->archiveFile.fileId = status->fileId;
      ftm->archiveFile.fileId = status->fileId;
239
      castor::tape::tapeFile::WriteFile wf(&ws, *ftm, archiveFileSize);
240
      ftr->nameServerTapeFile.tapeFileLocation.blockId = wf.getBlockId();
241
      ftr->remotePath = remoteFilePath.str();
242
243
244
245
      // Write the data (one block)
      wf.write(data, sizeof(data));
      // Close the file
      wf.close();
246

247
248
249
250
      // Create tape file entry in the archive namespace
      cta::NameServerTapeFile tapeFile;
      tapeFile.copyNb = 1;
      tapeFile.tapeFileLocation.fSeq = fseq;
251
      tapeFile.tapeFileLocation.blockId = wf.getBlockId();
252
253
254
255
256
257
258
259
260
261
262
263
      tapeFile.tapeFileLocation.vid = volInfo.vid;
      tapeFile.tapeFileLocation.copyNb = 1;
      tapeFile.size = archiveFileSize;
      tapeFile.compressedSize = archiveFileSize; // No compression
      cta::Checksum tapeFileChecksum(cta::Checksum::CHECKSUMTYPE_ADLER32,
        cta::ByteArray(cta::Utils::getAdler32(data, sizeof data)));
      tapeFile.checksum = tapeFileChecksum;
      ASSERT_NO_THROW(ns.addTapeFile(
        requester,
        archiveFilePath.str(),
        tapeFile));

264
265
266
      // Schedule the retrieval of the file
      std::list<std::string> archiveFilePaths;
      archiveFilePaths.push_back(archiveFilePath.str());
267
      ASSERT_NO_THROW(scheduler.queueRetrieveRequest(
268
269
        requester,
        archiveFilePaths,
270
        remoteFilePath.str()));
271
272
    }
  }
273
274

  // 6) Create the data transfer session
275
  DriveConfig driveConfig("T10D6116", "T10KD6", "/dev/tape_T10D6116", "manual");
276
277
278
279
280
281
  DataTransferConfig castorConf;
  castorConf.bufsz = 1024*1024; // 1 MB memory buffers
  castorConf.nbBufs = 10;
  castorConf.bulkRequestRecallMaxBytes = UINT64_C(100)*1000*1000*1000;
  castorConf.bulkRequestRecallMaxFiles = 1000;
  castorConf.nbDiskThreads = 1;
282
283
284
285
  castor::messages::AcsProxyDummy acs;
  castor::mediachanger::MmcProxyDummy mmc;
  castor::legacymsg::RmcProxyDummy rmc;
  castor::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
286
  castor::server::ProcessCap capUtils;
287
  castor::messages::TapeserverProxyDummy initialProcess;
288
  DataTransferSession sess("tapeHost", logger, mockSys,
289
    driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
290
291

  // 7) Run the data transfer session
292
  ASSERT_NO_THROW(sess.execute());
293
294

  // 8) Check the session git the correct VID
295
  ASSERT_EQ("V12345", sess.getVid());
296

297
  // 9) Check the remote files exist and have the correct size
298
299
300
301
  for(auto pathItor = remoteFilePaths.cbegin(); pathItor !=
    remoteFilePaths.cend(); pathItor++) {
    struct stat statBuf;
    bzero(&statBuf, sizeof(statBuf));
302
    const int statRc = stat(pathItor->substr(7).c_str(), &statBuf); //remove the "file://" for stat-ing
303
    ASSERT_EQ(0, statRc);
304
    ASSERT_EQ(1000, statBuf.st_size); //same size of data
305
  }
306
}
307

308
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionWrongRecall) {
309
310
311
  // This test is the same as the previous one, with 
  // wrong parameters set for the recall, so that we fail 
  // to recall the first file and cancel the second.
312
313

  // 0) Prepare the logger for everyone
314
315
  castor::log::StringLogger logger("tapeServerUnitTest");
  
316
  // 1) prepare the fake scheduler
317
  std::string vid = "V12345";
318
319
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

320
321
322
323
324
325
326
327
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete 
328
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive;
329
330
331
332

  // 4) Create the scheduler
  cta::MockNameServer ns;
  cta::MockRemoteNS rns;
333
  cta::OStoreDBWrapper<cta::objectstore::BackendVFS> db("Unittest");
334
335
336
337
338
339
340
341
  cta::Scheduler scheduler(ns, db, rns);

  // Always use the same requester
  const cta::SecurityIdentity requester;

  // List to remember the path of each remote file so that the existance of the
  // files can be tested for at the end of the test
  std::list<std::string> remoteFilePaths;
342
  
343
344
345
346
347
348
349
350
351
352
353
354
  // 5) Create the tapepool, library and tape for the scheduler.
  // Make mounts immediate.
  ASSERT_NO_THROW(scheduler.createAdminUserWithoutAuthorizingRequester(requester, requester.getUser(), ""));
  ASSERT_NO_THROW(scheduler.createAdminHostWithoutAuthorizingRequester(requester, requester.getHost(), ""));
  ASSERT_NO_THROW(scheduler.createTapePool(requester, "TapePool", 1, ""));
  cta::MountCriteria immediateMount;
  immediateMount.maxAge = 0;
  immediateMount.maxBytesQueued = 1;
  immediateMount.maxFilesQueued = 1;
  immediateMount.quota = 10;
  ASSERT_NO_THROW(scheduler.setTapePoolMountCriteria("TapePool", cta::MountCriteriaByDirection(immediateMount, immediateMount)));                   
  ASSERT_NO_THROW(scheduler.createLogicalLibrary(requester, "T10KD6", ""));
355
  ASSERT_NO_THROW(scheduler.createTape(requester, "V12345", "T10KD6", "TapePool", 10*1000*1000, ""));
356
  
357
  // 5) Prepare files for reading by writing them to the mock system
358
359
360
  {
    // Label the tape
    castor::tape::tapeFile::LabelSession ls(*mockSys.fake.m_pathToDrive["/dev/nst0"], 
361
        "V12345");
362
363
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    // And write to it
364
    castor::tape::tapeserver::daemon::VolumeInfo volInfo;
365
366
367
    volInfo.vid="V12345";
    castor::tape::tapeFile::WriteSession ws(*mockSys.fake.m_pathToDrive["/dev/nst0"],
       volInfo , 0, true);
368
369
370

    // Write a few files on the virtual tape and modify the archive name space
    // so that it is in sync
371
372
    uint8_t data[1000];
    castor::tape::SCSI::Structures::zeroStruct(&data);
373
374
    int fseq=1;
    {
375
376
      // Create a path to a remote destination file
      std::ostringstream remoteFilePath;
377
      remoteFilePath << "file://" << m_tmpDir << "/test" << fseq;
378
379
      remoteFilePaths.push_back(remoteFilePath.str());

380
      // Create an archive file entry in the archive namespace
381
382
383
      std::ostringstream archiveFilePath;
      archiveFilePath << "/test" << fseq;
      const mode_t archiveFileMode = 0655;
384
      const uint64_t archiveFileSize = 1000;
385
      ASSERT_NO_THROW(ns.createFile(
386
387
388
        requester,
        archiveFilePath.str(),
        archiveFileMode,
389
        archiveFileSize));
390
391

      // Write the file to tape
392
393
394
395
396
      cta::MockNameServer mns;
      cta::MockArchiveMount mam(mns);
      cta::MockRetrieveMount mrm;
      std::unique_ptr<cta::RetrieveJob> ftr(new cta::MockRetrieveJob(mrm));
      std::unique_ptr<cta::ArchiveJob> ftm_temp(new cta::MockArchiveJob(mam, mns));
397
      ftr->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
398
      ftm_temp->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
399
400
      ftr->archiveFile.fileId = 1000 + fseq;
      ftm_temp->archiveFile.fileId = 1000 + fseq;
401
      castor::tape::tapeFile::WriteFile wf(&ws, *ftm_temp, archiveFileSize);
402
      ftr->nameServerTapeFile.tapeFileLocation.blockId = wf.getBlockId();
403
      ftr->remotePath = remoteFilePath.str();
404
405
406
407
      // Write the data (one block)
      wf.write(data, sizeof(data));
      // Close the file
      wf.close();
408

409
410
411
412
413
      // Create tape file entry in the archive namespace that is beyond the end
      // of data
      cta::NameServerTapeFile tapeFile;
      tapeFile.copyNb = 1;
      tapeFile.tapeFileLocation.fSeq = fseq + 10000;
414
      tapeFile.tapeFileLocation.blockId = wf.getBlockId() + 10000;
415
416
417
418
419
420
421
422
423
424
425
426
      tapeFile.tapeFileLocation.vid = volInfo.vid;
      tapeFile.tapeFileLocation.copyNb = 1;
      tapeFile.size = archiveFileSize;
      tapeFile.compressedSize = archiveFileSize; // No compression
      cta::Checksum tapeFileChecksum(cta::Checksum::CHECKSUMTYPE_ADLER32,
        cta::ByteArray(cta::Utils::getAdler32(data, sizeof data)));
      tapeFile.checksum = tapeFileChecksum;
      ASSERT_NO_THROW(ns.addTapeFile(
        requester,
        archiveFilePath.str(),
        tapeFile));

427
428
429
      // Schedule the retrieval of the file
      std::list<std::string> archiveFilePaths;
      archiveFilePaths.push_back(archiveFilePath.str());
430
      ASSERT_NO_THROW(scheduler.queueRetrieveRequest(
431
432
        requester,
        archiveFilePaths,
433
        remoteFilePath.str()));
434
435
    }
  }
436
437

  // 6) Create the data transfer session
438
  DriveConfig driveConfig("T10D6116", "T10KD6", "/dev/tape_T10D6116", "manual");
439
440
441
442
443
444
  DataTransferConfig castorConf;
  castorConf.bufsz = 1024*1024; // 1 MB memory buffers
  castorConf.nbBufs = 10;
  castorConf.bulkRequestRecallMaxBytes = UINT64_C(100)*1000*1000*1000;
  castorConf.bulkRequestRecallMaxFiles = 1000;
  castorConf.nbDiskThreads = 1;
445
446
447
448
  castor::messages::AcsProxyDummy acs;
  castor::mediachanger::MmcProxyDummy mmc;
  castor::legacymsg::RmcProxyDummy rmc;
  castor::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
449
450
  castor::server::ProcessCap capUtils;
  castor::messages::TapeserverProxyDummy initialProcess;
451
  DataTransferSession sess("tapeHost", logger, mockSys,
452
    driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
453
454
455
456
457

  // 7) Run the data transfer session
  ASSERT_NO_THROW(sess.execute());

  // 8) Check the session git the correct VID
458
  ASSERT_EQ("V12345", sess.getVid());
459
460

  // 9) Check the remote files exist and have the correct size
461
462
  std::string temp = logger.getLog();
  ASSERT_NE(std::string::npos, logger.getLog().find("trying to position beyond the end of data"));
463
}
464

465
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionNoSuchDrive) {
466
467
468
469
470
  
  // 0) Prepare the logger for everyone
  castor::log::StringLogger logger("tapeServerUnitTest");
  
  // 1) prepare the fake scheduler
471
  std::string vid = "V12345";
472
473
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

474
475
476
477
478
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
479
480
481
482
483
484
485
486
  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete 
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive;

  // 4) Create the scheduler
  cta::MockNameServer ns;
  cta::MockRemoteNS rns;
487
  cta::OStoreDBWrapper<cta::objectstore::BackendVFS> db("Unittest");
488
489
490
491
492
  cta::Scheduler scheduler(ns, db, rns);

  // Always use the same requester
  const cta::SecurityIdentity requester;
  
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
  // List to remember the path of each remote file so that the existance of the
  // files can be tested for at the end of the test
  std::list<std::string> remoteFilePaths;
  
  // 5) Create the tapepool, library and tape for the scheduler.
  // Make mounts immediate.
  ASSERT_NO_THROW(scheduler.createAdminUserWithoutAuthorizingRequester(requester, requester.getUser(), ""));
  ASSERT_NO_THROW(scheduler.createAdminHostWithoutAuthorizingRequester(requester, requester.getHost(), ""));
  ASSERT_NO_THROW(scheduler.createTapePool(requester, "TapePool", 1, ""));
  cta::MountCriteria immediateMount;
  immediateMount.maxAge = 0;
  immediateMount.maxBytesQueued = 1;
  immediateMount.maxFilesQueued = 1;
  immediateMount.quota = 10;
  ASSERT_NO_THROW(scheduler.setTapePoolMountCriteria("TapePool", cta::MountCriteriaByDirection(immediateMount, immediateMount)));                   
  ASSERT_NO_THROW(scheduler.createLogicalLibrary(requester, "T10KD6", ""));
509
  ASSERT_NO_THROW(scheduler.createTape(requester, "V12345", "T10KD6", "TapePool", 10*1000*1000, ""));
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
  
  // 5) Prepare files for reading by writing them to the mock system
  {
    // Label the tape
    castor::tape::tapeFile::LabelSession ls(*mockSys.fake.m_pathToDrive["/dev/nst0"], 
        "V12345");
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    // And write to it
    castor::tape::tapeserver::daemon::VolumeInfo volInfo;
    volInfo.vid="V12345";
    castor::tape::tapeFile::WriteSession ws(*mockSys.fake.m_pathToDrive["/dev/nst0"],
       volInfo , 0, true);

    // Write a few files on the virtual tape and modify the archive name space
    // so that it is in sync
    uint8_t data[1000];
    castor::tape::SCSI::Structures::zeroStruct(&data);
    int fseq=1;
    {
      // Create a path to a remote destination file
      std::ostringstream remoteFilePath;
      remoteFilePath << "file://" << m_tmpDir << "/test" << fseq;
      remoteFilePaths.push_back(remoteFilePath.str());

      // Create an archive file entry in the archive namespace
      std::ostringstream archiveFilePath;
      archiveFilePath << "/test" << fseq;
      const mode_t archiveFileMode = 0655;
      const uint64_t archiveFileSize = 1000;
      ASSERT_NO_THROW(ns.createFile(
        requester,
        archiveFilePath.str(),
        archiveFileMode,
        archiveFileSize));

      // Write the file to tape
546
547
548
549
550
      cta::MockNameServer mns;
      cta::MockArchiveMount mam(mns);
      cta::MockRetrieveMount mrm;
      std::unique_ptr<cta::RetrieveJob> ftr(new cta::MockRetrieveJob(mrm));
      std::unique_ptr<cta::ArchiveJob> ftm_temp(new cta::MockArchiveJob(mam, mns));
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
      ftr->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
      ftm_temp->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
      ftr->archiveFile.fileId = 1000 + fseq;
      ftm_temp->archiveFile.fileId = 1000 + fseq;
      castor::tape::tapeFile::WriteFile wf(&ws, *ftm_temp, archiveFileSize);
      ftr->nameServerTapeFile.tapeFileLocation.blockId = wf.getBlockId();
      ftr->remotePath = remoteFilePath.str();
      // Write the data (one block)
      wf.write(data, sizeof(data));
      // Close the file
      wf.close();

      // Create tape file entry in the archive namespace that is beyond the end
      // of data
      cta::NameServerTapeFile tapeFile;
      tapeFile.copyNb = 1;
      tapeFile.tapeFileLocation.fSeq = fseq + 1000;
      tapeFile.tapeFileLocation.blockId = wf.getBlockId();
      tapeFile.tapeFileLocation.vid = volInfo.vid;
      tapeFile.tapeFileLocation.copyNb = 1;
      tapeFile.size = archiveFileSize;
      tapeFile.compressedSize = archiveFileSize; // No compression
      cta::Checksum tapeFileChecksum(cta::Checksum::CHECKSUMTYPE_ADLER32,
        cta::ByteArray(cta::Utils::getAdler32(data, sizeof data)));
      tapeFile.checksum = tapeFileChecksum;
      ASSERT_NO_THROW(ns.addTapeFile(
        requester,
        archiveFilePath.str(),
        tapeFile));

      // Schedule the retrieval of the file
      std::list<std::string> archiveFilePaths;
      archiveFilePaths.push_back(archiveFilePath.str());
      ASSERT_NO_THROW(scheduler.queueRetrieveRequest(
        requester,
        archiveFilePaths,
        remoteFilePath.str()));
    }
  }
  
  DriveConfig driveConfig("T10D6116", "T10KD6", "/dev/noSuchDrive", "manual");
592
593
594
  DataTransferConfig castorConf;
  castorConf.bufsz = 1024;
  castorConf.nbBufs = 10;
595
596
597
598
  castor::messages::AcsProxyDummy acs;
  castor::mediachanger::MmcProxyDummy mmc;
  castor::legacymsg::RmcProxyDummy rmc;
  castor::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
599
  castor::messages::TapeserverProxyDummy initialProcess;
600
  castor::server::ProcessCapDummy capUtils;
601
  DataTransferSession sess("tapeHost", logger, mockSys,
602
    driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
603
  ASSERT_NO_THROW(sess.execute());
604
  std::string temp = logger.getLog();
605
  ASSERT_NE(std::string::npos, logger.getLog().find("Could not stat path: /dev/noSuchDrive"));
606
607
}

608
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionFailtoMount) {
609
610
  
  // 0) Prepare the logger for everyone
611
612
  castor::log::StringLogger logger("tapeServerUnitTest");
  
613
  // 1) prepare the fake scheduler
614
  std::string vid = "V12345";
615
616
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

617
618
619
620
621
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
622
623
624
625
626
627
628
629
  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete 
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive;

  // 4) Create the scheduler
  cta::MockNameServer ns;
  cta::MockRemoteNS rns;
630
  cta::OStoreDBWrapper<cta::objectstore::BackendVFS> db("Unittest");
631
632
633
634
635
636
637
638
  cta::Scheduler scheduler(ns, db, rns);

  // Always use the same requester
  const cta::SecurityIdentity requester;
  
  // List to remember the path of each remote file so that the existance of the
  // files can be tested for at the end of the test
  std::list<std::string> remoteFilePaths;
639
640
641
642
643
644
645
646
647
648
649
650
651
  
  // 5) Create the tapepool, library and tape for the scheduler.
  // Make mounts immediate.
  ASSERT_NO_THROW(scheduler.createAdminUserWithoutAuthorizingRequester(requester, requester.getUser(), ""));
  ASSERT_NO_THROW(scheduler.createAdminHostWithoutAuthorizingRequester(requester, requester.getHost(), ""));
  ASSERT_NO_THROW(scheduler.createTapePool(requester, "TapePool", 1, ""));
  cta::MountCriteria immediateMount;
  immediateMount.maxAge = 0;
  immediateMount.maxBytesQueued = 1;
  immediateMount.maxFilesQueued = 1;
  immediateMount.quota = 10;
  ASSERT_NO_THROW(scheduler.setTapePoolMountCriteria("TapePool", cta::MountCriteriaByDirection(immediateMount, immediateMount)));                   
  ASSERT_NO_THROW(scheduler.createLogicalLibrary(requester, "T10KD6", ""));
652
  ASSERT_NO_THROW(scheduler.createTape(requester, "V12345", "T10KD6", "TapePool", 10*1000*1000, ""));
653
654
655
656
657
658
659
660
661

  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete 
  const bool failOnMount=true;
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive(failOnMount);
  
  // We can prepare files for reading on the drive
  {
662
    
663
664
    // Label the tape
    castor::tape::tapeFile::LabelSession ls(*mockSys.fake.m_pathToDrive["/dev/nst0"], 
665
        "V12345");
666
667
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    // And write to it
668
    castor::tape::tapeserver::daemon::VolumeInfo volInfo;
669
    volInfo.vid="V12345";
670
671
672
673
674
675
676
    castor::tape::tapeFile::WriteSession ws(*mockSys.fake.m_pathToDrive["/dev/nst0"],
       volInfo , 0, true);

    // Write a few files on the virtual tape and modify the archive name space
    // so that it is in sync
    uint8_t data[1000];
    castor::tape::SCSI::Structures::zeroStruct(&data);
677
    for (int fseq=1; fseq <= 10 ; fseq ++) {
678
679
      // Create a path to a remote destination file
      std::ostringstream remoteFilePath;
680
      remoteFilePath << "file://" << m_tmpDir << "/test" << fseq;
681
682
      remoteFilePaths.push_back(remoteFilePath.str());

683
      // Create an archive file entry in the archive namespace
684
685
686
      std::ostringstream archiveFilePath;
      archiveFilePath << "/test" << fseq;
      const mode_t archiveFileMode = 0655;
687
      const uint64_t archiveFileSize = 1000;
688
      ASSERT_NO_THROW(ns.createFile(
689
690
691
        requester,
        archiveFilePath.str(),
        archiveFileMode,
692
        archiveFileSize));
693
694

      // Write the file to tape
695
696
697
698
699
      cta::MockNameServer  mns;
      cta::MockArchiveMount mam(mns);
      cta::MockRetrieveMount mrm;
      std::unique_ptr<cta::RetrieveJob> ftr(new cta::MockRetrieveJob(mrm));
      std::unique_ptr<cta::ArchiveJob> ftm_temp(new cta::MockArchiveJob(mam, mns));
700
      ftr->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
701
      ftm_temp->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
702
      ftr->archiveFile.fileId = 1000 + fseq;
703
704
      ftm_temp->archiveFile.fileId = 1000 + fseq;
      castor::tape::tapeFile::WriteFile wf(&ws, *ftm_temp, archiveFileSize);
705
706
      ftr->nameServerTapeFile.tapeFileLocation.blockId = wf.getPosition();
      ftr->remotePath = remoteFilePath.str();
707
708
709
710
711
      // Write the data (one block)
      wf.write(data, sizeof(data));
      // Close the file
      wf.close();

712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
      // Create tape file entry in the archive namespace
      cta::NameServerTapeFile tapeFile;
      tapeFile.copyNb = 1;
      tapeFile.tapeFileLocation.fSeq = fseq;
      tapeFile.tapeFileLocation.blockId = wf.getPosition();
      tapeFile.tapeFileLocation.vid = volInfo.vid;
      tapeFile.tapeFileLocation.copyNb = 1;
      tapeFile.size = archiveFileSize;
      tapeFile.compressedSize = archiveFileSize; // No compression
      cta::Checksum tapeFileChecksum(cta::Checksum::CHECKSUMTYPE_ADLER32,
        cta::ByteArray(cta::Utils::getAdler32(data, sizeof data)));
      tapeFile.checksum = tapeFileChecksum;
      ASSERT_NO_THROW(ns.addTapeFile(
        requester,
        archiveFilePath.str(),
        tapeFile));

729
730
731
      // Schedule the retrieval of the file
      std::list<std::string> archiveFilePaths;
      archiveFilePaths.push_back(archiveFilePath.str());
732
      ASSERT_NO_THROW(scheduler.queueRetrieveRequest(
733
734
        requester,
        archiveFilePaths,
735
        remoteFilePath.str()));
736
737
    }
  }
738
  DriveConfig driveConfig("T10D6116", "T10KD6", "/dev/tape_T10D6116", "manual");
739
740
741
742
743
744
745
746
747
748
749
750
  DataTransferConfig castorConf;
  castorConf.bufsz = 1024*1024; // 1 MB memory buffers
  castorConf.nbBufs = 10;
  castorConf.bulkRequestRecallMaxBytes = UINT64_C(100)*1000*1000*1000;
  castorConf.bulkRequestRecallMaxFiles = 1000;
  castorConf.nbDiskThreads = 3;
  castor::messages::AcsProxyDummy acs;
  castor::mediachanger::MmcProxyDummy mmc;
  castor::legacymsg::RmcProxyDummy rmc;
  castor::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
  castor::server::ProcessCap capUtils;
  castor::messages::TapeserverProxyDummy initialProcess;
751
  DataTransferSession sess("tapeHost", logger, mockSys,
752
    driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
753
  ASSERT_NO_THROW(sess.execute());
754
  std::string temp = logger.getLog();
755
  ASSERT_NE(std::string::npos, logger.getLog().find("Failed to mount the tape"));
756
757
}

758
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionEmptyOnVolReq) {
759
760
  
  // 0) Prepare the logger for everyone
761
762
  castor::log::StringLogger logger("tapeServerUnitTest");
  
763
  // 1) prepare the fake scheduler
764
  std::string vid = "V12345";
765
766
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

767
768
769
770
771
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
772
  
773
774
775
  // The drive will not even be opened. so no need for one.
  mockSys.fake.m_pathToDrive["/dev/nst0"] = NULL;
  
776
777
778
  // 4) Create the scheduler
  cta::MockNameServer ns;
  cta::MockRemoteNS rns;
779
  cta::OStoreDBWrapper<cta::objectstore::BackendVFS> db("Unittest");
780
781
782
783
784
  cta::Scheduler scheduler(ns, db, rns);

  // Always use the same requester
  const cta::SecurityIdentity requester;
  
785
  DriveConfig driveConfig("T10D6116", "T10KD6", "/dev/tape_T10D6116", "manual");
786
787
788
789
790
791
792
793
794
795
796
797
  DataTransferConfig castorConf;
  castorConf.bufsz = 1024*1024; // 1 MB memory buffers
  castorConf.nbBufs = 10;
  castorConf.bulkRequestRecallMaxBytes = UINT64_C(100)*1000*1000*1000;
  castorConf.bulkRequestRecallMaxFiles = 1000;
  castorConf.nbDiskThreads = 3;
  castor::messages::AcsProxyDummy acs;
  castor::mediachanger::MmcProxyDummy mmc;
  castor::legacymsg::RmcProxyDummy rmc;
  castor::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
  castor::server::ProcessCap capUtils;
  castor::messages::TapeserverProxyDummy initialProcess;
798
  DataTransferSession sess("tapeHost", logger, mockSys,
799
    driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
800
  ASSERT_NO_THROW(sess.execute());
801
802
803
804
805
806
  std::string temp = logger.getLog();
  temp += "";
  ASSERT_EQ("", sess.getVid());
  // We should not have logged any error
  ASSERT_EQ(std::string::npos, logger.getLog().find("LVL=E"));
}
807

808
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionGooddayMigration) {
809
  
Eric Cano's avatar
Eric Cano committed
810
811
812
  // 0) Prepare the logger for everyone
  castor::log::StringLogger logger("tapeServerUnitTest");
  
813
  // 1) prepare the fake scheduler
Eric Cano's avatar
Eric Cano committed
814
  std::string vid = "V12345";
815

Eric Cano's avatar
Eric Cano committed
816
817
818
819
820
821
822
823
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete 
824
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive;
825
826
827

  // 4) Create the scheduler
  cta::MockNameServer ns;
828
  cta::MockRemoteFullFS rns;
829
830
831
832
833
834
835
836
837
  cta::OStoreDBWrapper<cta::objectstore::BackendVFS> db("Unittest");
  cta::Scheduler scheduler(ns, db, rns);

  // Always use the same requester
  const cta::SecurityIdentity requester;
  
  // Create the bootstrap admin user and host
  ASSERT_NO_THROW(scheduler.createAdminUserWithoutAuthorizingRequester(requester, requester.getUser(), "admin user"));
  ASSERT_NO_THROW(scheduler.createAdminHostWithoutAuthorizingRequester(requester, requester.getHost(), "admin host"));
Eric Cano's avatar
Eric Cano committed
838
  
839
840
  // create a single copy storage class
  ASSERT_NO_THROW(scheduler.createStorageClass(requester, "SINGLE", 1, 1, "comment"));
Eric Cano's avatar
Eric Cano committed
841
  
842
843
844
845
  // assign it to the root directory
  ASSERT_NO_THROW(scheduler.setDirStorageClass(requester, "/", "SINGLE"));
  
  // create the logical library
846
  ASSERT_NO_THROW(scheduler.createLogicalLibrary(requester, "T10KD6", "the illogical library"));
847
848
849
850
  
  // create the tape pool
  ASSERT_NO_THROW(scheduler.createTapePool(requester, "swimmingpool", 2, "the swimming pool"));
  
851
852
853
854
855
856
857
  cta::MountCriteria immediateMount;
  immediateMount.maxAge = 0;
  immediateMount.maxBytesQueued = 1;
  immediateMount.maxFilesQueued = 1;
  immediateMount.quota = 10;
  ASSERT_NO_THROW(scheduler.setTapePoolMountCriteria("swimmingpool", cta::MountCriteriaByDirection(immediateMount, immediateMount)));
  
858
859
860
861
  // create the route
  ASSERT_NO_THROW(scheduler.createArchiveRoute(requester, "SINGLE", 1, "swimmingpool", "iArchive"));
  
  // create the tape
862
  std::string comment = "the magic tape";
863
  ASSERT_NO_THROW(scheduler.createTape(requester, "V12345", "T10KD6", "swimmingpool", 100000, comment));
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
  
  // List to remember the path of each remote file so that the existence of the
  // files can be tested for at the end of the test
  std::list<std::string> remoteFilePaths;

  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive();
  
  // We can prepare files for writing on the drive
  {    
    // Label the tape
    castor::tape::tapeFile::LabelSession ls(*mockSys.fake.m_pathToDrive["/dev/nst0"], "V12345");
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    
    // schedule the archivals
881
    for(int fseq=1; fseq <= 10 ; fseq ++) { 
882
      // Create a path to a remote source file
883
884
885
      std::ostringstream fileName;
      fileName << "/test" << fseq;
      remoteFilePaths.push_back(fileName.str());
886
      
887
888
889
      // Create the file to be migrated in the fake remote NS
      cta::RemotePath rpath(rns.createFullURL(fileName.str()));
      rns.createFile(rpath.getRaw(), 1000);
890
891
892

      // Schedule the archival of the file
      std::list<std::string> remoteFilePathList;
893
894
      remoteFilePathList.push_back(rns.createFullURL(fileName.str()));
      ASSERT_NO_THROW(scheduler.queueArchiveRequest(requester, remoteFilePathList, fileName.str()));
895
    }
Eric Cano's avatar
Eric Cano committed
896
  }
897
  DriveConfig driveConfig("T10D6116", "T10KD6", "/dev/tape_T10D6116", "manual");
898
899
900
  DataTransferConfig castorConf;
  castorConf.bufsz = 1024*1024; // 1 MB memory buffers
  castorConf.nbBufs = 10;
901
902
  castorConf.bulkRequestRecallMaxBytes = UINT64_C(100)*1000*1000*1000;
  castorConf.bulkRequestRecallMaxFiles = 1000;
903
  castorConf.nbDiskThreads = 1;
904
905
906
907
  castor::messages::AcsProxyDummy acs;
  castor::mediachanger::MmcProxyDummy mmc;
  castor::legacymsg::RmcProxyDummy rmc;
  castor::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
908
  castor::server::ProcessCap capUtils;
909
  castor::messages::TapeserverProxyDummy initialProcess;
910
  DataTransferSession sess("tapeHost", logger, mockSys, driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
911
  ASSERT_NO_THROW(sess.execute());
912
913
914
915
  std::string temp = logger.getLog();
  temp += "";
  ASSERT_EQ("V12345", sess.getVid());
  for(auto i=remoteFilePaths.begin(); i!=remoteFilePaths.end(); i++) {
916
    ASSERT_NO_THROW(ns.statFile(requester, *i));
917
    std::unique_ptr<cta::ArchiveFileStatus> stat(ns.statFile(requester, *i));
918
919
920
    ASSERT_NE(NULL, (uint64_t)(stat.get()));
    ASSERT_EQ(0100777, stat->mode);
    ASSERT_EQ(1000, stat->size);
921
  }
Eric Cano's avatar
Eric Cano committed
922
923
}

924
925
926
927
//
// This test is the same as the previous one, except that the files are deleted
// from filesystem immediately. The disk tasks will then fail on open.
///
928
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionMissingFilesMigration) {
929
  
930
931
932
  // 0) Prepare the logger for everyone
  castor::log::StringLogger logger("tapeServerUnitTest");
  
933
  // 1) prepare the fake scheduler
934
  std::string vid = "V12345";
935

936
937
938
939
940
941
942
943
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete 
944
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive;
945
946
947

  // 4) Create the scheduler
  cta::MockNameServer ns;
948
  cta::MockRemoteFullFS rns;
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
  cta::OStoreDBWrapper<cta::objectstore::BackendVFS> db("Unittest");
  cta::Scheduler scheduler(ns, db, rns);

  // Always use the same requester
  const cta::SecurityIdentity requester;
  
  // Create the bootstrap admin user and host
  ASSERT_NO_THROW(scheduler.createAdminUserWithoutAuthorizingRequester(requester, requester.getUser(), "admin user"));
  ASSERT_NO_THROW(scheduler.createAdminHostWithoutAuthorizingRequester(requester, requester.getHost(), "admin host"));
  
  // create a single copy storage class
  ASSERT_NO_THROW(scheduler.createStorageClass(requester, "SINGLE", 1, 1, "comment"));
  
  // assign it to the root directory
  ASSERT_NO_THROW(scheduler.setDirStorageClass(requester, "/", "SINGLE"));
  
  // create the logical library
966
  ASSERT_NO_THROW(scheduler.createLogicalLibrary(requester, "T10KD6", "the illogical library"));
967
968
969
  
  // create the tape pool
  ASSERT_NO_THROW(scheduler.createTapePool(requester, "swimmingpool", 2, "the swimming pool"));
970
971
972
973
974
975
976
977

  // Make the pool mount immediately
  cta::MountCriteria immediateMount;
  immediateMount.maxAge = 0;
  immediateMount.maxBytesQueued = 1;
  immediateMount.maxFilesQueued = 1;
  immediateMount.quota = 10;
  ASSERT_NO_THROW(scheduler.setTapePoolMountCriteria("swimmingpool", cta::MountCriteriaByDirection(immediateMount, immediateMount)));
978
979
980
  
  // create the route
  ASSERT_NO_THROW(scheduler.createArchiveRoute(requester, "SINGLE", 1, "swimmingpool", "iArchive"));
981
  
982
  // create the tape
983
  std::string comment = "the magic tape";
984
  ASSERT_NO_THROW(scheduler.createTape(requester, "V12345", "T10KD6", "swimmingpool", 100000, comment));
985
  
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
  // List to remember the path of each remote file so that the existence of the
  // files can be tested for at the end of the test
  std::list<std::string> remoteFilePaths;

  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive();
  
  // We can prepare files for writing on the drive
  {    
    // Label the tape
    castor::tape::tapeFile::LabelSession ls(*mockSys.fake.m_pathToDrive["/dev/nst0"], "V12345");
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();