Revision 710b1c43 snf-cyclades-app/synnefo/logic/tests/servers.py

b/snf-cyclades-app/synnefo/logic/tests/servers.py
61 61
        self.assertEqual(models.VirtualMachine.objects.count(), 0)
62 62

  
63 63
        subnet = mfactory.IPv4SubnetFactory(network__public=True)
64
        mfactory.BackendNetworkFactory(network=subnet.network)
64
        bn = mfactory.BackendNetworkFactory(network=subnet.network)
65
        backend = bn.backend
65 66

  
66 67
        # error in nics
67 68
        req = deepcopy(kwargs)
......
94 95
        self.assertEqual(vm.task, "BUILD")
95 96

  
96 97
        # test connect in IPv6 only network
97
        subnet = mfactory.IPv6SubnetFactory()
98
        subnet = mfactory.IPv6SubnetFactory(network__public=True)
98 99
        net = subnet.network
99
        mfactory.BackendNetworkFactory(network=net)
100
        mfactory.BackendNetworkFactory(network=net, backend=backend,
101
                                       operstate="ACTIVE")
100 102
        with override_settings(settings,
101 103
                               DEFAULT_INSTANCE_NETWORKS=[str(net.id)]):
102 104
            with mocked_quotaholder():
......
114 116
class ServerTest(TransactionTestCase):
115 117
    def test_connect_network(self, mrapi):
116 118
        # Common connect
117
        subnet = mfactory.IPv4SubnetFactory(network__flavor="CUSTOM",
118
                                            cidr="192.168.2.0/24",
119
                                            gateway="192.168.2.1",
120
                                            dhcp=True)
121
        net = subnet.network
122
        vm = mfactory.VirtualMachineFactory(operstate="STARTED")
123
        mfactory.BackendNetworkFactory(network=net, backend=vm.backend)
124
        mrapi().ModifyInstance.return_value = 42
125
        servers.connect(vm, net)
126
        pool = net.get_pool(locked=False)
127
        self.assertFalse(pool.is_available("192.168.2.2"))
128
        args, kwargs = mrapi().ModifyInstance.call_args
129
        nics = kwargs["nics"][0]
130
        self.assertEqual(kwargs["instance"], vm.backend_vm_id)
131
        self.assertEqual(nics[0], "add")
132
        self.assertEqual(nics[1], "-1")
133
        self.assertEqual(nics[2]["ip"], "192.168.2.2")
134
        self.assertEqual(nics[2]["network"], net.backend_id)
135

  
136
        # no dhcp
137
        vm = mfactory.VirtualMachineFactory(operstate="STARTED")
138
        subnet = mfactory.IPv4SubnetFactory(cidr="192.168.2.0/24",
139
                                            gateway="192.168.2.1",
140
                                            dhcp=False)
141
        net = subnet.network
142
        mfactory.BackendNetworkFactory(network=net, backend=vm.backend)
143
        servers.connect(vm, net)
144
        pool = net.get_pool(locked=False)
145
        self.assertTrue(pool.is_available("192.168.2.2"))
146
        args, kwargs = mrapi().ModifyInstance.call_args
147
        nics = kwargs["nics"][0]
148
        self.assertEqual(kwargs["instance"], vm.backend_vm_id)
149
        self.assertEqual(nics[0], "add")
150
        self.assertEqual(nics[1], "-1")
151
        self.assertEqual(nics[2]["ip"], None)
152
        self.assertEqual(nics[2]["network"], net.backend_id)
119
        for dhcp in [True, False]:
120
            subnet = mfactory.IPv4SubnetFactory(network__flavor="CUSTOM",
121
                                                cidr="192.168.2.0/24",
122
                                                gateway="192.168.2.1",
123
                                                dhcp=True)
124
            net = subnet.network
125
            vm = mfactory.VirtualMachineFactory(operstate="STARTED")
126
            mfactory.BackendNetworkFactory(network=net, backend=vm.backend)
127
            mrapi().ModifyInstance.return_value = 42
128
            servers.connect(vm, net)
129
            pool = net.get_pool(locked=False)
130
            self.assertFalse(pool.is_available("192.168.2.2"))
131
            args, kwargs = mrapi().ModifyInstance.call_args
132
            nics = kwargs["nics"][0]
133
            self.assertEqual(kwargs["instance"], vm.backend_vm_id)
134
            self.assertEqual(nics[0], "add")
135
            self.assertEqual(nics[1], "-1")
136
            self.assertEqual(nics[2]["ip"], "192.168.2.2")
137
            self.assertEqual(nics[2]["network"], net.backend_id)
153 138

  
154 139
        # Test connect to IPv6 only network
155 140
        vm = mfactory.VirtualMachineFactory(operstate="STARTED")

Also available in: Unified diff