marvin_refactor: Factories for DiskOffering, ServiceOffering

Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
Prasanna Santhanam 2013-03-30 22:16:39 +05:30
parent e0968d6937
commit b4ecf77de2
7 changed files with 75 additions and 25 deletions

View File

@ -23,7 +23,7 @@ from marvin.cloudstackAPI import updateAccount
from marvin.cloudstackAPI import disableAccount
from marvin.cloudstackAPI import deleteAccount
class Account(CloudStackEntity):
class Account(CloudStackEntity.CloudStackEntity):
def __init__(self, items):

View File

@ -15,9 +15,9 @@
# specific language governing permissions and limitations
# under the License.
from marvin.integration.lib.base import Account
import hashlib
from marvin.integration.lib.factory.CloudStackBaseFactory import *
from marvin.integration.lib.base import Account
from marvin.integration.lib.utils import random_gen
class AccountFactory(CloudStackBaseFactory):

View File

@ -16,9 +16,26 @@
# under the License.
import factory
from marvin.integration.lib.base import DiskOffering
from marvin.integration.lib.utils import random_gen
class DiskOfferingFactory(factory.Factory):
FACTORY_FOR = DiskOffering
displaytext = None
name = None
displaytext = factory.Sequence(lambda n : "DiskOffering" + random_gen())
name = factory.Sequence(lambda n : "DiskOffering" + random_gen())
class SharedDiskOfferingFactory(DiskOfferingFactory):
displaytext = "SharedDiskOffering"
name = factory.Sequence(lambda n : "SharedDiskOffering" + random_gen())
storagetype = "shared"
disksize = 10 #MB
class LocalDiskOfferingFactory(DiskOfferingFactory):
displaytext = "LocalDiskOffering"
name = factory.Sequence(lambda n : "LocalDiskOffering" + random_gen())
storagetype = "local"
disksize = 10 #MB

View File

@ -16,8 +16,9 @@
# under the License.
import factory
from marvin.integration.lib.base import Domain
from marvin.integration.lib.utils import random_gen
class DomainFactory(factory.Factory):
FACTORY_FOR = Domain
name = None
name = "Domain" + factory.Sequence(lambda n : random_gen())

View File

@ -20,8 +20,11 @@ class NetworkOfferingFactory(factory.Factory):
FACTORY_FOR = NetworkOffering
displaytext = None
guestiptype = None
name = None
supportedservices = None
traffictype = None
displaytext = "Network Offering"
guestiptype = "Isolated"
name = "Network Offering"
supportedservices = "Dhcp,Dns,SourceNat,PortForwarding"
traffictype = "Guest"
class DefaultIsolatedNetworkOffering

View File

@ -15,13 +15,24 @@
# specific language governing permissions and limitations
# under the License.
import factory
from marvin.integration.lib.factory.CloudStackBaseFactory import *
from marvin.integration.lib.base import ServiceOffering
class ServiceOfferingFactory(factory.Factory):
from marvin.integration.lib.utils import random_gen
FACTORY_FOR = ServiceOffering
class ServiceOfferingFactory(CloudStackBaseFactory):
cpunumber = None
cpuspeed = None
displaytext = None
memory = None
name = None
FACTORY_FOR = ServiceOffering.ServiceOffering
cpunumber = 1
cpuspeed = 1000 #Mhz
displaytext = "Service Offering"
memory = 512 #MB
name = factory.Sequence(lambda n: "ServiceOffering" + random_gen())
class SmallServiceOfferingFactory(ServiceOfferingFactory):
cpunumber = 1
cpuspeed = 100 #Mhz
memory = 100 #MB
displaytext = "Small Service Offering"
name = factory.Sequence(lambda n: "SmallServiceOffering" + random_gen())

View File

@ -16,8 +16,11 @@
# under the License.
import unittest
from marvin.integration.lib.factory import AccountFactory
from marvin.integration.lib.base import Account
from marvin.integration.lib.factory.AccountFactory import *
from marvin.integration.lib.base.Account import *
from marvin.integration.lib.factory.ServiceOfferingFactory import *
from marvin.integration.lib.base.ServiceOffering import *
from marvin.cloudstackTestClient import cloudstackTestClient
class AccountFactoryTest(unittest.TestCase):
@ -25,22 +28,37 @@ class AccountFactoryTest(unittest.TestCase):
self.apiClient = cloudstackTestClient(mgtSvr='localhost').getApiClient()
def test_userAccountFactory(self):
af = AccountFactory.AccountFactory()
accnt = Account.Account.create(apiclient=self.apiClient, AccountFactory=af)
af = AccountFactory()
accnt = Account.create(apiclient=self.apiClient, AccountFactory=af)
self.assertTrue(accnt is not None, msg="no account created by factory")
self.assertEqual(accnt.name, af.username, msg="account names are not same")
def test_adminAccountFactory(self):
af = AccountFactory.AccountFactory()
accnt = Account.Account.create(apiclient=self.apiClient, AccountFactory=af)
af = AdminAccountFactory()
accnt = Account.create(apiclient=self.apiClient, AccountFactory=af)
self.assertTrue(accnt is not None, msg="no account created by factory")
self.assertEqual(accnt.name, af.username, msg="account names are not same")
def test_userAccountFactoryCustomArgs(self):
af = AccountFactory.AccountFactory(firstname='test', lastname='test')
accnt = Account.Account.create(apiclient=self.apiClient, AccountFactory=af)
af = AccountFactory(firstname='test', lastname='test')
accnt = Account.create(apiclient=self.apiClient, AccountFactory=af)
self.assertTrue(accnt is not None, msg="no account created by factory")
self.assertEqual(accnt.name, af.username, msg="account names are not same")
def tearDown(self):
pass
class ServiceOfferingFactoryTest(unittest.TestCase):
def setUp(self):
self.apiClient = cloudstackTestClient(mgtSvr='localhost').getApiClient()
def test_serviceOfferingFactory(self):
sf = ServiceOfferingFactory()
soffering = ServiceOffering.create(apiclient=self.apiClient, ServiceOfferingFactory=sf)
self.assertTrue(soffering is not None, msg="no service offering was created")
self.assertEqual(soffering.name, sf.name, msg="error in service offering factory creation")
def tearDown(self):
pass