Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
0f46eb60
Commit
0f46eb60
authored
10 years ago
by
Daniele Kruse
Browse files
Options
Downloads
Patches
Plain Diff
Added unit test for VFS
parent
aad08ba8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libs/middletier/Vfs.cpp
+16
-14
16 additions, 14 deletions
libs/middletier/Vfs.cpp
libs/middletier/VfsTest.cpp
+98
-2
98 additions, 2 deletions
libs/middletier/VfsTest.cpp
with
114 additions
and
16 deletions
libs/middletier/Vfs.cpp
+
16
−
14
View file @
0f46eb60
...
...
@@ -2,6 +2,7 @@
#include
<sys/types.h>
#include
<sys/stat.h>
#include
<unistd.h>
#include
<iostream>
#include
<sstream>
#include
<stdlib.h>
#include
<string.h>
...
...
@@ -68,7 +69,7 @@ cta::Vfs::Vfs() {
throw
(
Exception
(
message
.
str
()));
}
rc
=
setxattr
(
m_fsDir
.
c_str
(),
"user.CTAStorageClass"
,
(
void
*
)
""
,
0
,
0
);
rc
=
setxattr
(
m_fsDir
.
c_str
(),
"user.CTAStorageClass"
,
""
,
0
,
0
);
if
(
rc
!=
0
)
{
char
buf
[
256
];
std
::
ostringstream
message
;
...
...
@@ -91,7 +92,7 @@ void cta::Vfs::setDirectoryStorageClass(const SecurityIdentity &requester, const
cta
::
Utils
::
checkAbsolutePathSyntax
(
path
);
checkDirectoryExists
(
m_fsDir
+
path
);
int
rc
=
setxattr
((
m_fsDir
+
path
).
c_str
(),
"user.CTAStorageClass"
,
(
void
*
)(
storageClassName
.
c_str
()
)
,
storageClassName
.
length
(),
0
);
int
rc
=
setxattr
((
m_fsDir
+
path
).
c_str
(),
"user.CTAStorageClass"
,
storageClassName
.
c_str
(),
storageClassName
.
length
(),
0
);
if
(
rc
!=
0
)
{
char
buf
[
256
];
std
::
ostringstream
message
;
...
...
@@ -107,11 +108,11 @@ void cta::Vfs::clearDirectoryStorageClass(const SecurityIdentity &requester, con
cta
::
Utils
::
checkAbsolutePathSyntax
(
path
);
checkDirectoryExists
(
m_fsDir
+
path
);
int
rc
=
remove
xattr
((
m_fsDir
+
path
).
c_str
(),
"user.CTAStorageClass"
);
int
rc
=
set
xattr
((
m_fsDir
+
path
).
c_str
(),
"user.CTAStorageClass"
,
""
,
0
,
0
);
if
(
rc
!=
0
)
{
char
buf
[
256
];
std
::
ostringstream
message
;
message
<<
"
set
DirectoryStorageClass() - "
<<
m_fsDir
+
path
<<
" setxattr error. Reason: "
<<
strerror_r
(
errno
,
buf
,
256
);
message
<<
"
clear
DirectoryStorageClass() - "
<<
m_fsDir
+
path
<<
" setxattr error. Reason: "
<<
strerror_r
(
errno
,
buf
,
256
);
throw
(
Exception
(
message
.
str
()));
}
}
...
...
@@ -124,11 +125,12 @@ std::string cta::Vfs::getDirectoryStorageClass(const SecurityIdentity &requester
checkDirectoryExists
(
m_fsDir
+
path
);
char
value
[
1024
];
int
rc
=
getxattr
((
m_fsDir
+
path
).
c_str
(),
"user.CTAStorageClass"
,
(
void
*
)
value
,
1024
);
if
(
rc
!=
0
)
{
bzero
(
value
,
1024
);
int
rc
=
getxattr
((
m_fsDir
+
path
).
c_str
(),
"user.CTAStorageClass"
,
value
,
1024
);
if
(
rc
==
-
1
)
{
char
buf
[
256
];
std
::
ostringstream
message
;
message
<<
"
s
etDirectoryStorageClass() - "
<<
m_fsDir
+
path
<<
" getxattr error. Reason: "
<<
strerror_r
(
errno
,
buf
,
256
);
message
<<
"
g
etDirectoryStorageClass() - "
<<
m_fsDir
+
path
<<
" getxattr error. Reason: "
<<
strerror_r
(
errno
,
buf
,
256
);
throw
(
Exception
(
message
.
str
()));
}
return
std
::
string
(
value
);
...
...
@@ -142,8 +144,8 @@ void cta::Vfs::createFile(const SecurityIdentity &requester, const std::string &
std
::
string
path
=
cta
::
Utils
::
getEnclosingDirPath
(
pathname
);
std
::
string
name
=
cta
::
Utils
::
getEnclosedName
(
pathname
);
checkDirectoryExists
(
m_fsDir
+
path
);
int
fd
=
open
((
m_fsDir
+
pathname
).
c_str
(),
O_WRONLY
|
O_CREAT
|
O_NOCTTY
|
O_NONBLOCK
,
0666
);
checkPathnameDoesNotExist
(
m_fsDir
+
pathname
);
int
fd
=
open
((
m_fsDir
+
pathname
).
c_str
(),
O_WRONLY
|
O_CREAT
|
O_NOCTTY
|
O_NONBLOCK
,
mode
);
if
(
fd
<
0
)
{
char
buf
[
256
];
std
::
ostringstream
message
;
...
...
@@ -169,7 +171,7 @@ void cta::Vfs::createDirectory(const SecurityIdentity &requester, const std::str
checkDirectoryExists
(
m_fsDir
+
path
);
std
::
string
inheritedStorageClass
=
getDirectoryStorageClass
(
requester
,
path
);
int
rc
=
mkdir
((
m_fsDir
+
pathname
).
c_str
(),
0777
);
int
rc
=
mkdir
((
m_fsDir
+
pathname
).
c_str
(),
mode
);
if
(
rc
!=
0
)
{
char
buf
[
256
];
std
::
ostringstream
message
;
...
...
@@ -251,11 +253,10 @@ cta::DirectoryEntry cta::Vfs::statDirectoryEntry(const SecurityIdentity &request
//------------------------------------------------------------------------------
// getDirectoryEntries
//------------------------------------------------------------------------------
std
::
list
<
cta
::
DirectoryEntry
>
cta
::
Vfs
::
getDirectoryEntries
(
const
SecurityIdentity
&
requester
,
const
std
::
string
&
dirPath
)
{
struct
dirent
*
entry
;
std
::
list
<
cta
::
DirectoryEntry
>
cta
::
Vfs
::
getDirectoryEntries
(
const
SecurityIdentity
&
requester
,
const
std
::
string
&
dirPath
)
{
DIR
*
dp
;
dp
=
opendir
((
m_fsDir
+
dirPath
).
c_str
());
if
(
dp
==
NULL
)
{
if
(
dp
==
NULL
)
{
char
buf
[
256
];
std
::
ostringstream
message
;
message
<<
"getDirectoryEntries() - opendir "
<<
m_fsDir
+
dirPath
<<
" error. Reason:
\n
"
<<
strerror_r
(
errno
,
buf
,
256
);
...
...
@@ -263,10 +264,11 @@ std::list<cta::DirectoryEntry> cta::Vfs::getDirectoryEntries(const SecurityIdent
}
std
::
list
<
DirectoryEntry
>
entries
;
struct
dirent
*
entry
;
while
((
entry
=
readdir
(
dp
)))
{
if
(
strcmp
(
entry
->
d_name
,
"."
)
!=
0
&&
strcmp
(
entry
->
d_name
,
".."
)
!=
0
)
{
const
std
::
string
dirEntryPathname
=
m_fsDir
+
dirPath
+
(
entry
->
d_name
);
const
std
::
string
dirEntryPathname
=
dirPath
+
(
entry
->
d_name
);
entries
.
push_back
(
statDirectoryEntry
(
requester
,
dirEntryPathname
));
}
}
...
...
This diff is collapsed.
Click to expand it.
libs/middletier/VfsTest.cpp
+
98
−
2
View file @
0f46eb60
...
...
@@ -14,11 +14,107 @@ protected:
}
};
TEST_F
(
cta_VfsTest
,
trimSlashes_emptyString
)
{
TEST_F
(
cta_VfsTest
,
constructor_consistency
)
{
using
namespace
cta
;
Vfs
vfs
;
const
std
::
string
s
;
cta
::
SecurityIdentity
requester
;
DirectoryIterator
itor
;
ASSERT_NO_THROW
(
itor
=
vfs
.
getDirectoryContents
(
requester
,
"/"
));
ASSERT_FALSE
(
itor
.
hasMore
());
ASSERT_EQ
(
std
::
string
(
""
),
vfs
.
getDirectoryStorageClass
(
requester
,
"/"
));
}
TEST_F
(
cta_VfsTest
,
mkdir_functionality
)
{
using
namespace
cta
;
Vfs
vfs
;
cta
::
SecurityIdentity
requester
;
DirectoryIterator
itor
;
ASSERT_NO_THROW
(
vfs
.
createDirectory
(
requester
,
"/dir1"
,
0777
));
ASSERT_THROW
(
vfs
.
createDirectory
(
requester
,
"/dir1"
,
0777
),
std
::
exception
);
ASSERT_NO_THROW
(
vfs
.
createDirectory
(
requester
,
"/dir2"
,
0777
));
ASSERT_NO_THROW
(
itor
=
vfs
.
getDirectoryContents
(
requester
,
"/"
));
ASSERT_EQ
(
itor
.
hasMore
(),
true
);
ASSERT_EQ
(
itor
.
next
().
getName
(),
"dir1"
);
ASSERT_EQ
(
itor
.
hasMore
(),
true
);
ASSERT_EQ
(
itor
.
next
().
getName
(),
"dir2"
);
ASSERT_EQ
(
itor
.
hasMore
(),
false
);
}
TEST_F
(
cta_VfsTest
,
createFile_functionality
)
{
using
namespace
cta
;
Vfs
vfs
;
cta
::
SecurityIdentity
requester
;
DirectoryIterator
itor
;
ASSERT_NO_THROW
(
vfs
.
createFile
(
requester
,
"/file1"
,
0666
));
ASSERT_THROW
(
vfs
.
createFile
(
requester
,
"/file1"
,
0666
),
std
::
exception
);
ASSERT_NO_THROW
(
vfs
.
createFile
(
requester
,
"/file2"
,
0666
));
ASSERT_NO_THROW
(
itor
=
vfs
.
getDirectoryContents
(
requester
,
"/"
));
ASSERT_EQ
(
itor
.
hasMore
(),
true
);
ASSERT_EQ
(
itor
.
next
().
getName
(),
"file1"
);
ASSERT_EQ
(
itor
.
hasMore
(),
true
);
ASSERT_EQ
(
itor
.
next
().
getName
(),
"file2"
);
ASSERT_EQ
(
itor
.
hasMore
(),
false
);
}
TEST_F
(
cta_VfsTest
,
rmdir_functionality
)
{
using
namespace
cta
;
Vfs
vfs
;
cta
::
SecurityIdentity
requester
;
DirectoryIterator
itor
;
ASSERT_NO_THROW
(
vfs
.
createDirectory
(
requester
,
"/dir1"
,
0777
));
ASSERT_NO_THROW
(
vfs
.
deleteDirectory
(
requester
,
"/dir1"
));
ASSERT_THROW
(
vfs
.
deleteDirectory
(
requester
,
"/dir1"
),
std
::
exception
);
ASSERT_NO_THROW
(
vfs
.
createDirectory
(
requester
,
"/dir2"
,
0777
));
ASSERT_NO_THROW
(
vfs
.
createFile
(
requester
,
"/dir2/file1"
,
0666
));
ASSERT_THROW
(
vfs
.
deleteDirectory
(
requester
,
"/dir2"
),
std
::
exception
);
ASSERT_NO_THROW
(
vfs
.
deleteFile
(
requester
,
"/dir2/file1"
));
ASSERT_NO_THROW
(
vfs
.
deleteDirectory
(
requester
,
"/dir2"
));
ASSERT_NO_THROW
(
itor
=
vfs
.
getDirectoryContents
(
requester
,
"/"
));
ASSERT_FALSE
(
itor
.
hasMore
());
ASSERT_EQ
(
std
::
string
(
""
),
vfs
.
getDirectoryStorageClass
(
requester
,
"/"
));
}
TEST_F
(
cta_VfsTest
,
storageClass_functionality
)
{
using
namespace
cta
;
Vfs
vfs
;
cta
::
SecurityIdentity
requester
;
DirectoryIterator
itor
;
ASSERT_NO_THROW
(
vfs
.
createDirectory
(
requester
,
"/dir1"
,
0777
));
ASSERT_EQ
(
std
::
string
(
""
),
vfs
.
getDirectoryStorageClass
(
requester
,
"/dir1"
));
ASSERT_NO_THROW
(
vfs
.
setDirectoryStorageClass
(
requester
,
"/dir1"
,
"cms"
));
ASSERT_EQ
(
std
::
string
(
"cms"
),
vfs
.
getDirectoryStorageClass
(
requester
,
"/dir1"
));
ASSERT_NO_THROW
(
vfs
.
clearDirectoryStorageClass
(
requester
,
"/dir1"
));
ASSERT_EQ
(
std
::
string
(
""
),
vfs
.
getDirectoryStorageClass
(
requester
,
"/dir1"
));
ASSERT_NO_THROW
(
vfs
.
setDirectoryStorageClass
(
requester
,
"/dir1"
,
"atlas"
));
ASSERT_EQ
(
std
::
string
(
"atlas"
),
vfs
.
getDirectoryStorageClass
(
requester
,
"/dir1"
));
}
TEST_F
(
cta_VfsTest
,
storageClass_inheritance
)
{
using
namespace
cta
;
Vfs
vfs
;
cta
::
SecurityIdentity
requester
;
DirectoryIterator
itor
;
ASSERT_NO_THROW
(
vfs
.
createDirectory
(
requester
,
"/dir1"
,
0777
));
ASSERT_EQ
(
std
::
string
(
""
),
vfs
.
getDirectoryStorageClass
(
requester
,
"/dir1"
));
ASSERT_NO_THROW
(
vfs
.
createDirectory
(
requester
,
"/dir1/dir1_1"
,
0777
));
ASSERT_EQ
(
std
::
string
(
""
),
vfs
.
getDirectoryStorageClass
(
requester
,
"/dir1/dir1_1"
));
ASSERT_NO_THROW
(
vfs
.
setDirectoryStorageClass
(
requester
,
"/dir1"
,
"cms"
));
ASSERT_EQ
(
std
::
string
(
"cms"
),
vfs
.
getDirectoryStorageClass
(
requester
,
"/dir1"
));
ASSERT_NO_THROW
(
vfs
.
createDirectory
(
requester
,
"/dir1/dir1_2"
,
0777
));
ASSERT_EQ
(
std
::
string
(
"cms"
),
vfs
.
getDirectoryStorageClass
(
requester
,
"/dir1/dir1_2"
));
ASSERT_EQ
(
std
::
string
(
""
),
vfs
.
getDirectoryStorageClass
(
requester
,
"/dir1/dir1_1"
));
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment