Merge "Skip existing VMs when hosts apply force_config_drive"
This commit is contained in:
commit
c7e9e66742
|
@ -56,7 +56,8 @@ Force injection to take place on a config drive
|
|||
|
||||
When this option is set to true configuration drive functionality will be
|
||||
forced enabled by default, otherwise user can still enable configuration
|
||||
drives via the REST API or image metadata properties.
|
||||
drives via the REST API or image metadata properties. Launched VMs are not
|
||||
affected by this option.
|
||||
|
||||
Possible values:
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ class LibvirtBlockInfoTest(test.NoDBTestCase):
|
|||
'ephemeral_gb': 20,
|
||||
'instance_type_id': 2, # m1.tiny
|
||||
'config_drive': None,
|
||||
'launched_at': None,
|
||||
'system_metadata': {},
|
||||
}
|
||||
self.test_image_meta = {
|
||||
|
|
|
@ -42,11 +42,12 @@ class ConfigDriveTestCase(test.NoDBTestCase):
|
|||
|
||||
self.assertTrue(configdrive.required_by(instance))
|
||||
|
||||
def test_config_flag_force(self):
|
||||
def test_config_flag_force_for_new_vms(self):
|
||||
self.flags(force_config_drive=True)
|
||||
|
||||
instance = objects.Instance(
|
||||
config_drive=None,
|
||||
launched_at=None,
|
||||
system_metadata={
|
||||
"image_img_config_drive": "optional",
|
||||
}
|
||||
|
@ -54,6 +55,19 @@ class ConfigDriveTestCase(test.NoDBTestCase):
|
|||
|
||||
self.assertTrue(configdrive.required_by(instance))
|
||||
|
||||
def test_config_flag_force_for_existing_vms(self):
|
||||
self.flags(force_config_drive=True)
|
||||
|
||||
instance = objects.Instance(
|
||||
config_drive=None,
|
||||
launched_at='2019-05-17T00:00:00.000000',
|
||||
system_metadata={
|
||||
"image_img_config_drive": "optional",
|
||||
}
|
||||
)
|
||||
|
||||
self.assertFalse(configdrive.required_by(instance))
|
||||
|
||||
def test_no_config_drive(self):
|
||||
self.flags(force_config_drive=False)
|
||||
|
||||
|
|
|
@ -160,8 +160,13 @@ def required_by(instance):
|
|||
"img_config_drive",
|
||||
fields.ConfigDrivePolicy.OPTIONAL)
|
||||
|
||||
# NOTE(pandatt): Option CONF.force_config_drive only applies to newly
|
||||
# being-built VMs. And already launched VMs shouldn't be forced a config
|
||||
# drive, because they may have been cloud-inited via metadata service, and
|
||||
# do not need and have any config drive device. The `launched_at` property
|
||||
# is an apparent flag to tell VMs being built from launched ones.
|
||||
return (instance.config_drive or
|
||||
CONF.force_config_drive or
|
||||
(CONF.force_config_drive and not instance.launched_at) or
|
||||
image_prop == fields.ConfigDrivePolicy.MANDATORY
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue