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:25 UTC

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

marvin_refactor: UnitTests for NetworkFactory

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/bc7f9165
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/bc7f9165
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/bc7f9165

Branch: refs/heads/marvin_refactor
Commit: bc7f9165c9025261bae5239e2818172a18136edd
Parents: 0678ce7
Author: Prasanna Santhanam <ts...@apache.org>
Authored: Sat Sep 7 11:11:59 2013 +0530
Committer: Prasanna Santhanam <ts...@apache.org>
Committed: Thu Oct 31 13:54:23 2013 +0530

----------------------------------------------------------------------
 tools/marvin/marvin/test/test_factories.py | 82 +++++++++++++++++--------
 1 file changed, 57 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bc7f9165/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 e415231..bf6f228 100644
--- a/tools/marvin/marvin/test/test_factories.py
+++ b/tools/marvin/marvin/test/test_factories.py
@@ -17,6 +17,7 @@
 
 import unittest
 import logging
+from nose.plugins.attrib import attr
 
 from marvin.cloudstackTestClient import cloudstackTestClient
 
@@ -25,6 +26,7 @@ from marvin.factory.data.serviceoffering import *
 from marvin.factory.data.template import *
 from marvin.factory.data.user import *
 from marvin.factory.data.networkoffering import *
+from marvin.factory.data.network import *
 
 from marvin.factory.virtualmachine import *
 
@@ -36,6 +38,9 @@ from marvin.entity.user import User
 from marvin.entity.network import Network
 
 from marvin.entity.ipaddress import IpAddress
+
+
+
 class BuildVsCreateStrategyTest(unittest.TestCase):
     def setUp(self):
         self.apiClient = cloudstackTestClient(mgtSvr='localhost', logging=logging.getLogger('factory.cloudstack')).getApiClient()
@@ -44,11 +49,11 @@ class BuildVsCreateStrategyTest(unittest.TestCase):
         pass
 
     def test_buildUserAccountFactory(self):
-        af = UserAccountFactory()
+        af = UserAccountFactory.build()
         self.assert_(af is not None, msg="Account factory didn't initialize")
 
     def test_createAccountFactory(self):
-        af = UserAccountFactory.create(apiclient=self.apiClient)
+        af = UserAccountFactory(apiclient=self.apiClient)
         self.assert_(isinstance(af, Account))
         self.assert_(af.id is not None, msg="Account creation failed")
         self.assert_(af.domain is not None, msg="Account belongs to no domain")
@@ -59,18 +64,19 @@ class AccountFactoryTest(unittest.TestCase):
         self.apiClient = cloudstackTestClient(mgtSvr='localhost', logging=logging.getLogger('factory.cloudstack')).getApiClient()
 
     def test_adminAccountFactory(self):
-        accnt = AdminAccountFactory.create(apiclient=self.apiClient)
+        accnt = AdminAccountFactory(apiclient=self.apiClient)
         self.assert_(accnt is not None, msg="no account created by factory")
         self.assert_(accnt.name is not None)
 
     def test_userAccountFactoryCustomArgs(self):
-        accnt = UserAccountFactory.create(apiclient=self.apiClient, firstname='test', lastname='test')
+        accnt = UserAccountFactory(apiclient=self.apiClient, firstname='test', lastname='test')
         a = accnt.list(apiclient=self.apiClient, account=accnt.name, domainid=accnt.domainid)
         self.assert_(accnt is not None, msg="no account created by factory")
         self.assert_(accnt.name is not None)
 
     def test_disableAccountPostFactoryGeneration(self):
-        domadmin = DomainAdminFactory.create(apiclient=self.apiClient)
+        domadmin = DomainAdminFactory(apiclient=self.apiClient)
+        a = Account.list(apiclient=self.apiClient, id=domadmin.id)
         self.assert_(domadmin is not None, msg="no account was created")
         domadmin.disable(self.apiClient, lock=True, account=domadmin.name, domainid=domadmin.domainid)
 
@@ -83,7 +89,7 @@ class ServiceOfferingFactoryTest(unittest.TestCase):
         self.apiClient = cloudstackTestClient(mgtSvr='localhost', logging=logging.getLogger('factory.cloudstack')).getApiClient()
 
     def test_serviceOfferingFactory(self):
-        soffering = SmallServiceOfferingFactory.create(apiclient=self.apiClient)
+        soffering = SmallServiceOfferingFactory(apiclient=self.apiClient)
         self.assert_(soffering is not None, msg="no service offering was created")
         self.assert_(soffering.name is not None, msg="error in service offering factory creation")
 
@@ -97,12 +103,12 @@ class NetworkOfferingFactoryTest(unittest.TestCase):
         self.apiClient = cloudstackTestClient(mgtSvr='localhost', logging=logging.getLogger('factory.cloudstack')).getApiClient()
 
     def test_defaultSourceNatOfferingFactory(self):
-        snatOffering = DefaultIsolatedNetworkOfferingWithSourceNatServiceFactory.create(apiclient=self.apiClient)
+        snatOffering = DefaultIsolatedNetworkOfferingWithSourceNatServiceFactory(apiclient=self.apiClient)
         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")
 
     def test_defaultSGOfferingEnable(self):
-        sgOffering = DefaultSharedNetworkOfferingWithSGServiceFactory.create(apiclient=self.apiClient)
+        sgOffering = DefaultSharedNetworkOfferingWithSGServiceFactory(apiclient=self.apiClient)
         sgOffering.update(self.apiClient, state='Enabled', name=sgOffering.name, id=sgOffering.id)
 
     def tearDown(self):
@@ -114,24 +120,25 @@ class VirtualMachineFactoryTest(unittest.TestCase):
         self.apiClient = cloudstackTestClient(mgtSvr='localhost', logging=logging.getLogger('factory.cloudstack')).getApiClient()
 
     def tearDown(self):
-        pass
+        self.vm.destroy(apiclient=self.apiClient)
 
     def test_virtualMachineDeploy(self):
-        accnt = UserAccountFactory.create(apiclient=self.apiClient)
-        service = SmallServiceOfferingFactory.create(apiclient=self.apiClient)
-        tf = DefaultBuiltInTemplateFactory.build() #FIXME: Using build() strategy is confusing
+        accnt = UserAccountFactory(apiclient=self.apiClient)
+        service = SmallServiceOfferingFactory(apiclient=self.apiClient)
+        tf = DefaultBuiltInTemplateFactory.build()
         zones = Zone.list(apiclient=self.apiClient)
         template = Template.list(apiclient=self.apiClient,
                                  templatefilter="featured",
                                  ostype = tf.ostype,
                                  zoneid = zones[0].id)
-        vm = VirtualMachineFactory.create(apiclient=self.apiClient,
+        self.vm = VirtualMachineFactory(apiclient=self.apiClient,
                                           serviceofferingid = service.id,
                                           templateid = template[0].id,
                                           zoneid = zones[0].id,
                                           account = accnt.name,
                                           domainid = accnt.domainid)
-        vm.destroy(apiclient=self.apiClient)
+
+
 
 class UserFactorySubFactoryTest(unittest.TestCase):
     def setUp(self):
@@ -150,36 +157,61 @@ class UserFactorySubFactoryTest(unittest.TestCase):
         caller is not to create the user before creating the account
         @return:
         """
-        uf = UserFactory.create(apiclient=self.apiClient)
+        uf = UserFactory(apiclient=self.apiClient)
         user = User.list(apiclient=self.apiClient, username=uf.username)
         self.assert_(uf.username == user[0].username, msg="Usernames don't match")
 
 
 class IpAddressFactoryTest(unittest.TestCase):
     def setUp(self):
-        self.apiClient = cloudstackTestClient(mgtSvr='localhost', logging=logging.getLogger('factory.cloudstack')).getApiClient()
+        self.apiClient = cloudstackTestClient(mgtSvr='localhost',
+            logging=logging.getLogger('factory.cloudstack')).getApiClient()
 
     def tearDown(self):
         self.vm.destroy(apiclient=self.apiClient)
 
     def test_associateIpAddressToNetwork(self):
-        accnt = UserAccountFactory.create(apiclient=self.apiClient)
-        self.assert_(accnt is not None)
+        # user account where we run test
+        accnt = UserAccountFactory(apiclient=self.apiClient)
         self.assert_(isinstance(accnt, Account))
+
+        # get required arguments - templates, service offerings, zone
         service = ServiceOffering.list(apiclient=self.apiClient, displaytext='Small')
-        self.assert_(len(service) > 0)
         template = Template.list(apiclient=self.apiClient, templatefilter="featured")
-        self.assert_(len(template) > 0)
         zones = Zone.list(apiclient=self.apiClient)
-        self.vm = VirtualMachineFactory.create(
+
+        self.vm = VirtualMachineFactory(
             apiclient=self.apiClient,
-            serviceofferingid = service[0].id,
-            templateid = template[0].id,
-            zoneid = zones[0].id,
+            serviceofferingid=service[0].id,
+            templateid=template[0].id,
+            zoneid=zones[0].id,
             account=accnt.name,
             domainid=accnt.domainid)
+
         all_ips = IpAddress.listPublic(apiclient=self.apiClient)
         firstip = all_ips[0]
-        networks = Network.list(apiclient=self.apiClient, account = accnt.name, domainid = accnt.domainid)
+        networks = Network.list(apiclient=self.apiClient,
+            account = accnt.name, domainid = accnt.domainid)
         firstip.associate(apiclient=self.apiClient, networkid = networks[0].id)
 
+
+class NetworkFactoryTest(unittest.TestCase):
+    def setUp(self):
+        self.apiClient = cloudstackTestClient(mgtSvr='localhost',
+            logging=logging.getLogger('factory.cloudstack')).getApiClient()
+
+    def tearDown(self):
+        pass
+
+    @attr(tags='network')
+    def test_isolatedGuestNetwork(self):
+        """Test to create a network within a guest account
+        @return:
+        """
+        accnt = UserAccountFactory(apiclient=self.apiClient)
+        zones = Zone.list(apiclient=self.apiClient)
+        network = GuestIsolatedNetworkFactory(
+            apiclient=self.apiClient,
+            zoneid=zones[0].id,
+            )
+        self.debug("network created with id, name" %(network.id, network.name))
\ No newline at end of file