neutron unit tests creation issues

asked 2014-07-10 05:28:22 -0500

Hello,

I'm trying to write a unit test for neutron to verify if port update works if the device_id is specified.

This is what my code looks like:

def test_update_port_id_not_changed(self):
    res = self._create_network(self.fmt, 'net2', True,
                               tenant_id='not_admin',
                               set_context=True)
    net2 = self.deserialize(self.fmt, res)
    data = {'port': {'admin_state_up': False}}
    res = self._create_port(self.fmt,
                            net2['network']['id'],
                            webob.exc.HTTPCreated.code,
                            tenant_id='another_tenant',
                            set_context=True)

    port = self.deserialize(self.fmt, res)
    data = {'port': {'admin_state_up': True,
                     'device_id': port['port']['device_id'],
                    },
           }
    res = self._update_port(self.fmt,
                            port['port']['id'],
                            data)
    updt_port = self.deserialize(self.fmt, res)
    self.assertEqual(updt_port['port']['admin_state_up'], True)

When I run the test though, I see it failing with the following error:

======================================================================
FAIL: neutron.tests.unit.test_db_plugin.TestPortsV2XML.test_update_port_id_not_changed
neutron.tests.unit.test_db_plugin.TestPortsV2XML.test_update_port_id_not_changed
----------------------------------------------------------------------
_StringException: Empty attachments:
  stderr
  stdout

pythonlogging:'': {{{
2014-07-10 14:50:58,200     INFO [neutron.manager] Loading core plugin: neutron.db.db_base_plugin_v2.NeutronDbPluginV2
2014-07-10 14:50:58,421    ERROR [neutron.api.extensions] Extension path 'unit/extensions' doesn't exist!
2014-07-10 14:50:58,506     INFO [neutron.api.v2.resource] create failed (client error): Network a07487d3-b026-4bf5-944e-553584751904 could not be found
}}}

pythonlogging:'neutron.api.extensions': {{{2014-07-10 14:50:58,421    ERROR [neutron.api.extensions] Extension path 'unit/extensions' doesn't exist!}}}

Traceback (most recent call last):
  File "/home/mithil/neutron/neutron/tests/unit/test_db_plugin.py", line 1118, in test_update_port_id_not_changed
    set_context=True)
  File "/home/mithil/neutron/neutron/tests/unit/test_db_plugin.py", line 366, in _create_port
    self.assertEqual(port_res.status_int, expected_res_status)
  File "/home/mithil/neutron/.venv/local/lib/python2.7/site-packages/testtools/testcase.py", line 321, in assertEqual
    self.assertThat(observed, matcher, message)
  File "/home/mithil/neutron/.venv/local/lib/python2.7/site-packages/testtools/testcase.py", line 406, in assertThat
    raise mismatch_error
MismatchError: 404 != 201

Could you please tell me what I am doing wrong here? I'm not familiar with writing unit tests, and any pointers would greatly help.

Thanks!

Mithil

edit retag flag offensive close merge delete

Comments

Hi Mithil,

Did you get the solution for the error that you mentioned. Recently I did some changes in openstack neutron repo as part of bug fix and I see the similar error. You can see the diffs at this link. https://review.openstack.org/#/c/1125... Below are the stack trace.

======================================================================
FAIL: test_floatingips_op_agent (neutron.tests.unit.test_l3_plugin.L3AgentDbSepTestCase)
neutron.tests.unit.test_l3_plugin.L3AgentDbSepTestCase.test_floatingips_op_agent
----------------------------------------------------------------------
_StringException: pythonlogging:'': {{{
2014-08-12 11:29:31,113     INFO [neutron.manager] Loading core plugin: neutron.tests.unit.test_l3_plugin.TestNoL3NatPlugin
2014-08-12 11:29:31,136     INFO [neutron.manager] Loading Plugin: neutron.tests.unit.test_l3_plugin.TestL3NatServicePlugin
2014-08-12 11:29:31,144    ERROR [neutron.api.extensions] Extension path 'unit/extensions' doesn't exist!
2014-08-12 11:29:31,171     INFO [neutron.common.config] Config paste file: /opt/stack/neutron/neutron/tests/etc/api-paste.ini.test
2014-08-12 11:29:31,174  WARNING [neutron.quota] router is already registered.
2014-08-12 11:29 ...
(more)
Vinod Kumar gravatar imageVinod Kumar ( 2014-08-12 01:20:31 -0500 )edit

Snip from email conversation:

--snip--

Hi Mithil,

Ok. I found the solution. Yes the problem was due to invalid number of argument passed to the function update_router(). This function was existing function which I overrode in derived class, and there were some UT code still pointing to older version of update_router() method in Base class. I changed the UT code such that it now started calling derived class function which solved the problem.

Thanks anyways.

Vinod

From: Mithil Arun [mailto:arun.mithil@gmail.com]

Hi Vinod,

Call me Mithil :)

This is quite different from the problem I was facing.

From a quick look at the logs, it appears that you are passing too many arguments to your update router() function:

2014-08-11 09:21:56.994 | Traceback (most recent call last):
2014-08-11 09:21:56.994 |   File "neutron/api/v2/resource.py", line 87, in resource
2014-08-11 09:21:56.994 ...
(more)
mithilarun gravatar imagemithilarun ( 2014-08-13 00:34:43 -0500 )edit