Skip to content

Commit c7e9e66

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Skip existing VMs when hosts apply force_config_drive"
2 parents a7058b1 + 2af89cf commit c7e9e66

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

nova/conf/configdrive.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
5757
When this option is set to true configuration drive functionality will be
5858
forced enabled by default, otherwise user can still enable configuration
59-
drives via the REST API or image metadata properties.
59+
drives via the REST API or image metadata properties. Launched VMs are not
60+
affected by this option.
6061
6162
Possible values:
6263

nova/tests/unit/virt/libvirt/test_blockinfo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def setUp(self):
5555
'ephemeral_gb': 20,
5656
'instance_type_id': 2, # m1.tiny
5757
'config_drive': None,
58+
'launched_at': None,
5859
'system_metadata': {},
5960
}
6061
self.test_image_meta = {

nova/tests/unit/virt/test_configdrive.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,32 @@ def test_image_meta_force(self):
4242

4343
self.assertTrue(configdrive.required_by(instance))
4444

45-
def test_config_flag_force(self):
45+
def test_config_flag_force_for_new_vms(self):
4646
self.flags(force_config_drive=True)
4747

4848
instance = objects.Instance(
4949
config_drive=None,
50+
launched_at=None,
5051
system_metadata={
5152
"image_img_config_drive": "optional",
5253
}
5354
)
5455

5556
self.assertTrue(configdrive.required_by(instance))
5657

58+
def test_config_flag_force_for_existing_vms(self):
59+
self.flags(force_config_drive=True)
60+
61+
instance = objects.Instance(
62+
config_drive=None,
63+
launched_at='2019-05-17T00:00:00.000000',
64+
system_metadata={
65+
"image_img_config_drive": "optional",
66+
}
67+
)
68+
69+
self.assertFalse(configdrive.required_by(instance))
70+
5771
def test_no_config_drive(self):
5872
self.flags(force_config_drive=False)
5973

nova/virt/configdrive.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,13 @@ def required_by(instance):
160160
"img_config_drive",
161161
fields.ConfigDrivePolicy.OPTIONAL)
162162

163+
# NOTE(pandatt): Option CONF.force_config_drive only applies to newly
164+
# being-built VMs. And already launched VMs shouldn't be forced a config
165+
# drive, because they may have been cloud-inited via metadata service, and
166+
# do not need and have any config drive device. The `launched_at` property
167+
# is an apparent flag to tell VMs being built from launched ones.
163168
return (instance.config_drive or
164-
CONF.force_config_drive or
169+
(CONF.force_config_drive and not instance.launched_at) or
165170
image_prop == fields.ConfigDrivePolicy.MANDATORY
166171
)
167172

0 commit comments

Comments
 (0)