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

kubevirt_vm: Improve create VM from template #56833

Merged
merged 4 commits into from
May 30, 2019

Conversation

machacekondra
Copy link
Contributor

@machacekondra machacekondra commented May 23, 2019

SUMMARY
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME
ADDITIONAL INFORMATION

Cherry-pick of : #55927

@ansibot
Copy link
Contributor

ansibot commented May 23, 2019

@machacekondra: Greetings! Thanks for taking the time to open this pullrequest. In order for the community to handle your pullrequest effectively, we need a bit more information.

Here are the items we could not find in your description:

  • issue type

Please set the description of this pullrequest with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/PULL_REQUEST_TEMPLATE.md

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented May 23, 2019

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 backport This PR does not target the devel branch. cloud module This issue/PR relates to a module. needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. needs_triage Needs a first human triage before being processed. owner_pr This PR is made by the module's maintainer. support:community This issue/PR relates to code supported by the Ansible community. bug This issue/PR relates to a bug. community_review In order to be merged, this PR must follow the community review workflow. and removed needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. labels May 23, 2019
@pkliczewski
Copy link

@machacekondra Please provide some information what is improved in this PR

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label May 23, 2019
@mmazur
Copy link
Contributor

mmazur commented May 23, 2019

Backporting this to 2.8… do we have any tests that verify this works? Can we add some?

@machacekondra
Copy link
Contributor Author

Yeah, it's backport of #55927. No tests we have to add some, when we are on openshift.

@pkliczewski
Copy link

+1

@ansibot ansibot added shipit This PR is ready to be merged by Core and removed community_review In order to be merged, this PR must follow the community review workflow. labels May 23, 2019
@abadger
Copy link
Contributor

abadger commented May 24, 2019

Hi, this needs a changelog fragment in order to be merged.

@@ -126,21 +127,28 @@ def __init__(self, *args, **kwargs):
super(KubeVirtRawModule, self).__init__(*args, **kwargs)

@staticmethod
def merge_dicts(x, y):
def merge_dicts(x, yy):
Copy link
Contributor

Choose a reason for hiding this comment

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

A note: As long as we're renaming parameters... this whole function could do with better names for its parameters and variables. For instance, base_dict, and merging_dict might be candidates for x and yy.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, staticmethods are usually a sign that the method should be a toplevel function instead. In python, every file is its own namespace so you don't have to throw unrelated functions inside of classes like you do in other languages.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also note.... from the way you're using merge_dicts in your code, it's probably a lot clearer to implement this using dict.update() like this:

def merge_dicts(base_dict, merging_dicts):
    """This function merges a base dictionary with one or more other dictionaries.
    The base dictionary takes precedence when there is a key collision.
    merging_dicts can be a dict or a list or tuple of dicts.  In the latter case, the
    dictionaries at the front of the list have higher precedence over the ones at the end.
    """
    if not merging_dicts:
        merging_dicts = ({},)

    if not isinstance(merging_dicts, Sequence):
        merging_dicts = (merging_dicts,)

    new_dict = {}
    for d in reversed(merging_dicts):
        new_dict.update(d)

    new_dict.update(base_dict)

    return new_dict

Note about this change.. I think that your current code actually has the opposite precedence when using a list of dicts for the second argument. However, that seems like a really confusing API (In the parameters list, the leftmost dict has precedence but within the second parameter, the rightmost dict has precedence) so I did not replicate that here. You could replicate it if you absolutely need to keep backwards compatibility.

@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed owner_pr This PR is made by the module's maintainer. shipit This PR is ready to be merged by Core labels May 27, 2019
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed community_review In order to be merged, this PR must follow the community review workflow. labels May 30, 2019
@abadger
Copy link
Contributor

abadger commented May 30, 2019

This looks good now. Could you open a PR for devel with the changes that aren't there yet and let me know? Then I can merge that and then merge this backport.

@machacekondra
Copy link
Contributor Author

This looks good now. Could you open a PR for devel with the changes that aren't there yet and let me know? Then I can merge that and then merge this backport.

Thanks! Here it is: #57179

@abadger abadger merged commit 4591f36 into ansible:stable-2.8 May 30, 2019
@abadger
Copy link
Contributor

abadger commented May 30, 2019

Merged for the 2.8.1 release. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 backport This PR does not target the devel branch. bug This issue/PR relates to a bug. cloud core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants