Tests: Remove --force options from tracker base class

Removing --force option from tracker base class so it would not be required to
be implemented in every specific tracker, even though it's not necessary.
Modifying existing trackers to reflect this change.

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

Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
Lenka Doudova 2016-09-20 17:29:02 +02:00 committed by Martin Basti
parent 361105a3d5
commit a07c4bdd4f
14 changed files with 32 additions and 18 deletions

View File

@ -128,7 +128,7 @@ class TestProfileCRUD(XMLRPC_test):
def test_create_duplicate(self, user_profile): def test_create_duplicate(self, user_profile):
msg = u'Certificate Profile with name "{}" already exists' msg = u'Certificate Profile with name "{}" already exists'
user_profile.ensure_exists() user_profile.ensure_exists()
command = user_profile.make_create_command(force=True) command = user_profile.make_create_command()
with raises_exact(errors.DuplicateEntry( with raises_exact(errors.DuplicateEntry(
message=msg.format(user_profile.name))): message=msg.format(user_profile.name))):
command() command()

View File

@ -38,8 +38,7 @@ class AutomemberTracker(Tracker):
self.dn = DN(('cn', self.cn), ('cn', self.membertype.title()), self.dn = DN(('cn', self.cn), ('cn', self.membertype.title()),
('cn', 'automember'), ('cn', 'etc'), api.env.basedn) ('cn', 'automember'), ('cn', 'etc'), api.env.basedn)
def make_create_command(self, def make_create_command(self, *args, **kwargs):
force=True, *args, **kwargs):
""" Make function that creates an automember using 'automember-add' """ """ Make function that creates an automember using 'automember-add' """
return self.make_command('automember_add', self.cn, return self.make_command('automember_add', self.cn,
description=self.description, description=self.description,

View File

@ -167,7 +167,7 @@ class Tracker(object):
"""If the entry does not exist (according to tracker state), create it """If the entry does not exist (according to tracker state), create it
""" """
if not self.exists: if not self.exists:
self.create(force=True) self.create()
def ensure_missing(self): def ensure_missing(self):
"""If the entry exists (according to tracker state), delete it """If the entry exists (according to tracker state), delete it
@ -175,7 +175,7 @@ class Tracker(object):
if self.exists: if self.exists:
self.delete() self.delete()
def make_create_command(self, force=True): def make_create_command(self):
"""Make function that creates the plugin entry object.""" """Make function that creates the plugin entry object."""
raise NotImplementedError(self._override_me_msg) raise NotImplementedError(self._override_me_msg)
@ -199,11 +199,11 @@ class Tracker(object):
"""Make function that modifies the entry using ${CMD}_mod""" """Make function that modifies the entry using ${CMD}_mod"""
raise NotImplementedError(self._override_me_msg) raise NotImplementedError(self._override_me_msg)
def create(self, force=True): def create(self):
"""Helper function to create an entry and check the result""" """Helper function to create an entry and check the result"""
self.ensure_missing() self.ensure_missing()
self.track_create() self.track_create()
command = self.make_create_command(force=force) command = self.make_create_command()
result = command() result = command()
self.check_create(result) self.check_create(result)

View File

@ -37,7 +37,7 @@ class CATracker(Tracker):
self.api.env.container_ca, self.api.env.container_ca,
self.api.env.basedn) self.api.env.basedn)
def make_create_command(self, force=True): def make_create_command(self):
"""Make function that creates the plugin entry object.""" """Make function that creates the plugin entry object."""
return self.make_command( return self.make_command(
'ca_add', self.name, ipacasubjectdn=self.ipasubjectdn, 'ca_add', self.name, ipacasubjectdn=self.ipasubjectdn,

View File

@ -87,7 +87,7 @@ class CAACLTracker(Tracker):
""" """
return {cat: [v] for cat, v in self.categories.items() if v} return {cat: [v] for cat, v in self.categories.items() if v}
def make_create_command(self, force=True): def make_create_command(self):
return self.make_command(u'caacl_add', self.name, return self.make_command(u'caacl_add', self.name,
description=self.description, description=self.description,
**self.categories) **self.categories)

View File

@ -57,7 +57,7 @@ class CertprofileTracker(Tracker):
content = f.read() content = f.read()
return unicode(content) return unicode(content)
def make_create_command(self, force=True): def make_create_command(self):
if not self.profile: if not self.profile:
raise RuntimeError('Tracker object without path to profile ' raise RuntimeError('Tracker object without path to profile '
'cannot be used to create profile entry.') 'cannot be used to create profile entry.')

View File

@ -30,7 +30,7 @@ class GroupTracker(Tracker):
self.dn = get_group_dn(self.cn) self.dn = get_group_dn(self.cn)
def make_create_command(self, nonposix=False, external=False, def make_create_command(self, nonposix=False, external=False,
force=True, *args, **kwargs): *args, **kwargs):
""" Make function that creates a group using 'group-add' """ """ Make function that creates a group using 'group-add' """
return self.make_command('group_add', self.cn, return self.make_command('group_add', self.cn,
description=self.description, description=self.description,

View File

@ -93,6 +93,14 @@ class HostTracker(KerberosAliasMixin, Tracker):
"""Make function that modifies the host using host_mod""" """Make function that modifies the host using host_mod"""
return self.make_command('host_mod', self.fqdn, **updates) return self.make_command('host_mod', self.fqdn, **updates)
def create(self, force=True):
"""Helper function to create an entry and check the result"""
self.ensure_missing()
self.track_create()
command = self.make_create_command(force=force)
result = command()
self.check_create(result)
def track_create(self): def track_create(self):
"""Update expected state for host creation""" """Update expected state for host creation"""
self.attrs = dict( self.attrs = dict(

View File

@ -43,13 +43,13 @@ class LocationTracker(Tracker):
self.servers = {} self.servers = {}
def make_create_command(self, force=None): def make_create_command(self):
"""Make function that creates this location using location-add""" """Make function that creates this location using location-add"""
return self.make_command( return self.make_command(
'location_add', self.idnsname, description=self.description, 'location_add', self.idnsname, description=self.description,
) )
def make_delete_command(self, force=None): def make_delete_command(self):
"""Make function that removes this location using location-del""" """Make function that removes this location using location-del"""
return self.make_command('location_del', self.idnsname) return self.make_command('location_del', self.idnsname)

View File

@ -85,6 +85,14 @@ class ServiceTracker(KerberosAliasMixin, Tracker):
return self.make_command('service_mod', self.name, **updates) return self.make_command('service_mod', self.name, **updates)
def create(self, force=True):
"""Helper function to create an entry and check the result"""
self.ensure_missing()
self.track_create()
command = self.make_create_command(force=force)
result = command()
self.check_create(result)
def track_create(self, **options): def track_create(self, **options):
""" Update expected state for service creation """ """ Update expected state for service creation """
self.attrs = { self.attrs = {

View File

@ -71,7 +71,7 @@ class StageUserTracker(Tracker):
self.kwargs = kwargs self.kwargs = kwargs
def make_create_command(self, options=None, force=None): def make_create_command(self, options=None):
""" Make function that creates a staged user using stageuser-add """ """ Make function that creates a staged user using stageuser-add """
if options is not None: if options is not None:
self.kwargs = options self.kwargs = options

View File

@ -32,7 +32,7 @@ class SudoCmdTracker(Tracker):
""" Property holding the name of the entry in LDAP """ """ Property holding the name of the entry in LDAP """
return self.cmd return self.cmd
def make_create_command(self, force=True): def make_create_command(self):
""" Make function that creates a sudocmd using 'sudocmd-add' """ """ Make function that creates a sudocmd using 'sudocmd-add' """
return self.make_command('sudocmd_add', self.cmd, return self.make_command('sudocmd_add', self.cmd,
description=self.description) description=self.description)

View File

@ -36,8 +36,7 @@ class SudoCmdGroupTracker(Tracker):
self.dn = DN(('cn', self.cn), ('cn', 'sudocmdgroups'), self.dn = DN(('cn', self.cn), ('cn', 'sudocmdgroups'),
('cn', 'sudo'), api.env.basedn) ('cn', 'sudo'), api.env.basedn)
def make_create_command(self, def make_create_command(self, *args, **kwargs):
force=True, *args, **kwargs):
""" Make function that creates a sudocmdgroup """ Make function that creates a sudocmdgroup
using 'sudocmdgroup-add' """ using 'sudocmdgroup-add' """
return self.make_command('sudocmdgroup_add', self.cn, return self.make_command('sudocmdgroup_add', self.cn,

View File

@ -71,7 +71,7 @@ class UserTracker(KerberosAliasMixin, Tracker):
self.kwargs = kwargs self.kwargs = kwargs
def make_create_command(self, force=None): def make_create_command(self):
""" Make function that crates a user using user-add """ """ Make function that crates a user using user-add """
return self.make_command( return self.make_command(
'user_add', self.uid, 'user_add', self.uid,