fix(xo-server/utils/parseXml): keep all values as strings (#5581)

Fixes #5497

All values must be kept as strings because that's what the previous implementation used to do.

Introduced by 525369e0ce

See https://github.com/vatesfr/xen-orchestra/issues/5497#issuecomment-780314187

```
{
  'iscsi-target': {
    LUN: {
      vendor: 'TrueNAS',
      serial: '9eaa394581f3003',
      LUNid: 55,
      size: 10995116277760,
      SCSIid: '36589cfc000000581d40d6d5140d9b9da'
    }
  }
}
```
This commit is contained in:
Rajaa.BARHTAOUI
2021-02-18 09:46:17 +01:00
committed by GitHub
parent 7a13771198
commit fce56cbf4c
3 changed files with 50 additions and 5 deletions

View File

@@ -22,6 +22,7 @@
- [Servers] Hide pool's objects if its master is unreachable [#5475](https://github.com/vatesfr/xen-orchestra/issues/5475) (PR [#5526](https://github.com/vatesfr/xen-orchestra/pull/5526))
- [Host] Restart toolstack: fix `ECONNREFUSED` error (PR [#5553](https://github.com/vatesfr/xen-orchestra/pull/5553))
- [VM migration] Intra-pool: don't automatically select migration network if no default migration network is defined on the pool (PR [#5564](https://github.com/vatesfr/xen-orchestra/pull/5564))
- [New SR] Fix `lun.LUNid.trim is not a function` error [#5497](https://github.com/vatesfr/xen-orchestra/issues/5497) (PR [#5581](https://github.com/vatesfr/xen-orchestra/pull/5581))
### Packages to release

View File

@@ -102,6 +102,8 @@ export const parseXml = (function () {
const opts = {
attributeNamePrefix: '',
ignoreAttributes: false,
parseNodeValue: false,
parseAttributeValue: false,
}
return xml => {

View File

@@ -51,7 +51,7 @@ describe('extractProperty()', function () {
describe('parseXml()', () => {
// excerpt of http://updates.xensource.com/XenServer/updates.xml
const str = `<?xml version="1.0" ?>
const strA = `<?xml version="1.0" ?>
<patchdata>
<!-- Generated by cfu.py, do not edit -->
<patches>
@@ -63,8 +63,9 @@ describe('parseXml()', () => {
</patch>
</patches>
</patchdata>`
const buf = Buffer.from(str)
const result = {
const bufA = Buffer.from(strA)
const resultA = {
patchdata: {
patches: {
patch: [
@@ -94,13 +95,54 @@ describe('parseXml()', () => {
},
},
}
const strB = `<?xml version="1.0" ?>
<iscsi-target>
<LUN>
<vendor>TrueNAS</vendor>
<serial>9eaa394581f3003</serial>
<LUNid>55</LUNid>
<size>10995116277760</size>
<SCSIid>36589cfc000000581d40d6d5140d9b9da</SCSIid>
</LUN>
<LUN>
<vendor>TrueNAS</vendor>
<serial>9eaa394581f3004</serial>
<LUNid>56</LUNid>
<size>10995116277761</size>
<SCSIid>36589cfc000000581d40d6d5140d9b9df</SCSIid>
</LUN>
</iscsi-target>`
const bufB = Buffer.from(strB)
const resultB = {
'iscsi-target': {
LUN: [
{
vendor: 'TrueNAS',
serial: '9eaa394581f3003',
LUNid: '55',
size: '10995116277760',
SCSIid: '36589cfc000000581d40d6d5140d9b9da',
},
{
vendor: 'TrueNAS',
serial: '9eaa394581f3004',
LUNid: '56',
size: '10995116277761',
SCSIid: '36589cfc000000581d40d6d5140d9b9df',
},
],
},
}
it('supports strings', () => {
expect(parseXml(str)).toEqual(result)
expect(parseXml(strA)).toEqual(resultA)
expect(parseXml(strB)).toEqual(resultB)
})
it('supports buffers', () => {
expect(parseXml(buf)).toEqual(result)
expect(parseXml(bufA)).toEqual(resultA)
expect(parseXml(bufB)).toEqual(resultB)
})
})