You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ts...@apache.org on 2013/11/18 09:50:34 UTC

[27/50] [abbrv] git commit: updated refs/heads/marvin_refactor to b784012

marvin_refactor: include apiclient as part of factory

The apiclient is required for creation of any factory and should be the
in the FACTORY_ARGS list. This is useful for post_generation hooks to
call other methods on the resulting object. For eg: A network creation
triggers a networkoffering creation and so the enabling of the
networkoffering.

Signed-off-by: Prasanna Santhanam <ts...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4268f24a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4268f24a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4268f24a

Branch: refs/heads/marvin_refactor
Commit: 4268f24aca5c1310429e2acefecd542492154621
Parents: 422c7b0
Author: Prasanna Santhanam <ts...@apache.org>
Authored: Wed Sep 11 20:00:05 2013 +0530
Committer: Prasanna Santhanam <ts...@apache.org>
Committed: Thu Oct 31 13:54:24 2013 +0530

----------------------------------------------------------------------
 tools/marvin/marvin/factory/data/network.py         | 1 -
 tools/marvin/marvin/factory/data/networkoffering.py | 6 +++---
 tools/marvin/marvin/generate/entity.py              | 5 +++--
 tools/marvin/marvin/generate/factory.py             | 4 +++-
 tools/marvin/marvin/test/test_factories.py          | 6 +++---
 tools/marvin/pom.xml                                | 1 +
 6 files changed, 13 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4268f24a/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 962d24f..ad6101c 100644
--- a/tools/marvin/marvin/factory/data/network.py
+++ b/tools/marvin/marvin/factory/data/network.py
@@ -30,7 +30,6 @@ 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/4268f24a/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 96f77cf..41cda56 100644
--- a/tools/marvin/marvin/factory/data/networkoffering.py
+++ b/tools/marvin/marvin/factory/data/networkoffering.py
@@ -48,7 +48,7 @@ class DefaultIsolatedNetworkOfferingWithSourceNatServiceFactory(NetworkOfferingF
     def enable(self, create, extracted, **kwargs):
         if not create:
             return
-        self.update(apiclient=kwargs['apiclient'], id=self.id, state='Enabled')
+        self.update(apiclient=self.apiclient, id=self.id, state='Enabled')
 
 
 class DefaultSharedNetworkOfferingWithSGServiceFactory(NetworkOfferingFactory):
@@ -83,7 +83,7 @@ class DefaultSharedNetworkOfferingWithSGServiceFactory(NetworkOfferingFactory):
     def enable(self, create, extracted, **kwargs):
         if not create:
             return
-        self.update(apiclient=kwargs['apiclient'], id=self.id, state='Enabled')
+        self.update(apiclient=self.apiclient, id=self.id, state='Enabled')
 
 
 
@@ -115,4 +115,4 @@ class DefaultSharedNetworkOfferingFactory(NetworkOfferingFactory):
     def enable(self, create, extracted, **kwargs):
         if not create:
             return
-        self.update(apiclient=kwargs['apiclient'], id=self.id, state='Enabled')
+        self.update(apiclient=self.apiclient, id=self.id, state='Enabled')

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4268f24a/tools/marvin/marvin/generate/entity.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/generate/entity.py b/tools/marvin/marvin/generate/entity.py
index 76316ef..dc96a14 100644
--- a/tools/marvin/marvin/generate/entity.py
+++ b/tools/marvin/marvin/generate/entity.py
@@ -96,11 +96,12 @@ class Entity(object):
                     m.signature = 'def __init__(self, apiclient=None, %s, factory=None, **kwargs):' % (
                     ', '.join(map(lambda arg: arg + '=None', list(set(details['args'])))))
                 else:
-                    m.signature = 'def %s(cls, apiclient=None, factory=None, **kwargs):' % action
+                    m.signature = 'def %s(cls, apiclient, factory=None, **kwargs):' % action
 
+                m.body.append(self.tabspace + 'self.__update__(kwargs)')
                 m.body.append(self.tabspace + 'if not apiclient:')
-                m.body.append(self.tabspace * 2 + 'self.__update__(kwargs)')
                 m.body.append(self.tabspace*2 + 'return')
+                m.body.append(self.tabspace + 'self.apiclient = apiclient')
 
                 m.body.append(self.tabspace + 'cmd = %(module)s.%(command)s()' % {"module": details["apimodule"],
                                                                                "command": details["apicmd"]})

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4268f24a/tools/marvin/marvin/generate/factory.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/generate/factory.py b/tools/marvin/marvin/generate/factory.py
index d31f916..7c717f0 100644
--- a/tools/marvin/marvin/generate/factory.py
+++ b/tools/marvin/marvin/generate/factory.py
@@ -52,7 +52,9 @@ class Factory(object):
         code += '\n\n'
         code += 'class %sFactory(Factory):' % entity
         code += '\n\n'
-        code += tabspace + 'FACTORY_FOR = %s\n\n' % entity
+        code += tabspace + 'FACTORY_FOR = %s\n' % entity
+        code += tabspace + 'FACTORY_ARG_PARAMETERS = (\'apiclient\',)\n\n'
+        code += tabspace + 'apiclient = None\n'
         for arg in factory_defaults:
             code += tabspace + '%s = None\n' % arg
         self.name = entity

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4268f24a/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 2dd5069..81e78a7 100644
--- a/tools/marvin/marvin/test/test_factories.py
+++ b/tools/marvin/marvin/test/test_factories.py
@@ -107,9 +107,9 @@ class NetworkOfferingFactoryTest(unittest.TestCase):
         self.assert_(snatOffering is not None, msg = "no network offering was created")
         self.assert_(snatOffering.name is not None, msg="error in network offering creation")
 
+    @attr(tags='offering')
     def test_defaultSGOfferingEnable(self):
-        sgOffering = DefaultSharedNetworkOfferingWithSGServiceFactory(apiclient=self.apiClient)
-        sgOffering.update(self.apiClient, state='Enabled', name=sgOffering.name, id=sgOffering.id)
+        DefaultSharedNetworkOfferingWithSGServiceFactory(apiclient=self.apiClient)
 
     def tearDown(self):
         pass
@@ -201,7 +201,7 @@ class NetworkFactoryTest(unittest.TestCase):
             logging=logging.getLogger('factory.cloudstack')).getApiClient()
 
     def tearDown(self):
-        self.accnt.delete()
+        self.accnt.delete(apiclient=self.apiClient)
 
     @attr(tags='network')
     def test_isolatedGuestNetwork(self):

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4268f24a/tools/marvin/pom.xml
----------------------------------------------------------------------
diff --git a/tools/marvin/pom.xml b/tools/marvin/pom.xml
index 9876122..053a1a1 100644
--- a/tools/marvin/pom.xml
+++ b/tools/marvin/pom.xml
@@ -62,6 +62,7 @@
                 <argument>codegenerator.py</argument>
                 <argument>-s</argument>
                 <argument>${basedir}/commands.xml</argument>
+                <argument>-y</argument>
               </arguments>
             </configuration>
           </execution>