Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

[1LP][RFR] modify snapshot testing #5126

Merged
merged 1 commit into from
Aug 23, 2017

Conversation

apagac
Copy link
Contributor

@apagac apagac commented Aug 9, 2017

This modifies some core components used in snapshot testing. Features:

  • testing VM gets always deployed with a different name [1]
  • able to choose a template for testing VM [2]
  • able to choose to create a snapshot with/without memory

[1] This is needed due to a known (?) issue with pytest scopes. Solves the intermittent error that sometimes appears when destroying and then again deploying a VM with the same name.

[2] Some of the snapshot tests need a testing VM that has network configured, sshd running and automation can connect to it. This is not possible when the VM is deployed from the smallest template. On the other hand, most of the snapshot tests do not need bigger template, so it makes no sense to run them all with default template. Thus, we can now choose what template to use in each test.

@apagac apagac changed the title [WIP] modify snapshot testing [WIPTEST] modify snapshot testing Aug 10, 2017
@dajoRH dajoRH added WIP-testing and removed WIP labels Aug 10, 2017
@apagac apagac changed the title [WIPTEST] modify snapshot testing [RFR] modify snapshot testing Aug 10, 2017
vm.create_on_provider(find_in_cfme=True, allow_skip="default")
request.addfinalizer(vm.delete_from_provider)
return vm
return _test_vm
Copy link
Contributor

Choose a reason for hiding this comment

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

REQUIRED
I would make two separate fixtures: small_test_vm and full_test_vm:

def provision_vm(request, name, provider, small_template=True):
    if small_template:
        vm = VM.factory(name, provider, template_name=provider.data['small_template'])
    else: 
        vm = VM.factory(name, provider, template_name=provider.data['full_template']['name'])
    if not provider.mgmt.does_vm_exist(name):
        vm.create_on_provider(find_in_cfme=True, allow_skip="default")
        request.addfinalizer(vm.delete_from_provider)
    return vm

@pytest.fixture(scope="module")
def small_test_vm(request, setup_provider_modscope, provider, vm_name):
    return provision_vm(request, vm_name(), provider)

@pytest.fixture(scope="module")
def full_test_vm(request, setup_provider_modscope, provider, vm_name):
    return provision_vm(request, vm_name(), provider, small_template=False)

@quarckster quarckster changed the title [RFR] modify snapshot testing [WIP] modify snapshot testing Aug 13, 2017
@dajoRH dajoRH added the WIP label Aug 13, 2017
"""Tests snapshot crud

Metadata:
test_flag: snapshot, provision
"""
test_vm = small_test_vm
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 can refactor if requested.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although I personally think this is a) faster and b) nicer, I did expect that I would have to refactor :) On it.

@apagac apagac changed the title [WIP] modify snapshot testing [WIPTEST] modify snapshot testing Aug 15, 2017
@dajoRH dajoRH added WIP-testing and removed WIP labels Aug 15, 2017
@apagac apagac changed the title [WIPTEST] modify snapshot testing [RFR] modify snapshot testing Aug 15, 2017
@@ -31,7 +31,9 @@

@pytest.fixture(scope="module")
def vm_name():
return "test_snpsht_" + fauxfactory.gen_alphanumeric()
def _vm_name():
return "test_snpsht_" + fauxfactory.gen_alphanumeric()
Copy link
Contributor

Choose a reason for hiding this comment

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

REQUIRED
Please use format

@quarckster quarckster changed the title [RFR] modify snapshot testing [1LP][RFR] modify snapshot testing Aug 17, 2017
Copy link
Contributor

@psav psav left a comment

Choose a reason for hiding this comment

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

Some changes

@@ -31,7 +31,9 @@

@pytest.fixture(scope="module")
def vm_name():
return "test_snpsht_" + fauxfactory.gen_alphanumeric()
Copy link
Contributor

Choose a reason for hiding this comment

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

REQUIRED: If I understand correctly, you just need to change the scope of the fixture to function to get a new vm name every time right?

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 do need to change the scope, yes. I did try, it didn't work. What you see here is just a workaround, the underlying problem is a bit different.

There's a PR with new snapshot test #5003 . The test is parametrized and it's using module-scoped test_vm. Either I'm not getting the scopes at all, or it doesn't work, because instead of creating one VM for the test with all it's parametrization, it creates a new VM each time the test is run with different parameter. This means that the VM gets created, the test is run once with one parameter, then the VM is destroyed and immediately created again, the test is run the second time, and so on. Because of this, there were issues with multiple VMs in CFME with the same name, some of which were orphaned, and the automation was choosing the already destroyed one.

This of course isn't enough trouble, while running this I was hitting and issue with virtualcenter.delete_vm() RedHatQE/wrapanapi#154 . Can't reproduce that locally, it does happen with PRT. Can't run PRT, because I need this PR to be merged first.

My solution is what you are looking at now. I turned my back on scopes, changed fixtures so that the VMs have always different name, problem went away.

Copy link
Member

@mshriver mshriver Aug 18, 2017

Choose a reason for hiding this comment

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

Please use the existing utils.generators.random_vm_name() for this

https://github.com/ManageIQ/integration_tests/blob/master/utils/generators.py#L6

There's no need for this to be a fixture, provision_vm should be the function scoped fixture that just uses this generator to specify a unique name.

vm = VM.factory(vm_name, provider, template_name=provider.data['full_template']['name'])
def provision_vm(provider, vm_name, request, small_template=True):
if small_template:
vm = VM.factory(vm_name, provider, template_name=provider.data['small_template'])
Copy link
Contributor

Choose a reason for hiding this comment

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

small_template doesn't follow the same format and have a name attribute? That seems poor. (not blaming you for this). Would be nice to fix this up so it looks like

template_source = 'small_template' if small_template else 'full_template':
vm = VM.factory(vm_name, provider, template_name=provider.data[template_source]['name'])

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 requires change in the structure of yaml file if I understand your request correctly. Probably affecting a lot of stuff. It is not my ambition to change lot of stuff in this PR, I just need to change bits of snapshot testing.

Copy link
Member

@mshriver mshriver Aug 18, 2017

Choose a reason for hiding this comment

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

@psav @apagac There is inconsistency in the template naming throughout providers in cfme_data.yaml, which has been recorded in an issue, and that I have an open card to address. I'll be adding a 'templates' section to each provider, with consistent structure for small_template, full_template arrays that define name and creds for each template.

At that time I'll be auditing tests to update their access of the templates in the yaml, and can collapse this to a consistent access path at that time.

#5071

)
return new_snapshot


@pytest.mark.uncollectif(lambda provider:
not provider.one_of(RHEVMProvider, VMwareProvider) or
(provider.one_of(RHEVMProvider) and provider.version < 4))
def test_snapshot_crud(test_vm, provider):
def test_snapshot_crud(small_test_vm, provider):
Copy link
Contributor

Choose a reason for hiding this comment

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

This obviously won't get a new vm name each time, I assume this is OK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, this works just fine.

"""Tests snapshot crud

Metadata:
test_flag: snapshot, provision
"""
test_vm = small_test_vm
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice...

'username': credentials[provider.data['full_template']['creds']]['username'],
'password': credentials[provider.data['full_template']['creds']]['password']
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for the reorder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

None whatsoever. I thought dictionaries are unordered.

@psav psav changed the title [1LP][RFR] modify snapshot testing [1LP][WIP] modify snapshot testing Aug 17, 2017
@dajoRH dajoRH added the WIP label Aug 17, 2017
@apagac apagac changed the title [1LP][WIP] modify snapshot testing [1LP][WIPTEST] modify snapshot testing Aug 17, 2017
@dajoRH dajoRH removed the WIP label Aug 17, 2017
@apagac apagac changed the title [1LP][WIPTEST] modify snapshot testing [1LP][RFR] modify snapshot testing Aug 18, 2017
Copy link
Contributor

@psav psav left a comment

Choose a reason for hiding this comment

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

@mshriver has some replies to comments that need addressing

@psav psav changed the title [1LP][RFR] modify snapshot testing [1LP][WIP] modify snapshot testing Aug 22, 2017
@jkrocil jkrocil assigned jkrocil and unassigned jkrocil Aug 22, 2017
@dajoRH dajoRH added the WIP label Aug 22, 2017
@apagac apagac changed the title [1LP][WIP] modify snapshot testing [1LP][WIPTEST] modify snapshot testing Aug 22, 2017
@dajoRH dajoRH added WIP-testing and removed WIP labels Aug 22, 2017
"""Fixture to provision appliance to the provider being tested if necessary"""
vm = VM.factory(vm_name, provider, template_name=provider.data['full_template']['name'])
def provision_vm(provider, request, small_template=True):
vm_name = random_vm_name(context="snapshot")
Copy link
Member

Choose a reason for hiding this comment

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

👍

@apagac apagac changed the title [1LP][WIPTEST] modify snapshot testing [1LP][RFR] modify snapshot testing Aug 22, 2017
@mshriver
Copy link
Member

@psav My concerns have been addressed and latest PRT looks good, leaving to you to merge since you've got outstanding 'Requested changes' review.

@mshriver mshriver merged commit 8829f87 into ManageIQ:master Aug 23, 2017
@apagac apagac deleted the modify_snapshot_testing branch September 13, 2017 13:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants