Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
16ffdbe2
Commit
16ffdbe2
authored
Dec 16, 2013
by
Eric Cano
Browse files
Fixed wrong usage of find when detecting drives.
Fixed wrong reading of /sys files. Added unit tests.
parent
7e3a8e44
Changes
3
Hide whitespace changes
Inline
Side-by-side
castor/tape/tapeserver/SCSI/Device.cpp
View file @
16ffdbe2
...
...
@@ -196,22 +196,19 @@ SCSI::DeviceInfo SCSI::DeviceVector::getDeviceInfo(const char * path) {
/* Get vendor (trimmed of trailing newline, not of spaces) */
{
buf
=
readfile
(
ret
.
sysfs_entry
+
"/vendor"
);
size_t
endpos
=
buf
.
find_first_not_of
(
"
\n
"
);
if
(
std
::
string
::
npos
!=
endpos
)
endpos
++
;
size_t
endpos
=
buf
.
find_first_of
(
"
\n
"
);
ret
.
vendor
=
buf
.
substr
(
0
,
endpos
);
}
/* Get model (trimmed of trailing newline, not of spaces) */
{
buf
=
readfile
(
ret
.
sysfs_entry
+
"/model"
);
size_t
endpos
=
buf
.
find_first_not_of
(
"
\n
"
);
if
(
std
::
string
::
npos
!=
endpos
)
endpos
++
;
size_t
endpos
=
buf
.
find_first_of
(
"
\n
"
);
ret
.
product
=
buf
.
substr
(
0
,
endpos
);
}
/* Get revision (trimmed of trailing newline, not of spaces) */
{
buf
=
readfile
(
ret
.
sysfs_entry
+
"/rev"
);
size_t
endpos
=
buf
.
find_first_not_of
(
"
\n
"
);
if
(
std
::
string
::
npos
!=
endpos
)
endpos
++
;
size_t
endpos
=
buf
.
find_first_of
(
"
\n
"
);
ret
.
productRevisionLevel
=
buf
.
substr
(
0
,
endpos
);
}
/* Get name of sg device */
...
...
castor/tape/tapeserver/drive/Drive.hpp
View file @
16ffdbe2
...
...
@@ -365,11 +365,11 @@ namespace drives {
class
Drive
{
public:
Drive
(
SCSI
::
DeviceInfo
di
,
System
::
virtualWrapper
&
sw
)
:
m_drive
(
NULL
)
{
if
(
di
.
product
.
find
(
"T10000"
))
{
if
(
std
::
string
::
npos
!=
di
.
product
.
find
(
"T10000"
))
{
m_drive
=
new
DriveT10000
(
di
,
sw
);
}
else
if
(
di
.
product
.
find
(
"ULT"
||
di
.
product
.
find
(
"Ultrium"
)))
{
}
else
if
(
std
::
string
::
npos
!=
di
.
product
.
find
(
"ULT"
||
std
::
string
::
npos
!=
di
.
product
.
find
(
"Ultrium"
)))
{
m_drive
=
new
DriveLTO
(
di
,
sw
);
}
else
if
(
di
.
product
.
find
(
"03592"
))
{
}
else
if
(
std
::
string
::
npos
!=
di
.
product
.
find
(
"03592"
))
{
m_drive
=
new
DriveIBM3592
(
di
,
sw
);
}
else
{
throw
Exception
(
std
::
string
(
"Unsupported drive type: "
)
+
di
.
product
);
...
...
castor/tape/tapeserver/drive/DriveTest.cpp
View file @
16ffdbe2
...
...
@@ -27,6 +27,7 @@
#include
"../SCSI/Device.hpp"
#include
"../system/Wrapper.hpp"
#include
"Drive.hpp"
#include
<typeinfo>
using
::
testing
::
AtLeast
;
using
::
testing
::
Return
;
...
...
@@ -56,10 +57,20 @@ TEST(castor_tape_drives_Drive, OpensCorrectly) {
/* Test: detect devices, then open the device files */
castor
::
tape
::
SCSI
::
DeviceVector
dl
(
sysWrapper
);
/* Check we detected things properly */
ASSERT_EQ
(
"VL32STK1"
,
dl
[
0
].
product
);
ASSERT_EQ
(
"STK"
,
dl
[
0
].
vendor
);
ASSERT_EQ
(
"0104"
,
dl
[
0
].
productRevisionLevel
);
ASSERT_EQ
(
"T10000B"
,
dl
[
1
].
product
);
ASSERT_EQ
(
"STK"
,
dl
[
1
].
vendor
);
ASSERT_EQ
(
"0104"
,
dl
[
1
].
productRevisionLevel
);
for
(
std
::
vector
<
castor
::
tape
::
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
i
!=
dl
.
end
();
i
++
)
{
if
(
castor
::
tape
::
SCSI
::
Types
::
tape
==
i
->
type
)
{
castor
::
tape
::
drives
::
Drive
drive
(
*
i
,
sysWrapper
);
std
::
string
expected_classid
(
typeid
(
castor
::
tape
::
drives
::
DriveT10000
).
name
());
std
::
string
found_classid
(
typeid
((
castor
::
tape
::
drives
::
DriveGeneric
&
)
drive
).
name
());
ASSERT_EQ
(
expected_classid
,
found_classid
);
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment