tstOVF.cpp revision d8b658a6b59104fdf0a35e569136f9b42fcf672d
72e560433c691132e8f21f463955515d4511c34bvboxsync * tstOVF - testcases for OVF import and export
72e560433c691132e8f21f463955515d4511c34bvboxsync * Copyright (C) 2010 Oracle Corporation
72e560433c691132e8f21f463955515d4511c34bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
72e560433c691132e8f21f463955515d4511c34bvboxsync * available from http://www.virtualbox.org. This file is free software;
72e560433c691132e8f21f463955515d4511c34bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
72e560433c691132e8f21f463955515d4511c34bvboxsync * General Public License (GPL) as published by the Free Software
72e560433c691132e8f21f463955515d4511c34bvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
72e560433c691132e8f21f463955515d4511c34bvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
72e560433c691132e8f21f463955515d4511c34bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
72e560433c691132e8f21f463955515d4511c34bvboxsyncusing namespace com;
72e560433c691132e8f21f463955515d4511c34bvboxsync///////////////////////////////////////////////////////////////////////////////
72e560433c691132e8f21f463955515d4511c34bvboxsync * Quick hack exception structure.
72e560433c691132e8f21f463955515d4511c34bvboxsync const char *pcsz,
72e560433c691132e8f21f463955515d4511c34bvboxsync if (!info.isFullAvailable() && !info.isBasicAvailable())
72e560433c691132e8f21f463955515d4511c34bvboxsync * Imports the given OVF file, with all bells and whistles.
72e560433c691132e8f21f463955515d4511c34bvboxsync * Throws MyError on errors.
72e560433c691132e8f21f463955515d4511c34bvboxsync * @param pVirtualBox VirtualBox instance.
72e560433c691132e8f21f463955515d4511c34bvboxsync * @param pcszOVF File to import.
72e560433c691132e8f21f463955515d4511c34bvboxsync const char *pcszOVF0)
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync RTPrintf("%s: reading appliance \"%s\"...\n", pcszPrefix, szAbsOVF);
72e560433c691132e8f21f463955515d4511c34bvboxsync HRESULT rc = pVirtualBox->CreateAppliance(pAppl.asOutParam());
72e560433c691132e8f21f463955515d4511c34bvboxsync rc = pAppl->Read(Bstr(szAbsOVF), pProgress.asOutParam());
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync throw MyError(rc, "Progress::WaitForCompletion() failed\n");
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync throw MyError(rc2, "Appliance::Read() failed\n", pProgress);
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync RTPrintf("%s: interpreting appliance \"%s\"...\n", pcszPrefix, szAbsOVF);
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync throw MyError(rc, "Appliance::Interpret() failed\n");
72e560433c691132e8f21f463955515d4511c34bvboxsync com::SafeIfaceArray<IVirtualSystemDescription> aDescriptions;
72e560433c691132e8f21f463955515d4511c34bvboxsync rc = pAppl->COMGETTER(VirtualSystemDescriptions)(ComSafeArrayAsOutParam(aDescriptions));
72e560433c691132e8f21f463955515d4511c34bvboxsync ComPtr<IVirtualSystemDescription> pVSys = aDescriptions[u];
72e560433c691132e8f21f463955515d4511c34bvboxsync com::SafeArray<VirtualSystemDescriptionType_T> aTypes;
72e560433c691132e8f21f463955515d4511c34bvboxsync rc = pVSys->GetDescription(ComSafeArrayAsOutParam(aTypes),
72e560433c691132e8f21f463955515d4511c34bvboxsync const char *pcszType;
72e560433c691132e8f21f463955515d4511c34bvboxsync case VirtualSystemDescriptionType_HardDiskControllerIDE:
72e560433c691132e8f21f463955515d4511c34bvboxsync case VirtualSystemDescriptionType_HardDiskControllerSATA:
72e560433c691132e8f21f463955515d4511c34bvboxsync case VirtualSystemDescriptionType_HardDiskControllerSAS:
72e560433c691132e8f21f463955515d4511c34bvboxsync case VirtualSystemDescriptionType_HardDiskControllerSCSI:
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync throw MyError(E_UNEXPECTED, "Invalid VirtualSystemDescriptionType\n");
72e560433c691132e8f21f463955515d4511c34bvboxsync RTPrintf(" vsys %2u item %2u: type %2d (%s), ovf: \"%ls\", vbox: \"%ls\", extra: \"%ls\"\n",
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync RTPrintf("%s: importing %d machine(s)...\n", pcszPrefix, aDescriptions.size());
72e560433c691132e8f21f463955515d4511c34bvboxsync rc = pAppl->ImportMachines(pProgress.asOutParam());
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync throw MyError(rc, "Appliance::ImportMachines() failed\n");
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync throw MyError(rc, "Progress::WaitForCompletion() failed\n");
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync throw MyError(rc2, "Progress::GetResultCode() failed\n");
72e560433c691132e8f21f463955515d4511c34bvboxsync * Copies ovf-testcases/ovf-dummy.vmdk to the given target and appends that
72e560433c691132e8f21f463955515d4511c34bvboxsync * target as a string to the given list so that the caller can delete it
72e560433c691132e8f21f463955515d4511c34bvboxsync * again later.
72e560433c691132e8f21f463955515d4511c34bvboxsync * @param llFiles2Delete List of strings to append the target file path to.
72e560433c691132e8f21f463955515d4511c34bvboxsync * @param pcszDest Target for dummy VMDK.
72e560433c691132e8f21f463955515d4511c34bvboxsyncvoid copyDummyDiskImage(std::list<Utf8Str> &llFiles2Delete, const char *pcszDest)
72e560433c691132e8f21f463955515d4511c34bvboxsync int vrc = RTFileCopy("ovf-testcases/ovf-dummy.vmdk", pcszDest);
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync throw MyError(0, Utf8StrFmt("Cannot copy ovf-dummy.vmdk to %s: %Rra\n", pcszDest, vrc).c_str());
72e560433c691132e8f21f463955515d4511c34bvboxsync * @param argc
72e560433c691132e8f21f463955515d4511c34bvboxsync * @param argv[]
72e560433c691132e8f21f463955515d4511c34bvboxsync rc = pVirtualBox.createLocalObject(CLSID_VirtualBox);
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync throw MyError(rc, "failed to create the VirtualBox object!\n");
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync throw MyError(rc, "failed to create a session object!\n");
72e560433c691132e8f21f463955515d4511c34bvboxsync // create the event queue
72e560433c691132e8f21f463955515d4511c34bvboxsync // (here it is necessary only to process remaining XPCOM/IPC events after the session is closed)
72e560433c691132e8f21f463955515d4511c34bvboxsync // testcase 1: import ovf-joomla-0.9/joomla-1.1.4-ovf.ovf
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync// copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-0.vmdk");
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync// copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-1.vmdk");
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync// importOVF("joomla-0.9", pVirtualBox, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf.ovf");
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync // testcase 2: import ovf-winxp-vbox-sharedfolders/winxp.ovf
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-winxp-vbox-sharedfolders/Windows 5.1 XP 1 merged.vmdk");
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-winxp-vbox-sharedfolders/smallvdi.vmdk");
d8b658a6b59104fdf0a35e569136f9b42fcf672dvboxsync importOVF("winxp-vbox-sharedfolders", pVirtualBox, "ovf-testcases/ovf-winxp-vbox-sharedfolders/winxp.ovf");
72e560433c691132e8f21f463955515d4511c34bvboxsync // todo: cleanup created machines, created disk images
72e560433c691132e8f21f463955515d4511c34bvboxsync // clean up