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

Generate GX conformant credentials for VM Images #75

Merged

Conversation

anjastrunk
Copy link
Contributor

@anjastrunk anjastrunk commented Feb 29, 2024

Duplicate #69 to sign commits.

closes #67, #66

Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
@anjastrunk anjastrunk self-assigned this Feb 29, 2024
@anjastrunk anjastrunk added the SCS-VP10 Related to tender lot SCS-VP10 label Feb 29, 2024
Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
Copy link
Member

@martinmo martinmo left a comment

Choose a reason for hiding this comment

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

I reviewed your PR and left some suggestions inline. However, I did not yet try the tool with an OpenStack cloud and plan to do this later.

As a general remark: there are a lot of commented out code lines which I think should be removed. You can always restore old code from the Git history, if necessary.

Some of the new dependencies in requirements.txt are not up-to-date anymore.

.github/workflows/python-app.yml Outdated Show resolved Hide resolved
.github/workflows/python-app.yml Outdated Show resolved Hide resolved
config/config.yaml Outdated Show resolved Hide resolved
requirements.txt Show resolved Hide resolved
tests/common.py Outdated Show resolved Hide resolved
.github/workflows/python-app.yml Outdated Show resolved Hide resolved
README_old.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@martinmo
Copy link
Member

martinmo commented Mar 6, 2024

One more remark: I noticed that the original issues #66 and #67 contain a lot of useful information which could be part of the docs (e.g., design/implementation decisions and information about the mapping from SCS to GX). They were helpful for me to understand the context of this PR and in my opinion it would be a pity if they are hidden in the (soon to be closed) GitHub issues.

anjastrunk and others added 6 commits March 14, 2024 14:20
Co-authored-by: Martin Morgenstern <martinmo@users.noreply.github.com>
Signed-off-by: anjastrunk <119566837+anjastrunk@users.noreply.github.com>
Co-authored-by: Martin Morgenstern <martinmo@users.noreply.github.com>
Signed-off-by: anjastrunk <119566837+anjastrunk@users.noreply.github.com>
Co-authored-by: Martin Morgenstern <martinmo@users.noreply.github.com>
Signed-off-by: anjastrunk <119566837+anjastrunk@users.noreply.github.com>
Co-authored-by: Martin Morgenstern <martinmo@users.noreply.github.com>
Signed-off-by: anjastrunk <119566837+anjastrunk@users.noreply.github.com>
Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
@anjastrunk
Copy link
Contributor Author

One more remark: I noticed that the original issues #66 and #67 contain a lot of useful information which could be part of the docs (e.g., design/implementation decisions and information about the mapping from SCS to GX). They were helpful for me to understand the context of this PR and in my opinion it would be a pity if they are hidden in the (soon to be closed) GitHub issues.

You are right. I will link both issues in documentation later on.

@anjastrunk anjastrunk requested a review from martinmo March 14, 2024 13:36
@anjastrunk
Copy link
Contributor Author

@martinmo Please review my changes and approve PR.

Copy link
Contributor

@mbuechse mbuechse left a comment

Choose a reason for hiding this comment

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

This is some impressive reorganization.
I have mostly minor remarks, but it would be good to address them nonetheless.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
tests/common.py Show resolved Hide resolved
tests/gaia-x.shacl.ttl Outdated Show resolved Hide resolved
tests/test_vm_image_discovery.py Outdated Show resolved Hide resolved
tests/test_vm_image_discovery.py Show resolved Hide resolved
tests/test_vm_image_discovery.py Outdated Show resolved Hide resolved
Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
@martinmo
Copy link
Member

@anjastrunk was the merge of the other PR #67 into this PR intentional (fe1b9a7)?

@anjastrunk
Copy link
Contributor Author

@anjastrunk was the merge of the other PR #67 into this PR intentional (fe1b9a7)?

No, it was not.

@anjastrunk anjastrunk force-pushed the 67-make-generation-of-vm-image-credentuial-gaia-x-compliant_new branch from fe1b9a7 to af60bf1 Compare March 18, 2024 14:22
Copy link
Member

@martinmo martinmo left a comment

Choose a reason for hiding this comment

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

I reviewed again and only found some minor things 👍

Some of the earlier suggestions have been marked as resolved but the suggestions have not been applied (these are separate steps in the GitHub UI).

In the "Docker" section of the README.md there are some examples which I don't agree with, but the section has not been changed with this PR, so I'll create a separate issue for that.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
cli.py Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
@anjastrunk
Copy link
Contributor Author

@mbuechse @martinmo I improved code quality according to your feedback. Please review again.

@anjastrunk anjastrunk requested review from martinmo and mbuechse March 20, 2024 14:15
Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
Copy link
Contributor

@mbuechse mbuechse left a comment

Choose a reason for hiding this comment

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

Minor things. Most notable: I don't know how the EnumDefinitionImpl constructor works -- does it accept objects of the enum class in question, or does it only accept str? In the latter case, in a few instances .text should be added.

In some instances, I was wondering whether a value could be None or the empty string etc. It would be good to convey this information to the reader by making the code as explicit as possible; see my individual remarks.

generator/discovery/openstack/vm_images_discovery.py Outdated Show resolved Hide resolved
generator/discovery/openstack/vm_images_discovery.py Outdated Show resolved Hide resolved
generator/discovery/openstack/vm_images_discovery.py Outdated Show resolved Hide resolved
Comment on lines 174 to 179
if os_image.disk_format:
return VMDiskType(
DISK_LOOKUP.get(os_image.disk_format.lower(), VMDiskType.RAW.text)
)
else:
return VMDiskType("RAW")
Copy link
Contributor

Choose a reason for hiding this comment

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

even better (again, provided that disk_format can be None)

Suggested change
if os_image.disk_format:
return VMDiskType(
DISK_LOOKUP.get(os_image.disk_format.lower(), VMDiskType.RAW.text)
)
else:
return VMDiskType("RAW")
if os_image.disk_format is None:
return VMDiskType(VMDiskType.RAW.text)
return VMDiskType(
DISK_LOOKUP.get(os_image.disk_format.lower(), VMDiskType.RAW.text)
)

generator/discovery/openstack/vm_images_discovery.py Outdated Show resolved Hide resolved
generator/discovery/openstack/vm_images_discovery.py Outdated Show resolved Hide resolved
Comment on lines 707 to 708
if os_image.properties and "patchlevel" in os_image.properties:
return os_image.properties["patchlevel"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if os_image.properties and "patchlevel" in os_image.properties:
return os_image.properties["patchlevel"]
return os_image.properties and os_image.properties.get("patchlevel", False)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good hint, thanks.

Comment on lines 712 to 713
if os_image.properties and "internal_version" in os_image.properties:
return os_image.properties["internal_version"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if os_image.properties and "internal_version" in os_image.properties:
return os_image.properties["internal_version"]
return os_image.properties and os_image.properties.get("internal_version", False)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good hint, thanks.

def _get_hypervisor_type(os_image: OS_Image) -> HypervisorType:
if os_image.hypervisor_type:
return HypervisorType(
HYPER_LOOKUP.get(os_image.hypervisor_type.lower(), HypervisorType.other)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need HypervisorType.other.text here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

HypervisorType.other.text and HypervisorType.other are similar in this context.

@mbuechse
Copy link
Contributor

@anjastrunk And one addendum to my review: it seems that your formatter (black?) is set to some very narrow line width, maybe 80 characters. That is hard to read. Maybe you can set it to 110 characters or so.

Copy link
Member

@martinmo martinmo left a comment

Choose a reason for hiding this comment

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

As @mbuechse has suspected, every place where the constructor of an EnumDefinitionImpl subclass is used is currently broken.

For instance, VMDiskType("RAW") should be replaced with VMDiskType.RAW and so on. If this is not possible because the string is not known until runtime, you can use getattr(…): getattr(VMDiskType, type_str, VMDiskType.RAW).

anjastrunk and others added 3 commits March 20, 2024 21:11
Co-authored-by: Matthias Büchse <github@mbue.de>
Signed-off-by: anjastrunk <119566837+anjastrunk@users.noreply.github.com>
Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
…iant_new' of github.com:SovereignCloudStack/gx-self-description-generator into 67-make-generation-of-vm-image-credentuial-gaia-x-compliant_new
@anjastrunk
Copy link
Contributor Author

anjastrunk commented Mar 20, 2024

As @mbuechse has suspected, every place where the constructor of an EnumDefinitionImpl subclass is used is currently broken.

For instance, VMDiskType("RAW") should be replaced with VMDiskType.RAW and so on. If this is not possible because the string is not known until runtime, you can use getattr(…): getattr(VMDiskType, type_str, VMDiskType.RAW).

This is not correct. Constructor of every EnumDefinitionImpl is used in a right way. I used it several times throughout my tests.

@martinmo Your assumption is wrong: VMDiskType("RAW"), VMDiskType(VMDiskType.RAW) as well as VMDiskType(VMDiskType.RAW.text) construct an object of class VMDiskType, which is a subclass of EnumDefinitionImpl. EnumDefinitionImpl does not have an attribute called text. Only PermissibleValue has text as an attribute. If you want to get text of VMDiskType, you have to call VMDiskType.code.text

classDiagram
EnumDefinitionImpl <|-- VMDiskType
EnumDefinitionImpl --> PermissibleValue:code

class PermissibleValue{
    text: str
}
Loading

Calling VMDiskType.RAW, creates an object of class PermissibleValue, which is not requested, as an instance of class VMDiskType is required.

>>> from generator.common.gx_schema import VMDiskType
>>> type(VMDiskType('RAW')).__name__
'VMDiskType'
>>> type(VMDiskType(VMDiskType.RAW)).__name__
'VMDiskType'
>>> type(VMDiskType(VMDiskType.RAW.text)).__name__
'VMDiskType'
>>> type(VMDiskType.RAW).__name__
'PermissibleValue'
>>> VMDiskType('RAW').code.text
'RAW'
>>> 

anjastrunk and others added 4 commits March 20, 2024 22:05
Co-authored-by: Matthias Büchse <github@mbue.de>
Signed-off-by: anjastrunk <119566837+anjastrunk@users.noreply.github.com>
Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
…iant_new' of github.com:SovereignCloudStack/gx-self-description-generator into 67-make-generation-of-vm-image-credentuial-gaia-x-compliant_new
Co-authored-by: Matthias Büchse <github@mbue.de>
Signed-off-by: anjastrunk <119566837+anjastrunk@users.noreply.github.com>
@martinmo
Copy link
Member

@martinmo Your assumption is wrong: VMDiskType("RAW"), VMDiskType(VMDiskType.RAW) as well as VMDiskType(VMDiskType.RAW.text) construct an object of class VMDiskType, which is a subclass of EnumDefinitionImpl. EnumDefinitionImpl does not have an attribute called text. Only PermissibleValue has text as an attribute. If you want to get text of VMDiskType, you have to call VMDiskType.code.text

You're right, thanks for the clarification, @anjastrunk! I am sorry and take back my comment.

For me it was confusing that the enum member is not of the enum type (like it is with Python stdlib enums) and that VMDiskType("RAW") has a misleading repr of (text='RAW'), which made me think it has a text attribute. E.g.,

>>> from generator.common.gx_schema import VMDiskType
>>> VMDiskType("RAW")
(text='RAW')

but

>>> VMDiskType("RAW").text
AttributeError: 'VMDiskType' object has no attribute 'text'

@mbuechse
Copy link
Contributor

Confusing indeed.

Copy link
Member

@martinmo martinmo left a comment

Choose a reason for hiding this comment

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

LGTM, but can you please check the mandatory attributes section README.md again. There is still a typo in the attributes, somehow the suggestion was again not applied:

  • copyrigthowner (t and h switched and missing space), should be copyright owner as in the YAML.
  • resourcePolicy (P should be lower case and missing space), should be resource policy as in the YAML.

(Or maybe my understanding here is wrong: I think the section talks about the keys in the YAML file.)

Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
@anjastrunk
Copy link
Contributor Author

@martinmo @martinmo Thanks for our tremendous feedback and very carefully review. It helped my a lot to improve code quality and documentation.

@anjastrunk
Copy link
Contributor Author

LGTM, but can you please check the mandatory attributes section README.md again. There is still a typo in the attributes, somehow the suggestion was again not applied:

* `copyrigthowner` (t and h switched and missing space), should be `copyright owner` as in the YAML.

* `resourcePolicy` (P should be lower case and missing space), should be `resource policy` as in the YAML.

(Or maybe my understanding here is wrong: I think the section talks about the keys in the YAML file.)

Indeed. I changed it.

anjastrunk and others added 5 commits March 22, 2024 14:29
Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
…iant_new' of github.com:SovereignCloudStack/gx-self-description-generator into 67-make-generation-of-vm-image-credentuial-gaia-x-compliant_new
Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
@anjastrunk anjastrunk merged commit 81752d6 into main Mar 22, 2024
2 checks passed
@anjastrunk anjastrunk deleted the 67-make-generation-of-vm-image-credentuial-gaia-x-compliant_new branch March 22, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SCS-VP10 Related to tender lot SCS-VP10
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Generate GX conformant credentials for VM Images
3 participants