]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Make string representation of DictModel generic
authorKevin Benton <blak111@gmail.com>
Tue, 3 Nov 2015 15:31:54 +0000 (07:31 -0800)
committerKevin Benton <blak111@gmail.com>
Tue, 3 Nov 2015 15:31:54 +0000 (07:31 -0800)
The previous version was specific to a port dict and would
fail if str() was called on other models. This iterates over
and logs all values of the dict instead so it works under any
dictionary.

Change-Id: I630b39338e4e67080e100a9f32c9b6e341a93472
Closes-Bug: #1512753

neutron/agent/linux/dhcp.py
neutron/tests/unit/agent/linux/test_dhcp.py

index df79225a5e15f0485095838c523fcb2fa9c9f357..3781e14170219c7d66bf732ab3155cf06efa6da8 100644 (file)
@@ -97,7 +97,8 @@ class DictModel(dict):
         del self[name]
 
     def __str__(self):
-        return "id=%s, network_id=%s" % (self.id, self.network_id)
+        pairs = ['%s=%s' % (k, v) for k, v in self.items()]
+        return ', '.join(sorted(pairs))
 
 
 class NetModel(DictModel):
index ac264c308189cfcab359b8f2abde9df5b96c70b5..3a00ee86694f7b85d1ccdcbd74c2e6e665a6670e 100644 (file)
@@ -2104,3 +2104,14 @@ class TestDeviceManager(TestConfBase):
         mgr.driver.init_l3.assert_called_with('ns-XXX',
                                               ['192.168.0.6/24'],
                                               namespace='qdhcp-ns')
+
+
+class TestDictModel(base.BaseTestCase):
+
+    def test_string_representation_port(self):
+        port = dhcp.DictModel({'id': 'id', 'network_id': 'net_id'})
+        self.assertEqual('id=id, network_id=net_id', str(port))
+
+    def test_string_representation_network(self):
+        net = dhcp.DictModel({'id': 'id', 'name': 'myname'})
+        self.assertEqual('id=id, name=myname', str(net))