added persistence option to HostWithPrivateDirs. also attached mount namespaces when mnexec -a is specified

This commit is contained in:
Cody Burkard
2014-06-19 15:08:26 -07:00
parent ebc1eae679
commit 6a81b6dfb3
3 changed files with 34 additions and 5 deletions
+3 -1
View File
@@ -20,7 +20,9 @@ from functools import partial
def testHostWithPrivateDirs():
"Test bind mounts"
topo = SingleSwitchTopo( 10 )
privateDirs = [ '/var/log', '/var/run' ]
privateDirs = [ ( '/var/log', '/onos/%(name)s/var/log' ),
( '/var/run', '/ovx/%(name)s/var/run' ),
'/mn' ]
host = partial( HostWithPrivateDirs,
privateDirs=privateDirs )
net = Mininet( topo=topo, host=host )
+17 -3
View File
@@ -728,14 +728,28 @@ class CPULimitedHost( Host ):
class HostWithPrivateDirs( Host ):
"Host with private directories"
def __init__(self, *args, **kwargs ):
def __init__(self, name, *args, **kwargs ):
"""privateDirs: list of private directories"""
self.name = name
self.privateDirs = kwargs.pop( 'privateDirs', [] )
Host.__init__( self, *args, **kwargs )
Host.__init__( self, name, *args, **kwargs )
self.mountPrivateDirs()
def mountPrivateDirs( self ):
"mount the directories that have specified mountpoints"
for directory in self.privateDirs:
if isinstance( directory, tuple ):
privateDir = directory[ 1 ] %self.__dict__
mountPoint = directory[ 0 ]
self.cmd( 'mkdir -p %s' %privateDir )
self.cmd( 'mkdir -p %s' %mountPoint )
self.cmd( 'mount --bind %s %s' %( privateDir, mountPoint ) )
else:
self.cmd( 'mkdir -p %s' %directory )
self.cmd( 'mount -n -t tmpfs tmpfs %s' %directory )
def mountTempDirs( self ):
"Mount tmpfs for each private directory"
for dir_ in self.privateDirs:
self.cmd( 'mkdir -p ' + dir_ )
+14 -1
View File
@@ -133,6 +133,7 @@ int main(int argc, char *argv[])
perror("mount");
return 1;
}
break;
case 'p':
/* print pid */
@@ -140,7 +141,7 @@ int main(int argc, char *argv[])
fflush(stdout);
break;
case 'a':
/* Attach to pid's network namespace */
/* Attach to pid's network namespace and mount namespace*/
pid = atoi(optarg);
sprintf(path, "/proc/%d/ns/net", pid );
nsid = open(path, O_RDONLY);
@@ -152,6 +153,18 @@ int main(int argc, char *argv[])
perror("setns");
return 1;
}
sprintf(path, "/proc/%d/ns/mnt", pid );
nsid = open(path, O_RDONLY);
if (nsid < 0) {
perror(path);
return 1;
}
if (setns(nsid, 0) != 0) {
perror("setns");
return 1;
}
break;
case 'g':
/* Attach to cgroup */