feat: VM insert/eject CD (#34)

This commit is contained in:
badrAZ
2017-03-10 16:10:08 +01:00
committed by Julien Fontanet
parent d0fa5ff385
commit 84943e7fe6
2 changed files with 122 additions and 84 deletions

View File

@@ -367,90 +367,6 @@ describe('vm', () => {
})
})
// ------------------------------------------------------------------
describe('.ejectCd()', () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5e3
let isoId
beforeAll(async () => {
isoId = getIsoId()
})
beforeEach(async () => {
vmId = await getVmXoTestPvId(xo)
await xo.call('vm.insertCd', {
id: vmId,
cd_id: isoId,
force: false
})
})
it('ejects an ISO', async () => {
await xo.call('vm.ejectCd', {id: vmId})
const vbdId = await getCdVbdPosition(vmId)
await waitObjectState(xo, vbdId, vbd => {
expect(vbd.VDI).to.be.null()
})
})
})
// -------------------------------------------------------------------
describe('.insertCd()', () => {
let isoId
beforeAll(async () => {
isoId = getIsoId()
})
afterEach(async () => {
await xo.call('vm.ejectCd', {id: vmId})
})
it('mount an ISO on the VM (force: false)', async () => {
vmId = await getVmXoTestPvId(xo)
await xo.call('vm.insertCd', {
id: vmId,
cd_id: isoId,
force: false
})
const vbdId = await getCdVbdPosition(vmId)
// TODO: check type CD
await waitObjectState(xo, vbdId, vbd => {
expect(vbd.VDI).to.be.equal(isoId)
})
})
it('mount an ISO on the VM (force: true)', async () => {
vmId = await getVmXoTestPvId(xo)
await xo.call('vm.insertCd', {
id: vmId,
cd_id: isoId,
force: true
})
const vbdId = await getCdVbdPosition(vmId)
await waitObjectState(xo, vbdId, vbd => {
expect(vbd.VDI).to.be.equal(isoId)
})
})
it('mount an ISO on a VM which do not have already cd\'s VBD', async () => {
vmId = await createVmTest()
await xo.call('vm.insertCd', {
id: vmId,
cd_id: isoId,
force: false
})
await waitObjectState(xo, vmId, vm => {
expect(vm.$VBDs).not.to.be.empty()
})
const vm = await xo.getOrWaitObject(vmId)
await waitObjectState(xo, vm.$VBDs, vbd => {
expect(vbd.is_cd_drive).to.be.true()
expect(vbd.position).to.be.equal('3')
})
})
})
// -------------------------------------------------------------------
describe('.migrate', () => {

122
src/vm/cd.spec.js Normal file
View File

@@ -0,0 +1,122 @@
/* eslint-env jest */
import {
config,
getOrWaitCdVbdPosition,
rejectionOf,
waitObjectState,
xo
} from './../util'
// ===================================================================
beforeAll(async () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20e3
})
describe('cd', () => {
let vmId
// ----------------------------------------------------------------------
beforeAll(async () => {
vmId = await xo.call('vm.create', {
name_label: 'vmTest',
template: config.templatesId.debian
})
await waitObjectState(xo, vmId, vm => {
if (vm.type !== 'VM') throw new Error('retry')
})
})
afterAll(() => xo.call('vm.delete', {id: vmId}))
// ===================================================================
describe('.insertCd()', () => {
afterEach(() => xo.call('vm.ejectCd', {id: vmId}))
it('mount an ISO on the VM (force: false)', async () => {
await xo.call('vm.insertCd', {
id: vmId,
cd_id: config.windowsIsoId,
force: false
})
const vbdId = await getOrWaitCdVbdPosition(vmId)
await waitObjectState(xo, vbdId, vbd => {
expect(vbd.VDI).toBe(config.windowsIsoId)
expect(vbd.is_cd_drive).toBeTruthy()
expect(vbd.position).toBe('3')
})
})
it('mount an ISO on the VM (force: false) which has already a CD in the VBD', async () => {
await xo.call('vm.insertCd', {
id: vmId,
cd_id: config.windowsIsoId,
force: false
})
await getOrWaitCdVbdPosition(vmId)
expect((await rejectionOf(xo.call('vm.insertCd', {
id: vmId,
cd_id: config.ubuntuIsoId,
force: false
}))).message).toBe('unknown error from the peer')
})
it('mount an ISO on the VM (force: true) which has already a CD in the VBD', async () => {
await xo.call('vm.insertCd', {
id: vmId,
cd_id: config.windowsIsoId,
force: true
})
const vbdId = await getOrWaitCdVbdPosition(vmId)
await xo.call('vm.insertCd', {
id: vmId,
cd_id: config.ubuntuIsoId,
force: true
})
await waitObjectState(xo, vbdId, vbd => {
expect(vbd.VDI).toBe(config.ubuntuIsoId)
expect(vbd.is_cd_drive).toBeTruthy()
expect(vbd.position).toBe('3')
})
})
it('mount an ISO on a VM which do not have already cd\'s VBD', async () => {
await xo.call('vm.insertCd', {
id: vmId,
cd_id: config.windowsIsoId,
force: false
})
await waitObjectState(xo, vmId, async vm => {
expect(vm.$VBDs).toHaveLength(1)
const vbd = await xo.getOrWaitObject(vm.$VBDs)
expect(vbd.is_cd_drive).toBeTruthy()
expect(vbd.position).toBe('3')
})
})
})
describe('.ejectCd()', () => {
it('ejects an ISO', async () => {
await xo.call('vm.insertCd', {
id: vmId,
cd_id: config.windowsIsoId,
force: false
})
const vbdId = await getOrWaitCdVbdPosition(vmId)
await xo.call('vm.ejectCd', {id: vmId})
await waitObjectState(xo, vbdId, vbd => {
expect(vbd.VDI).toBeNull()
})
})
})
})