[openstack-dev] A proposal for code reduction

Clark, Robert Graham robert.clark at hp.com
Wed May 21 11:34:23 UTC 2014


From: Abhijeet Jain [mailto:abhijeet.jain at nectechnologies.in] 
Sent: 21 May 2014 12:27
To: openstack-dev at lists.openstack.org
Subject: [openstack-dev] A proposal for code reduction

 

Hi Openstack-developers,

 

I am Abhijeet Jain. One of the contributor in OpenStack.

 

I was just working on optimizing the codes in Neutron , Keystone, Cinder
modules.

Then, I came across with a very common scenario that I can see at many
places.

at many places, I saw that the users have written the code in such form
:

 

assertEqual(user1['id'], user2['id']);

assertEqual(user1['name'], user2['name']);

assertEqual(user1['status'], user2['status']);

assertEqual(user1['xyz'], user2['xyz']);

 

 

To optimize such redundancy, I created a help function like below :

 

def _check(self, expected, actual, keys):

    for key in keys:

        assertEqual( expected[key], actual[key])

 

 

So, everywhere we just need to call this function like this :

_check(user1, user2, ['id', 'name', 'status', 'xyz'])

 

So, this way lots of code can be reduced.

but, currently i need to put that function in every test file , I want
to use. There is no global space.

 

My proposal is :

How about putting this function in some utils like place, which can be
accessed in every test function.

but for that, I need your approval.

Kindly, provide your valuable feedback on this.

 

 

 

Thanks,

Abhijeet Jain

 
 
Hi Abhijeet,
 
Excuse me if I've missed the point but it sounds like the oslo project
would be the place you'd want to put bits of shared code like this.
 
If you weren't already aware of it there's some great content here:
https://wiki.openstack.org/wiki/Oslo
 
Hope this helps
-Rob
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20140521/e5475256/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 6187 bytes
Desc: not available
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20140521/e5475256/attachment.bin>


More information about the OpenStack-dev mailing list