DataTransferSessionTest.cpp 66.8 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/messages/TapeserverProxyDummy.hpp"
31
#include "castor/tape/tapeserver/daemon/DataTransferSession.hpp"
32
#include "castor/tape/tapeserver/daemon/VolumeInfo.hpp"
33
34
#include "castor/tape/tapeserver/system/Wrapper.hpp"
#include "castor/tape/tapeserver/file/File.hpp"
35
#include "castor/tape/tapeserver/drive/FakeDrive.hpp"
36
#include "catalogue/InMemoryCatalogue.hpp"
37
#include "common/exception/Exception.hpp"
38
#include "common/log/StringLogger.hpp"
39
#include "common/make_unique.hpp"
40
41
#include "common/processCap/ProcessCapDummy.hpp"
#include "common/threading/Threading.hpp"
42
#include "common/utils/utils.hpp"
43
44
45
46
#include "mediachanger/AcsProxyDummy.hpp"
#include "mediachanger/MediaChangerFacade.hpp"
#include "mediachanger/MmcProxyDummy.hpp"
#include "mediachanger/RmcProxyDummy.hpp"
47
48
//#include "smc_struct.h"
//#include "scheduler/DummyScheduler.hpp"
49
#include "scheduler/OStoreDB/OStoreDBFactory.hpp"
50
#include "scheduler/MountType.hpp"
51
//#include "nameserver/NameServer.hpp"
52
#include "scheduler/Scheduler.hpp"
53
54
55
#include "scheduler/testingMocks/MockRetrieveMount.hpp"
#include "scheduler/testingMocks/MockArchiveJob.hpp"
#include "scheduler/testingMocks/MockArchiveMount.hpp"
56
#include "tests/TempFile.hpp"
57

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

67
using namespace castor::tape::tapeserver;
68
using namespace castor::tape::tapeserver::daemon;
69

Eric Cano's avatar
Eric Cano committed
70
namespace unitTests {
71

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
namespace {

/**
 * This structure is used to parameterize scheduler tests.
 */
struct DataTransferSessionTestParam {
  cta::SchedulerDatabaseFactory &dbFactory;

  DataTransferSessionTestParam(
    cta::SchedulerDatabaseFactory &dbFactory):
    dbFactory(dbFactory) {
 }
}; // struct DataTransferSessionTest

}

/**
 * The data transfer test is a parameterized test.  It takes a pair of name server
 * and scheduler database factories as a parameter.
 */
class DataTransferSessionTest: public ::testing::TestWithParam<DataTransferSessionTestParam> {
public:
  
  DataTransferSessionTest() { }
96

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

  class FailedToGetCatalogue: public std::exception {
  public:
    const char *what() const throw() {
      return "Failed to get catalogue";
    }
  };

  class FailedToGetScheduler: public std::exception {
  public:
    const char *what() const throw() {
      return "Failed to get scheduler";
    }
  };

    virtual void SetUp() {
    using namespace cta;

    const DataTransferSessionTestParam &param = GetParam();
    m_db = param.dbFactory.create();
117
    const uint64_t nbConns = 1;
118
119
120
    //m_catalogue = cta::make_unique<catalogue::SchemaCreatingSqliteCatalogue>(m_tempSqliteFile.path(), nbConns);
    m_catalogue = cta::make_unique<catalogue::InMemoryCatalogue>(nbConns);
    m_scheduler = cta::make_unique<Scheduler>(*m_catalogue, *m_db, 5, 2*1000*1000);
121
    
122
123
    strncpy(m_tmpDir, "/tmp/DataTransferSessionTestXXXXXX", sizeof(m_tmpDir));
    if(!mkdtemp(m_tmpDir)) {
124
      const std::string errMsg = cta::utils::errnoToString(errno);
125
126
127
128
129
130
      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());
    }
131
    
132
133
134
    struct stat statBuf;
    bzero(&statBuf, sizeof(statBuf));
    if(stat(m_tmpDir, &statBuf)) {
135
      const std::string errMsg = cta::utils::errnoToString(errno);
136
137
138
139
140
141
142
143
      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());
144
145
  }

146
147
148
149
150
  virtual void TearDown() {
    m_scheduler.reset();
    m_catalogue.reset();
    m_db.reset();
    
151
152
153
154
155
156
157
    // 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()) {
158
        const std::string errMsg = cta::utils::errnoToString(errno);
159
160
161
162
163
164
165
166
167
168
169
170
        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())) {
171
            const std::string errMsg = cta::utils::errnoToString(errno);
172
173
174
175
176
177
178
179
180
            std::ostringstream msg;
            msg << "Failed to unlink " << entryPath;
            throw cta::exception::Exception(msg.str());
          }
        }
      }

      // Delete the now empty directory
      if(rmdir(m_tmpDir)) {
181
        const std::string errMsg = cta::utils::errnoToString(errno);
182
183
184
185
186
        std::ostringstream msg;
        msg << "Failed to delete directory " << m_tmpDir << ": " << errMsg;
        throw cta::exception::Exception(msg.str());
      }
    }
187
  }
188

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
  cta::catalogue::Catalogue &getCatalogue() {
    cta::catalogue::Catalogue *const ptr = m_catalogue.get();
    if(NULL == ptr) {
      throw FailedToGetCatalogue();
    }
    return *ptr;
  }
    
  cta::Scheduler &getScheduler() {
    cta::Scheduler *const ptr = m_scheduler.get();
    if(NULL == ptr) {
      throw FailedToGetScheduler();
    }
    return *ptr;
  }
  
  void setupDefaultCatalogue() {
    using namespace cta;
    auto & catalogue=getCatalogue();

    const std::string mountPolicyName = "mount_group";
    const uint64_t archivePriority = 1;
    const uint64_t minArchiveRequestAge = 2;
    const uint64_t retrievePriority = 3;
    const uint64_t minRetrieveRequestAge = 4;
    const uint64_t maxDrivesAllowed = 5;
    const std::string mountPolicyComment = "create mount group";

    ASSERT_TRUE(catalogue.getMountPolicies().empty());

    catalogue.createMountPolicy(
      s_adminOnAdminHost,
      mountPolicyName,
      archivePriority,
      minArchiveRequestAge,
      retrievePriority,
      minRetrieveRequestAge,
      maxDrivesAllowed,
      mountPolicyComment);

    const std::list<common::dataStructures::MountPolicy> groups = catalogue.getMountPolicies();
    ASSERT_EQ(1, groups.size());
    const common::dataStructures::MountPolicy group = groups.front();
    ASSERT_EQ(mountPolicyName, group.name);
    ASSERT_EQ(archivePriority, group.archivePriority);
    ASSERT_EQ(minArchiveRequestAge, group.archiveMinRequestAge);
    ASSERT_EQ(retrievePriority, group.retrievePriority);
    ASSERT_EQ(minRetrieveRequestAge, group.retrieveMinRequestAge);
    ASSERT_EQ(maxDrivesAllowed, group.maxDrivesAllowed);
    ASSERT_EQ(mountPolicyComment, group.comment);

    const std::string ruleComment = "create requester mount-rule";
    cta::common::dataStructures::UserIdentity userIdentity;
    catalogue.createRequesterMountRule(s_adminOnAdminHost, mountPolicyName, s_diskInstance, s_userName, ruleComment);

    const std::list<common::dataStructures::RequesterMountRule> rules = catalogue.getRequesterMountRules();
    ASSERT_EQ(1, rules.size());

    const common::dataStructures::RequesterMountRule rule = rules.front();

    ASSERT_EQ(s_userName, rule.name);
    ASSERT_EQ(mountPolicyName, rule.mountPolicy);
    ASSERT_EQ(ruleComment, rule.comment);
    ASSERT_EQ(s_adminOnAdminHost.username, rule.creationLog.username);
    ASSERT_EQ(s_adminOnAdminHost.host, rule.creationLog.host);
    ASSERT_EQ(rule.creationLog, rule.lastModificationLog);

    common::dataStructures::StorageClass storageClass;
    storageClass.diskInstance = s_diskInstance;
    storageClass.name = s_storageClassName;
    storageClass.nbCopies = 1;
    storageClass.comment = "create storage class";
    m_catalogue->createStorageClass(s_adminOnAdminHost, storageClass);

    const uint16_t nbPartialTapes = 1;
    const std::string tapePoolComment = "Tape-pool comment";
    const bool tapePoolEncryption = false;
    ASSERT_NO_THROW(catalogue.createTapePool(s_adminOnAdminHost, s_tapePoolName,
      nbPartialTapes, tapePoolEncryption, tapePoolComment));
    const uint16_t copyNb = 1;
    const std::string archiveRouteComment = "Archive-route comment";
    catalogue.createArchiveRoute(s_adminOnAdminHost, s_diskInstance, s_storageClassName, copyNb, s_tapePoolName,
      archiveRouteComment);
  }

private:

  // Prevent copying
  DataTransferSessionTest(const DataTransferSessionTest &) = delete;

  // Prevent assignment
  DataTransferSessionTest & operator= (const DataTransferSessionTest &) = delete;

  std::unique_ptr<cta::SchedulerDatabase> m_db;
  std::unique_ptr<cta::catalogue::Catalogue> m_catalogue;
  std::unique_ptr<cta::Scheduler> m_scheduler;
  
protected:
  // Default parameters for storage classes, etc...
  const std::string s_userName = "user_name";
  const std::string s_diskInstance = "disk_instance";
  const std::string s_storageClassName = "TestStorageClass";
  const cta::common::dataStructures::SecurityIdentity s_adminOnAdminHost = { "admin1", "host1" };
  const std::string s_tapePoolName = "TestTapePool";
  const std::string s_libraryName = "TestLogicalLibrary";
294
  const std::string s_vid = "TstVid"; // We really need size <= 6 characters due to tape label format.
295
  //TempFile m_tempSqliteFile;
296
297
298
299
300
301
302
  /**
   * 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.
   */
303
  char m_tmpDir[100];
304

305
306
}; // class DataTransferSessionTest

307
TEST_P(DataTransferSessionTest, DataTransferSessionGooddayRecall) {
Eric Cano's avatar
Eric Cano committed
308
  // 0) Prepare the logger for everyone
Victor Kotlyar's avatar
Victor Kotlyar committed
309
  cta::log::StringLogger logger("tapeServerUnitTest",cta::log::DEBUG);
Eric Cano's avatar
Eric Cano committed
310
  
311
  setupDefaultCatalogue();
312
  // 1) prepare the fake scheduler
313
  std::string vid = s_vid;
314
315
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

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

  // 4) Create the scheduler
327
328
  auto & catalogue = getCatalogue();
  auto & scheduler = getScheduler();
329
  
330
  // Always use the same requester
331
  const cta::common::dataStructures::SecurityIdentity requester;
332
333
334
335

  // 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;
336
  
337
338
  // 5) Create the environment for the migration to happen (library + tape) 
    const std::string libraryComment = "Library comment";
339
340
  catalogue.createLogicalLibrary(s_adminOnAdminHost, s_libraryName,
    libraryComment);
341
342
343
344
345
346
347
348
349
350
  {
    auto libraries = catalogue.getLogicalLibraries();
    ASSERT_EQ(1, libraries.size());
    ASSERT_EQ(s_libraryName, libraries.front().name);
    ASSERT_EQ(libraryComment, libraries.front().comment);
  }
  const uint64_t capacityInBytes = 12345678;
  const std::string tapeComment = "Tape comment";
  bool notDisabled = false;
  bool notFull = false;
351
352
  catalogue.createTape(s_adminOnAdminHost, s_vid, s_libraryName, s_tapePoolName, cta::nullopt, capacityInBytes,
    notDisabled, notFull, tapeComment);
353
  
354
  // 6) Prepare files for reading by writing them to the mock system
355
356
357
  {
    // Label the tape
    castor::tape::tapeFile::LabelSession ls(*mockSys.fake.m_pathToDrive["/dev/nst0"], 
358
        s_vid, false);
359
360
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    // And write to it
361
    castor::tape::tapeserver::daemon::VolumeInfo volInfo;
362
    volInfo.vid=s_vid;
363
    castor::tape::tapeFile::WriteSession ws(*mockSys.fake.m_pathToDrive["/dev/nst0"],
364
       volInfo , 0, true, false);
365
366
367

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

377
      // Create an archive file entry in the archive namespace
378
      cta::catalogue::TapeFileWritten tapeFileWritten;
379
      
380
      // Write the file to tape
381
      cta::MockArchiveMount mam(catalogue);
382
383
384
385
      std::unique_ptr<cta::ArchiveJob> aj(new cta::MockArchiveJob(mam, catalogue));
      aj->tapeFile.fSeq = fseq;
      aj->archiveFile.archiveFileID = fseq;
      castor::tape::tapeFile::WriteFile wf(&ws, *aj, archiveFileSize);
386
      tapeFileWritten.blockId = wf.getBlockId();
387
      // Write the data (one block)
388
      wf.write(data, archiveFileSize);
389
390
      // Close the file
      wf.close();
391

392
393
394
395
396
397
398
399
400
      // Create file entry in the archive namespace
      tapeFileWritten.archiveFileId=fseq;
      tapeFileWritten.checksumType="ADLER32";
      tapeFileWritten.checksumValue=cta::utils::getAdler32String(data, archiveFileSize);
      tapeFileWritten.vid=volInfo.vid;
      tapeFileWritten.size=archiveFileSize;
      tapeFileWritten.fSeq=fseq;
      tapeFileWritten.copyNb=1;
      tapeFileWritten.compressedSize=archiveFileSize; // No compression
401
402
403
404
405
406
407
408
      tapeFileWritten.diskInstance = s_diskInstance;
      tapeFileWritten.diskFileId = fseq;
      tapeFileWritten.diskFilePath = remoteFilePath.str();
      tapeFileWritten.diskFileUser = s_userName;
      tapeFileWritten.diskFileGroup = "someGroup";
      tapeFileWritten.diskFileRecoveryBlob = "B106";
      tapeFileWritten.storageClassName = s_storageClassName;
      tapeFileWritten.tapeDrive = "drive0";
409
      catalogue.fileWrittenToTape(tapeFileWritten);
410

411
      // Schedule the retrieval of the file
Daniele Kruse's avatar
Daniele Kruse committed
412
      std::string diskInstance="disk_instance";
413
414
      cta::common::dataStructures::RetrieveRequest rReq;
      rReq.archiveFileID=fseq;
415
416
      rReq.requester.name = s_userName;
      rReq.requester.group = "someGroup";
417
      rReq.dstURL = remoteFilePaths.back();
418
      std::list<std::string> archiveFilePaths;
Daniele Kruse's avatar
Daniele Kruse committed
419
      scheduler.queueRetrieve(diskInstance, rReq);
420
421
    }
  }
422
423
    
  // 6) Report the drive's existence and put it up in the drive register.
424
  cta::tape::daemon::TpconfigLine driveConfig("T10D6116", "TestLogicalLibrary", "/dev/tape_T10D6116", "manual");
425
  cta::common::dataStructures::DriveInfo driveInfo;
426
427
  driveInfo.driveName=driveConfig.unitName;
  driveInfo.logicalLibrary=driveConfig.rawLibrarySlot;
428
429
  // We need to create the drive in the registry before being able to put it up.
  scheduler.reportDriveStatus(driveInfo, cta::common::dataStructures::MountType::NoMount, cta::common::dataStructures::DriveStatus::Down);
430
  scheduler.setDesiredDriveState(s_adminOnAdminHost, driveConfig.unitName, true, false);
431
432

  // 7) Create the data transfer session
433
434
435
436
437
438
  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;
439
440
441
442
  cta::mediachanger::AcsProxyDummy acs;
  cta::mediachanger::MmcProxyDummy mmc;
  cta::mediachanger::RmcProxyDummy rmc;
  cta::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
443
  cta::server::ProcessCap capUtils;
444
  castor::messages::TapeserverProxyDummy initialProcess;
445
  castor::tape::tapeserver::daemon::DataTransferSession sess("tapeHost", logger, mockSys,
446
    driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
447

448
  // 8) Run the data transfer session
449
  sess.execute();
450

451
  // 9) Check the session git the correct VID
452
  ASSERT_EQ(s_vid, sess.getVid());
453

454
  // 10) Check the remote files exist and have the correct size
455
  for(auto & path: remoteFilePaths) {
456
457
    struct stat statBuf;
    bzero(&statBuf, sizeof(statBuf));
458
    const int statRc = stat(path.substr(7).c_str(), &statBuf); //remove the "file://" for stat-ing
459
    ASSERT_EQ(0, statRc);
460
    ASSERT_EQ(1000, statBuf.st_size); //same size of data
461
  }
462
463
464
465

  // 10) Check logs
  std::string logToCheck = logger.getLog();
  logToCheck += "";
466
  ASSERT_NE(std::string::npos, logToCheck.find("firmwareVersion=\"123A\" serialNumber=\"123456\" "
467
468
                                               "mountTotalCorrectedReadErrors=\"5\" mountTotalReadBytesProcessed=\"4096\" "
                                               "mountTotalUncorrectedReadErrors=\"1\" mountTotalNonMediumErrorCounts=\"2\""));
469
  ASSERT_NE(std::string::npos, logToCheck.find("firmwareVersion=\"123A\" serialNumber=\"123456\" lifetimeMediumEfficiencyPrct=\"100\" "
470
471
472
473
                                               "mountReadEfficiencyPrct=\"100\" mountWriteEfficiencyPrct=\"100\" "
                                               "mountReadTransients=\"10\" "
                                               "mountServoTemps=\"10\" mountServoTransients=\"5\" mountTemps=\"100\" "
                                               "mountTotalReadRetries=\"25\" mountTotalWriteRetries=\"25\" mountWriteTransients=\"10\""));
474
}
475
476
477
478
479
480
481

TEST_P(DataTransferSessionTest, DataTransferSessionWrongRecall) {
  // 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.

  // 0) Prepare the logger for everyone
Victor Kotlyar's avatar
Victor Kotlyar committed
482
  cta::log::StringLogger logger("tapeServerUnitTest",cta::log::DEBUG);
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
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
546
547
548
549
550
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
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
  
  setupDefaultCatalogue();
  // 1) prepare the fake scheduler
  std::string vid = s_vid;
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

  // 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 
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive;

  // 4) Create the scheduler
  auto & catalogue = getCatalogue();
  auto & scheduler = getScheduler();

  // Always use the same requester
  const cta::common::dataStructures::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;
  
  // 5) Create the environment for the migration to happen (library + tape) 
    const std::string libraryComment = "Library comment";
  catalogue.createLogicalLibrary(s_adminOnAdminHost, s_libraryName,
    libraryComment);
  {
    auto libraries = catalogue.getLogicalLibraries();
    ASSERT_EQ(1, libraries.size());
    ASSERT_EQ(s_libraryName, libraries.front().name);
    ASSERT_EQ(libraryComment, libraries.front().comment);
  }
  const uint64_t capacityInBytes = 12345678;
  const std::string tapeComment = "Tape comment";
  bool notDisabled = false;
  bool notFull = false;
  catalogue.createTape(s_adminOnAdminHost, s_vid, s_libraryName, s_tapePoolName, cta::nullopt, capacityInBytes,
    notDisabled, notFull, tapeComment);
  
  // 6) 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"], 
        s_vid, false);
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    // And write to it
    castor::tape::tapeserver::daemon::VolumeInfo volInfo;
    volInfo.vid=s_vid;
    castor::tape::tapeFile::WriteSession ws(*mockSys.fake.m_pathToDrive["/dev/nst0"],
       volInfo , 0, true, false);

    // 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());
      
      // Write the file to tape
      const uint64_t archiveFileSize = 1000;
      cta::MockArchiveMount mam(catalogue);
      cta::MockRetrieveMount mrm;
      std::unique_ptr<cta::ArchiveJob> aj(new cta::MockArchiveJob(mam, catalogue));
      aj->tapeFile.fSeq = fseq;
      aj->archiveFile.archiveFileID = 1000 + fseq;
      castor::tape::tapeFile::WriteFile wf(&ws, *aj, archiveFileSize);
      // Write the data (one block)
      wf.write(data, sizeof(data));
      // Close the file
      wf.close();
      
      // Create a fictious file record on the tape to allow adding one to fseq=2 afterwards.
      cta::catalogue::TapeFileWritten tapeFileWritten;
      tapeFileWritten.archiveFileId=666;
      tapeFileWritten.checksumType="ADLER32";
      tapeFileWritten.checksumValue="0xDEADBEEF";
      tapeFileWritten.vid=volInfo.vid;
      tapeFileWritten.size=archiveFileSize;
      tapeFileWritten.fSeq=1;
      tapeFileWritten.blockId=0;
      tapeFileWritten.copyNb=1;
      tapeFileWritten.compressedSize=archiveFileSize; // No compression
      tapeFileWritten.diskInstance = s_diskInstance;
      tapeFileWritten.diskFileId = 1;
      tapeFileWritten.diskFilePath = "/somefile";
      tapeFileWritten.diskFileUser = s_userName;
      tapeFileWritten.diskFileGroup = "someGroup";
      tapeFileWritten.diskFileRecoveryBlob = "B106";
      tapeFileWritten.storageClassName = s_storageClassName;
      tapeFileWritten.tapeDrive = "drive0";
      catalogue.fileWrittenToTape(tapeFileWritten);
      
      // Create an archive file entry in the archive catalogue
      tapeFileWritten.archiveFileId=1000 + fseq;
      tapeFileWritten.checksumType="ADLER32";
      tapeFileWritten.checksumValue=cta::utils::getAdler32String(data, archiveFileSize);
      tapeFileWritten.vid=volInfo.vid;
      tapeFileWritten.size=archiveFileSize;
      tapeFileWritten.fSeq=fseq + 1;
      tapeFileWritten.blockId=wf.getBlockId() + 10000;
      tapeFileWritten.copyNb=1;
      tapeFileWritten.compressedSize=archiveFileSize; // No compression
      tapeFileWritten.diskInstance = s_diskInstance;
      tapeFileWritten.diskFileId = fseq;
      tapeFileWritten.diskFilePath = remoteFilePath.str();
      tapeFileWritten.diskFileUser = s_userName;
      tapeFileWritten.diskFileGroup = "someGroup";
      tapeFileWritten.diskFileRecoveryBlob = "B106";
      tapeFileWritten.storageClassName = s_storageClassName;
      tapeFileWritten.tapeDrive = "drive0";
      catalogue.fileWrittenToTape(tapeFileWritten);

      // Schedule the retrieval of the file
      std::string diskInstance="disk_instance";
      cta::common::dataStructures::RetrieveRequest rReq;
      rReq.archiveFileID=1000 + fseq;
      rReq.requester.name = s_userName;
      rReq.requester.group = "someGroup";
      rReq.dstURL = remoteFilePaths.back();
      std::list<std::string> archiveFilePaths;
      scheduler.queueRetrieve(diskInstance, rReq);
    }
  }
615
616
  
  // 6) Report the drive's existence and put it up in the drive register.
617
  cta::tape::daemon::TpconfigLine driveConfig("T10D6116", "TestLogicalLibrary", "/dev/tape_T10D6116", "manual");
618
  cta::common::dataStructures::DriveInfo driveInfo;
619
620
  driveInfo.driveName=driveConfig.unitName;
  driveInfo.logicalLibrary=driveConfig.rawLibrarySlot;
621
622
  // We need to create the drive in the registry before being able to put it up.
  scheduler.reportDriveStatus(driveInfo, cta::common::dataStructures::MountType::NoMount, cta::common::dataStructures::DriveStatus::Down);
623
  scheduler.setDesiredDriveState(s_adminOnAdminHost, driveConfig.unitName, true, false);
624
625
626
627
628
629
630
631

  // 7) Create the data transfer session
  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;
632
633
634
635
  cta::mediachanger::AcsProxyDummy acs;
  cta::mediachanger::MmcProxyDummy mmc;
  cta::mediachanger::RmcProxyDummy rmc;
  cta::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
636
  cta::server::ProcessCap capUtils;
637
638
639
640
641
642
643
644
645
646
647
648
649
  castor::messages::TapeserverProxyDummy initialProcess;
  DataTransferSession sess("tapeHost", logger, mockSys,
    driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);

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

  // 9) Check the session git the correct VID
  ASSERT_EQ(s_vid, sess.getVid());

  // 10) Check the remote files exist and have the correct size
  std::string temp = logger.getLog();
  ASSERT_NE(std::string::npos, logger.getLog().find("trying to position beyond the end of data"));
650
651
652
653

  // 11) Check logs for drive statistics
  std::string logToCheck = logger.getLog();
  logToCheck += "";
654
  ASSERT_NE(std::string::npos, logToCheck.find("firmwareVersion=\"123A\" serialNumber=\"123456\" "
655
656
                                               "mountTotalCorrectedReadErrors=\"5\" mountTotalReadBytesProcessed=\"4096\" "
                                               "mountTotalUncorrectedReadErrors=\"1\" mountTotalNonMediumErrorCounts=\"2\""));
657
  ASSERT_NE(std::string::npos, logToCheck.find("firmwareVersion=\"123A\" serialNumber=\"123456\" lifetimeMediumEfficiencyPrct=\"100\" "
658
659
660
661
                                               "mountReadEfficiencyPrct=\"100\" mountWriteEfficiencyPrct=\"100\" "
                                               "mountReadTransients=\"10\" "
                                               "mountServoTemps=\"10\" mountServoTransients=\"5\" mountTemps=\"100\" "
                                               "mountTotalReadRetries=\"25\" mountTotalWriteRetries=\"25\" mountWriteTransients=\"10\""));
662
663
}

664
665
666
TEST_P(DataTransferSessionTest, DataTransferSessionNoSuchDrive) {
  
  // 0) Prepare the logger for everyone
Victor Kotlyar's avatar
Victor Kotlyar committed
667
  cta::log::StringLogger logger("tapeServerUnitTest",cta::log::DEBUG);
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
  
  setupDefaultCatalogue();
  // 1) prepare the fake scheduler
  std::string vid = s_vid;
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

  // 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 
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive;

  // 4) Create the scheduler
  auto & catalogue = getCatalogue();
  auto & scheduler = getScheduler();
  
  // Always use the same requester
  const cta::common::dataStructures::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;
  
  // 5) Create the environment for the migration to happen (library + tape) 
    const std::string libraryComment = "Library comment";
  catalogue.createLogicalLibrary(s_adminOnAdminHost, s_libraryName,
    libraryComment);
  {
    auto libraries = catalogue.getLogicalLibraries();
    ASSERT_EQ(1, libraries.size());
    ASSERT_EQ(s_libraryName, libraries.front().name);
    ASSERT_EQ(libraryComment, libraries.front().comment);
  }
  const uint64_t capacityInBytes = 12345678;
  const std::string tapeComment = "Tape comment";
  bool notDisabled = false;
  bool notFull = false;
  catalogue.createTape(s_adminOnAdminHost, s_vid, s_libraryName, s_tapePoolName, cta::nullopt, capacityInBytes,
    notDisabled, notFull, tapeComment);
  
  // 6) 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"], 
        s_vid, false);
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    // And write to it
    castor::tape::tapeserver::daemon::VolumeInfo volInfo;
    volInfo.vid=s_vid;
    castor::tape::tapeFile::WriteSession ws(*mockSys.fake.m_pathToDrive["/dev/nst0"],
       volInfo , 0, true, false);

    // Write a few files on the virtual tape and modify the archive name space
    // so that it is in sync
    uint8_t data[1000];
    size_t archiveFileSize=sizeof(data);
    castor::tape::SCSI::Structures::zeroStruct(&data);
    for (int fseq=1; fseq <= 10 ; fseq ++) {
      // 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
      cta::catalogue::TapeFileWritten tapeFileWritten;
      
      // Write the file to tape
      cta::MockArchiveMount mam(catalogue);
      std::unique_ptr<cta::ArchiveJob> aj(new cta::MockArchiveJob(mam, catalogue));
      aj->tapeFile.fSeq = fseq;
      aj->archiveFile.archiveFileID = fseq;
      castor::tape::tapeFile::WriteFile wf(&ws, *aj, archiveFileSize);
      tapeFileWritten.blockId = wf.getBlockId();
      // Write the data (one block)
      wf.write(data, archiveFileSize);
      // Close the file
      wf.close();

      // Create file entry in the archive namespace
      tapeFileWritten.archiveFileId=fseq;
      tapeFileWritten.checksumType="ADLER32";
      tapeFileWritten.checksumValue=cta::utils::getAdler32String(data, archiveFileSize);
      tapeFileWritten.vid=volInfo.vid;
      tapeFileWritten.size=archiveFileSize;
      tapeFileWritten.fSeq=fseq;
      tapeFileWritten.copyNb=1;
      tapeFileWritten.compressedSize=archiveFileSize; // No compression
      tapeFileWritten.diskInstance = s_diskInstance;
      tapeFileWritten.diskFileId = fseq;
      tapeFileWritten.diskFilePath = remoteFilePath.str();
      tapeFileWritten.diskFileUser = s_userName;
      tapeFileWritten.diskFileGroup = "someGroup";
      tapeFileWritten.diskFileRecoveryBlob = "B106";
      tapeFileWritten.storageClassName = s_storageClassName;
      tapeFileWritten.tapeDrive = "drive0";
      catalogue.fileWrittenToTape(tapeFileWritten);

      // Schedule the retrieval of the file
      std::string diskInstance="disk_instance";
      cta::common::dataStructures::RetrieveRequest rReq;
      rReq.archiveFileID=fseq;
      rReq.requester.name = s_userName;
      rReq.requester.group = "someGroup";
      rReq.dstURL = remoteFilePaths.back();
      std::list<std::string> archiveFilePaths;
      scheduler.queueRetrieve(diskInstance, rReq);
    }
  }
780
781
    
  // 7) Report the drive's existence and put it up in the drive register.
782
  cta::tape::daemon::TpconfigLine driveConfig("T10D6116", "TestLogicalLibrary", "/dev/noSuchDrive", "manual");
783
  cta::common::dataStructures::DriveInfo driveInfo;
784
785
  driveInfo.driveName=driveConfig.unitName;
  driveInfo.logicalLibrary=driveConfig.rawLibrarySlot;
786
787
  // We need to create the drive in the registry before being able to put it up.
  scheduler.reportDriveStatus(driveInfo, cta::common::dataStructures::MountType::NoMount, cta::common::dataStructures::DriveStatus::Down);
788
  scheduler.setDesiredDriveState(s_adminOnAdminHost, driveConfig.unitName, true, false);
789
790

  // 8) Create the data transfer session
791
792
793
  DataTransferConfig castorConf;
  castorConf.bufsz = 1024;
  castorConf.nbBufs = 10;
794
795
796
797
  cta::mediachanger::AcsProxyDummy acs;
  cta::mediachanger::MmcProxyDummy mmc;
  cta::mediachanger::RmcProxyDummy rmc;
  cta::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
798
  castor::messages::TapeserverProxyDummy initialProcess;
799
  cta::server::ProcessCapDummy capUtils;
800
801
802
803
804
805
806
  DataTransferSession sess("tapeHost", logger, mockSys,
    driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
  ASSERT_NO_THROW(sess.execute());
  std::string temp = logger.getLog();
  ASSERT_NE(std::string::npos, logger.getLog().find("Could not stat path: /dev/noSuchDrive"));
}

807
808
809
TEST_P(DataTransferSessionTest, DataTransferSessionFailtoMount) {
  
  // 0) Prepare the logger for everyone
Victor Kotlyar's avatar
Victor Kotlyar committed
810
  cta::log::StringLogger logger("tapeServerUnitTest",cta::log::DEBUG);
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
  
  setupDefaultCatalogue();
  // 1) prepare the fake scheduler
  std::string vid = s_vid;
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

  // 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 
  const bool failOnMount=true;
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive(failOnMount);
  
  // 4) Create the scheduler
  auto & catalogue = getCatalogue();
  auto & scheduler = getScheduler();
  
  // Always use the same requester
  const cta::common::dataStructures::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;
  
  // 5) Create the environment for the migration to happen (library + tape) 
    const std::string libraryComment = "Library comment";
  catalogue.createLogicalLibrary(s_adminOnAdminHost, s_libraryName,
    libraryComment);
  {
    auto libraries = catalogue.getLogicalLibraries();
    ASSERT_EQ(1, libraries.size());
    ASSERT_EQ(s_libraryName, libraries.front().name);
    ASSERT_EQ(libraryComment, libraries.front().comment);
  }
  const uint64_t capacityInBytes = 12345678;
  const std::string tapeComment = "Tape comment";
  bool notDisabled = false;
  bool notFull = false;
  catalogue.createTape(s_adminOnAdminHost, s_vid, s_libraryName, s_tapePoolName, cta::nullopt, capacityInBytes,
    notDisabled, notFull, tapeComment);
  
  // 6) 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"], 
        s_vid, false);
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    // And write to it
    castor::tape::tapeserver::daemon::VolumeInfo volInfo;
    volInfo.vid=s_vid;
    castor::tape::tapeFile::WriteSession ws(*mockSys.fake.m_pathToDrive["/dev/nst0"],
       volInfo , 0, true, false);

    // Write a few files on the virtual tape and modify the archive name space
    // so that it is in sync
    uint8_t data[1000];
    size_t archiveFileSize=sizeof(data);
    castor::tape::SCSI::Structures::zeroStruct(&data);
    for (int fseq=1; fseq <= 10 ; fseq ++) {
      // 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
      cta::catalogue::TapeFileWritten tapeFileWritten;
      
      // Write the file to tape
      cta::MockArchiveMount mam(catalogue);
      std::unique_ptr<cta::ArchiveJob> aj(new cta::MockArchiveJob(mam, catalogue));
      aj->tapeFile.fSeq = fseq;
      aj->archiveFile.archiveFileID = fseq;
      castor::tape::tapeFile::WriteFile wf(&ws, *aj, archiveFileSize);
      tapeFileWritten.blockId = wf.getBlockId();
      // Write the data (one block)
      wf.write(data, archiveFileSize);
      // Close the file
      wf.close();

      // Create file entry in the archive namespace
      tapeFileWritten.archiveFileId=fseq;
      tapeFileWritten.checksumType="ADLER32";
      tapeFileWritten.checksumValue=cta::utils::getAdler32String(data, archiveFileSize);
      tapeFileWritten.vid=volInfo.vid;
      tapeFileWritten.size=archiveFileSize;
      tapeFileWritten.fSeq=fseq;
      tapeFileWritten.copyNb=1;
      tapeFileWritten.compressedSize=archiveFileSize; // No compression
      tapeFileWritten.diskInstance = s_diskInstance;
      tapeFileWritten.diskFileId = fseq;
      tapeFileWritten.diskFilePath = remoteFilePath.str();
      tapeFileWritten.diskFileUser = s_userName;
      tapeFileWritten.diskFileGroup = "someGroup";
      tapeFileWritten.diskFileRecoveryBlob = "B106";
      tapeFileWritten.storageClassName = s_storageClassName;
      tapeFileWritten.tapeDrive = "drive0";
      catalogue.fileWrittenToTape(tapeFileWritten);

      // Schedule the retrieval of the file
      std::string diskInstance="disk_instance";
      cta::common::dataStructures::RetrieveRequest rReq;
      rReq.archiveFileID=fseq;
      rReq.requester.name = s_userName;
      rReq.requester.group = "someGroup";
      rReq.dstURL = remoteFilePaths.back();
      std::list<std::string> archiveFilePaths;
      scheduler.queueRetrieve(diskInstance, rReq);
    }
  }

925
  // 7) Report the drive's existence and put it up in the drive register.
926
  cta::tape::daemon::TpconfigLine driveConfig("T10D6116", "TestLogicalLibrary", "/dev/tape_T10D6116", "manual");
927
  cta::common::dataStructures::DriveInfo driveInfo;
928
929
  driveInfo.driveName=driveConfig.unitName;
  driveInfo.logicalLibrary=driveConfig.rawLibrarySlot;
930
931
  // We need to create the drive in the registry before being able to put it up.
  scheduler.reportDriveStatus(driveInfo, cta::common::dataStructures::MountType::NoMount, cta::common::dataStructures::DriveStatus::Down);
932
  scheduler.setDesiredDriveState(s_adminOnAdminHost, driveConfig.unitName, true, false);
933
934

  // 8) Create the data transfer session
935
936
937
938
939
940
  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;
941
942
943
944
  cta::mediachanger::AcsProxyDummy acs;
  cta::mediachanger::MmcProxyDummy mmc;
  cta::mediachanger::RmcProxyDummy rmc;
  cta::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
945
  cta::server::ProcessCap capUtils;
946
947
948
949
950
951
  castor::messages::TapeserverProxyDummy initialProcess;
  DataTransferSession sess("tapeHost", logger, mockSys,
    driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
  ASSERT_NO_THROW(sess.execute());
  std::string temp = logger.getLog();
  ASSERT_NE(std::string::npos, logger.getLog().find("Failed to mount the tape"));
952
953
954
955

  // 10) Check logs for drive statistics
  std::string logToCheck = logger.getLog();
  logToCheck += "";
956
  ASSERT_NE(std::string::npos, logToCheck.find("firmwareVersion=\"123A\" serialNumber=\"123456\" "
957
958
                                               "mountTotalCorrectedReadErrors=\"5\" mountTotalReadBytesProcessed=\"4096\" "
                                               "mountTotalUncorrectedReadErrors=\"1\" mountTotalNonMediumErrorCounts=\"2\""));
959
  ASSERT_NE(std::string::npos, logToCheck.find("firmwareVersion=\"123A\" serialNumber=\"123456\" lifetimeMediumEfficiencyPrct=\"100\" "
960
961
962
963
                                               "mountReadEfficiencyPrct=\"100\" mountWriteEfficiencyPrct=\"100\" "
                                               "mountReadTransients=\"10\" "
                                               "mountServoTemps=\"10\" mountServoTransients=\"5\" mountTemps=\"100\" "
                                               "mountTotalReadRetries=\"25\" mountTotalWriteRetries=\"25\" mountWriteTransients=\"10\""));
964
965
}

966
967
968
TEST_P(DataTransferSessionTest, DataTransferSessionGooddayMigration) {
   
  // 0) Prepare the logger for everyone
Victor Kotlyar's avatar
Victor Kotlyar committed
969
  cta::log::StringLogger logger("tapeServerUnitTest",cta::log::DEBUG);
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
  
  setupDefaultCatalogue();
  // 1) prepare the fake scheduler
  std::string vid = s_vid;
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
  
  // 4) Create the scheduler
  auto & catalogue = getCatalogue();
  auto & scheduler = getScheduler();
  
  // Always use the same requester
  const cta::common::dataStructures::SecurityIdentity requester("user", "group");
  
  // 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 environment for the migration to happen (library + tape) 
    const std::string libraryComment = "Library comment";
  catalogue.createLogicalLibrary(s_adminOnAdminHost, s_libraryName,
    libraryComment);
  {
    auto libraries = catalogue.getLogicalLibraries();
    ASSERT_EQ(1, libraries.size());
    ASSERT_EQ(s_libraryName, libraries.front().name);