tapeserverdTest.cpp 7.67 KB
Newer Older
1
/******************************************************************************
Eric Cano's avatar
Eric Cano committed
2
 *                      tapeserverdTest.cpp
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * 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
 *****************************************************************************/

25
26
27
28
#define __STDC_CONSTANT_MACROS // For using stdint macros (stdint is included
// by inttypes.h, so we shoot first)
#include <stdint.h>
#include <inttypes.h>
29
#include <gtest/gtest.h>
30
31
32
#include "castor/tape/tapeserver/client/ClientSimulator.hpp"
#include "castor/tape/tapeserver/client/ClientSimSingleReply.hpp"
#include "castor/tape/tapeserver/client/ClientProxy.hpp"
33
#include "../threading/Threading.hpp"
Eric Cano's avatar
Eric Cano committed
34
35
#include "castor/log/StringLogger.hpp"
#include "MountSession.hpp"
36
37
#include "../system/Wrapper.hpp"
#include "Ctape.h"
38
39
40
41
#include "castor/tape/tapegateway/Volume.hpp"
#include "castor/tape/tapegateway/NoMoreFiles.hpp"
#include "castor/tape/tapegateway/EndNotificationErrorReport.hpp"
#include "castor/tape/tapegateway/NotificationAcknowledge.hpp"
42
#include "castor/tape/tapeserver/file/File.hpp"
43

44
using namespace castor::tape::tapeserver;
45
using namespace castor::tape::tapeserver::daemon;
46
47
48
49
namespace unitTest {

class clientRunner: public castor::tape::threading::Thread {
public:
50
  clientRunner(client::ClientSimulator &client): m_sim(client) {}
51
52
53
54
private:
  void run() {
    m_sim.sessionLoop();
  }
55
  client::ClientSimulator & m_sim;
56
57
58
};

  
Eric Cano's avatar
Eric Cano committed
59
TEST(tapeServer, MountSessionGoodday) {
60
61
62
63
  // TpcpClients only supports 32 bits session number
  // This number has to be less than 2^31 as in addition there is a mix
  // of signed and unsigned numbers
  // As the current ids in prod are ~30M, we are far from overflow (Feb 2013)
64
  // 1) prepare the client and run it in another thread
65
66
  uint32_t volReq = 0xBEEF;
  std::string vid = "V12345";
67
  std::string density = "8000GC";
68
69
  client::ClientSimulator sim(volReq, vid, density);
  client::ClientSimulator::ipPort clientAddr = sim.getCallbackAddress();
70
71
  clientRunner simRun(sim);
  simRun.start();
72
73
74
75
76
  
  // 2) Prepare the VDQM request
  castor::tape::legacymsg::RtcpJobRqstMsgBody VDQMjob;
  snprintf(VDQMjob.clientHost, CA_MAXHOSTNAMELEN+1, "%d.%d.%d.%d",
    clientAddr.a, clientAddr.b, clientAddr.c, clientAddr.d);
77
78
  snprintf(VDQMjob.driveUnit, CA_MAXUNMLEN+1, "T10D6116");
  snprintf(VDQMjob.dgn, CA_MAXDGNLEN+1, "LIBXX");
79
80
81
  VDQMjob.clientPort = clientAddr.port;
  VDQMjob.volReqId = volReq;
  
82
83
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  // construct and run the session.
Eric Cano's avatar
Eric Cano committed
84
  castor::log::StringLogger logger("tapeServerUnitTest");
85
  castor::tape::System::mockWrapper mockSys;
86
87
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
88
  mockSys.fake.setupForVirtualDriveSLC6();
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::drives::FakeDrive;
  // We can prepare files for reading on the drive
  {
    // Label the tape
    castor::tape::tapeFile::LabelSession ls(*mockSys.fake.m_pathToDrive["/dev/nst0"], 
        "V12345", true);
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    // And write to it
    castor::tape::tapeFile::WriteSession ws(*mockSys.fake.m_pathToDrive["/dev/nst0"],
        "V12345", 0, true);
    // Write a few files on the virtual tape
    // Prepare the data
    uint8_t data[1000];
    castor::tape::SCSI::Structures::zeroStruct(&data);
    for (int fseq=1; fseq <= 10 ; fseq ++) {
      castor::tape::tapegateway::FileToRecallStruct ftr;
      castor::tape::tapegateway::FileToMigrateStruct ftm_temp;
      ftr.setFseq(fseq);
      ftm_temp.setFseq(fseq);
      ftr.setFileid(1000 + fseq);
      ftm_temp.setFileid(1000 + fseq);
      castor::tape::tapeFile::WriteFile wf(&ws, ftm_temp, 256*1024);
      // Cut up the position into the old-style BlockId0-3
      ftr.setBlockId0(wf.getPosition() >> 24);
      ftr.setBlockId1( (wf.getPosition() >> 16) & 0xFF);
      ftr.setBlockId2( (wf.getPosition() >> 8) & 0xFF);
      ftr.setBlockId3(wf.getPosition() & 0xFF);
      // Write the data (one block)
      wf.write(data, sizeof(data));
      // Close the file
      wf.close();
      // Record the file for recall
      sim.addFileToRecall(ftr, sizeof(data));
    }
  }
124
125
126
127
128
129
  utils::TpconfigLines tpConfig;
  // Actual TPCONFIG lifted from prod
  tpConfig.push_back(utils::TpconfigLine("T10D6116", "T10KD6", 
  "/dev/tape_T10D6116", "8000GC", "down", "acs0,1,1,6", "T10000"));
  tpConfig.push_back(utils::TpconfigLine("T10D6116", "T10KD6", 
  "/dev/tape_T10D6116", "5000GC", "down", "acs0,1,1,6", "T10000"));
130
  MountSession::CastorConf castorConf;
131
  castorConf.rtcopydBufsz = 1024*1024; // 1 MB memory buffers
132
  castorConf.rtcopydNbBufs = 10;
133
134
  castorConf.tapebridgeBulkRequestRecallMaxBytes = UINT64_C(100)*1000*1000*1000;
  castorConf.tapebridgeBulkRequestRecallMaxFiles = 1000;
135
  castorConf.tapeserverdDiskThreads = 1;
136
  MountSession sess(VDQMjob, logger, mockSys, tpConfig, castorConf);
Eric Cano's avatar
Eric Cano committed
137
  sess.execute();
138
  simRun.wait();
Eric Cano's avatar
Eric Cano committed
139
140
  std::string temp = logger.getLog();
  temp += "";
141
  ASSERT_EQ("V12345", sess.getVid());
142
143
}

144
145
146
147
148
149
150
151
152
TEST(tapeServer, MountSessionNoSuchDrive) {
  // TpcpClients only supports 32 bits session number
  // This number has to be less than 2^31 as in addition there is a mix
  // of signed and unsigned numbers
  // As the current ids in prod are ~30M, we are far from overflow (Feb 2013)
  // 1) prepare the client and run it in another thread
  uint32_t volReq = 0xBEEF;
  std::string vid = "V12345";
  std::string density = "8000GC";
153
154
  client::ClientSimulator sim(volReq, vid, density);
  client::ClientSimulator::ipPort clientAddr = sim.getCallbackAddress();
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
  clientRunner simRun(sim);
  simRun.start();
  
  // 2) Prepare the VDQM request
  castor::tape::legacymsg::RtcpJobRqstMsgBody VDQMjob;
  snprintf(VDQMjob.clientHost, CA_MAXHOSTNAMELEN+1, "%d.%d.%d.%d",
    clientAddr.a, clientAddr.b, clientAddr.c, clientAddr.d);
  snprintf(VDQMjob.driveUnit, CA_MAXUNMLEN+1, "T10D6116");
  snprintf(VDQMjob.dgn, CA_MAXDGNLEN+1, "LIBXX");
  VDQMjob.clientPort = clientAddr.port;
  VDQMjob.volReqId = volReq;
  
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  // construct and run the session.
  castor::log::StringLogger logger("tapeServerUnitTest");
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
  utils::TpconfigLines tpConfig;
  // Actual TPCONFIG lifted from prod
  tpConfig.push_back(utils::TpconfigLine("T10D6116", "T10KD6", 
  "/dev/noSuchTape", "8000GC", "down", "acs0,1,1,6", "T10000"));
  tpConfig.push_back(utils::TpconfigLine("T10D6116", "T10KD6", 
  "/dev/noSuchTape", "5000GC", "down", "acs0,1,1,6", "T10000"));
180
181
182
183
  MountSession::CastorConf castorConf;
  castorConf.rtcopydBufsz = 1024;
  castorConf.rtcopydNbBufs = 10;
  MountSession sess(VDQMjob, logger, mockSys, tpConfig, castorConf);
184
185
186
187
188
189
190
  sess.execute();
  simRun.wait();
  std::string temp = logger.getLog();
  temp += "";
  ASSERT_NE(std::string::npos, logger.getLog().find("Drive not found on this path"));
}

191
}