Commit 0943cc19 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

cyclades: Auto-fill project in test objects

Use factory.LazyAttribute to set project equal to userid in test objects
created with a factory.
parent abc6e458
...@@ -103,6 +103,7 @@ class VirtualMachineFactory(factory.DjangoModelFactory): ...@@ -103,6 +103,7 @@ class VirtualMachineFactory(factory.DjangoModelFactory):
suspended = False suspended = False
#operstate = factory.Sequence(round_seq_first(FACTORY_FOR.OPER_STATES)) #operstate = factory.Sequence(round_seq_first(FACTORY_FOR.OPER_STATES))
operstate = "STARTED" operstate = "STARTED"
project = factory.LazyAttribute(lambda a: a.userid)
class VolumeFactory(factory.DjangoModelFactory): class VolumeFactory(factory.DjangoModelFactory):
...@@ -113,6 +114,7 @@ class VolumeFactory(factory.DjangoModelFactory): ...@@ -113,6 +114,7 @@ class VolumeFactory(factory.DjangoModelFactory):
machine = factory.SubFactory(VirtualMachineFactory, machine = factory.SubFactory(VirtualMachineFactory,
userid=factory.SelfAttribute('..userid')) userid=factory.SelfAttribute('..userid'))
volume_type = factory.SubFactory(VolumeTypeFactory) volume_type = factory.SubFactory(VolumeTypeFactory)
project = factory.LazyAttribute(lambda a: a.userid)
class DeletedVirtualMachine(VirtualMachineFactory): class DeletedVirtualMachine(VirtualMachineFactory):
...@@ -162,6 +164,7 @@ class NetworkFactory(factory.DjangoModelFactory): ...@@ -162,6 +164,7 @@ class NetworkFactory(factory.DjangoModelFactory):
public = False public = False
deleted = False deleted = False
state = "ACTIVE" state = "ACTIVE"
project = factory.LazyAttribute(lambda a: a.userid)
class DeletedNetwork(NetworkFactory): class DeletedNetwork(NetworkFactory):
...@@ -241,6 +244,7 @@ class IPv4AddressFactory(factory.DjangoModelFactory): ...@@ -241,6 +244,7 @@ class IPv4AddressFactory(factory.DjangoModelFactory):
nic = factory.SubFactory(NetworkInterfaceFactory, nic = factory.SubFactory(NetworkInterfaceFactory,
userid=factory.SelfAttribute('..userid'), userid=factory.SelfAttribute('..userid'),
network=factory.SelfAttribute('..network')) network=factory.SelfAttribute('..network'))
project = factory.LazyAttribute(lambda a: a.userid)
class IPv6AddressFactory(IPv4AddressFactory): class IPv6AddressFactory(IPv4AddressFactory):
......
...@@ -39,12 +39,12 @@ class GetDBHoldingsTestCase(TestCase): ...@@ -39,12 +39,12 @@ class GetDBHoldingsTestCase(TestCase):
mfactory.VirtualMachineFactory(flavor=flavor, userid="user1", mfactory.VirtualMachineFactory(flavor=flavor, userid="user1",
operstate="BUILD") operstate="BUILD")
mfactory.VolumeFactory(userid="user1", size=20, machine=None) mfactory.VolumeFactory(userid="user1", size=20, machine=None)
user_holdings = {"user1": {None: {"cyclades.vm": 1, user_holdings = {"user1": {"user1": {"cyclades.vm": 1,
"cyclades.total_cpu": 24, "cyclades.total_cpu": 24,
"cyclades.cpu": 24, "cyclades.cpu": 24,
"cyclades.disk": 20 << 30, "cyclades.disk": 20 << 30,
"cyclades.total_ram": 8192 << 20, "cyclades.total_ram": 8192 << 20,
"cyclades.ram": 8192 << 20}}} "cyclades.ram": 8192 << 20}}}
holdings = util.get_db_holdings(user="user1") holdings = util.get_db_holdings(user="user1")
self.assertEqual(holdings, user_holdings) self.assertEqual(holdings, user_holdings)
holdings = util.get_db_holdings() holdings = util.get_db_holdings()
...@@ -54,26 +54,27 @@ class GetDBHoldingsTestCase(TestCase): ...@@ -54,26 +54,27 @@ class GetDBHoldingsTestCase(TestCase):
mfactory.VirtualMachineFactory(flavor=flavor, userid="user2", mfactory.VirtualMachineFactory(flavor=flavor, userid="user2",
operstate="STARTED") operstate="STARTED")
mfactory.VolumeFactory(userid="user2", size=30, machine=None) mfactory.VolumeFactory(userid="user2", size=30, machine=None)
user_holdings = {"user2": {None: {"cyclades.vm": 1, user_holdings = {"user2": {"user2": {"cyclades.vm": 1,
"cyclades.total_cpu": 24, "cyclades.total_cpu": 24,
"cyclades.cpu": 24, "cyclades.cpu": 24,
"cyclades.disk": 30 << 30, "cyclades.disk": 30 << 30,
"cyclades.total_ram": 8192 << 20, "cyclades.total_ram": 8192 << 20,
"cyclades.ram": 8192 << 20}}} "cyclades.ram": 8192 << 20}}}
holdings = util.get_db_holdings(user="user2") holdings = util.get_db_holdings(user="user2")
self.assertEqual(holdings, user_holdings) self.assertEqual(holdings, user_holdings)
mfactory.VirtualMachineFactory(flavor=flavor, userid="user3", mfactory.VirtualMachineFactory(flavor=flavor, userid="user3",
operstate="STOPPED") operstate="STOPPED")
user_holdings = {"user3": {None: {"cyclades.vm": 1, user_holdings = {"user3": {"user3": {"cyclades.vm": 1,
"cyclades.total_cpu": 24, "cyclades.total_cpu": 24,
"cyclades.total_ram": 8589934592}}} "cyclades.total_ram": 8589934592}}
}
holdings = util.get_db_holdings(user="user3") holdings = util.get_db_holdings(user="user3")
self.assertEqual(holdings, user_holdings) self.assertEqual(holdings, user_holdings)
def test_network_holdings(self): def test_network_holdings(self):
mfactory.NetworkFactory(userid="user1") mfactory.NetworkFactory(userid="user1")
mfactory.NetworkFactory(userid="user2") mfactory.NetworkFactory(userid="user2")
user_holdings = {"user2": {None: {"cyclades.network.private": 1}}} user_holdings = {"user2": {"user2": {"cyclades.network.private": 1}}}
holdings = util.get_db_holdings(user="user2") holdings = util.get_db_holdings(user="user2")
self.assertEqual(holdings, user_holdings) self.assertEqual(holdings, user_holdings)
holdings = util.get_db_holdings() holdings = util.get_db_holdings()
...@@ -85,9 +86,9 @@ class GetDBHoldingsTestCase(TestCase): ...@@ -85,9 +86,9 @@ class GetDBHoldingsTestCase(TestCase):
mfactory.IPv4AddressFactory(userid="user2", floating_ip=True) mfactory.IPv4AddressFactory(userid="user2", floating_ip=True)
mfactory.IPv4AddressFactory(userid="user3", floating_ip=True) mfactory.IPv4AddressFactory(userid="user3", floating_ip=True)
holdings = util.get_db_holdings() holdings = util.get_db_holdings()
self.assertEqual(holdings["user1"][None]["cyclades.floating_ip"], 2) self.assertEqual(holdings["user1"]["user1"]["cyclades.floating_ip"], 2)
self.assertEqual(holdings["user2"][None]["cyclades.floating_ip"], 1) self.assertEqual(holdings["user2"]["user2"]["cyclades.floating_ip"], 1)
self.assertEqual(holdings["user3"][None]["cyclades.floating_ip"], 1) self.assertEqual(holdings["user3"]["user3"]["cyclades.floating_ip"], 1)
@patch("synnefo.quotas.get_quotaholder_pending") @patch("synnefo.quotas.get_quotaholder_pending")
...@@ -123,6 +124,7 @@ class GetCommissionInfoTest(TestCase): ...@@ -123,6 +124,7 @@ class GetCommissionInfoTest(TestCase):
vm = mfactory.VirtualMachineFactory(flavor=flavor) vm = mfactory.VirtualMachineFactory(flavor=flavor)
mfactory.VolumeFactory(size=20, machine=vm, deleted=False, mfactory.VolumeFactory(size=20, machine=vm, deleted=False,
delete_on_termination=True) delete_on_termination=True)
vm.volumes.update(project=vm.project)
#commission = quotas.get_commission_info(vm, "BUILD") #commission = quotas.get_commission_info(vm, "BUILD")
#self.assertEqual({"cyclades.vm": 1, #self.assertEqual({"cyclades.vm": 1,
# "cyclades.cpu": 2, # "cyclades.cpu": 2,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment