Skip to contentSkip to conversation

Bug fixes for libsemanage/src/pywrap-test.py

PATCH Applied Nicolas Iooss 2 participants 4 messages Jun 14, 2014 – Jun 24, 2014 SELinux security module

lore
Share & tools
lore
#0 lore raw

cover Bug fixes for libsemanage/src/pywrap-test.py

Hello,

While working on porting to Python scripts in sepolgen and policycoreutils to Python 3, I found libsemanage/src/pywrap-test.py. As this script is written in Python 2, I tried to make it compatible with Python 3 too. However there are at least two problems:

* The current script bugs when asked to perform all tests in verbose mode. Here are two patches to fix the script. Can you review and apply them?

* The file indentation mixes tabs and spaces. Python 2 understands such a thing but Python 3 only supports indenting with tabs or spaces but not both. How should the scripts be indented?

Nicolas Iooss (2):
libsemanage: fix src/pywrap-test.py -v -F
libsemanage: use semanage_bool_get_value to print a boolean

 libsemanage/src/pywrap-test.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
Signature · 1 line
2.0.0
#1 lore raw

PATCH 1/2 libsemanage: fix src/pywrap-test.py -v -F

Running "libsemanage/src/pywrap-test.py -v -F" gives following error:

Traceback (most recent call last):
File "pywrap-test.py", line 1139, in <module>
sys.exit(main())
File "pywrap-test.py", line 1121, in main
tests.run(sh)
File "pywrap-test.py", line 107, in run
self.test_writefcontext(handle)
File "pywrap-test.py", line 622, in test_writefcontext
if self.verbose: print "SEFContext type set: ", semanage.semanage_fcontext_get_type_str(fcon)
TypeError: in method 'semanage_fcontext_get_type_str', argument 1 of type 'int'

The argument of semanage_fcontext_get_type_str is the type recorded in fcon and not fcon itself. This type can be retrieved with semanage_fcontext_get_type.

---
 libsemanage/src/pywrap-test.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
libsemanage/src/pywrap-test.py +3 -1
index d087e47..5d8aad1 100644
@@ -619,7 +619,9 @@ class Tests:
 		if self.verbose: print "SEFContext expr set: ", semanage.semanage_fcontext_get_expr(fcon)
 
 		semanage.semanage_fcontext_set_type(fcon, semanage.SEMANAGE_FCONTEXT_REG)
-		if self.verbose: print "SEFContext type set: ", semanage.semanage_fcontext_get_type_str(fcon)
+		if self.verbose:
+			ftype = semanage.semanage_fcontext_get_type(fcon)
+			print "SEFContext type set: ", semanage.semanage_fcontext_get_type_str(ftype)
 
 		(status, con) = semanage.semanage_context_create(sh)
 		if status < 0:
Signature · 1 line
2.0.0
#2 lore raw

PATCH 2/2 libsemanage: use semanage_bool_get_value to print a boolean

In reply to Nicolas Iooss

... and not semanage_bool_set_value.

This fixes "python2 pywrap-test.py -v -B -C"

---
 libsemanage/src/pywrap-test.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libsemanage/src/pywrap-test.py +2 -2
index 5d8aad1..c00d2c7 100644
@@ -829,7 +829,7 @@ class Tests:
 		if self.verbose: print "SEBool name set: ", semanage.semanage_bool_get_name(pbool)
 
 		semanage.semanage_bool_set_value(pbool, 0)
-		if self.verbose: print "SEbool value set: ", semanage.semanage_bool_set_value(pbool)
+		if self.verbose: print "SEbool value set: ", semanage.semanage_bool_get_value(pbool)
 
 		(status,key) = semanage.semanage_bool_key_extract(sh, pbool)
 		if status < 0:
@@ -912,7 +912,7 @@ class Tests:
 		if self.verbose: print "SEBool name set: ", semanage.semanage_bool_get_name(abool)
 
 		semanage.semanage_bool_set_value(abool, 0)
-		if self.verbose: print "SEbool value set: ", semanage.semanage_bool_set_value(abool)
+		if self.verbose: print "SEbool value set: ", semanage.semanage_bool_get_value(abool)
 
 		print "Starting transaction..."
 		status = semanage.semanage_begin_transaction(sh)
Signature · 1 line
2.0.0
#3 lore raw
In reply to Nicolas Iooss
Quoted 10 lines · Nicolas Iooss

Hello,

While working on porting to Python scripts in sepolgen and policycoreutils to Python 3, I found libsemanage/src/pywrap-test.py. As this script is written in Python 2, I tried to make it compatible with Python 3 too. However there are at least two problems:

* The current script bugs when asked to perform all tests in verbose mode. Here are two patches to fix the script. Can you review and apply them?

Thanks, applied on #next.

Quoted 3 lines

* The file indentation mixes tabs and spaces. Python 2 understands such a thing but Python 3 only supports indenting with tabs or spaces but not both. How should the scripts be indented?

I would say spaces as per PEP-8 but I don't really care either way.

Quoted 8 lines

Nicolas Iooss (2):
libsemanage: fix src/pywrap-test.py -v -F
libsemanage: use semanage_bool_get_value to print a boolean

 libsemanage/src/pywrap-test.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)