Revision 9db290b4

b/snf-cyclades-app/synnefo/quotas/tests.py
45 45

  
46 46

  
47 47
class GetDBHoldingsTestCase(TestCase):
48
    maxDiff = None
49

  
48 50
    def test_no_holdings(self):
49 51
        holdings = util.get_db_holdings(user=None)
50 52
        self.assertEqual(holdings, {})
......
52 54
    def test_vm_holdings(self):
53 55
        flavor = mfactory.FlavorFactory(cpu=24, ram=8192, disk=20,
54 56
                                        disk_template='drbd')
55
        mfactory.VirtualMachineFactory()
57
        mfactory.VirtualMachineFactory(userid="user1", deleted=True)
56 58
        mfactory.VirtualMachineFactory(flavor=flavor, userid="user1",
57 59
                                       operstate="BUILD")
60
        mfactory.VolumeFactory(userid="user1", size=20, machine=None)
58 61
        user_holdings = {"user1": {"cyclades.vm": 1,
59 62
                                   "cyclades.total_cpu": 24,
60 63
                                   "cyclades.cpu": 24,
61
                                   "cyclades.disk": 21474836480,
62
                                   "cyclades.total_ram": 8589934592,
63
                                   "cyclades.ram": 8589934592}}
64
                                   "cyclades.disk": 20 << 30,
65
                                   "cyclades.total_ram": 8192 << 20,
66
                                   "cyclades.ram": 8192 << 20}}
64 67
        holdings = util.get_db_holdings(user="user1")
65 68
        self.assertEqual(holdings, user_holdings)
66 69
        holdings = util.get_db_holdings()
......
69 72
        ##
70 73
        mfactory.VirtualMachineFactory(flavor=flavor, userid="user2",
71 74
                                       operstate="STARTED")
75
        mfactory.VolumeFactory(userid="user2", size=30, machine=None)
72 76
        user_holdings = {"user2": {"cyclades.vm": 1,
73 77
                                   "cyclades.total_cpu": 24,
74 78
                                   "cyclades.cpu": 24,
75
                                   "cyclades.disk": 21474836480,
76
                                   "cyclades.total_ram": 8589934592,
77
                                   "cyclades.ram": 8589934592}}
79
                                   "cyclades.disk": 30 << 30,
80
                                   "cyclades.total_ram": 8192 << 20,
81
                                   "cyclades.ram": 8192 << 20}}
78 82
        holdings = util.get_db_holdings(user="user2")
79 83
        self.assertEqual(holdings, user_holdings)
80 84
        mfactory.VirtualMachineFactory(flavor=flavor, userid="user3",
81 85
                                       operstate="STOPPED")
82 86
        user_holdings = {"user3": {"cyclades.vm": 1,
83 87
                                   "cyclades.total_cpu": 24,
84
                                   "cyclades.disk": 21474836480,
85 88
                                   "cyclades.total_ram": 8589934592}}
86 89
        holdings = util.get_db_holdings(user="user3")
87 90
        self.assertEqual(holdings, user_holdings)
......
132 135

  
133 136

  
134 137
class GetCommissionInfoTest(TestCase):
138
    maxDiff = None
139

  
135 140
    def test_commissions(self):
136 141
        flavor = mfactory.FlavorFactory(cpu=2, ram=1024, disk=20)
137 142
        vm = mfactory.VirtualMachineFactory(flavor=flavor)
143
        mfactory.VolumeFactory(size=20, machine=vm, deleted=False,
144
                               delete_on_termination=True)
138 145
        #commission = quotas.get_commission_info(vm, "BUILD")
139 146
        #self.assertEqual({"cyclades.vm": 1,
140 147
        #                  "cyclades.cpu": 2,
......
169 176
        commission = quotas.get_commission_info(vm, "DESTROY")
170 177
        self.assertEqual({"cyclades.vm": -1,
171 178
                          "cyclades.total_cpu": -2,
172
                          "cyclades.total_ram": 1048576 * -1024,
173
                          "cyclades.disk": 1073741824 * -20}, commission)
179
                          "cyclades.total_ram": -1024 << 20,
180
                          "cyclades.disk": -20 << 30}, commission)
174 181
        commission = quotas.get_commission_info(vm, "RESIZE")
175 182
        self.assertEqual(None, commission)
176 183
        commission = quotas.get_commission_info(vm, "RESIZE",

Also available in: Unified diff