#6311 Fix or remove the `LDAPUpdate.update_from_dict` method
Closed: Fixed None Opened 7 years ago by mbabinsk.

Among the last few failures in our in-tree tests is the last test case of test_install/test_updates.py method:

===================================================== FAILURES =====================================================
____________________________________________ test_update.test_from_dict ____________________________________________

self = <ipatests.test_install.test_updates.test_update testMethod=test_from_dict>

    def test_from_dict(self):
        """
            Test updating from a dict.

            This replicates what was done in test 1.
            """

        # First make sure we're clean
        with self.assertRaises(errors.NotFound):
            entries = self.ld.get_entries(
                self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])

        with self.assertRaises(errors.NotFound):
            entries = self.ld.get_entries(
                self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])


        update = {
            self.container_dn:
                {'dn': self.container_dn,
                 'updates': ['add:objectClass: top',
                             'add:objectClass: nsContainer',
                             'add:cn: test'
                            ],
                },
            self.user_dn:
                {'dn': self.user_dn,
                 'updates': ['add:objectclass: top',
                             'add:objectclass: person',
                             'add:objectclass: posixaccount',
                             'add:objectclass: krbprincipalaux',
                             'add:objectclass: inetuser',
                             'add:homedirectory: /home/tuser',
                             'add:loginshell: /bin/bash',
                             'add:sn: User',
                             'add:uid: tuser',
                             'add:uidnumber: 999',
                             'add:gidnumber: 999',
                             'add:cn: Test User',
                            ],
                },
        }

>       modified = self.updater.update_from_dict(update)

test_install/test_updates.py:300: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../ipaserver/install/ldapupdate.py:932: in update_from_dict
    self._run_updates(updates)
../ipaserver/install/ldapupdate.py:886: in _run_updates
    if 'deleteentry' in update:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = ipapython.dn.DN('uid=tuser,cn=test,cn=accounts,dc=ipa,dc=test'), other = 'deleteentry'

    def __contains__(self, other):
        'Return the outcome of the test other in self. Note the reversed operands.'

        if isinstance(other, RDN):
            other = DN(other)
        if isinstance(other, DN):
            other_len = len(other)
            end = len(self) - other_len
            i = 0
            while i <= end:
                result = self._cmp_sequence(other, i, other_len)
                if result == 0:
                    return True
                i += 1
            return False
        else:
>           raise TypeError("expected DN or RDN but got %s" % (other.__class__.__name__))
E           TypeError: expected DN or RDN but got str

../ipapython/dn.py:1324: TypeError
======================================= 1 failed, 11 passed in 13.60 seconds =======================================

This error arises from the flawed logic of update_from_dict method, which passes the dictionary to the internal _run_updates method which, however expects a list of dicts and blows up.

However, upon grepping the usage of this method it became apparent that it is not used in any production code, only in tests:

$ git grep -ni update_from_dict
ipaserver/install/ldapupdate.py:924:    def update_from_dict(self, updates):
ipatests/test_install/test_updates.py:300:        modified = self.updater.update_from_dict(update)
ipatests/test_install/test_updates.py:341:        modified = self.updater.update_from_dict(update)

Given this fact it would be probably more efficient to just remove it and associated tests unless there is some special need for it.


  • 330a3ca Remove update_from_dict() method

ipa-4-4:

  • fd9434c Remove update_from_dict() method

ipa-4-3:

  • 126c7c6 Remove update_from_dict() method

Metadata Update from @mbabinsk:
- Issue assigned to stlaz
- Issue set to the milestone: FreeIPA 4.3.3

7 years ago

Login to comment on this ticket.

Metadata