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

opennebula inventory: add VM id and VM host to data #8532

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

aioue
Copy link
Contributor

@aioue aioue commented Jun 17, 2024

SUMMARY
To enable greater use of the inventory, add the ID of the VM, and the hostname of the host the VM is running on to the inventory output
ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME
opennebula.py
ADDITIONAL INFORMATION
                "host": "foo23.host",
                "id": 1234,

##### SUMMARY
<!--- Describe the change below, including rationale and design decisions --> To enable greater use of the inventory, add the ID of the VM, and the hostname of the host the VM is running on to the inventory output

<!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->

<!--- Please do not forget to include a changelog fragment:
      https://docs.ansible.com/ansible/devel/community/collection_development_process.html#creating-changelog-fragments
      No need to include one for docs-only or test-only PR, and for new plugin/module PRs.
      Read about more details in CONTRIBUTING.md.
      -->

##### ISSUE TYPE
<!--- Pick one or more below and delete the rest.
      'Test Pull Request' is for PRs that add/extend tests without code changes. -->
- Feature Pull Request

##### COMPONENT NAME
<!--- Write the SHORT NAME of the module, plugin, task or feature below. --> opennebula.py

##### ADDITIONAL INFORMATION
<!--- Include additional information to help people understand the change here --> <!--- A step-by-step reproduction of the problem is helpful if there is no related issue -->

<!--- Paste verbatim command output below, e.g. before and after your change -->
```paste below
                "host": "foo23.host",
                "id": 1234,
```
@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added cloud feature This issue/PR relates to a feature request inventory inventory plugin needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR plugins plugin (any type) labels Jun 17, 2024
@ansibullbot ansibullbot removed the needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI label Jun 17, 2024
@aioue
Copy link
Contributor Author

aioue commented Jun 17, 2024

Not sure why the tests are failing as I'm not adding a new import for the pyone library...?

@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-9 Automatically create a backport for the stable-9 branch labels Jun 17, 2024
@feldsam
Copy link
Contributor

feldsam commented Jun 20, 2024

Hi, problem is, that you added new method which is calling pyone package. To pass test, you need to also update tests to reflect this.

Anyway, for such infromation - host on which is VM running, there is easier method to get this. It is already in VM object, in history records, you just need to get last history record of VM to get host. So no need to do aditional api call and searching for host.

@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Jun 28, 2024
@ansibullbot ansibullbot removed the stale_ci CI is older than 7 days, rerun before merging label Jul 2, 2024
@aioue
Copy link
Contributor Author

aioue commented Jul 2, 2024

@feldsam updated PR to reflect the new information you provided. It's a very simple PR now!

I'm afraid I don't understand how to fix the tests.

@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Jul 12, 2024
@ansibullbot ansibullbot removed the stale_ci CI is older than 7 days, rerun before merging label Jul 17, 2024
@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Jul 26, 2024
@ansibullbot ansibullbot added tests tests unit tests/unit and removed stale_ci CI is older than 7 days, rerun before merging labels Aug 21, 2024
@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Aug 21, 2024
@ansibullbot ansibullbot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Aug 21, 2024
@ansibullbot ansibullbot removed the needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI label Aug 21, 2024
@ansibullbot ansibullbot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Aug 21, 2024
@ansibullbot ansibullbot removed the needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI label Aug 21, 2024
@ansibullbot ansibullbot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Aug 21, 2024
'HISTORY_RECORDS': [
{
'HISTORY': OrderedDict({
'OID': '42',
Copy link
Collaborator

Choose a reason for hiding this comment

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

This data structure looks very different from what the code is actually using. Here HISTORY_RECORDS is a list of dictionaries with a key HISTORY in them, and that in turn gives a dictionary with a key HOSTNAME in it.

The code expects HISTORY_RECORDS to be an object with an attribute HISTORY, which is a list, and contains objects that have an attribute called HOSTNAME.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm afraid I'm completely lost, this is way beyond my ability. Hoping the original author @feldsam can help.

@aioue aioue requested a review from feldsam August 27, 2024 13:26
@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Aug 27, 2024
Comment on lines +61 to +75
'HISTORY_RECORDS': [
{
'HISTORY': OrderedDict({
'OID': '42',
'SEQ': '384',
'HOSTNAME': 'sam-691-sam',
'HID': '10',
'CID': '0',
'DS_ID': '100',
'VM_MAD': 'kvm',
'TM_MAD': '3par',
'ACTION': '0'
}),
}
],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe something like:

Suggested change
'HISTORY_RECORDS': [
{
'HISTORY': OrderedDict({
'OID': '42',
'SEQ': '384',
'HOSTNAME': 'sam-691-sam',
'HID': '10',
'CID': '0',
'DS_ID': '100',
'VM_MAD': 'kvm',
'TM_MAD': '3par',
'ACTION': '0'
}),
}
],
'HISTORY_RECORDS': {
'HISTORY' : [
{
'OID': '42',
'SEQ': '384',
'HOSTNAME': 'sam-691-sam',
'HID': '10',
'CID': '0',
'DS_ID': '100',
'VM_MAD': 'kvm',
'TM_MAD': '3par',
'ACTION': '0',
},
],
},

By the way, this construct OrderedDict({ ... }) that appears throughout this test code is likely redundant, they could all be replaced with the dict content {...}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @russoz. Since my opennebula.py inventory change does work when run against OpenNebula servers, I am reasonably sure that changing HISTORY_RECORDS back to a {} rather than a [] will break the test, which means it doesn't reflect the actual data structure that ON returns.

If the code is working and the tests are currently passing, is this PR 'good enough' now?

I'm quite burnt out on it and don't want to make myself dislike adding features as I'll be using Open Nebula for the next year plus!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks @russoz. Since my opennebula.py inventory change does work when run against OpenNebula servers, I am reasonably sure that changing HISTORY_RECORDS back to a {} rather than a [] will break the test, which means it doesn't reflect the actual data structure that ON returns.

If the code is working and the tests are currently passing, is this PR 'good enough' now?

Well, the concern is that the piece of code that seems to parse that data goes like this:

            if hasattr(vm.HISTORY_RECORDS, 'HISTORY'):
                if isinstance(vm.HISTORY_RECORDS.HISTORY, Sequence) and len(vm.HISTORY_RECORDS.HISTORY) > 0:
                    if hasattr(vm.HISTORY_RECORDS.HISTORY[-1], 'HOSTNAME'):
                        server['host'] = vm.HISTORY_RECORDS.HISTORY[-1].HOSTNAME

That seems to indicate that HISTORY_RECORDS has an attribute HISTORY, which in its turn is a Sequence (with at least one element), from which you select the last element, and the attribute HOSTNAME out of it. That looks not coherent with the statement that HISTORY_RECORDS is a list. Could you please explain why that difference?

People other than you (me, Felix, @feldsam and future maintainers of the collection) will need to provide support to this code for potentially a long time and we cannot explain it. Either we are missing some piece of the puzzle, or the test might doing the wrong thing.

So, answering your question, to be 'good enough' we need to understand what's happening. Hope you don't take this badly, but the long-term health of the code is more important than short-term results.

I'm quite burnt out on it and don't want to make myself dislike adding features as I'll be using Open Nebula for the next year plus!

Sorry to hear that, hope you can find some time to decompress. There is no pressure from our side to solve this quickly, so take your time.

All the best.

Copy link
Collaborator

@felixfontein felixfontein Sep 5, 2024

Choose a reason for hiding this comment

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

Something like that should produce the data structure that the inventory plugin actually expects:

class HistoryEntry(object):
    def __init__(self):
        self.SEQ = '384'
        self.HOSTNAME = 'sam-691-sam'
        self.HID = '10'
        self.CID = '0'
        self.DS_ID = '100'
        self.VM_MAD = 'kvm'
        self.TM_MAD = '3par'
        self.ACTION = '0'

class HistoryRecords(object):
    def __init__(self):
        self.HISTORY = [HistoryEntry()]

def get_vm_pool():
    ...
        'HISTORY_RECORDS': HistoryRecords(),
    ...

@russoz russoz changed the title Add VM id and VM host to opennebula inventory data opennebula inventory: add VM id and VM host to data Aug 31, 2024
@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-9 Automatically create a backport for the stable-9 branch check-before-release PR will be looked at again shortly before release and merged if possible. cloud feature This issue/PR relates to a feature request inventory inventory plugin plugins plugin (any type) stale_ci CI is older than 7 days, rerun before merging tests tests unit tests/unit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants