On 11/14/2014 04:41 PM, Aline Manera wrote:

On 11/14/2014 04:36 PM, Crístian Viana wrote:
On 14-11-2014 15:15, Aline Manera wrote:
The reset() function is to clean up all the mockup resources as it is running for the first time.

The whole code is:

        params = {'vms': [u'test'], 'templates': [],
                  'networks': [u'default'], 'storagepools': [u'default-pool']}

        for res, items in params.iteritems():
            resources = getattr(self, '%s_get_list' % res)()
            for i in resources:
                if i in items:
continue

try:
                    getattr(self, '%s_deactivate' % res[:-1])(i)
except:
pass

                getattr(self, '%s_delete' % res[:-1])(i)


"params" hold the first time configuration - so one only VM named "test" must persist on 'test:///default' URI and the same for storagepools and networks.

The first loop (for res, items in params.iteritems()) is to go by the "params" list.
Then I collect all the resources for the API (resources = getattr(self, '%s_get_list' % res)()).
The seconds loop is to identify the resources that need to be removed, ie, will not be in the first run time. So I compared the item against the "params" values.

Does that make sense?

The logic makes sense but that's not what that code snippet does. The keyword "continue" will skip the current iteration of the *inner loop*, not the outer one - which I guess is what you intended. In other words, the inner loop doesn't do anything.

No - I want to skip only the inner loop


Try removing the inner loop entirely; the code will still work as before.

No! The outer loop is for pass along vms, storagepools, networks. The inner loop is for each VM, each storage pools, each network.

The inner loop will be skipped *only if* the resource is in the default config (represented by "params")

To clarify the inner loop could be replaced by:

       params = {'vms': [u'test'], 'templates': [],
                  'networks': [u'default'], 'storagepools': [u'default-pool']}

        for res, items in params.iteritems():
            resources = getattr(self, '%s_get_list' % res)()

            for i in list(set(resources) - set(items):
                try:
                    getattr(self, '%s_deactivate' % res[:-1])(i)
                except:
                    pass

                getattr(self, '%s_delete' % res[:-1])(i)




_______________________________________________
Kimchi-devel mailing list
Kimchi-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel