Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipatests: nested netgroups (intg) #409

Closed
wants to merge 1 commit into from

Conversation

celestian
Copy link
Member

@celestian celestian commented Jan 23, 2017

Adds a test case for issue in SSSD that manifested in
an inability to resolve nested membership in netgroups

The test case tests for direct and indirect membership.

https://fedorahosted.org/freeipa/ticket/6439

@celestian
Copy link
Member Author

I see there are some issues:

  1. It seems Travis hit some kind of time out. Maybe it is not connected to my proposed test.
  2. The QuantifiedCode issues are clear.

I have PTO now and I will be back in work on Friday. But I hope I find a time to fix it sooner.

@MartinBasti
Copy link
Contributor

Travis:

PEP-8 errors:
./ipatests/test_integration/test_netgroup.py:87:80: E501 line too long (84 > 79 characters)
./ipatests/test_integration/test_netgroup.py:96:80: E501 line too long (88 > 79 characters)


Pylint:
Pylint is running, please wait ...
************* Module ipatests.test_integration.test_netgroup
ipatests/test_integration/test_netgroup.py:2: [W0512(invalid-encoded-data), ] Cannot decode using encoding "ascii", unexpected byte at position 9)
ipatests/test_integration/test_netgroup.py:87: [E1101(no-member), TestNetgroups.check_users_in_netgroups] Class 'domain' has no 'name' member)
ipatests/test_integration/test_netgroup.py:96: [E1101(no-member), TestNetgroups.check_nested_netgroup_hierarchy] Class 'domain' has no 'name' member)
ipatests/test_integration/test_netgroup.py:125: [E1101(no-member), TestNetgroups.test_remove_nested_netgroup] Class 'domain' has no 'name' member)
ipatests/test_integration/test_netgroup.py:130: [E1101(no-member), TestNetgroups.test_remove_nested_netgroup] Class 'domain' has no 'name' member)
ipatests/test_integration/test_netgroup.py:131: [E1101(no-member), TestNetgroups.test_remove_nested_netgroup] Class 'domain' has no 'name' member)
ipatests/test_integration/test_netgroup.py:132: [E1101(no-member), TestNetgroups.test_remove_nested_netgroup] Class 'domain' has no 'name' member)
ipatests/test_integration/test_netgroup.py:147: [E1101(no-member), TestNetgroups.test_remove_nested_netgroup] Class 'domain' has no 'name' member)
ipatests/test_integration/test_netgroup.py:148: [E1101(no-member), TestNetgroups.test_remove_nested_netgroup] Class 'domain' has no 'name' member)
ipatests/test_integration/test_netgroup.py:149: [E1101(no-member), TestNetgroups.test_remove_nested_netgroup] Class 'domain' has no 'name' member)
make: *** [pylint] Error 6

I'm afraid that pylint cannot handle it, so probably you have to disable problematic lines.

Copy link
Contributor

@MartinBasti MartinBasti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a few comments. I think that relations and test data should be defined in a python structure and then used instead of doing iterations over range() call

@@ -0,0 +1,149 @@
# Authors:
# Petr Čech <pcech@redhat.com>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the short form of the header, you can find it in test_dnssec.py

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this import, print is not used in code


@pytest.fixture()
def three_netgroups(request):
for i in range(1, 4):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to have dict of names instead range(1, 4) all the time

test_data = [
    {
        'user': {
            'login': 'testuser1',
            'first': 'user1'
        },
        'netgroup': 'testgroup1',
        }
    }
]

# this dict can be generated, you don't have to write it manually

and then

for d in test_data:
    # user-add d['user']['login'] --first=d['user'][first] ...
    # netgroup-add d['netgroup']
    # netgroup-add-member d['netgroup'] --users=d['user']['name']

'--users=testuser%d' % i,
'test_netgroup%d' % i])

def teardown_three_netgroups():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use test_data from previous comment too here please

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and it can be in one cycle


def teardown_three_netgroups():
for i in range(1, 4):
request.cls.master.run_command(['ipa', 'netgroup-del',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to prevent failures in teardown method.

Please use run_command(['*'], raiseonerr=False) it will not raise an exception when failure occurs

super(TestNetgroups, cls).install(mh)

cls.client = cls.clients[0]
cls.clientname = cls.client.run_command(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need a clientname AFAIK client should contain hostname as attribute.

cls.clientname = cls.client.run_command(
['hostname', '-s']).stdout_text.strip()

cls.domain = cls.get_domains()[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO cls.domain should already contain the domain

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove all cls. definitions in install method, you can remove it

def install(cls, mh):
super(TestNetgroups, cls).install(mh)

cls.client = cls.clients[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rather use

client = self.clients[0]

directly in tests? It is more consistent with other tests

def check_users_in_netgroups(self):
clear_sssd_cache(self.client)
for i in range(1, 4):
result = self.client.run_command(['getent', 'passwd',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have to add raiseonerr=False to receive result, otherwise exception will be raised, or you can remove assert result.returncode == 0


def check_nested_netgroup_hierarchy(self):
clear_sssd_cache(self.client)
for i in range(1, 4):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO nesting hierarchy can be represent similarly as test_data

@celestian
Copy link
Member Author

I addressed all comment, I hope.
I know that there are still some pylint stuff like:

ipatests/test_integration/test_netgroup.py:91: [E1101(no-member), TestNetgroups.check_users_in_netgroups] Class 'domain' has no 'name' member)
ipatests/test_integration/test_netgroup.py:108: [E1101(no-member), TestNetgroups.check_nested_netgroup_hierarchy] Class 'domain' has no 'name' member)
ipatests/test_integration/test_netgroup.py:132: [E1101(no-member), TestNetgroups.test_remove_nested_netgroup] Class 'domain' has no 'name' member)

I don't know why due to line 228 and 230 in pylint_plugins.py. Missed I something?

@celestian
Copy link
Member Author

I addressed issue in Travis and Quantified.
New version pushed.

PS: Right way is self.master.domain.name

@@ -0,0 +1,183 @@
#
# Copyright (C) 2015 FreeIPA Contributors see COPYING for license
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2017 please

@celestian
Copy link
Member Author

2015-->2017 addressed. New version pushed.

}
test_data.append(data)

members = [d['user']['login'] for d in test_data] if test_data else []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You dont need, if test_data else [] it behaves the same when test_data == []

'last': 'User_{}'.format(i),
},
'netgroup': 'testgroup_{}'.format(i),
'nested_netgroup': 'testgroup_{}'.format(i-1) if i > 1 else ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer None for nothing, instead of empty string

from ipatests.test_integration.tasks import clear_sssd_cache


def get_test_data():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be test_data a module variable instead of function, I don't see reason to generate the same data again and again

Test Netgroups
"""

num_clients = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be this tested on server side? Do we need to install extra machine?

@celestian
Copy link
Member Author

celestian commented Feb 3, 2017

Addressed, pushed.
Thanks for useful comments :-)

Contributors.txt Outdated
@@ -98,6 +98,7 @@ Developers:
Adam Young
Jan Zelený
Pavel Zůna
Petr Čech
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this file is sorted alphabetically

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed, thanks.

Adds a test case for issue in SSSD that manifested in
an inability to resolve nested membership in netgroups

The test case tests for direct and indirect membership.

https://fedorahosted.org/freeipa/ticket/6439
@MartinBasti MartinBasti added the ack Pull Request approved, can be merged label Feb 6, 2017
@MartinBasti
Copy link
Contributor

@MartinBasti MartinBasti added the pushed Pull Request has already been pushed label Feb 7, 2017
@MartinBasti MartinBasti closed this Feb 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ack Pull Request approved, can be merged pushed Pull Request has already been pushed
Projects
None yet
3 participants