Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enforce boot-from-volume via flavor #190

Open
wants to merge 1 commit into
base: stable/rocky-m3
Choose a base branch
from

Conversation

mariusleu
Copy link

Booting from volume can now be enforced via flavor.
A flavor must have extra property boot_from_volume=true to
enable this.
It works by enforcing a boot_index=0 block device mapping based on
the source image, like the user would have requested it.
If the user specifies a root volume explicitly, this enforcement
will be skipped.

Copy link

@grandchild grandchild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See some stylistic comments below:

@@ -8774,6 +8774,81 @@ def test_create_instance_associates_security_groups(self):
self.assertEqual(1, len(reqspec.security_groups))
self.assertEqual(group.name, reqspec.security_groups[0].name)

def test_create_instance_enforced_bfv(self):
# Tests that, if a user creates a instance from an image,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Tests that, if a user creates a instance from an image,
# Tests that, if a user creates an instance from an image,

return
elif (root_bdm.get('destination_type') == 'local' and
root_bdm.get('source_type') == 'image'):
# In this case overwrite the image mapping to a volume.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment feels redundant and/or possibly misleading. I guess it's supposed to describe what's happening in all the rest of the function, but it looks like it's only describing the next line.

The code does describe itself well enough without this comment.

The other comment above is not quite as obvious, but the early return is a pretty strong indicator of "we're done early here". Personally, I'd also remove it.

Comment on lines 711 to 712
elif (root_bdm.get('destination_type') == 'local' and
root_bdm.get('source_type') == 'image'):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd switch the order here. Source -> Destination.

Or even refactor out into a separate variable or function that describes what this combination of conditions actually means. I read in the docs that image -> local is special for booting directly from a Glance image(?), and this could be made more explicit here.

@grandchild
Copy link

Two other questions:

  1. Do I read the code correctly, in that the enforcing of the BFV is only enforced in the special case that the request asks for boot-from-glance? The docs read like there's a bunch of other options when doing block device mappings. Do we not use all the others? If we do, then boot_from_volume=true reads a bit more powerful than it actually is.
  2. How does this change relate to this spec? From what I can tell they're not quite the same, but what is the difference in terms of the problem-to-solve, or the solution?

@joker-at-work
Copy link

2. How does this change relate to this spec? From what I can tell they're not quite the same, but what is the difference in terms of the problem-to-solve, or the solution?

I skimmed through the spec and from the problem-to-solve it seems to be the same. The spec is just not as restrictive as we want to be. We want to *force` BFV while the spec wants to default to BFV but allow the user to override it.

@joker-at-work
Copy link

  1. Do I read the code correctly, in that the enforcing of the BFV is only enforced in the special case that the request asks for boot-from-glance? The docs read like there's a bunch of other options when doing block device mappings. Do we not use all the others? If we do, then boot_from_volume=true reads a bit more powerful than it actually is.

The point of this is prohibiting use of ephemeral storage, because we will not have any. Therefore, anything having the destination "local" needs to be prohibited. In the docs you link, I only see 2 options that don't have volume as destination. Those two need to be prohibited.

Comment on lines +12778 to +12792
read_deleted="yes"):
instance_type = orig_get_flavor_by_flavor_id(flavor_id,
ctxt,
read_deleted)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines don't look like they're indented correctly. Is this only github?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it is a Github issue. pep8 passes.

Comment on lines 710 to 711
elif (root_bdm.get('source_type') == 'image' and
root_bdm.get('destination_type') == 'local'):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Jakob pointed out, there could be a blank disk/swap disk added via blank -> local. We don't support ephemeral storage and thus also cannot support that case. Anything requesting destination_type == 'local' needs to be prohibited.

Comment on lines 773 to 774
self._enforce_boot_from_volume(image_meta, instance_type,
block_device_mapping)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the above-called block_device.from_legacy_mapping() already add the image-bdm?

nova/nova/block_device.py

Lines 355 to 356 in 5b05204

if not volume_backed and image_uuid:
image_bdm = create_image_bdm(image_uuid, boot_index=0)

The flavor would then be unusable ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. This worked well initially, when the image mapping was silently overwritten to a volume mapping.

But now since we throw an error, it will indeed make it unusable. I'll revisit this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please have another look. Thanks.

@mariusleu mariusleu force-pushed the bfv_flavors branch 2 times, most recently from 511b92c to 949dfee Compare April 23, 2021 09:29
Booting from volume can now be enforced via flavor.
A flavor must have extra property `boot_from_volume=true` to
enable this.
It works by enforcing a boot_index=0 block device mapping based on
the source image, like the user would have requested it.
If the user specifies a root volume explicitly, this enforcement
will be skipped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants