CatalogueTest.cpp 8.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/******************************************************************************
 *
 * 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.
 *
 * 
 *
21
 * @author Castor Dev team, castor-dev@cern.ch
22
23
 *****************************************************************************/

24
#include "castor/legacymsg/CupvProxyDummy.hpp"
25
#include "castor/legacymsg/VdqmProxyDummy.hpp"
26
#include "castor/legacymsg/VmgrProxyDummy.hpp"
27
#include "castor/log/DummyLogger.hpp"
28
#include "castor/tape/tapeserver/daemon/Catalogue.hpp"
29
#include "castor/tape/tapeserver/daemon/ProcessForkerProxyDummy.hpp"
30
31
32
33
34
35
#include "castor/utils/utils.hpp"

#include <gtest/gtest.h>

namespace unitTests {

36
class castor_tape_tapeserver_daemon_CatalogueTest : public ::testing::Test {
37
38
39
40
41
42
43
44
45
protected:

  virtual void SetUp() {
  }

  virtual void TearDown() {
  }
};

46
TEST_F(castor_tape_tapeserver_daemon_CatalogueTest, goodDayPopulate) {
47
48
49
50
  using namespace castor::tape::tapeserver::daemon;

  castor::tape::utils::TpconfigLines lines;
  lines.push_back(castor::tape::utils::TpconfigLine(
51
    "UNIT1", "DGN1", "DEV1", "DEN11", "manual@SLOT1", "DEVTYPE1"));
52
  lines.push_back(castor::tape::utils::TpconfigLine(
53
    "UNIT1", "DGN1", "DEV1", "DEN12", "manual@SLOT1", "DEVTYPE1"));
54
  lines.push_back(castor::tape::utils::TpconfigLine(
55
    "UNIT2", "DGN2", "DEV2", "DEN21", "manual@SLOT2", "DEVTYPE2"));
56
  lines.push_back(castor::tape::utils::TpconfigLine(
57
    "UNIT2", "DGN2", "DEV2", "DEN22", "manual@SLOT2", "DEVTYPE2"));
58

59
60
61
  castor::tape::utils::DriveConfigMap driveConfigs;
  driveConfigs.enterTpconfigLines(lines);

62
63
  castor::log::DummyLogger log("unittest");
  ProcessForkerProxyDummy processForker;
64
65
  const bool isGrantedReturnValue = true;
  castor::legacymsg::CupvProxyDummy cupv(isGrantedReturnValue);
66
  castor::legacymsg::VdqmProxyDummy vdqm;
67
  castor::legacymsg::VmgrProxyDummy vmgr;
68
  const std::string hostName = "";
69
  const int netTimeout = 1;
70
71
  Catalogue catalogue(netTimeout, log, processForker, cupv, vdqm, vmgr,
    hostName);
72
  ASSERT_NO_THROW(catalogue.populate(driveConfigs));
Daniele Kruse's avatar
Daniele Kruse committed
73
  
74
75
76
77
78
79
80
81
  {
    std::list<std::string> fromCatalogue;
    ASSERT_NO_THROW(fromCatalogue = catalogue.getUnitNames());
    ASSERT_EQ((std::list<std::string>::size_type)2, fromCatalogue.size());
    ASSERT_EQ(std::string("UNIT1"), fromCatalogue.front());
    fromCatalogue.pop_front();
    ASSERT_EQ(std::string("UNIT2"), fromCatalogue.front());
  }
Daniele Kruse's avatar
Daniele Kruse committed
82
  
83
84
85
86
  ///////////////////
  // UNIT1 assertions
  ///////////////////

87
  const CatalogueDrive &unit1 = catalogue.findDrive("UNIT1");
88
  const castor::tape::utils::DriveConfig &unit1Config = unit1.getConfig();
Daniele Kruse's avatar
Daniele Kruse committed
89
  
90
91
  ASSERT_EQ(std::string("DGN1"), unit1Config.dgn);
  ASSERT_EQ(std::string("DEV1"), unit1Config.devFilename);
Daniele Kruse's avatar
Daniele Kruse committed
92
  
93
94
  {
    std::list<std::string> fromCatalogue;
95
    ASSERT_NO_THROW(fromCatalogue = unit1Config.densities);
96
97
98
99
100
101
    ASSERT_EQ((std::list<std::string>::size_type)2, 
      fromCatalogue.size());
    ASSERT_EQ("DEN11", fromCatalogue.front());
    fromCatalogue.pop_front();
    ASSERT_EQ("DEN12", fromCatalogue.front());
  }
Daniele Kruse's avatar
Daniele Kruse committed
102
  
103
  ASSERT_EQ(CatalogueDrive::DRIVE_STATE_DOWN, unit1.getState());
104
  ASSERT_EQ(castor::mediachanger::TAPE_LIBRARY_TYPE_MANUAL,
105
106
    unit1Config.librarySlot.getLibraryType());
  ASSERT_EQ(std::string("manual@SLOT1"), unit1Config.librarySlot.str());
107
  ASSERT_EQ(std::string("DEVTYPE1"), unit1Config.devType);
Daniele Kruse's avatar
Daniele Kruse committed
108
  
109
110
111
  ///////////////////
  // UNIT2 assertions
  ///////////////////
Daniele Kruse's avatar
Daniele Kruse committed
112
  
113
  const CatalogueDrive &unit2 = catalogue.findDrive("UNIT2");
114
  const castor::tape::utils::DriveConfig &unit2Config = unit2.getConfig();
Daniele Kruse's avatar
Daniele Kruse committed
115
  
116
117
  ASSERT_EQ(std::string("DGN2"), unit2Config.dgn);
  ASSERT_EQ(std::string("DEV2"), unit2Config.devFilename);
118
119
120

  {
    std::list<std::string> fromCatalogue;
121
    ASSERT_NO_THROW(fromCatalogue = unit2Config.densities);
122
123
124
125
126
127
128
    ASSERT_EQ((std::list<std::string>::size_type)2,
      fromCatalogue.size());
    ASSERT_EQ("DEN21", fromCatalogue.front());
    fromCatalogue.pop_front();
    ASSERT_EQ("DEN22", fromCatalogue.front());
  }

129
  ASSERT_EQ(CatalogueDrive::DRIVE_STATE_DOWN, unit2.getState());
130
  ASSERT_EQ(castor::mediachanger::TAPE_LIBRARY_TYPE_MANUAL,
131
132
    unit2Config.librarySlot.getLibraryType());
  ASSERT_EQ(std::string("manual@SLOT2"), unit2Config.librarySlot.str());
133
  ASSERT_EQ(std::string("DEVTYPE2"), unit2Config.devType);
134
135
}

136
TEST_F(castor_tape_tapeserver_daemon_CatalogueTest, 
137
138
139
140
  getStateOfNonExistingDrive) {
  using namespace castor::tape::tapeserver::daemon;

  const std::string unitName = "DRIVE";
141
  const int netTimeout = 1;
142
143
  castor::log::DummyLogger log("unittest");
  ProcessForkerProxyDummy processForker;
144
145
  const bool isGrantedReturnValue = true;
  castor::legacymsg::CupvProxyDummy cupv(isGrantedReturnValue);
146
  castor::legacymsg::VdqmProxyDummy vdqm;
147
  castor::legacymsg::VmgrProxyDummy vmgr;
148
  const std::string hostName = "";
149
150
  Catalogue catalogue(netTimeout, log, processForker, cupv, vdqm, vmgr,
    hostName);
151
  ASSERT_THROW(catalogue.findDrive(unitName), castor::exception::Exception);
152
153
}

154
TEST_F(castor_tape_tapeserver_daemon_CatalogueTest, dgnMismatchStart) {
155
  using namespace castor::tape::tapeserver::daemon;
156
157
  castor::tape::utils::TpconfigLines lines;
  lines.push_back(castor::tape::utils::TpconfigLine(
158
    "UNIT", "DGN1", "DEV", "DEN", "manual@SLOT", "DEVTYPE"));
159
160
  castor::tape::utils::DriveConfigMap driveConfigs;
  driveConfigs.enterTpconfigLines(lines);
161

162
  const int netTimeout = 1;
163
164
  castor::log::DummyLogger log("unittest");
  ProcessForkerProxyDummy processForker;
165
166
  const bool isGrantedReturnValue = true;
  castor::legacymsg::CupvProxyDummy cupv(isGrantedReturnValue);
167
  castor::legacymsg::VdqmProxyDummy vdqm;
168
  castor::legacymsg::VmgrProxyDummy vmgr;
169
  const std::string hostName = "";
170
171
  Catalogue catalogue(netTimeout, log, processForker, cupv, vdqm, vmgr,
    hostName);
172
  ASSERT_NO_THROW(catalogue.populate(driveConfigs));
173
174
  CatalogueDrive &unit = catalogue.findDrive("UNIT");
  ASSERT_EQ(CatalogueDrive::DRIVE_STATE_DOWN, unit.getState());
175
  ASSERT_NO_THROW(unit.configureUp());
176
  ASSERT_EQ(CatalogueDrive::DRIVE_STATE_UP, unit.getState());
177
  castor::legacymsg::RtcpJobRqstMsgBody job;
178
179
180
181
182
183
184
185
  job.volReqId = 1111;
  job.clientPort = 2222;
  job.clientEuid = 3333;
  job.clientEgid = 4444;
  castor::utils::copyString(job.clientHost, "CLIENT_HOST");
  castor::utils::copyString(job.dgn, "DGN2");
  castor::utils::copyString(job.driveUnit, "UNIT");
  castor::utils::copyString(job.clientUserName, "USER");
186
  ASSERT_THROW(unit.receivedVdqmJob(job), castor::exception::Exception);
187
188
}

189
TEST_F(castor_tape_tapeserver_daemon_CatalogueTest, getUnitNames) {
190
191
192
  using namespace castor::tape::tapeserver::daemon;
  castor::tape::utils::TpconfigLines lines;
  lines.push_back(castor::tape::utils::TpconfigLine(
193
    "UNIT1", "DGN1", "DEV1", "DEN1", "manual@SLOT1", "DEVTYPE1"));
194
  lines.push_back(castor::tape::utils::TpconfigLine(
195
    "UNIT2", "DGN2", "DEV2", "DEN2", "manual@SLOT2", "DEVTYPE2"));
196
197
  castor::tape::utils::DriveConfigMap driveConfigs;
  driveConfigs.enterTpconfigLines(lines);
198

199

200
  const int netTimeout = 1;
201
202
  castor::log::DummyLogger log("unittest");
  ProcessForkerProxyDummy processForker;
203
204
  const bool isGrantedReturnValue = true;
  castor::legacymsg::CupvProxyDummy cupv(isGrantedReturnValue);
205
  castor::legacymsg::VdqmProxyDummy vdqm;
206
  castor::legacymsg::VmgrProxyDummy vmgr;
207
  const std::string hostName = "";
208
209
  Catalogue catalogue(netTimeout, log, processForker, cupv, vdqm, vmgr,
    hostName);
210
  ASSERT_NO_THROW(catalogue.populate(driveConfigs));
211
212
213
214
215
216
217
218

  {
    std::list<std::string> allUnitNames;
    ASSERT_NO_THROW(allUnitNames = catalogue.getUnitNames());
    ASSERT_EQ((std::list<std::string>::size_type)2, allUnitNames.size());
    const std::string firstOfAllUnitNames = allUnitNames.front();
    allUnitNames.pop_front();
    const std::string secondOfAllUnitNames = allUnitNames.front();
Steven Murray's avatar
Steven Murray committed
219
220
221
222
    ASSERT_TRUE(firstOfAllUnitNames == "UNIT1" ||
      firstOfAllUnitNames == "UNIT2");
    ASSERT_TRUE(secondOfAllUnitNames == "UNIT1" ||
      secondOfAllUnitNames == "UNIT2");
223
224
225
    ASSERT_TRUE(firstOfAllUnitNames != secondOfAllUnitNames);
  }
}
226
} // namespace unitTests