def test_storage(self): """Test using Machine's storage. """ src_machine = Machine(uuid=self.uuid_1, provider_id=self.provider.provider_id, av_zone=self.av_zone) Machine.add(src_machine) dst_machine = Machine.fetch(self.uuid_1) self.assertEqual(src_machine, dst_machine) self.assertNotEqual(id(src_machine), id(dst_machine)) Machine.remove(src_machine) dst_machine = Machine.fetch(self.uuid_1) self.assertEqual(None, dst_machine)
def test_machine(self): """Test creating/destroying a machine """ # Try to create a machine with a wrong provider. status = self.proxy.server.create( "Doesn't exist", IMAGE, FLAVOR ) self.check_xmlrpc_command_result(status, has_error=True) # Create a machine. status = self.proxy.server.create( PROVIDER_ID, IMAGE, FLAVOR ) self.check_xmlrpc_command_result(status) status = self.proxy.server.list(PROVIDER_ID) info = self.check_xmlrpc_simple(status, {}) machine_uuid = info['uuid'] av_zone = info['av_zone'] machine = Machine.fetch(machine_uuid) self.assertEqual(str(machine.uuid), machine_uuid) self.assertEqual(machine.av_zone, av_zone) # Try to remove a machine with a wrong provider status = self.proxy.server.destroy("Don't exist", str(machine.uuid)) self.check_xmlrpc_command_result(status, has_error=True) # Remove a machine. status = self.proxy.server.destroy(PROVIDER_ID, machine_uuid) self.check_xmlrpc_command_result(status) # Try to remove a machine that does not exist. status = self.proxy.server.destroy(PROVIDER_ID, machine_uuid) self.check_xmlrpc_command_result(status, has_error=True)
def _retrieve_machine(provider_id, machine_uuid, skip_store): """Return a machine object from an id. """ machine = Machine.fetch(machine_uuid) if not machine and not skip_store: raise MachineError("Machine (%s) does not exist." % (machine_uuid, )) if machine and machine.provider_id != provider_id: raise MachineError("Machine (%s) does not belong to provider (%s)." % (machine_uuid, provider_id)) return machine
def _retrieve_machine(provider_id, machine_uuid, skip_store): """Return a machine object from an id. """ machine = Machine.fetch(machine_uuid) if not machine and not skip_store: raise MachineError( "Machine (%s) does not exist." % (machine_uuid, ) ) if machine and machine.provider_id != provider_id: raise MachineError( "Machine (%s) does not belong to provider (%s)." % (machine_uuid, provider_id) ) return machine