def setUp(self): super(CommandTest, self).setUp() vm_build(VM_HOSTNAME) self.check_vm_present() with _get_vm(VM_HOSTNAME) as vm: # For contacting VM over shell self.vm = vm
def test_rollback(self): obj = Query({'hostname': VM_HOSTNAME}, ['puppet_environment']).get() obj['puppet_environment'] = 'doesnotexist' obj.commit() with self.assertRaises(VMError): vm_build(VM_HOSTNAME) self.check_vm_absent()
def test_rollback(self): # TODO: consider the usage of self.vm_obj instead of new Query obj = Query({'hostname': VM_HOSTNAME}, ['puppet_environment']).get() obj['puppet_environment'] = 'doesnotexist' obj.commit() with self.assertRaises(VMError): vm_build(VM_HOSTNAME) self.check_vm_absent()
def test_postboot(self): with NamedTemporaryFile() as fd: fd.write('echo hello > /root/postboot_result'.encode()) fd.flush() vm_build(VM_HOSTNAME, postboot=fd.name) self.check_vm_present() with _get_vm(VM_HOSTNAME) as vm: output = vm.run('cat /root/postboot_result') self.assertIn('hello', output)
def test_delete(self): vm_build(VM_HOSTNAME) self.check_vm_present() # Fails while VM is powered on with self.assertRaises(IGVMError): vm_delete(VM_HOSTNAME) vm_stop(VM_HOSTNAME) vm_delete(VM_HOSTNAME, retire=True) self.check_vm_absent()
def test_delete(self): vm_build(VM_HOSTNAME) self.check_vm_present() # Fails while VM is powered on with self.assertRaises(IGVMError): vm_delete(VM_HOSTNAME) with _get_vm(VM_HOSTNAME) as vm: vm.shutdown() vm_delete(VM_HOSTNAME, retire=True) self.check_vm_absent()
def test_rebuild(self): vm_build(VM_HOSTNAME) # Build the VM again, this must fail, as it is already built with self.assertRaises(IGVMError): vm_build(VM_HOSTNAME) # Create files on VM to check later if the VM was really rebuilt with _get_vm(VM_HOSTNAME) as vm: vm.run('touch /root/initial_canary') vm.run('test -f /root/initial_canary') # Now stop it and rebuild it vm_stop(VM_HOSTNAME) vm_build(VM_HOSTNAME, rebuild=True) self.check_vm_present() # The VM was rebuild and thus the test file must be gone with _get_vm(VM_HOSTNAME) as vm: vm.run('test ! -f /root/initial_canary')
def setUp(self): super(MigrationTest, self).setUp() vm_build(VM_HOSTNAME) with _get_vm(VM_HOSTNAME) as vm: self.old_hv_name = vm.hypervisor.dataset_obj['hostname']
def test_build_stretch(self): vm_build(VM_HOSTNAME) self.check_vm_present()