From 422c7b08c66b4e4ae4951097a897ba30bf1e1e37 Mon Sep 17 00:00:00 2001 From: Prasanna Santhanam Date: Tue, 10 Sep 2013 16:46:35 +0530 Subject: [PATCH] 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 --- 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(-) diff --git a/tools/marvin/marvin/factory/data/network.py b/tools/marvin/marvin/factory/data/network.py index ad6101c013e..962d24f7029 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 diff --git a/tools/marvin/marvin/factory/data/networkoffering.py b/tools/marvin/marvin/factory/data/networkoffering.py index 829aee0488c..96f77cf3b42 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') diff --git a/tools/marvin/marvin/test/test_factories.py b/tools/marvin/marvin/test/test_factories.py index bf6f22836ac..2dd5069b670 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