Skip to content

Conversation

@cbosdo
Copy link
Contributor

@cbosdo cbosdo commented Mar 9, 2018

What does this PR do?

Libvirt API offers clients to register callbacks for various events.
libvirt_events engine will listen on a libvirt URI (local or remote)
for events and send them to the salt event bus.

What issues does this PR fix or reference?

Nothing that is in the issue tracker to my knowledge

Tests written?

No: those would require a running libvirt daemon
Yes

Commits signed with GPG?

Yes

@cbosdo
Copy link
Contributor Author

cbosdo commented Mar 12, 2018

I can't change the callback signature: codeclimate would need to be silenced for those functions that have more than 4 arguments.

I don't really know what to do with the docstrings of the callbacks: either pylint is complaining not having them or code climate complains because their are too similar. Honestly, considering how useless those would be, I'ld just let pylint complain.

Codeclimate complains that the file is too long... but is it possible at all to have the code of an engine split into several files? Ideally I would separate the callbacks from the rest of the engine, not sure if that is possible / wanted.

Copy link
Contributor

@isbm isbm left a comment

Choose a reason for hiding this comment

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

Can we also rename callbacks from dom_<something> to domain_...? Because this is confusing with DOM (document object model). The callbacks can be also "hidden", i.e. starts from the underscore: def _something.

('pmsuspended', ("memory",
"disk")),
('crashed', ("panicked"))
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would refactor all this into a dictionary. The def nth is not needed anywhere, because the dictionary has .get(...) function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found a way to get rid of these lists by introspecting libvirt module.

@isbm
Copy link
Contributor

isbm commented Mar 12, 2018

@cbosdo Unit tests do not need to have libvirt installed, only integration tests. So you can just mock.MagicMock all the output from the libvirt part and unit-test everything, since we do not really need to test the libvirt itself.

@cbosdo cbosdo force-pushed the develop branch 2 times, most recently from 7c1524c to 1b0daf9 Compare March 13, 2018 12:30
Copy link
Contributor

Choose a reason for hiding this comment

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

@cbosdo
Copy link
Contributor Author

cbosdo commented Mar 14, 2018

unit tests added now

@cbosdo cbosdo force-pushed the develop branch 2 times, most recently from ba50b0e to 7ea9446 Compare March 14, 2018 15:59
@rallytime
Copy link
Contributor

Thanks @cbosdo! There's some lint failures here: https://jenkins.saltstack.com/job/PR/job/salt-pr-lint-n/20144/violations/

@cbosdo
Copy link
Contributor Author

cbosdo commented Mar 15, 2018

Fixed the pylint errors now

Copy link
Contributor

@rallytime rallytime left a comment

Choose a reason for hiding this comment

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

@cbosdo I have a couple of comments here that need to be addressed. Thank you so much for writing the tests, too!

Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is picky, but can you make this encoding line the standard version?

# -*- coding: utf-8 -*-

Copy link
Contributor

Choose a reason for hiding this comment

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

resend --> resends

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add a version directive to this?

.. versionadded:: Fluorine

Copy link
Contributor

Choose a reason for hiding this comment

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

This type of msg handling and version checking should be done in the __virtual__() function.

Copy link
Contributor

Choose a reason for hiding this comment

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

@cbosdo actually @rallytime is right. So just move checks to the __virtual__ itself:

try:
    import libvirt
except ImportError:
    libvirt = None

def __virtual__():
    '''
    Only load if libvirt python binding is present
    '''
    if libvirt is None:
        msg = 'libvirt module not found'
    elif libvirt.getVersion() < 1000000:
        msg = 'libvirt >= 1.0.0 required'
    else:
        msg = ''

    return bool(libvirt), msg

OK, basically copypaste this. 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes pylint complain on the if libvirt is None: line:
[used-before-assignment] Using variable 'libvirt' before assignment

And on the libvirt = None line that you didn't move:
[redefined-outer-name] Redefining name 'libvirt' from outer scope

Copy link
Contributor

Choose a reason for hiding this comment

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

If checks has to be in __virtual__, then just mute Lint in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you document all of the arguments here? And provide an example of how they should be used?

Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here about docs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than commenting in many places repeatedly, I'll just say this here: Any public facing function needs docs for all args/kwargs and some examples of usage. If you could update all of those below, that would be great.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All these helper functions aren't intended to be used by external code, I'ld rather hide them, but adding those comments can't harm

Copy link
Contributor

Choose a reason for hiding this comment

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

@cbosdo even hidden usually should at least document what it does. But yes, I would underscore them in front, since they are all internal.

@cbosdo cbosdo force-pushed the develop branch 7 times, most recently from fb4ec0b to 53cb886 Compare March 22, 2018 08:11
@cbosdo
Copy link
Contributor Author

cbosdo commented Mar 28, 2018

any update on that PR?

@rallytime
Copy link
Contributor

Libvirt API offers clients to register callbacks for various events.
libvirt_events engine will listen on a libvirt URI (local or remote)
for events and send them to the salt event bus.

Special thanks to @isbm for the code cleanup help
@cbosdo
Copy link
Contributor Author

cbosdo commented Mar 28, 2018

@rallytime right! fixed all the pylint errors now.

@rallytime
Copy link
Contributor

@cbosdo Awesome! Thanks! We're working on getting some testing issues resolved here, so we'll restart them when that's resolved.

In the mean time, @garethgreenaway can you swing by here and review this when you get a moment?

@garethgreenaway
Copy link
Contributor

Looks good!

@cbosdo
Copy link
Contributor Author

cbosdo commented Mar 28, 2018

hum... looks like the branch would need a rebase before merging... should I do it now that it has been approved or you can still do it at merge time?

@cbosdo
Copy link
Contributor Author

cbosdo commented Apr 3, 2018

@rallytime is it me or the changes you requested (which have been implemented by the time) are blocking this PR?

@rallytime
Copy link
Contributor

re-run py2

@rallytime
Copy link
Contributor

@cbosdo Apologies for the delay. Some of the test results timed out so I am re-running some. Once those come back we can get this in. Thanks for the bump!

@rallytime rallytime merged commit 9ab8c26 into saltstack:develop Apr 5, 2018
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