marvin_refactor: PostGenerationMethodCall doesn't work in create strategy For performing post-generation hooks after the generation during the create strategy of a factory we need to use the post_generation hook instead of a PostGenerationMethodCall. Also, the `apiclient` attribute does not get passed to the postgenerator unless specified in the kwargs using the extended args notation (ATTR__ARGS)
Also Correct the network creation test Signed-off-by: Prasanna Santhanam <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/422c7b08 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/422c7b08 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/422c7b08 Branch: refs/heads/marvin_refactor Commit: 422c7b08c66b4e4ae4951097a897ba30bf1e1e37 Parents: 4ea9a2c Author: Prasanna Santhanam <[email protected]> Authored: Tue Sep 10 16:46:35 2013 +0530 Committer: Prasanna Santhanam <[email protected]> Committed: Thu Oct 31 13:54:24 2013 +0530 ---------------------------------------------------------------------- tools/marvin/marvin/factory/data/network.py | 1 + .../marvin/factory/data/networkoffering.py | 29 +++++++++++--------- tools/marvin/marvin/test/test_factories.py | 8 +++--- 3 files changed, 21 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/422c7b08/tools/marvin/marvin/factory/data/network.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/factory/data/network.py b/tools/marvin/marvin/factory/data/network.py index ad6101c..962d24f 100644 --- a/tools/marvin/marvin/factory/data/network.py +++ b/tools/marvin/marvin/factory/data/network.py @@ -30,6 +30,7 @@ class GuestIsolatedNetworkFactory(NetworkFactory): DefaultIsolatedNetworkOfferingWithSourceNatServiceFactory, apiclient=factory.SelfAttribute('..apiclient'), name=factory.Sequence(lambda n: 'GuestIsolatedNetworkOffering-%s' % random_gen()), + enable__apiclient=factory.SelfAttribute('..apiclient') ) networkofferingid = factory.LazyAttribute(lambda no: no.networkoffering.id if no.networkoffering else no.networkoffering) zoneid = None http://git-wip-us.apache.org/repos/asf/cloudstack/blob/422c7b08/tools/marvin/marvin/factory/data/networkoffering.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/factory/data/networkoffering.py b/tools/marvin/marvin/factory/data/networkoffering.py index 829aee0..96f77cf 100644 --- a/tools/marvin/marvin/factory/data/networkoffering.py +++ b/tools/marvin/marvin/factory/data/networkoffering.py @@ -44,11 +44,11 @@ class DefaultIsolatedNetworkOfferingWithSourceNatServiceFactory(NetworkOfferingF } ) # enable the offering post generation - factory.PostGenerationMethodCall('update', - factory.SelfAttribute('..apiclient'), - id=factory.SelfAttribute('..id'), - state='Enabled') - + @factory.post_generation + def enable(self, create, extracted, **kwargs): + if not create: + return + self.update(apiclient=kwargs['apiclient'], id=self.id, state='Enabled') class DefaultSharedNetworkOfferingWithSGServiceFactory(NetworkOfferingFactory): @@ -79,10 +79,12 @@ class DefaultSharedNetworkOfferingWithSGServiceFactory(NetworkOfferingFactory): ) # enable the offering post generation - factory.PostGenerationMethodCall('update', - factory.SelfAttribute('..apiclient'), - id=factory.SelfAttribute('..id'), - state='Enabled') + @factory.post_generation + def enable(self, create, extracted, **kwargs): + if not create: + return + self.update(apiclient=kwargs['apiclient'], id=self.id, state='Enabled') + class DefaultSharedNetworkOfferingFactory(NetworkOfferingFactory): @@ -109,7 +111,8 @@ class DefaultSharedNetworkOfferingFactory(NetworkOfferingFactory): ) # enable the offering post generation - factory.PostGenerationMethodCall('update', - factory.SelfAttribute('..apiclient'), - id=factory.SelfAttribute('..id'), - state='Enabled') + @factory.post_generation + def enable(self, create, extracted, **kwargs): + if not create: + return + self.update(apiclient=kwargs['apiclient'], id=self.id, state='Enabled') http://git-wip-us.apache.org/repos/asf/cloudstack/blob/422c7b08/tools/marvin/marvin/test/test_factories.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/test/test_factories.py b/tools/marvin/marvin/test/test_factories.py index bf6f228..2dd5069 100644 --- a/tools/marvin/marvin/test/test_factories.py +++ b/tools/marvin/marvin/test/test_factories.py @@ -201,17 +201,17 @@ class NetworkFactoryTest(unittest.TestCase): logging=logging.getLogger('factory.cloudstack')).getApiClient() def tearDown(self): - pass + self.accnt.delete() @attr(tags='network') def test_isolatedGuestNetwork(self): """Test to create a network within a guest account @return: """ - accnt = UserAccountFactory(apiclient=self.apiClient) + self.accnt = UserAccountFactory(apiclient=self.apiClient) zones = Zone.list(apiclient=self.apiClient) network = GuestIsolatedNetworkFactory( apiclient=self.apiClient, - zoneid=zones[0].id, + zoneid=zones[0].id ) - self.debug("network created with id, name" %(network.id, network.name)) \ No newline at end of file + logging.getLogger('factory.cloudstack').debug("network created with id %s, name %s" %(network.id, network.name)) \ No newline at end of file
