From: newton10471 on
Hi,

I'm trying to use subprocess.Popen() to do a Linux chroot to a mount
point passed in as a parameter to the following function:

def getInstalledKernelVersion(mountPoint):
linuxFsRoot = mountPoint + "/root"
print "type of linuxFsRoot is %s" % type(linuxFsRoot)
installedKernelVersionResult =
subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen'])
return installedKernelVersionResult

and it dies with the following:

type of linuxFsRoot is <type 'str'>
chroot: cannot change root directory to /storage/mounts/
mnt_3786314034939740895.mnt/root: No such file or directory

When I explicitly set linuxFsRoot = "/storage/mounts/
mnt_3786314034939740895.mnt/root", it works fine.

I also tried this to concatenate the mountpoint + /root, and it failed
in the same way:

linuxFsRoot = ("%s/root") % mountPoint

Anyone know what might be happening here?

Thanks in advance,

Matt Newton
From: Alf P. Steinbach on
* newton10471:
> Hi,
>
> I'm trying to use subprocess.Popen() to do a Linux chroot to a mount
> point passed in as a parameter to the following function:
>
> def getInstalledKernelVersion(mountPoint):
> linuxFsRoot = mountPoint + "/root"
> print "type of linuxFsRoot is %s" % type(linuxFsRoot)
> installedKernelVersionResult =
> subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen'])
> return installedKernelVersionResult
>
> and it dies with the following:
>
> type of linuxFsRoot is <type 'str'>
> chroot: cannot change root directory to /storage/mounts/
> mnt_3786314034939740895.mnt/root: No such file or directory
>
> When I explicitly set linuxFsRoot = "/storage/mounts/
> mnt_3786314034939740895.mnt/root", it works fine.
>
> I also tried this to concatenate the mountpoint + /root, and it failed
> in the same way:
>
> linuxFsRoot = ("%s/root") % mountPoint

Use the os.path functions.


> Anyone know what might be happening here?

Since the computed and literal paths /look/ identical and same type, the only
thing I can imagine is that there is some invisible character. Try comparing the
computed and literal path character by character. Print the difference or if
they're identical, that they are.

Possibly you have GIGO problem.


Cheers & hth.,

- Alf
From: newton10471 on
Hi Alf,

After doing some more research, including the character-by-character
comparison you suggested (thank you!), I was able to get things
working the way I wanted using the following:

def getInstalledKernelVersion(mountPoint):
linuxFsRoot = mountPoint + "/root"
installedKernelVersionResult = subprocess.Popen(['/usr/sbin/
chroot',linuxFsRoot,'/bin/rpm','-q','kernel-xen'],
stdout=subprocess.PIPE).communicate()[0]
return installedKernelVersionResult


Thanks very much for you help,

-Matt


On Mar 22, 9:33 am, "Alf P. Steinbach" <al...(a)start.no> wrote:
> * newton10471:
>
>
>
> > Hi,
>
> > I'm trying to use subprocess.Popen() to do a Linux chroot to a mount
> > point passed in as a parameter to the following function:
>
> > def getInstalledKernelVersion(mountPoint):
> >     linuxFsRoot = mountPoint + "/root"
> >     print "type of linuxFsRoot is %s" % type(linuxFsRoot)
> >     installedKernelVersionResult =
> > subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen'])
> >     return installedKernelVersionResult
>
> > and it dies with the following:
>
> > type of linuxFsRoot is <type 'str'>
> > chroot: cannot change root directory to /storage/mounts/
> > mnt_3786314034939740895.mnt/root: No such file or directory
>
> > When I explicitly set linuxFsRoot = "/storage/mounts/
> > mnt_3786314034939740895.mnt/root", it works fine.
>
> > I also tried this to concatenate the mountpoint + /root, and it failed
> > in the same way:
>
> > linuxFsRoot = ("%s/root") % mountPoint
>
> Use the os.path functions.
>
> > Anyone know what might be happening here?
>
> Since the computed and literal paths /look/ identical and same type, the only
> thing I can imagine is that there is some invisible character. Try comparing the
> computed and literal path character by character. Print the difference or if
> they're identical, that they are.
>
> Possibly you have GIGO problem.
>
> Cheers & hth.,
>
> - Alf

From: newton10471 on
Hi Alf,

After doing some more research, including the character-by-character
comparison you suggested (thank you!), I was able to get things
working the way I wanted using the following:

def getInstalledKernelVersion(mountPoint):
linuxFsRoot = mountPoint + "/root"
installedKernelVersionResult = subprocess.Popen(['/usr/sbin/
chroot',linuxFsRoot,'/bin/rpm','-q','kernel-xen'],
stdout=subprocess.PIPE).communicate()[0]
return installedKernelVersionResult


Thanks very much for you help,

-Matt


On Mar 22, 9:33 am, "Alf P. Steinbach" <al...(a)start.no> wrote:
> * newton10471:
>
>
>
> > Hi,
>
> > I'm trying to use subprocess.Popen() to do a Linux chroot to a mount
> > point passed in as a parameter to the following function:
>
> > def getInstalledKernelVersion(mountPoint):
> >     linuxFsRoot = mountPoint + "/root"
> >     print "type of linuxFsRoot is %s" % type(linuxFsRoot)
> >     installedKernelVersionResult =
> > subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen'])
> >     return installedKernelVersionResult
>
> > and it dies with the following:
>
> > type of linuxFsRoot is <type 'str'>
> > chroot: cannot change root directory to /storage/mounts/
> > mnt_3786314034939740895.mnt/root: No such file or directory
>
> > When I explicitly set linuxFsRoot = "/storage/mounts/
> > mnt_3786314034939740895.mnt/root", it works fine.
>
> > I also tried this to concatenate the mountpoint + /root, and it failed
> > in the same way:
>
> > linuxFsRoot = ("%s/root") % mountPoint
>
> Use the os.path functions.
>
> > Anyone know what might be happening here?
>
> Since the computed and literal paths /look/ identical and same type, the only
> thing I can imagine is that there is some invisible character. Try comparing the
> computed and literal path character by character. Print the difference or if
> they're identical, that they are.
>
> Possibly you have GIGO problem.
>
> Cheers & hth.,
>
> - Alf