Revision 8c7c9813

b/snf-cyclades-app/synnefo/db/models_factory.py
203 203
class IPv4SubnetFactory(SubnetFactory):
204 204
    ipversion = 4
205 205
    cidr = factory.Sequence(lambda n: '192.168.{0}.0/24'.format(n))
206
    gateway = factory.Sequence(lambda n: '192.168.{0}.1'.format(n))
206
    gateway = factory.LazyAttribute(lambda a: a.cidr[:-4] + '1')
207 207
    pool = factory.RelatedFactory(IPPoolTableFactory, 'subnet')
208 208

  
209 209

  
b/snf-cyclades-app/synnefo/db/pools/tests.py
210 210
class IPPoolTestCase(TestCase):
211 211
    def test_auto_reservations(self):
212 212
        obj = DummyObject(0)
213
        network = DummyObject(0)
214
        obj.network = network
215
        network.subnet = '192.168.2.0/24'
216
        network.gateway = '192.168.2.1'
213
        subnet = DummyObject(0)
214
        obj.subnet = subnet
215
        subnet.cidr = '192.168.2.0/24'
216
        subnet.gateway = '192.168.2.1'
217 217
        pool = IPPool(obj)
218 218
        self.assertEqual(pool.is_available('192.168.2.0'), False)
219 219
        self.assertEqual(pool.is_available('192.168.2.1'), False)
......
225 225

  
226 226
    def test_auto_reservations_2(self):
227 227
        obj = DummyObject(0)
228
        network = DummyObject(0)
229
        obj.network = network
230
        network.subnet = '192.168.2.0/31'
231
        network.gateway = '192.168.2.1'
228
        subnet = DummyObject(0)
229
        obj.subnet = subnet
230
        subnet.cidr = '192.168.2.0/31'
231
        subnet.gateway = '192.168.2.1'
232 232
        pool = IPPool(obj)
233 233
        self.assertEqual(pool.is_available('192.168.2.0'), False)
234 234
        self.assertEqual(pool.is_available('192.168.2.1'), False)
b/snf-cyclades-app/synnefo/db/tests.py
132 132
        with override_settings(snf_settings,
133 133
                               GANETI_CREATEINSTANCE_KWARGS=kwargs):
134 134
            self.assertEqual(kvm_backend.get_create_params(),
135
                    {"os": "snf-image+default",
136
                     "hvparams": {"foo1": "mpaz1"}})
135
                             {"os": "snf-image+default",
136
                              "hvparams": {"foo1": "mpaz1"}})
137 137
            self.assertEqual(xen_pvm_backend.get_create_params(),
138
                    {"os": "snf-image+default",
139
                     "hvparams": {"foo2": "mpaz2"}})
138
                             {"os": "snf-image+default",
139
                              "hvparams": {"foo2": "mpaz2"}})
140 140
            self.assertEqual(xen_hvm_backend.get_create_params(),
141
                    {"os": "snf-image+default",
142
                     "hvparams": {"foo3": "mpaz3"}})
141
                             {"os": "snf-image+default",
142
                              "hvparams": {"foo3": "mpaz3"}})
143 143
        with override_settings(snf_settings, GANETI_CREATEINSTANCE_KWARGS={}):
144 144
            self.assertEqual(kvm_backend.get_create_params(), {"hvparams": {}})
145 145

  
......
172 172

  
173 173
class NetworkTest(TestCase):
174 174
    def setUp(self):
175
        self.net = mfact.NetworkFactory()
175
        self.net = mfact.NetworkWithSubnetFactory()
176 176

  
177 177
    def test_tags(self):
178 178
        net1 = mfact.NetworkFactory(flavor='IP_LESS_ROUTED')
......
199 199
        self.assertTrue(isinstance(pool, IPPool))
200 200

  
201 201
    def test_reserve_ip(self):
202
        net1 = mfact.NetworkFactory(subnet='192.168.2.0/24')
202
        net1 = mfact.NetworkWithSubnetFactory(subnet__cidr='192.168.2.0/24')
203 203
        net1.reserve_address('192.168.2.12')
204 204
        pool = net1.get_pool()
205 205
        self.assertFalse(pool.is_available('192.168.2.12'))
......
220 220
        network = mfact.NetworkFactory(mac_prefix='zz:bb:c')
221 221
        backend = mfact.BackendFactory()
222 222
        self.assertRaises(utils.InvalidMacAddress,
223
                mfact.BackendNetworkFactory, network=network, backend=backend)
223
                          mfact.BackendNetworkFactory,
224
                          network=network, backend=backend)
224 225

  
225 226

  
226 227
class BridgePoolTest(TestCase):

Also available in: Unified diff