Skip to content

Commit

Permalink
feat: VM insert/eject CD (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
badrAZ authored and julien-f committed Mar 10, 2017
1 parent d0fa5ff commit 84943e7
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 84 deletions.
84 changes: 0 additions & 84 deletions src/vm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
122 changes: 122 additions & 0 deletions src/vm/cd.spec.js
Original file line number Diff line number Diff line change
@@ -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()
})
})
})
})

0 comments on commit 84943e7

Please sign in to comment.