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 <tsp@apache.org>
This commit is contained in:
Prasanna Santhanam 2013-09-10 16:46:35 +05:30
parent 4ea9a2c402
commit 422c7b08c6
3 changed files with 21 additions and 17 deletions

View File

@ -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

View File

@ -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')

View File

@ -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))
logging.getLogger('factory.cloudstack').debug("network created with id %s, name %s" %(network.id, network.name))