Specify proper container_format for 'vhd' disk_format

When editing an image, if the disk_fomrat is 'vhd',
the container_format was wrongly set to 'bare' before.
'ovf' is the correct container_format for 'vhd' disk images.

Closes-Bug: #1539722
Change-Id: Ic6b0c66af0d5c8db2d802d6eea2b97721d92b7eb
This commit is contained in:
白子玉 2019-06-08 15:14:51 +08:00 committed by Ziyu Bai
parent 437e32d18e
commit ba75bafc69
4 changed files with 37 additions and 0 deletions

View File

@ -481,6 +481,10 @@ def create_image_metadata(data):
# 'raw' as the disk format and 'docker' as the container format.
meta['disk_format'] = 'raw'
meta['container_format'] = 'docker'
elif meta['disk_format'] == 'vhd':
# If the user wishes to upload a vhd using Horizon, then
# 'ovf' must be the container format
meta['container_format'] = 'ovf'
elif meta['disk_format'] == 'ova':
# If the user wishes to upload an OVA using Horizon, then
# 'ova' must be the container format and 'vmdk' must be the disk

View File

@ -113,6 +113,9 @@
ctrl.image.container_format = 'docker';
ctrl.image.disk_format = 'raw';
}
if (ctrl.image_format === 'vhd') {
ctrl.image.container_format = 'ovf';
}
}
} // end of controller

View File

@ -137,5 +137,14 @@
expect(ctrl.image.container_format).toEqual('ari');
});
it('should set container to ovf when disk format is vhd', function() {
setImagePromise({id: '1', disk_format: 'vhd', container_format: '',
is_public: false, properties: []});
var ctrl = createController();
$timeout.flush();
expect(ctrl.image.container_format).toEqual('ovf');
});
});
})();

View File

@ -446,3 +446,24 @@ class GlanceApiTests(test.APIMockTestCase):
self.assertNotIn('properties', meta)
self.assertEqual(meta['description'], form_data['description'])
self.assertEqual(meta['architecture'], form_data['architecture'])
def test_create_image_metadata_vhd(self):
form_data = {
'name': u'OVF image',
'description': u'OVF image test',
'source_type': u'url',
'image_url': u'/',
'disk_format': u'vhd',
'architecture': u'x86-64',
'min_disk': 15,
'min_ram': 512,
'is_public': False,
'protected': False,
'is_copying': False
}
meta = api.glance.create_image_metadata(form_data)
self.assertEqual(meta['disk_format'], 'vhd')
self.assertEqual(meta['container_format'], 'ovf')
self.assertNotIn('properties', meta)
self.assertEqual(meta['description'], form_data['description'])
self.assertEqual(meta['architecture'], form_data['architecture'])