-
Notifications
You must be signed in to change notification settings - Fork 165
[1LP][WIPTEST]Added invalid cidr/ip tests for floating_ip_add and subnet_add #10033
base: master
Are you sure you want to change the base?
Conversation
45c0bf4
to
79d8344
Compare
@pytest.fixture() | ||
def network_manager(appliance, provider): | ||
network_managers = appliance.collections.network_providers.filter({"provider": provider}) | ||
yield network_managers.all()[0] |
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 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?
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.
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): |
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 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.
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.
Well, in the future when they add another providers with network managers the fixture makes sense.
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.
@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)) |
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.
Interesting that Travis didn't complain/converted this to f-string
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.
What is f-string?
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 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)) |
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.
Interesting that Travis didn't complain/converted this to f-string
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.
Changed fstring.
|
||
@pytest.fixture() | ||
def network_manager(appliance, provider): | ||
network_managers = appliance.collections.network_providers.filter({"provider": 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.
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)
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.
Sorry, I don't understand the code.
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.
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.
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.
Okay, got it. Thanks. Changed as you proposed.
79d8344
to
5c64fb1
Compare
5c64fb1
to
601268d
Compare
@JaryN are you okay to move this one to 1LP? |
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.
Sorry for the delay.
'fixed_ip_address': fixed_ip_address, | ||
'cloud_tenant': tenant}) | ||
view.add.click() | ||
view.flash.assert_success_message(f'Floating IP "{floating_ip_address}" created') |
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.
We want to assert_no error()
here instead and have the actual flash message asserted in a test.
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.
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.
One small comments but otherwise looks good!
|
||
@pytest.fixture() | ||
def network_manager(appliance, provider): | ||
network_manager, = appliance.collections.network_providers.filter({"provider": provider}).all() |
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.
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.
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 Is this something like you wanted? https://github.com/ManageIQ/integration_tests/pull/10033/files#diff-d0ee99cb7213e3f233490166c76aab34R15
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.
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 |
I detected some fixture changes in commit 18e93fb The local fixture
Please, consider creating a PRT run to make sure your fixture changes do not break existing usage 😃 |
Also added needed views and create function.