Exemple #1
0
 def setUp(self):
     self._snapshots = []
     self.box = VirtualBox(self.vm_name, self.vbox_command)
     self.activate_snapshot(self.snapshot)
Exemple #2
0
class VirtualBoxTest(unittest.TestCase):
    vm_name = "Squeeze"  # name or uuid of VirtualBox VM
    vbox_command = "VBoxManage"  # command to execute VBoxManage
    snapshot = "fabtest-initial"  # snapshot to load before each test
    keep_box = False  # don't stop the VM after tests; useful for manual investigation

    # set this to False if snapshots are taken during tests
    # or if you want to be able to login to VM in a separate shell
    headless = True

    def setUp(self):
        self._snapshots = []
        self.box = VirtualBox(self.vm_name, self.vbox_command)
        self.activate_snapshot(self.snapshot)

    def tearDown(self):
        if self.keep_box:
            return
        self.box.stop()
        for name in self._snapshots:
            self.box.snapshot("delete", name)

    def activate_snapshot(self, name):
        self.box.stop()
        assert self.box.snapshot_exists(name), 'Snapshot "%s" does not exist' % name
        self.box.snapshot("restore", name)
        self.box.start(self.headless)

    def take_test_snapshot(self, name):
        """
        Creates temporary snapshot that will be deleted after test.
        """
        self._snapshots.append(name)
        self.box.snapshot_take(name)