OpenStack Compute (Nova)

test_libvirt shouldn't mock import_class/import_object

Reported by Dan Prince on 2011-09-13
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Medium
Dan Prince

Bug Description

I'm getting some libvirt test failures when using nova trunk:

[dan.prince@dovetail trunk]$ ./run_tests.sh -N test_libvirt
CacheConcurrencyTestCase
    test_different_fname_concurrency OK 0.00
    test_same_fname_concurrency OK 0.00
IptablesFirewallTestCase
    test_do_refresh_security_group_rules OK 0.01
    test_filters_for_instance_with_ip_v6 OK 0.00
    test_filters_for_instance_without_ip_v6 OK 0.00
    test_multinic_iptables OK 0.03
    test_provider_firewall_rules OK 0.07
    test_static_filters OK 0.37
    test_unfilter_instance_undefines_nwfilter OK 0.05
LibvirtConnTestCase
    test_attach_invalid_device OK 0.03
    test_ensure_filtering_rules_for_instance_timeout ERROR
ERROR
    test_get_host_ip_addr OK 0.01
    test_get_instance_disk_info_works_correctly OK 0.02
    test_live_migration_raises_exception OK 0.40
    test_lxc_container_and_uri OK 0.16
    test_multi_nic OK 0.08
    test_pre_block_migration_works_correctly OK 0.02
    test_preparing_xml_info OK 0.14
    test_snapshot OK 0.01
    test_snapshot_no_image_architecture OK 0.01
    test_spawn_with_network_info FAIL
    test_update_available_resource_works_correctly OK 0.05
    test_update_resource_info_no_compute_record_found OK 0.01
    test_volume_in_mapping OK 0.01
    test_xml_and_uri OK 0.31
    test_xml_and_uri_no_kernel OK 0.30
    test_xml_and_uri_no_ramdisk OK 0.34
    test_xml_and_uri_no_ramdisk_no_kernel OK 0.30
    test_xml_and_uri_rescue OK 0.39
NWFilterTestCase
    test_cidr_rule_nwfilter_xml OK 0.21
    test_create_network_filters OK 0.01
    test_creates_base_rule_first OK 0.39
    test_unfilter_instance_undefines_nwfilters OK 0.36

======================================================================
ERROR: test_ensure_filtering_rules_for_instance_timeout (nova.tests.test_libvirt.LibvirtConnTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dan.prince/projects/nova/trunk/nova/tests/test_libvirt.py", line 606, in test_ensure_filtering_rules_for_instance_timeout
    network_info = _fake_network_info(self.stubs, 1)
  File "/home/dan.prince/projects/nova/trunk/nova/tests/fake_network.py", line 142, in fake_get_instance_nw_info
    network = network_manager.FlatManager(host=HOST)
  File "/home/dan.prince/projects/nova/trunk/nova/network/manager.py", line 334, in __init__
    self.compute_api = compute_api.API()
  File "/home/dan.prince/projects/nova/trunk/nova/compute/api.py", line 102, in __init__
    nova.image.get_default_image_service()
  File "/home/dan.prince/projects/nova/trunk/nova/image/__init__.py", line 29, in get_default_image_service
    return ImageService()
  File "/usr/lib/python2.7/site-packages/mox.py", line 927, in Check
    % (' '.join(sorted(still_needed))))
AttributeError: No values given for arguments: import_str

======================================================================
ERROR: test_ensure_filtering_rules_for_instance_timeout (nova.tests.test_libvirt.LibvirtConnTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dan.prince/projects/nova/trunk/nova/test.py", line 141, in tearDown
    self.mox.VerifyAll()
  File "/usr/lib/python2.7/site-packages/mox.py", line 284, in VerifyAll
    mock_obj._Verify()
  File "/usr/lib/python2.7/site-packages/mox.py", line 504, in _Verify
    raise ExpectedMethodCallsError(self._expected_calls_queue)
ExpectedMethodCallsError: Verify: Expected methods never called:
  0. import_class.__call__(<IgnoreArg>) -> <class 'nova.tests.test_libvirt.FakeIptablesFirewallDriver'>
  1. import_class.__call__() -> None

======================================================================
FAIL: test_spawn_with_network_info (nova.tests.test_libvirt.LibvirtConnTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dan.prince/projects/nova/trunk/nova/tests/test_libvirt.py", line 790, in test_spawn_with_network_info
    network_info = _fake_network_info(self.stubs, 1)
  File "/home/dan.prince/projects/nova/trunk/nova/tests/fake_network.py", line 142, in fake_get_instance_nw_info
    network = network_manager.FlatManager(host=HOST)
  File "/home/dan.prince/projects/nova/trunk/nova/network/manager.py", line 332, in __init__
    self.driver = utils.import_object(network_driver)
  File "/usr/lib/python2.7/site-packages/mox.py", line 763, in __call__
    return mock_method(*params, **named_params)
  File "/usr/lib/python2.7/site-packages/mox.py", line 1000, in __call__
    expected_method = self._VerifyMethodCall()
  File "/usr/lib/python2.7/site-packages/mox.py", line 1047, in _VerifyMethodCall
    expected = self._PopNextMethod()
  File "/usr/lib/python2.7/site-packages/mox.py", line 1033, in _PopNextMethod
    raise UnexpectedMethodCallError(self, None)
UnexpectedMethodCallError: Unexpected method call import_object.__call__('nova.network.linux_net') -> None

----------------------------------------------------------------------
Ran 33 tests in 5.130s

FAILED (errors=2, failures=1)
Slowest 5 tests took 1.90 secs:
    0.40 test_live_migration_raises_exception (nova.tests.test_libvirt.LibvirtConnTestCase)
    0.39 test_xml_and_uri_rescue (nova.tests.test_libvirt.LibvirtConnTestCase)
    0.39 test_creates_base_rule_first (nova.tests.test_libvirt.NWFilterTestCase)
    0.37 test_static_filters (nova.tests.test_libvirt.IptablesFirewallTestCase)
    0.36 test_unfilter_instance_undefines_nwfilters (nova.tests.test_libvirt.NWFilterTestCase)

---

The failures seem to stem from the fact that we are mocking out import_class and import_object. Using flags and fakes seems like a saner way to implement things in test_libvirt...

Related branches

lp:~rackspace-titan/nova/nuke_naughty_mox
Merged into lp:~hudson-openstack/nova/trunk at revision 1569
Brian Lamar (community): Approve on 2011-09-14
Sandy Walsh (community): Approve on 2011-09-14
Devin Carlen (community): Approve on 2011-09-13
Dan Prince (dan-prince) on 2011-09-13
Changed in nova:
status: New → In Progress
assignee: nobody → Dan Prince (dan-prince)
importance: Undecided → Medium
Dan Prince (dan-prince) on 2011-09-14
Changed in nova:
status: In Progress → Fix Committed

> The failures seem to stem from the fact that we are mocking out
> import_class and import_object. Using flags and fakes seems like a saner
> way to implement things in test_libvirt...

I have a branch awaiting review that does exactly this
(~soren/nova/virt-test-improvements). It has a fakelibvirt
implementation that has an API identical to libvirt's, but doesn't
actually do anything apart from bookkeeping.

Dan Prince (dan-prince) wrote :

Hey Soren,

I like the refactoring you've done as well. What I did was much more specific to some test failures that crept in late last week. I was getting libvirt test failures all of a sudden. I did a bit of refactoring mostly targeted at removing the mocking of import_class and import_object.

Sorry. I missed that your branch was another possible solution here. Let me know if I can help merge any conflicts. If your tests are better it should just be a matter of overwritting the test_libvirt.py in trunk and moving forward.

Thierry Carrez (ttx) on 2011-11-09
Changed in nova:
milestone: none → essex-1
Thierry Carrez (ttx) on 2011-11-17
Changed in nova:
status: Fix Committed → Fix Released
Thierry Carrez (ttx) on 2012-04-05
Changed in nova:
milestone: essex-1 → 2012.1
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers