diff --git a/src/vm/test/VirtualMachinePoolTest.cc b/src/vm/test/VirtualMachinePoolTest.cc
index aa3a418f65..4544e02a32 100644
--- a/src/vm/test/VirtualMachinePoolTest.cc
+++ b/src/vm/test/VirtualMachinePoolTest.cc
@@ -82,6 +82,28 @@ const string xml_dump_where =
"IME>000000000000000";
+const string xml_history_dump =
+ "00one_user_test"
+ "VM one01"
+ "000000000000"
+ "000"
+ "010"
+ "one_user_testSecond VM0"
+ "200000000000"
+ "000"
+ "000"
+ "A_hostname000"
+ "0000"
+ "0002"
+ "0one_user_testVM one"
+ "020"
+ "000000000000"
+ "0001"
+ "C_hostname200"
+ "0000"
+ "000"
+ "";
+
const string replacement = "0000000000";
@@ -102,6 +124,7 @@ class VirtualMachinePoolTest : public PoolTest
CPPUNIT_TEST (update);
CPPUNIT_TEST (dump);
CPPUNIT_TEST (dump_where);
+ CPPUNIT_TEST (dump_history);
CPPUNIT_TEST (history);
CPPUNIT_TEST_SUITE_END ();
@@ -235,7 +258,7 @@ public:
void dump()
{
VirtualMachinePool * vmp = static_cast(pool);
-
+
set_up_user_pool();
ostringstream oss;
@@ -266,7 +289,7 @@ public:
vmp->allocate(1, templates[0], &oid, false);
vmp->allocate(2, templates[1], &oid, true);
-
+
where << "uid < 2";
rc = vmp->dump(oss, where.str());
CPPUNIT_ASSERT(rc == 0);
@@ -276,6 +299,94 @@ public:
CPPUNIT_ASSERT( result == xml_dump_where );
}
+ void dump_history()
+ {
+ VirtualMachinePool * vmp = static_cast(pool);
+ VirtualMachine* vm;
+
+ string hostnames[] = {"A_hostname", "B_hostname", "C_hostname"};
+ string vm_dirs[] = {"A_vm_dir", "B_vm_dir", "C_vm_dir"};
+ string vmm_mads[] = {"A_vmm_mad", "B_vmm_mad", "C_vmm_mad"};
+ string tm_mads[] = {"A_tm_mad", "B_tm_mad", "C_tm_mad"};
+
+ int oid, rc;
+ ostringstream oss;
+ ostringstream where;
+
+
+ set_up_user_pool();
+
+ // Allocate a VM
+ rc = vmp->allocate(0, templates[0], &oid, false);
+ CPPUNIT_ASSERT( rc == oid );
+ CPPUNIT_ASSERT( oid >= 0 );
+ //----------------------------------------------------------------------
+
+ // Allocate a VM with one history item
+ rc = vmp->allocate(0, templates[1], &oid, true);
+ CPPUNIT_ASSERT( rc == oid );
+ CPPUNIT_ASSERT( oid >= 0 );
+
+ vm = vmp->get(oid, false);
+ CPPUNIT_ASSERT( vm != 0 );
+
+ // Add a history item
+ vm->add_history(0, hostnames[0], vm_dirs[0], vmm_mads[0], tm_mads[0]);
+
+ rc = vmp->update_history(vm);
+ CPPUNIT_ASSERT( rc == 0 );
+ //----------------------------------------------------------------------
+
+ // Allocate a VM with two history items
+ rc = vmp->allocate(0, templates[2], &oid, true);
+ CPPUNIT_ASSERT( rc == oid );
+ CPPUNIT_ASSERT( oid >= 0 );
+
+ vm = vmp->get(oid, false);
+ CPPUNIT_ASSERT( vm != 0 );
+
+ // Add a history item
+ vm->add_history(1, hostnames[1], vm_dirs[1], vmm_mads[1], tm_mads[1]);
+ rc = vmp->update_history(vm);
+ CPPUNIT_ASSERT( rc == 0 );
+
+ // Add another history item
+ vm->add_history(2, hostnames[2], vm_dirs[2], vmm_mads[2], tm_mads[2]);
+ rc = vmp->update_history(vm);
+ CPPUNIT_ASSERT( rc == 0 );
+ //----------------------------------------------------------------------
+
+ // Allocate a VM, will be set to DONE
+ rc = vmp->allocate(1, templates[0], &oid, false);
+ CPPUNIT_ASSERT( rc == oid );
+ CPPUNIT_ASSERT( oid >= 0 );
+
+ vm = vmp->get(oid, false);
+ CPPUNIT_ASSERT( vm != 0 );
+
+ vm->set_state(VirtualMachine::DONE);
+ vmp->update(vm);
+ //----------------------------------------------------------------------
+
+ // Call dump. Should return:
+ // the first VM, with no history.
+ // the second VM, with the first and only history item
+ // the third VM, with only its last history item
+
+ where << "uid < 2";
+ rc = vmp->dump(oss, where.str());
+ CPPUNIT_ASSERT(rc == 0);
+
+ // Get the xml and replace the STIME to 0, so we can compare it
+ string result = oss.str();
+
+ result.replace(159, 10, replacement);
+ result.replace(440, 10, replacement);
+ result.replace(950, 10, replacement);
+
+ CPPUNIT_ASSERT( result == xml_history_dump );
+ }
+
void history()
{
VirtualMachine * vm;