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

[1LP][WIPTEST]Added invalid cidr/ip tests for floating_ip_add and subnet_add #10033

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mmojzis
Copy link
Contributor

@mmojzis mmojzis commented Apr 1, 2020

Also added needed views and create function.

@mmojzis mmojzis changed the title Added invalid cidr/ip tests for floating_ip_add and subnet_add [WIPTEST]Added invalid cidr/ip tests for floating_ip_add and subnet_add Apr 1, 2020
@mmojzis mmojzis changed the title [WIPTEST]Added invalid cidr/ip tests for floating_ip_add and subnet_add [RFR]Added invalid cidr/ip tests for floating_ip_add and subnet_add Apr 2, 2020
@dajoRH dajoRH removed the WIP-testing label Apr 2, 2020
@pytest.fixture()
def network_manager(appliance, provider):
network_managers = appliance.collections.network_providers.filter({"provider": provider})
yield network_managers.all()[0]
Copy link
Contributor

@jarovo jarovo Apr 2, 2020

Choose a reason for hiding this comment

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

This is bit suspicious to me. How is it ensured the first returned network_manager is the one the test wants? Is it because you assume all other providers will get removed and only the OpenStack will be ensured to be present?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, how can openstack provider have multiple network managers? Never seen this option in CFME.
Also we are using the same fixture for storage managers and it works well. : https://github.com/ManageIQ/integration_tests/blob/master/cfme/tests/storage/test_manager.py#L31



@pytest.fixture()
def network_manager(appliance, provider):
Copy link
Contributor

@jarovo jarovo Apr 2, 2020

Choose a reason for hiding this comment

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

This method does the same as the one in the other file, so I am frowning on picking the first network_manager here as well.

But I think also having this a fixture doesn't provide enough (any) benefits yet it just creates some potential problems in future because it is a code dup. It is fixture for effectively a one-liner. I am sure one-liners dups are not considered a problem most of the times.

I will ask other reviewers what they think about fixtures like this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, in the future when they add another providers with network managers the fixture makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

@JaryN valid concern for sure.

I wouldn't consider this a blocker to merging this PR, but warrants some future enhancement.

This could be a globally available fixture (cfme/fixtures/), or even a subcollection of the parent cloud provider.

view = subnets_collection.create_view(SubnetView)
view.flash.assert_message(
"Unable to create Cloud Subnet: Invalid input for cidr. Reason: '{}' is not a valid IP "
"subnet.".format(invalid_cidr))
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting that Travis didn't complain/converted this to f-string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is f-string?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is f-string.

my_identifier = "baz"
f"foo {my_identifier} bar"
``

view = subnets_collection.create_view(SubnetView)
view.flash.assert_message(
"Unable to create Cloud Subnet: Invalid input for cidr. Reason: '{}' is not a valid IP "
"subnet.".format(invalid_cidr))
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting that Travis didn't complain/converted this to f-string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed fstring.


@pytest.fixture()
def network_manager(appliance, provider):
network_managers = appliance.collections.network_providers.filter({"provider": provider})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
network_managers = appliance.collections.network_providers.filter({"provider": provider})
network_manager, = appliance.collections.network_providers.filter({"provider": provider}).all()
yield network_manager

This way, when there are more than one network_provider, we will get an error. This is a good thing as it will notify us that something is not as we did expect.

In [6]: a, = (b for b in range(1))                                                            

In [7]: a                                                                                     
Out[7]: 0

In [8]: a, = (b for b in range(2))                                                            
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-c3f22dcf86ee> in <module>
----> 1 a, = (b for b in range(2))

ValueError: too many values to unpack (expected 1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I don't understand the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

The code is using Pythons value unpacking to make sure the value we get is only one in the iterable.

You can do this with tuples:

a, b, c = 1, 2, 3

which assigns a with 1 and b with 2, c with 3

Of course ths works with single-item tuples:

a, = [1]

this assings a with 1. But it has the advantage of failing when more items are being unpacked:

a, = 1,2

will fail with ValueError: too many values to unpack (expected 1)

This works for any iterable, including generators. So when you are tempting to do
my_variable = some_iterable[0]
and you assume only single item is available in some_variable, it is good to do
my_variable, = some_iterable
instead, because it will fail when the assumption is not met.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, got it. Thanks. Changed as you proposed.

@dajoRH dajoRH changed the title [RFR]Added invalid cidr/ip tests for floating_ip_add and subnet_add [WIP]Added invalid cidr/ip tests for floating_ip_add and subnet_add Apr 7, 2020
@dajoRH dajoRH added lint-ok and removed needs-lint labels Apr 7, 2020
@mmojzis mmojzis changed the title [WIP]Added invalid cidr/ip tests for floating_ip_add and subnet_add [RFR]Added invalid cidr/ip tests for floating_ip_add and subnet_add Apr 7, 2020
@dajoRH dajoRH removed the WIP label Apr 7, 2020
@john-dupuy
Copy link
Contributor

@JaryN are you okay to move this one to 1LP?

Copy link
Contributor

@jarovo jarovo left a comment

Choose a reason for hiding this comment

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

Sorry for the delay.

@jarovo jarovo changed the title [RFR]Added invalid cidr/ip tests for floating_ip_add and subnet_add [1LP][RFR]Added invalid cidr/ip tests for floating_ip_add and subnet_add Apr 23, 2020
@jawatts jawatts self-assigned this Apr 24, 2020
'fixed_ip_address': fixed_ip_address,
'cloud_tenant': tenant})
view.add.click()
view.flash.assert_success_message(f'Floating IP "{floating_ip_address}" created')
Copy link
Contributor

Choose a reason for hiding this comment

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

We want to assert_no error() here instead and have the actual flash message asserted in a test.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed @jawatts, @mmojzis can you cover this flash assertion with a positive CRUD test case? Looks like only negative test cases are included in this PR.

Copy link
Contributor

@jawatts jawatts left a comment

Choose a reason for hiding this comment

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

One small comments but otherwise looks good!


@pytest.fixture()
def network_manager(appliance, provider):
network_manager, = appliance.collections.network_providers.filter({"provider": provider}).all()
Copy link
Member

Choose a reason for hiding this comment

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

Can you wrap this potential ValueError in a pytest.skip call, so it doesn't start throwing errors when there's more/less than 1 element in the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@mshriver mshriver left a comment

Choose a reason for hiding this comment

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

Two small changes requested.

For the positive flash message, I'd accept this PR with just a flash.assert_no_error in the create method and no positive flash message text assertion.

@mshriver mshriver changed the title [1LP][RFR]Added invalid cidr/ip tests for floating_ip_add and subnet_add [1LP][WIPTEST]Added invalid cidr/ip tests for floating_ip_add and subnet_add Apr 24, 2020
@mmojzis
Copy link
Contributor Author

mmojzis commented Apr 27, 2020

Two small changes requested.

For the positive flash message, I'd accept this PR with just a flash.assert_no_error in the create method and no positive flash message text assertion.

@jawatts @mshriver
These tests are only negative. It should check the format of flash message when invalid cidr is filled in.
I added these tests only because there was qe_test_coverage needed for these BZs.
I understand that you also want positive test that passes, but I didn't have qe_test_coverage for that.
I have no more time to write positive test.

@dajoRH
Copy link
Contributor

dajoRH commented Apr 27, 2020

I detected some fixture changes in commit 18e93fb

The local fixture network_manager is used in the following files:

  • cfme/tests/networks/test_sdn_subnets.py
    • test_network_subnet_invalid_cidr

Please, consider creating a PRT run to make sure your fixture changes do not break existing usage 😃

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.

6 participants