tstOVF.cpp revision 6739cf90e4aa3b3344768b8da241802f80ff455c
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 m_str.append("Most likely, the VirtualBox COM server is not running or failed to start.");
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)
72e560433c691132e8f21f463955515d4511c34bvboxsync RTPrintf("Reading appliance \"%s\"...\n", szAbsOVF);
72e560433c691132e8f21f463955515d4511c34bvboxsync HRESULT rc = pVirtualBox->CreateAppliance(pAppl.asOutParam());
72e560433c691132e8f21f463955515d4511c34bvboxsync rc = pAppl->Read(Bstr(szAbsOVF), pProgress.asOutParam());
72e560433c691132e8f21f463955515d4511c34bvboxsync throw MyError(rc, "Progress::WaitForCompletion() failed");
72e560433c691132e8f21f463955515d4511c34bvboxsync throw MyError(rc2, "Appliance::Read() failed", pProgress);
72e560433c691132e8f21f463955515d4511c34bvboxsync RTPrintf("Interpreting appliance \"%s\"...\n", szAbsOVF);
72e560433c691132e8f21f463955515d4511c34bvboxsync throw MyError(rc, "Appliance::Interpret() failed");
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:
72e560433c691132e8f21f463955515d4511c34bvboxsync throw MyError(-1, "Invalid VirtualSystemDescriptionType");
72e560433c691132e8f21f463955515d4511c34bvboxsync RTPrintf(" vsys %2u item %2u: type %2d (%s), ovf: \"%ls\", vbox: \"%ls\", extra: \"%ls\"\n",
72e560433c691132e8f21f463955515d4511c34bvboxsync rc = pAppl->ImportMachines(pProgress.asOutParam());
72e560433c691132e8f21f463955515d4511c34bvboxsync throw MyError(rc, "Appliance::ImportMachines() failed");
72e560433c691132e8f21f463955515d4511c34bvboxsync throw MyError(rc, "Progress::WaitForCompletion() failed");
72e560433c691132e8f21f463955515d4511c34bvboxsync throw MyError(rc2, "Appliance::ImportMachines() failed", pProgress);
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);
72e560433c691132e8f21f463955515d4511c34bvboxsync * @param argc
72e560433c691132e8f21f463955515d4511c34bvboxsync * @param argv[]
72e560433c691132e8f21f463955515d4511c34bvboxsync rc = pVirtualBox.createLocalObject(CLSID_VirtualBox);
72e560433c691132e8f21f463955515d4511c34bvboxsync throw MyError(rc, "failed to create the VirtualBox object!");
72e560433c691132e8f21f463955515d4511c34bvboxsync throw MyError(rc, "failed to create a session object!");
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
72e560433c691132e8f21f463955515d4511c34bvboxsync copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-0.vmdk");
72e560433c691132e8f21f463955515d4511c34bvboxsync copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-1.vmdk");
72e560433c691132e8f21f463955515d4511c34bvboxsync importOVF(pVirtualBox, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf.ovf");
72e560433c691132e8f21f463955515d4511c34bvboxsync // todo: cleanup created machines, created disk images
72e560433c691132e8f21f463955515d4511c34bvboxsync // clean up