libvirt: add os_admin_user to use with set admin password
In order to pass an admin user mostly used for Windows to set the admin password, a new image property has been introduced os_admin_user. Change-Id: I215bb82668df074141397909b58fa9189f46b4da Implement: blueprint libvirt-set-admin-password
This commit is contained in:
@@ -28,7 +28,8 @@ class ImageMeta(base.NovaObject):
|
||||
# Version 1.2: ImageMetaProps version 1.2
|
||||
# Version 1.3: ImageMetaProps version 1.3
|
||||
# Version 1.4: ImageMetaProps version 1.4
|
||||
VERSION = '1.4'
|
||||
# Version 1.5: ImageMetaProps version 1.5
|
||||
VERSION = '1.5'
|
||||
|
||||
# These are driven by what the image client API returns
|
||||
# to Nova from Glance. This is defined in the glance
|
||||
@@ -66,6 +67,7 @@ class ImageMeta(base.NovaObject):
|
||||
('1.2', '1.2'),
|
||||
('1.3', '1.3'),
|
||||
('1.4', '1.4'),
|
||||
('1.5', '1.5'),
|
||||
],
|
||||
}
|
||||
|
||||
@@ -116,6 +118,7 @@ class ImageMetaProps(base.NovaObject):
|
||||
# Version 1.2: added img_hv_type and img_hv_requested_version fields
|
||||
# Version 1.3: HVSpec version 1.1
|
||||
# Version 1.4: added hw_vif_multiqueue_enabled field
|
||||
# Version 1.5: added os_admin_user field
|
||||
VERSION = ImageMeta.VERSION
|
||||
|
||||
# Maximum number of NUMA nodes permitted for the guest topology
|
||||
@@ -285,6 +288,9 @@ class ImageMetaProps(base.NovaObject):
|
||||
# integer value 1
|
||||
'img_version': fields.IntegerField(),
|
||||
|
||||
# string of username with admin privileges
|
||||
'os_admin_user': fields.StringField(),
|
||||
|
||||
# string of boot time command line arguments for the guest kernel
|
||||
'os_command_line': fields.StringField(),
|
||||
|
||||
|
||||
@@ -1111,8 +1111,8 @@ object_data = {
|
||||
'FloatingIPList': '1.8-7f2ba670714e1b7bab462ab3290f7159',
|
||||
'HostMapping': '1.0-1a3390a696792a552ab7bd31a77ba9ac',
|
||||
'HVSpec': '1.1-6b4f7c0f688cbd03e24142a44eb9010d',
|
||||
'ImageMeta': '1.4-642d1b2eb3e880a367f37d72dd76162d',
|
||||
'ImageMetaProps': '1.4-ae965c3b7a0ce2dc0f714cfec554ca76',
|
||||
'ImageMeta': '1.5-642d1b2eb3e880a367f37d72dd76162d',
|
||||
'ImageMetaProps': '1.5-93a74996a8d3c2aa821fddab301a9b1a',
|
||||
'Instance': '1.21-260d385315d4868b6397c61a13109841',
|
||||
'InstanceAction': '1.1-f9f293e526b66fca0d05c3b3a2d13914',
|
||||
'InstanceActionEvent': '1.1-e56a64fa4710e43ef7af2ad9d6028b33',
|
||||
@@ -1187,7 +1187,7 @@ object_relationships = {
|
||||
'FloatingIP': {'FixedIP': '1.11'},
|
||||
'FloatingIPList': {'FloatingIP': '1.7'},
|
||||
'HostMapping': {'CellMapping': '1.0'},
|
||||
'ImageMeta': {'ImageMetaProps': '1.4'},
|
||||
'ImageMeta': {'ImageMetaProps': '1.5'},
|
||||
'Instance': {'InstanceFault': '1.2',
|
||||
'InstanceInfoCache': '1.5',
|
||||
'InstanceNUMATopology': '1.1',
|
||||
|
||||
@@ -715,6 +715,25 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
||||
mock_guest.set_user_password.assert_called_once_with(
|
||||
"Administrator", "123")
|
||||
|
||||
@mock.patch('nova.utils.get_image_from_system_metadata')
|
||||
@mock.patch.object(host.Host,
|
||||
'has_min_version', return_value=True)
|
||||
@mock.patch('nova.virt.libvirt.host.Host.get_guest')
|
||||
def test_set_admin_password_image(self, mock_get_guest, ver, mock_image):
|
||||
self.flags(virt_type='kvm', group='libvirt')
|
||||
instance = objects.Instance(**self.test_instance)
|
||||
mock_image.return_value = {"properties": {
|
||||
"hw_qemu_guest_agent": "yes",
|
||||
"os_admin_user": "foo"
|
||||
}}
|
||||
mock_guest = mock.Mock(spec=libvirt_guest.Guest)
|
||||
mock_get_guest.return_value = mock_guest
|
||||
|
||||
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
drvr.set_admin_password(instance, "123")
|
||||
|
||||
mock_guest.set_user_password.assert_called_once_with("foo", "123")
|
||||
|
||||
@mock.patch('nova.utils.get_image_from_system_metadata')
|
||||
@mock.patch.object(host.Host,
|
||||
'has_min_version', return_value=False)
|
||||
|
||||
@@ -1431,11 +1431,12 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
self._can_set_admin_password(image_meta)
|
||||
|
||||
guest = self._host.get_guest(instance)
|
||||
if instance.os_type == "windows":
|
||||
user = "Administrator"
|
||||
else:
|
||||
user = "root"
|
||||
|
||||
user = image_meta.properties.get("os_admin_user")
|
||||
if not user:
|
||||
if instance.os_type == "windows":
|
||||
user = "Administrator"
|
||||
else:
|
||||
user = "root"
|
||||
try:
|
||||
guest.set_user_password(user, new_pass)
|
||||
except libvirt.libvirtError as ex:
|
||||
|
||||
Reference in New Issue
Block a user