ImportError: No module named apparmor.tools

Bug #1510365 reported by Park, JaeSuk
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
AppArmor
New
Undecided
Unassigned

Bug Description

1. sudo apt-get install apparmor-utils works fine with my ubuntu 1404 (virtualbox)

2. apparmor install "without apt-get" has problem
$ sudo aa-complain // error (No Module named apparmor.tools)
Traceback (most recent call last):
  File "/usr/sbin/aa-complain", line 17, in <module>
    import apparmor.tools
ImportError: No module named apparmor.tools

$ sudo aa-status //this is ok
apparmor module is loaded.
0 profiles are loaded.
0 profiles are in enforce mode.
0 profiles are in complain mode.

===== I followed apparmor/README, like this. ===============
cd ./libraries/libapparmor
./autogen.sh
./configure --prefix=/usr --with-perl
make
sudo make install

cd utils
make
sudo make install

cd parser
make
sudo make install

I don't want to install changehat/ and profiles/ for a while.

Park, JaeSuk (jspark99)
description: updated
description: updated
Park, JaeSuk (jspark99)
summary: - (No module named apparmor.tools) user-space problem
+ ImportError: No module named apparmor.tools
Revision history for this message
Park, JaeSuk (jspark99) wrote :

I wonder if there are something more to do when installing with Makefile.
I found tools.py tools.pyc __init__.py etc are in "/usr/lib/python2.7/site-packages/apparmor"

cat "/usr/lib/python2.7/site-packages/apparmor-2.8.95-py2.7.egg-info" shows like this.
$ cat apparmor-2.8.95-py2.7.egg-info
Metadata-Version: 1.0
Name: apparmor
Version: 2.8.95
Summary: Python libraries for AppArmor utilities
Home-page: https://launchpad.net/apparmor
Author: AppArmor Developers
Author-email: <email address hidden>
License: GPL-2
Description: Python libraries for AppArmor utilities
Platform: UNKNOWN

Revision history for this message
Park, JaeSuk (jspark99) wrote :

I tried to get system path with these command (though, result was same with apt-get install case)

>>> import sys
>>> sys.path

['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-i386-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client'

Revision history for this message
Park, JaeSuk (jspark99) wrote :

ubuntu 14.04]$ sudo aa-complain
Traceback (most recent call last):
  File "/usr/sbin/aa-complain", line 17, in <module>
    import apparmor.tools
ImportError: No module named apparmor.tools

I tried 2ways to install apparmor (apt-get case and 'make install' case)
For apt-get case, I found apparmor-python related .deb packages in /var/cache/apt/archives
and found python modules are installed in /usr/lib/python3/dist-packages/apparmor/tools.py

apparmor-profiles_2.8.95~2430-ubuntu5.3_all.deb
apparmor-utils_2.8.95~2430-0ubuntu5.1_i386.deb
python3-apparmor_2.8.95~2430-0ubuntu5.1_i386.deb
python3-libapparmor_2.8.95~2430-0ubuntu5.1_i386.deb

$ dpkg --contents python3-apparmor_2.8.95~2430-0ubuntu5.1_i386.deb
./usr/lib/python3/dist-packages/
./usr/lib/python3/dist-packages/apparmor/logparser.py

$ dpkg --contents python3-libapparmor_2.8.95~2430-0ubuntu5.1_i386.deb
./usr/lib/python3/dist-packages/LibAppArmor-2.8.95.egg-info
./usr/lib/python3/dist-packages/LibAppArmor/

For 'make install' case, /usr/lib/python2.7/site-packages/apparmor/tools.py
This seems to be cause of "Import Error: No module named apparmor.tools"
When I copied it manually to /usr/lib/python2.7/dist-packages/apparmor/tools.py, it worked ok
Apparmor/utils/python-tools-setup.py imports distutils.command.install.py and it copies to relevant paths.
So README file in apparmor source packages needs newer version.

Revision history for this message
Park, JaeSuk (jspark99) wrote :

// for make install case:
 apparmor-related python libs are installed in /usr/lib/python2.7/site-packages/apparmor and LibAppArmor

// and this error happens.
ubuntu 14.04]$ sudo aa-complain
Traceback (most recent call last):
  File "/usr/sbin/aa-complain", line 17, in <module>
    import apparmor.tools
ImportError: No module named apparmor.tools

// when I copied like this, there was no error
/usr/lib/python2.7/site-packages/apparmor => /usr/lib/python2.7/dist-packages/apparmor
/usr/lib/python2.7/site-packages/LibApparmor=> /usr/lib/python2.7/dist-packages/LibApparmor
// No error without arguments
]$ sudo aa-complain
usage: aa-complain [-h] [-d DIR] program [program ...]
aa-complain: error: too few arguments

// But error with argument
===============================================
]$ sudo aa-complain /etc/apparmor.d/bin.ping
Traceback (most recent call last):
  File "/usr/sbin/aa-complain", line 30, in <module>
    tool.cmd_complain()
  File "/usr/lib/python2.7/dist-packages/apparmor/tools.py", line 171, in cmd_complain
    apparmor.read_profiles()
  File "/usr/lib/python2.7/dist-packages/apparmor/aa.py", line 2558, in read_profiles
    read_profile(profile_dir + '/' + file, True)
  File "/usr/lib/python2.7/dist-packages/apparmor/aa.py", line 2584, in read_profile
    profile_data = parse_profile_data(data, file, 0)
  File "/usr/lib/python2.7/dist-packages/apparmor/aa.py", line 2914, in parse_profile_data
    load_include(include_name)
  File "/usr/lib/python2.7/dist-packages/apparmor/aa.py", line 4170, in load_include
    incdata = parse_profile_data(data, incfile, True)
  File "/usr/lib/python2.7/dist-packages/apparmor/aa.py", line 3031, in parse_profile_data
    raise AppArmorException(_('Syntax Error: Unknown line found in file: %s line: %s') % (file, lineno + 1))

==when I comment out these regular expressions handling routine, it seemed to work!! ==============
/usr/lib/python2.7/dist-packages/apparmor/aa.py
RE_PROFILE_VARIABLE = re.compile('^\s*(@\{?\w+\}?)\s*(\+?=)\s*(@*.+?)\s*,?\s*(#.*)?$')

Revision history for this message
Park, JaeSuk (jspark99) wrote :

These 2 lines didn't work
export PYTHON=/usr/bin/python2.7
export PYTHONPATH='/usr/lib/python2.7/site-packages/:/usr/lib/python2.7/site-packages/apparmor:/usr/lib/python2.7/site-packages/LibAppArmor'

I added 4 lines in aa-complain, aa-enforce before "import apparmor.tools"
import sys
sys.path.append('/usr/lib/python2.7/site-packages/')
sys.path.append('/usr/lib/python2.7/site-packages/apparmor')
sys.path.append('/usr/lib/python2.7/site-packages/LibAppArmor')

and ImportError: No module named apparmor.tools disappeared

Revision history for this message
Christian Boltz (cboltz) wrote :

This looks like an Ubuntu packaging or package dependency bug.

Search for a package named python3-apparmor or something like that (I only know the openSUSE package name ;-)

Revision history for this message
Seth Arnold (seth-arnold) wrote :

Mixing precompiled packages with compiled-from-source packages is bound to be confusing. It's best to stick to either entirely distribution-provided packaging or entirely built from source yourself. Mixing the two is probably trouble for most projects, not just AppArmor.

Thanks

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.