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

[WIP] Refactor Nuage enterprise sandbox so that it also returns count values #8458

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aljazkosir
Copy link
Contributor

Test that were using Nuage enterprise sandbox were using hard-coded values to validate test data. Those hard-coded values were moved to Nuage enterprise sandbox.

\cc @miha-plesko

Copy link
Contributor

@miha-plesko miha-plesko left a comment

Choose a reason for hiding this comment

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

Thanks @aljazkosir that's something @mshriver has requested long ago and we promised to refactor it later. Well, here we are :)

return create_namespace_from_enterprise(box)


def create_namespace_from_enterprise(enterprise):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to first create a hash box and then convert into object? Wouldn't it read better if we do object just right away in L10, like this:

box = Namespace()

# Create empty enterprise aka 'sandbox'.
box.enterprise = dict(obj=nuage.create_enterprise())

# Fill the sandbox with some entities.
 # Method `create_child` returns a tuple (object, connection) and we only need object.
box.template = dict(
  obj=box.enterprise.create_child(nuage.vspk.NUDomainTemplate(name=random_name()))[0]
)
box.domain = dict(
  obj=enterprise.create_child(nuage.vspk.NUDomain(name=random_name(), template_id=box.template['obj'].id))[0],
  num_subnets=1,
  num_security_groups=1  
)
...

return box

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I created objects directly into Namespace. I also saved their names and ids, so we won't have to access 'obj' key everytime.

Copy link
Member

Choose a reason for hiding this comment

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

Coming back to these older comments after having made some new ones. @miha-plesko I think your suggestion is on the right track, but its still not clear to me why the objects are being wrapped in dictionaries at all here. Can box.enterprise and box.template not be objects? Is this a Namespace limitation? If so, let's use something other than Namespace.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mshriver the idea here was to make it "flat" - the object itself comes directly from Nuage python library which we wanted to only use within this fixture. So we were thinking to create anonymous class (Namespace) and only copy attributes we are interested in later for tests, then drop the object itself.

Another reason why just passing on the object itself didn't seem a good idea was that it uses some fancy caching mechanism which in turn yield wrong values unless correctly handled in the test, which makes the whole thing less readable.

To make the story short: we want to use Nuage python library barely to CREATE some entities. We don't need to READ any of them, because we know exactly what we created, hence the plain simple Namespace. If we wanted to use the real object, then we would have to move it to wrapanapi, which is an overkill in this case, I think :)

Please let me know if that answers your question, we can also have a quick call to talk it out in person.


def create_namespace_from_enterprise(enterprise):
box = Namespace(**{key: {'obj': value} for key, value in enterprise.items()})
box.domain['num_subnets'] = '1'
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it have to be string? Perhaps we could update ValidateStats mixin to convert value to 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.

All the values in the mixin are now converted to strings.

targeted_refresh.register_target(sandbox.l2_cont_vport['obj'].id, 'Container vPort (L2)')
targeted_refresh.register_target(sandbox.l2_vm_vport['obj'].id, 'VM vPort (L2)')
targeted_refresh.register_target(sandbox.group['obj'].id, 'Security group (L3)')
targeted_refresh.register_target(sandbox.l2_group['obj'].id, 'Security group (L2)')
Copy link
Contributor

Choose a reason for hiding this comment

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

Honestly, I'd prefer if test would do just

sandbox.l2_group['name']

Because test reads a bit strange with this 'obj' thing. I don't mind having 'obj' stored, but since 99% of our tests just accesses 'name' and 'id' I'd add those two keys to the dictionary. Wdyt?

PS: Yes, fixture would be slightly redundant then, but the key aspect IMAO is to have easily usable fixture, not nicest implementation :)

@aljazkosir aljazkosir force-pushed the refactor-hardcoded-test-data branch 2 times, most recently from a13ad1f to b3190b3 Compare February 13, 2019 10:29
Copy link
Contributor

@miha-plesko miha-plesko left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mshriver mshriver changed the title [WIP] Refactor Nuage enterprise sandbox so that it also returns count values [WIPTEST] Refactor Nuage enterprise sandbox so that it also returns count values Feb 15, 2019
@mshriver mshriver self-assigned this Feb 15, 2019
@aljazkosir aljazkosir force-pushed the refactor-hardcoded-test-data branch from b3190b3 to 111104c Compare March 7, 2019 13:01
@aljazkosir aljazkosir force-pushed the refactor-hardcoded-test-data branch from 111104c to 5edcdbc Compare March 7, 2019 13:59
@aljazkosir
Copy link
Contributor Author

@mshriver I rebased this PR, should be ready for a review :).

@aljazkosir aljazkosir force-pushed the refactor-hardcoded-test-data branch 3 times, most recently from 338e2a6 to e14bd88 Compare March 8, 2019 12:35
@aljazkosir aljazkosir changed the title [WIPTEST] Refactor Nuage enterprise sandbox so that it also returns count values [RFR] Refactor Nuage enterprise sandbox so that it also returns count values Mar 8, 2019
@dajoRH dajoRH removed the WIP-testing label Mar 8, 2019
logger.info('Created sandbox enterprise %s (%s)', enterprise.name, enterprise.id)
box.enterprise = get_object_dictionary(nuage.create_enterprise())
logger.info('Created sandbox enterprise %s (%s)',
box.enterprise['obj'].name, box.enterprise['obj'].id)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is a good or efficient pattern, get_object_dictionary. It odd to me in general, and combined with the use of argparse.Namespace makes me wonder what you're really trying to solve here. I think collections.namedtuple is more appropriate in this context, as you define the object type and parameter names before using them. Namespace does give you more freedome to arbitrarily add attributes to box.

Back to my point - you've written and called get_object_dictionary to create a dictionary with name and id keys, and then right here after doing so you still directly reference box.enterprise['obj'].name, instead of box.enterprise['name']. Both seem like awkward references, when box.enterprise should be the object.

box['zone'] = box['domain'].create_child(
nuage.vspk.NUZone(name=random_name()))[0]
box['subnet'] = box['zone'].create_child(
box.template = get_object_dictionary(box.enterprise['obj'].create_child(
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this layer-cake of Namespace/attribute/dictionary/key makes this entity generation very readable. I'll keep reading, but I'm continuing to think this get_object_dictionary layer is a bad pattern.

@mshriver mshriver changed the title [RFR] Refactor Nuage enterprise sandbox so that it also returns count values [WIPTEST] Refactor Nuage enterprise sandbox so that it also returns count values Mar 8, 2019
We move hardcoded values inside tests that uses nuage sandbox fixture to
fixture where we use python dictionary to store count values
@aljazkosir aljazkosir force-pushed the refactor-hardcoded-test-data branch from e14bd88 to d5b96ce Compare March 11, 2019 08:44
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.

The get_object_dictionary method is a bad pattern here, I don't think its something I would merge into integration_tests. Happy to discuss what you're trying to achieve with that method, and find a more suitable way to structure and reference the data.

@dajoRH
Copy link
Contributor

dajoRH commented Aug 7, 2019

I detected some fixture changes in commit d5b96ce

The global fixture with_nuage_sandbox is used in the following files:

  • cfme/tests/networks/nuage/test_events_are_triggered.py
    • test_creating_entities_emits_events
    • test_creating_entities_triggers_targeted_refresh
  • cfme/tests/networks/nuage/test_operations.py
    • test_router_add_subnet

The global fixture with_nuage_sandbox_modscope is used in the following files:

  • cfme/tests/networks/nuage/test_inventory.py
    • test_tenant_details
    • test_subnet_details
    • test_l2_subnet_details
    • test_network_router_details
    • test_network_port_vm
    • test_network_port_container
    • test_network_port_l2_vm
    • test_network_port_l2_container

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

@dajoRH dajoRH changed the title [WIPTEST] Refactor Nuage enterprise sandbox so that it also returns count values [WIP] Refactor Nuage enterprise sandbox so that it also returns count values Oct 18, 2019
@dajoRH
Copy link
Contributor

dajoRH commented Oct 18, 2019

Would you mind rebasing this Pull Request against latest master, please? :trollface:
CFME QE Bot

@dajoRH dajoRH added WIP and removed WIP-testing labels Oct 18, 2019
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.

4 participants