[Kimchi-devel] [PATCH 2/2] MockModel refactor: Create MockModel based on Model("test:///default")
Crístian Viana
vianac at linux.vnet.ibm.com
Fri Nov 14 18:36:42 UTC 2014
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.
Try removing the inner loop entirely; the code will still work as before.
More information about the Kimchi-devel
mailing list