[Freeipa-devel] [PATCH 0388] tests: Add hostmask detection for sudo rules validating

Lukas Slebodnik lslebodn at redhat.com
Thu Dec 10 08:05:13 UTC 2015


On (08/12/15 14:47), Tomas Babej wrote:
>
>
>On 12/03/2015 04:33 PM, Tomas Babej wrote:
>> 
>> 
>> On 12/03/2015 04:26 PM, Aleš Mareček wrote:
>>> Hello,
>>>
>>> ACK for code
>>> NACK for the placing "get_client_ip_with_hostmask" function to test_sudo.py (this function should be in some more general file)
>>>
>> 
>> What place would you propose? The task.py is not a good place, as this
>> is not really a task.
>> 
>> Nevertheless, I'd rather have it moved when an use case outside
>> test_sudo.py actually arises. Right now it would lead to unnecessary
>> cluttering.
>> 
>> Tomas
>> 
>
>I re-discovered ipatests.test_integration.util (two years after I
>created it :D) - which seemed ideal for this function.
>
>Updated patch attached.
>
>Tomas

>From 33552d6078d75ee99f9ec19ae143df5a61ba84a4 Mon Sep 17 00:00:00 2001
>From: Tomas Babej <tbabej at redhat.com>
>Date: Wed, 2 Dec 2015 15:25:49 +0100
>Subject: [PATCH] tests: Add hostmask detection for sudo rules validating on
> hostmask
>
>IPA sudo tests worked under the assumption that the clients
>that are executing the sudo commands have their IPs assigned
>within 255.255.255.0 hostmask.
>
>Removes this (invalid) assumption and adds a
>dynamic detection of the hostmask of the IPA client.
>
>https://fedorahosted.org/freeipa/ticket/5501
>---
> ipatests/test_integration/test_sudo.py | 33 +++++++++++++++++++++++++++------
> ipatests/test_integration/util.py      | 16 ++++++++++++++++
> 2 files changed, 43 insertions(+), 6 deletions(-)
>
>diff --git a/ipatests/test_integration/util.py b/ipatests/test_integration/util.py
>index 1a1bb3fcc923c9f2721f0a4c1cb7a1ba2ccc2dd8..187f39e80e84af0eb4938fb19ac3d3c7c2280ed9 100644
>--- a/ipatests/test_integration/util.py
>+++ b/ipatests/test_integration/util.py
>@@ -58,3 +58,19 @@ def run_repeatedly(host, command, assert_zero_rc=True, test=None,
>                          .format(cmd=' '.join(command),
>                                  times=timeout / time_step,
>                                  timeout=timeout))
>+
>+
>+def get_host_ip_with_hostmask(host):
>+    """
>+    Detects the IP of the host including the hostmask.
>+
>+    Returns None if the IP could not be detected.
>+    """
>+
>+    ip = host.ip
>+    result = host.run_command(['ip', 'addr'])
>+    full_ip_regex = r'(?P<full_ip>%s/\d{1,2}) ' % re.escape(ip)
>+    match = re.search(full_ip_regex, result.stdout_text)
./make-lint 
************* Module ipatests.test_integration.util
ipatests/test_integration/util.py:72: [E0602(undefined-variable), get_host_ip_with_hostmask] Undefined variable 're')
ipatests/test_integration/util.py:73: [E0602(undefined-variable), get_host_ip_with_hostmask] Undefined variable 're')
===============================================================================
Errors were found during the static code check.
If you are certain that any of the reported errors are false positives, please
mark them in the source code according to the pylint documentation.
===============================================================================
Makefile:124: recipe for target 'lint' failed

LS




More information about the Freeipa-devel mailing list