Ejemplo n.º 1
0
 def create_snapshotter(self, url):
     starter = vm_snapshot.url_to_vm_snapshot_based(
         url, VirtualBoxBasedSnapshotter)
     if starter:
         starter.hosted_guest = guest.VirtualBoxHostedGuest(
             starter.vm_name, self.executor)
         return starter
Ejemplo n.º 2
0
    def test_restore_fails_if_snapshot_not_found(self):
        mock_executor = MockExecutor()
        vb = guest.VirtualBoxHostedGuest("windows", executor=mock_executor)

        with self.assertRaises(guest.SnapshotNotFoundException) as ctx:
            vb.restore('test_snapshot')

        self.assertIn('test_snapshot', ctx.exception.message)
Ejemplo n.º 3
0
    def test_start_vm_runs_vboxmanage(self):
        mock_executor = MockExecutor()
        vb = guest.VirtualBoxHostedGuest("windows", executor=mock_executor)

        vb.start()

        self.assertEquals(
            ['vboxmanage startvm windows --type headless'.split()],
            mock_executor.executed_commands)
Ejemplo n.º 4
0
    def test_snapshot_takes_snapshot(self):
        mock_executor = MockExecutor()
        vb = guest.VirtualBoxHostedGuest("windows", executor=mock_executor)

        vb.snap('test_snapshot')

        self.assertEquals(
            ['vboxmanage snapshot windows take test_snapshot --pause'.split()],
            mock_executor.executed_commands)
Ejemplo n.º 5
0
    def test_stop_runs_controlvm(self):
        mock_executor = MockExecutor()
        vb = guest.VirtualBoxHostedGuest("windows", executor=mock_executor)

        vb.stop()

        self.assertEquals([
            'vboxmanage showvminfo windows --machinereadable'.split(),
            'vboxmanage controlvm windows poweroff'.split()
        ], mock_executor.executed_commands)
Ejemplo n.º 6
0
    def test_stop_does_nothing_if_vm_is_stopped(self):
        mock_executor = MockExecutor()
        mock_executor.if_found('showvminfo').then_return(
            stdout='VMState="poweroff"')
        vb = guest.VirtualBoxHostedGuest("windows", executor=mock_executor)

        vb.stop()

        self.assertEquals([
            'vboxmanage showvminfo windows --machinereadable'.split(),
        ], mock_executor.executed_commands)
Ejemplo n.º 7
0
    def test_restore_reverts_from_snapshot(self):
        mock_executor = MockExecutor()
        mock_executor.if_found(
            'snapshot',
            'list').then_return(stdout='SnapshotName="test_snapshot"')
        vb = guest.VirtualBoxHostedGuest("windows", executor=mock_executor)

        vb.restore('test_snapshot')

        self.assertEquals([
            'vboxmanage snapshot windows list --machinereadable'.split(),
            'vboxmanage snapshot windows restore test_snapshot'.split()
        ], mock_executor.executed_commands)
Ejemplo n.º 8
0
 def start(self):
     guest_vm = guest.VirtualBoxHostedGuest(self.vm_name, self.executor)
     guest_vm.stop()
     guest_vm.restore(self.snapshot_name)
     guest_vm.start()
     return self.ports_forwarded_to