Revision 2522e489 snf-cyclades-app/synnefo/api/tests/servers.py

b/snf-cyclades-app/synnefo/api/tests/servers.py
202 202
            server = json.loads(response.content)['server']
203 203
            self.assertEqual(server["SNF:fqdn"], nic.ipv4)
204 204

  
205
    def test_server_port_forwarding(self):
206
        vm = mfactory.VirtualMachineFactory()
207
        ports = {
208
            22: ("foo", 61000),
209
            80: lambda ip, id, fqdn, user: ("bar", 61001)}
210
        with override_settings(settings,
211
                               CYCLADES_PORT_FORWARDING=ports):
212
            response = self.myget("servers/%d" % vm.id, vm.userid)
213
            server = json.loads(response.content)['server']
214
            self.assertEqual(server["SNF:port_forwarding"],
215
                             {"22": {"host": "foo", "port": "61000"},
216
                              "80": {"host": "bar", "port": "61001"}})
217

  
218
        def _port_from_ip(ip, base):
219
            fields = ip.split('.', 4)
220
            return (base + 256*int(fields[2]) + int(fields[3]))
221

  
222
        ports = {
223
            22: lambda ip, id, fqdn, user:
224
            ip and ("gate", _port_from_ip(ip, 10000)) or None}
225
        with override_settings(settings,
226
                               CYCLADES_PORT_FORWARDING=ports):
227
            response = self.myget("servers/%d" % vm.id, vm.userid)
228
            server = json.loads(response.content)['server']
229
            self.assertEqual(server["SNF:port_forwarding"], {})
230

  
231
        mfactory.NetworkInterfaceFactory(machine=vm, ipv4="192.168.2.2",
232
                                         network__public=True)
233
        with override_settings(settings,
234
                               CYCLADES_PORT_FORWARDING=ports):
235
            response = self.myget("servers/%d" % vm.id, vm.userid)
236
            server = json.loads(response.content)['server']
237
            self.assertEqual(server["SNF:port_forwarding"],
238
                             {"22": {"host": "gate", "port": "10514"}})
239

  
205 240
    def test_server_building_nics(self):
206 241
        db_vm = self.vm2
207 242
        user = self.vm2.userid

Also available in: Unified diff