本文整理汇总了Python中synnefo.logic.callbacks.update_db函数的典型用法代码示例。如果您正苦于以下问题:Python update_db函数的具体用法?Python update_db怎么用?Python update_db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了update_db函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_changed_nic
def test_changed_nic(self, client):
ip = mfactory.IPv4AddressFactory(subnet__cidr="10.0.0.0/24",
address="10.0.0.2")
network = ip.network
subnet = ip.subnet
vm = ip.nic.machine
pool = subnet.get_ip_pools()[0]
pool.reserve("10.0.0.2")
pool.save()
msg = self.create_msg(instance_nics=[{'network': network.backend_id,
'ip': '10.0.0.3',
'mac': 'aa:bb:cc:00:11:22',
'name': ip.nic.backend_uuid}],
instance=vm.backend_vm_id)
update_db(client, msg)
self.assertTrue(client.basic_ack.called)
db_vm = VirtualMachine.objects.get(id=vm.id)
nics = db_vm.nics.all()
self.assertEqual(len(nics), 1)
self.assertEqual(nics[0].index, 0)
self.assertEqual(nics[0].ipv4_address, '10.0.0.3')
self.assertEqual(nics[0].mac, 'aa:bb:cc:00:11:22')
pool = subnet.get_ip_pools()[0]
self.assertTrue(pool.is_available('10.0.0.2'))
self.assertFalse(pool.is_available('10.0.0.3'))
pool.save()
示例2: test_reboot
def test_reboot(self, client):
vm = mfactory.VirtualMachineFactory()
msg = self.create_msg(operation='OP_INSTANCE_REBOOT',
instance=vm.backend_vm_id)
update_db(client, msg)
client.basic_ack.assert_called_once()
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertEqual(db_vm.operstate, 'STARTED')
示例3: test_create
def test_create(self, client):
vm = mfactory.VirtualMachineFactory()
msg = self.create_msg(operation='OP_INSTANCE_CREATE',
instance=vm.backend_vm_id)
update_db(client, msg)
self.assertTrue(client.basic_ack.called)
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertEqual(db_vm.operstate, 'STARTED')
示例4: test_stop
def test_stop(self, client):
vm = mfactory.VirtualMachineFactory()
msg = self.create_msg(operation='OP_INSTANCE_SHUTDOWN',
instance=vm.backend_vm_id)
with mocked_quotaholder():
update_db(client, msg)
self.assertTrue(client.basic_ack.called)
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertEqual(db_vm.operstate, 'STOPPED')
示例5: test_create_error
def test_create_error(self, client):
"""Test that error create sets vm to ERROR state"""
vm = mfactory.VirtualMachineFactory()
msg = self.create_msg(operation='OP_INSTANCE_CREATE',
instance=vm.backend_vm_id,
status='error')
update_db(client, msg)
self.assertTrue(client.basic_ack.called)
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertEqual(db_vm.operstate, 'ERROR')
示例6: test_other_error
def test_other_error(self, client):
"""Test that other error messages do no affect the VM"""
vm = mfactory.VirtualMachineFactory()
msg = self.create_msg(operation='OP_INSTANCE_STARTUP',
instance=vm.backend_vm_id,
status='error')
update_db(client, msg)
self.assertTrue(client.basic_ack.called)
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertEqual(db_vm.operstate, vm.operstate)
self.assertEqual(db_vm.backendtime, vm.backendtime)
示例7: test_no_nics
def test_no_nics(self, client):
vm = mfactory.VirtualMachineFactory(operstate='ERROR')
mfactory.NetworkInterfaceFactory(machine=vm, state="ACTIVE")
mfactory.NetworkInterfaceFactory(machine=vm, state="ACTIVE")
mfactory.NetworkInterfaceFactory(machine=vm, state="ACTIVE")
self.assertEqual(len(vm.nics.all()), 3)
msg = self.create_msg(instance_nics=[],
instance=vm.backend_vm_id)
update_db(client, msg)
self.assertTrue(client.basic_ack.called)
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertEqual(len(db_vm.nics.all()), 0)
示例8: test_remove
def test_remove(self, client):
vm = mfactory.VirtualMachineFactory(flavor__cpu=1, flavor__ram=128)
mfactory.VolumeFactory(userid=vm.userid, machine=vm, size=1)
mfactory.VolumeFactory(userid=vm.userid, machine=vm, size=3)
# Also create a NIC
ip = mfactory.IPv4AddressFactory(nic__machine=vm)
nic = ip.nic
nic.network.get_ip_pools()[0].reserve(nic.ipv4_address)
msg = self.create_msg(operation='OP_INSTANCE_REMOVE',
instance=vm.backend_vm_id)
with mocked_quotaholder() as m:
update_db(client, msg)
self.assertTrue(client.basic_ack.called)
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertEqual(db_vm.operstate, 'DESTROYED')
self.assertTrue(db_vm.deleted)
# Check that nics are deleted
self.assertFalse(db_vm.nics.all())
self.assertTrue(nic.network.get_ip_pools()[0].is_available(ip.address))
# Check that volumes are deleted
self.assertFalse(db_vm.volumes.filter(deleted=False))
# Check quotas
name, args, kwargs = m.mock_calls[0]
for (userid, res), value in args[1].items():
if res == 'cyclades.disk':
self.assertEqual(value, -4 << 30)
elif res == 'cyclades.cpu':
self.assertEqual(value, -1)
elif res == 'cyclades.ram':
self.assertEqual(value, -128 << 20)
vm2 = mfactory.VirtualMachineFactory()
fp1 = mfactory.IPv4AddressFactory(nic__machine=vm2, floating_ip=True,
network__floating_ip_pool=True)
network = fp1.network
nic1 = mfactory.NetworkInterfaceFactory(machine=vm2)
fp1.nic = nic1
fp1.save()
pool = network.get_ip_pools()[0]
pool.reserve(fp1.address)
pool.save()
msg = self.create_msg(operation='OP_INSTANCE_REMOVE',
instance=vm2.backend_vm_id)
with mocked_quotaholder():
update_db(client, msg)
client.basic_ack.assert_called_once()
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertEqual(db_vm.operstate, 'DESTROYED')
self.assertTrue(db_vm.deleted)
self.assertEqual(IPAddress.objects.get(id=fp1.id).nic, None)
pool = network.get_ip_pools()[0]
# Test that floating ips are not released
self.assertFalse(pool.is_available(fp1.address))
示例9: test_remove
def test_remove(self, client):
vm = mfactory.VirtualMachineFactory()
# Also create a NIC
mfactory.NetworkInterfaceFactory(machine=vm)
msg = self.create_msg(operation='OP_INSTANCE_REMOVE',
instance=vm.backend_vm_id)
with mocked_quotaholder():
update_db(client, msg)
client.basic_ack.assert_called_once()
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertEqual(db_vm.operstate, 'DESTROYED')
self.assertTrue(db_vm.deleted)
# Check that nics are deleted
self.assertFalse(db_vm.nics.all())
示例10: test_old_msg
def test_old_msg(self, client):
from time import sleep
from datetime import datetime
old_time = time()
sleep(0.01)
new_time = datetime.fromtimestamp(time())
vm = mfactory.VirtualMachineFactory(backendtime=new_time)
vm.operstate = 'STOPPED'
vm.save()
msg = self.create_msg(operation='OP_INSTANCE_STARTUP',
event_time=split_time(old_time),
instance=vm.backend_vm_id)
update_db(client, msg)
self.assertTrue(client.basic_ack.called)
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertEquals(db_vm.operstate, "STOPPED")
self.assertEquals(db_vm.backendtime, new_time)
示例11: test_empty_nic
def test_empty_nic(self, client):
vm = mfactory.VirtualMachineFactory(operstate='ERROR')
for public in [True, False]:
net = mfactory.NetworkFactory(public=public)
msg = self.create_msg(nics=[{'network': net.backend_id}],
instance=vm.backend_vm_id)
update_db(client, msg)
client.basic_ack.assert_called_once()
db_vm = VirtualMachine.objects.get(id=vm.id)
nics = db_vm.nics.all()
self.assertEqual(len(nics), 1)
self.assertEqual(nics[0].index, 0)
self.assertEqual(nics[0].ipv4, '')
self.assertEqual(nics[0].ipv6, '')
self.assertEqual(nics[0].mac, '')
if public:
self.assertEqual(nics[0].firewall_profile,
settings.DEFAULT_FIREWALL_PROFILE)
else:
self.assertEqual(nics[0].firewall_profile, '')
示例12: test_error_snapshot
def test_error_snapshot(self, pithos_backend, client):
vm = mfactory.VirtualMachineFactory()
disks = [
(0, {"snapshot_info": json.dumps({"snapshot_id":
"test_snapshot_id"})})
]
msg = self.create_msg(operation='OP_INSTANCE_SNAPSHOT',
instance=vm.backend_vm_id,
job_fields={'disks': disks},
status="running")
update_db(client, msg)
self.assertEqual(pithos_backend().update_object_status.mock_calls, [])
msg = self.create_msg(operation='OP_INSTANCE_SNAPSHOT',
instance=vm.backend_vm_id,
job_fields={'disks': disks},
event_time=split_time(time()),
status="error")
update_db(client, msg)
pithos_backend().update_object_status\
.assert_called_once_with("test_snapshot_id", state=-1)
pithos_backend.reset_mock()
msg = self.create_msg(operation='OP_INSTANCE_SNAPSHOT',
instance=vm.backend_vm_id,
job_fields={'disks': disks},
event_time=split_time(time()),
status="success")
update_db(client, msg)
pithos_backend().update_object_status\
.assert_called_once_with("test_snapshot_id", state=1)
示例13: test_full_nic
def test_full_nic(self, client):
vm = mfactory.VirtualMachineFactory(operstate='ERROR')
net = mfactory.NetworkFactory(subnet='10.0.0.0/24')
pool = net.get_pool()
self.assertTrue(pool.is_available('10.0.0.22'))
pool.save()
msg = self.create_msg(nics=[{'network': net.backend_id,
'ip': '10.0.0.22',
'mac': 'aa:bb:cc:00:11:22'}],
instance=vm.backend_vm_id)
update_db(client, msg)
client.basic_ack.assert_called_once()
db_vm = VirtualMachine.objects.get(id=vm.id)
nics = db_vm.nics.all()
self.assertEqual(len(nics), 1)
self.assertEqual(nics[0].index, 0)
self.assertEqual(nics[0].ipv4, '10.0.0.22')
self.assertEqual(nics[0].ipv6, '')
self.assertEqual(nics[0].mac, 'aa:bb:cc:00:11:22')
pool = net.get_pool()
self.assertFalse(pool.is_available('10.0.0.22'))
pool.save()
示例14: test_remove
def test_remove(self, client):
vm = mfactory.VirtualMachineFactory()
# Also create a NIC
ip = mfactory.IPv4AddressFactory(nic__machine=vm)
nic = ip.nic
nic.network.get_ip_pools()[0].reserve(nic.ipv4_address)
msg = self.create_msg(operation='OP_INSTANCE_REMOVE',
instance=vm.backend_vm_id)
with mocked_quotaholder():
update_db(client, msg)
self.assertTrue(client.basic_ack.called)
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertEqual(db_vm.operstate, 'DESTROYED')
self.assertTrue(db_vm.deleted)
# Check that nics are deleted
self.assertFalse(db_vm.nics.all())
self.assertTrue(nic.network.get_ip_pools()[0].is_available(ip.address))
vm2 = mfactory.VirtualMachineFactory()
fp1 = mfactory.IPv4AddressFactory(nic__machine=vm2, floating_ip=True,
network__floating_ip_pool=True)
network = fp1.network
nic1 = mfactory.NetworkInterfaceFactory(machine=vm2)
fp1.nic = nic1
fp1.save()
pool = network.get_ip_pools()[0]
pool.reserve(fp1.address)
pool.save()
msg = self.create_msg(operation='OP_INSTANCE_REMOVE',
instance=vm2.backend_vm_id)
with mocked_quotaholder():
update_db(client, msg)
client.basic_ack.assert_called_once()
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertEqual(db_vm.operstate, 'DESTROYED')
self.assertTrue(db_vm.deleted)
self.assertEqual(IPAddress.objects.get(id=fp1.id).nic, None)
pool = network.get_ip_pools()[0]
# Test that floating ips are not released
self.assertFalse(pool.is_available(fp1.address))
示例15: test_remove_error
def test_remove_error(self, rapi, client):
vm = mfactory.VirtualMachineFactory()
# Also create a NIC
msg = self.create_msg(operation='OP_INSTANCE_REMOVE',
status="error",
instance=vm.backend_vm_id)
rapi().GetInstance.return_value = {}
update_db(client, msg)
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertFalse(db_vm.deleted)
rapi().GetInstance.side_effect = GanetiApiError(msg="msg",
code=503)
update_db(client, msg)
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertFalse(db_vm.deleted)
rapi().GetInstance.side_effect = GanetiApiError(msg="msg",
code=404)
with mocked_quotaholder():
update_db(client, msg)
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertTrue(db_vm.deleted)