-
Notifications
You must be signed in to change notification settings - Fork 165
Conversation
7130124
to
5db2391
Compare
vm.create_on_provider(find_in_cfme=True, allow_skip="default") | ||
request.addfinalizer(vm.delete_from_provider) | ||
return vm | ||
return _test_vm |
There was a problem hiding this comment.
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)
5db2391
to
b8f9ba0
Compare
"""Tests snapshot crud | ||
|
||
Metadata: | ||
test_flag: snapshot, provision | ||
""" | ||
test_vm = small_test_vm |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice...
There was a problem hiding this comment.
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.
@@ -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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
REQUIRED
Please use format
b8f9ba0
to
787e7e1
Compare
There was a problem hiding this 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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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']) |
There was a problem hiding this comment.
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'])
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
) | ||
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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'] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
787e7e1
to
d5e7c3a
Compare
There was a problem hiding this 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
d5e7c3a
to
e5d319b
Compare
"""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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@psav My concerns have been addressed and latest PRT looks good, leaving to you to merge since you've got outstanding 'Requested changes' review. |
This modifies some core components used in snapshot testing. Features:
[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.