Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement realpath for remote root with nfs #331

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/MirrorCache/WebAPI/Plugin/Dir.pm
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ sub _render_from_db {
$dirname = $dm->root_subtree . $f->dirname unless $dirname;
$c->log->error($c->dumper('dirname:', $dirname)) if $MCDEBUG;
if (my $parent_folder = $rsFolder->find({path => $dirname})) {
if ($dirname eq $root->realpath($dm->root_subtree . $f->dirname)) {
my $realpath_subtree = $root->realpath($dm->root_subtree . $f->dirname) // '';
if ($dirname eq $realpath_subtree) {
$dm->folder_id($parent_folder->id) if $dirname eq $f->dirname;
} else {
my $another_folder = $rsFolder->find({path => $dm->root_subtree . $f->dirname});
Expand Down
2 changes: 1 addition & 1 deletion lib/MirrorCache/WebAPI/Plugin/RenderFileFromMirror.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use Mojo::Date;
use Mojo::Util;
use Mojo::IOLoop::Subprocess;

my $MCDEBUG = $ENV{MCDEBUG_RENDER_FILE_FROM_MIRROR} // $ENV{MC_DEBUG_ALL} // 0;
my $MCDEBUG = $ENV{MCDEBUG_RENDER_FILE_FROM_MIRROR} // $ENV{MCDEBUG_ALL} // 0;

sub register {
my ($self, $app) = @_;
Expand Down
12 changes: 12 additions & 0 deletions lib/MirrorCache/WebAPI/Plugin/RootRemote.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ sub is_remote {
}

sub realpath {
return undef unless $nfs;

my ($self, $path) = @_;
return undef unless $path;

my $localpath = $nfs . $path;
my $realpathlocal = Cwd::realpath($localpath);

if ($realpathlocal && (0 == rindex($realpathlocal, $nfs, 0))) {
my $realpath = substr($realpathlocal, length($nfs));
return $realpath if $realpath ne $path;
}
return undef;
}

Expand Down
31 changes: 13 additions & 18 deletions t/environ/04-remote-nfs.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!lib/test-in-container-environ.sh
set -ex

# we need mc1 to emulate problem with nfs mount, so content of nfs is different from content of ROOT in mc2
mc1=$(environ mc1 $(pwd))
mc2=$(environ mc2 $(pwd))

Expand All @@ -10,14 +11,11 @@ FAKEURL="notexists${RANDOM}.com"

MIRRORCACHE_SCHEDULE_RETRY_INTERVAL=3

$mc1/gen_env \
MIRRORCACHE_SCHEDULE_RETRY_INTERVAL=$MIRRORCACHE_SCHEDULE_RETRY_INTERVAL \
MIRRORCACHE_REDIRECT=$FAKEURL

$mc2/gen_env \
MIRRORCACHE_ROOT=http://$($ap9/print_address) \
MIRRORCACHE_SCHEDULE_RETRY_INTERVAL=$MIRRORCACHE_SCHEDULE_RETRY_INTERVAL \
MIRRORCACHE_ROOT_NFS=$mc2/dt
MIRRORCACHE_REDIRECT=$FAKEURL \
MIRRORCACHE_ROOT_NFS=$mc1/dt

rm -r $mc2/db
ln -s $mc1/db $mc2/
Expand Down Expand Up @@ -46,40 +44,37 @@ $mc1/status
$mc2/start
$mc2/status

$mc1/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap7/print_address)','','t','us','na'"
$mc2/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap7/print_address)','','t','us','na'"

# remove one of folders from NFS, imitating mount issue
rm -r $mc2/dt/folder2
rm -r $mc1/dt/folder2

echo first time REDIRECT is used
$mc1/curl -I /download/folder1/file1.1.dat | grep -C30 '302 Found' | grep $FAKEURL
$mc2/curl -I /download/folder1/file1.1.dat | grep -C30 '302 Found' | grep $FAKEURL

echo first time REDIRECT is used even if folder is missing from NFS
$mc1/curl -I /download/folder2/file1.1.dat | grep -C30 '302 Found' | grep $FAKEURL
$mc2/curl -I /download/folder2/file1.1.dat | grep -C30 '302 Found' | grep $FAKEURL

$mc2/backstage/job -e folder_sync_schedule_from_misses
# $mc/backstage/shoot
$mc2/backstage/job -e folder_sync_schedule
# $mc/backstage/shoot
$mc2/backstage/job -e mirror_scan_schedule
$mc2/backstage/shoot

$mc1/sql_test 2 == "select count(*) from minion_jobs where task = 'folder_sync'"
$mc1/sql_test 2 == "select count(*) from folder"
$mc2/sql_test 2 == "select count(*) from minion_jobs where task = 'folder_sync'"
$mc2/sql_test 2 == "select count(*) from folder"

$mc1/curl -I /download/folder1/file1.1.dat | grep -C30 '302 Found' | grep $($ap7/print_address)
$mc2/curl -I /download/folder1/file1.1.dat | grep -C30 '302 Found' | grep $($ap7/print_address)

echo Now the scan happened despite the folder is missing in ROOT_NFS
$mc1/curl -I /download/folder2/file1.1.dat | grep -C30 '302 Found' | grep $($ap7/print_address)
$mc2/curl -I /download/folder2/file1.1.dat | grep -C30 '302 Found' | grep $($ap7/print_address)

$mc1/curl /download/updates/tool/latest/file1.1.dat.meta4 | grep $($ap7/print_address)/folder1/file1.1.dat
$mc2/curl /download/updates/tool/latest/file1.1.dat.meta4 | grep $($ap7/print_address)/folder1/file1.1.dat

sleep $MIRRORCACHE_SCHEDULE_RETRY_INTERVAL

$mc2/backstage/shoot

echo now we learned about all 3 folders
mc1/sql_test 3 == 'select count(*) from folder'

$mc2/sql_test 3 == 'select count(*) from folder'

echo success
2 changes: 1 addition & 1 deletion templates/branding/openSUSE/footer.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<a class="list-inline-item" href="https://github.com/openSUSE/MirrorCache">Source code</a>
<a class="list-inline-item" href="https://bugzilla.opensuse.org/">Report issue</a>
% if (my $ver = eval '$current_version') {
<a>Version <%= $ver %></a>
<a>MirrorCache <%= $ver %></a>
% }
</div>
% if (my $msg = eval '$custom_footer_message') {
Expand Down