Ejemplo n.º 1
0
Archivo: ips.py Proyecto: grnet/synnefo
    def test_delete(self):
        """Test if the delete action succeeds/fails properly."""
        # Create a floating IP and force-attach it to a NIC instance.
        vm = mfactory.VirtualMachineFactory()
        nic = mfactory.NetworkInterfaceFactory(network=self.network,
                                               machine=vm)
        with mocked_quotaholder():
            ip = ips.create_floating_ip(
                self.credentials, network_id=self.network.id)
        ip.nic = nic
        ip.save()

        # Test 1 - Check if we can delete an IP attached to a VM.
        #
        # The validate function and the action should both fail with the
        # following message.
        expected_msg = "IP '{}' is used by server '{}'".format(ip.id, vm.id)

        # Verify that the validate function fails in silent mode.
        res, msg = ips.validate_ip_action(ip, "DELETE", silent=True)
        self.assertFalse(res)
        self.assertEqual(msg, expected_msg)

        # Verify that the validate function fails in non-silent mode.
        with self.assertRaises(faults.Conflict) as cm:
            ips.validate_ip_action(ip, "DELETE", silent=False)
        self.assertEqual(cm.exception.message, expected_msg)

        # Verify that the delete action fails with exception.
        with mocked_quotaholder():
            with self.assertRaises(faults.Conflict) as cm:
                ips.delete_floating_ip(ip.id, self.credentials)
        self.assertEqual(cm.exception.message, expected_msg)

        # Test 2 - Check if we can delete a free IP.
        #
        # Force-detach IP from NIC.
        ip.nic = None
        ip.save()

        # Verify that the validate function passes in silent mode.
        res, _ = ips.validate_ip_action(ip, "DELETE", silent=True)
        self.assertTrue(res)

        # Verify that the delete action succeeds.
        with mocked_quotaholder():
            ips.delete_floating_ip(ip.id, self.credentials)
        with self.assertRaises(ObjectDoesNotExist):
            IPAddress.objects.get(id=ip.id)
Ejemplo n.º 2
0
    def test_delete(self):
        """Test if the delete action succeeds/fails properly."""
        # Create a floating IP and force-attach it to a NIC instance.
        vm = mfactory.VirtualMachineFactory()
        nic = mfactory.NetworkInterfaceFactory(network=self.network,
                                               machine=vm)
        with mocked_quotaholder():
            ip = ips.create_floating_ip(self.credentials,
                                        network_id=self.network.id)
        ip.nic = nic
        ip.save()

        # Test 1 - Check if we can delete an IP attached to a VM.
        #
        # The validate function and the action should both fail with the
        # following message.
        expected_msg = "IP '{}' is used by server '{}'".format(ip.id, vm.id)

        # Verify that the validate function fails in silent mode.
        res, msg = ips.validate_ip_action(ip, "DELETE", silent=True)
        self.assertFalse(res)
        self.assertEqual(msg, expected_msg)

        # Verify that the validate function fails in non-silent mode.
        with self.assertRaises(faults.Conflict) as cm:
            ips.validate_ip_action(ip, "DELETE", silent=False)
        self.assertEqual(cm.exception.message, expected_msg)

        # Verify that the delete action fails with exception.
        with mocked_quotaholder():
            with self.assertRaises(faults.Conflict) as cm:
                ips.delete_floating_ip(ip.id, self.credentials)
        self.assertEqual(cm.exception.message, expected_msg)

        # Test 2 - Check if we can delete a free IP.
        #
        # Force-detach IP from NIC.
        ip.nic = None
        ip.save()

        # Verify that the validate function passes in silent mode.
        res, _ = ips.validate_ip_action(ip, "DELETE", silent=True)
        self.assertTrue(res)

        # Verify that the delete action succeeds.
        with mocked_quotaholder():
            ips.delete_floating_ip(ip.id, self.credentials)
        with self.assertRaises(ObjectDoesNotExist):
            IPAddress.objects.get(id=ip.id)
Ejemplo n.º 3
0
 def check(ip, action):
     res, _ = ips.validate_ip_action(ip, action)
     return res