Antoni Segura Puimedon has uploaded a new change for review.

Change subject: tc_wrapper: Fix errno reporting
......................................................................

tc_wrapper: Fix errno reporting

When tc fails in and of itself, it returns with code 1. When it is
due to kernel error as relayed by the kernel in rtnl_talk, it sets
the return code to 2 and prints like so:

    fprintf(stderr, "RTNETLINK answers: %s\n",
            strerror(-err->error));

Thus, if wrapper._process_request is to raise proper errno
verifiable error codes in its TrafficControlExceptions, it is
necessary that we do the inverse process, strerror -> errno.

After this patch:

When deleting a non-existing class as root:

In [6]: wrapper._process_request(['class', 'del', 'dev', 'em1',
                                  'classid', '1:2'])
TrafficControlException:
(2, 'RTNETLINK answers: No such file or directory\n',
['/usr/sbin/tc', 'class', 'del', 'dev', 'em1', 'classid', '1:2'])

And as regular user:
In [49]: wrapper._process_request(['class', 'del', 'dev', 'em1',
                                   'classid', '1:2']
TrafficControlException:
(1, 'RTNETLINK answers: Operation not permitted\n',
['/usr/sbin/tc', 'class', 'del', 'dev', 'em1', 'classid', '1:2'])

Both being the correct errno codes.

Change-Id: I0483b694d805e8f7d686146c3545b93dc8962d76
Signed-off-by: Antoni S. Puimedon <[email protected]>
---
M vdsm/network/tc/wrapper.py
1 file changed, 8 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/59/30459/1

diff --git a/vdsm/network/tc/wrapper.py b/vdsm/network/tc/wrapper.py
index 07777c7..8c18cd2 100644
--- a/vdsm/network/tc/wrapper.py
+++ b/vdsm/network/tc/wrapper.py
@@ -16,14 +16,22 @@
 #
 # Refer to the README and COPYING files for full details of the license
 #
+import os
+import errno
+
 from vdsm.constants import EXT_TC
 from vdsm.utils import execCmd
+
+_TC_ERR_PREFIX = 'RTNETLINK answers: '
+_errno_trans = dict(((os.strerror(code), code) for code in errno.errorcode))
 
 
 def _process_request(command):
     command.insert(0, EXT_TC)
     retcode, out, err = execCmd(command, raw=True)
     if retcode != 0:
+        if retcode == 2:
+            retcode = _errno_trans.get(err[len(_TC_ERR_PREFIX):].strip())
         raise TrafficControlException(retcode, err, command)
     return out
 


-- 
To view, visit http://gerrit.ovirt.org/30459
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0483b694d805e8f7d686146c3545b93dc8962d76
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to