yahoo-eng-team team mailing list archive
-
yahoo-eng-team team
-
Mailing list archive
-
Message #51947
[Bug 1589181] [NEW] Unit test scene of test_cleanup_incomplete_migrations_dest_node is set error.
Public bug reported:
1. version
tecs@tecs-Aspire-4740:/opt/stack/nova/nova/compute$ git log -1
commit 545d8d8666389f33601b0b003dec844004694919
Merge: a224d5e f5c9ebd
Author: Jenkins <jenkins@xxxxxxxxxxxxxxxxxxxx>
Date: Fri Jun 3 19:25:23 2016 +0000
Merge "Fall back to flat config drive if not found in rbd"
2. code
@mock.patch.object(objects.Migration, 'obj_as_admin')
@mock.patch.object(objects.Migration, 'save')
@mock.patch.object(objects.MigrationList, 'get_by_filters')
@mock.patch.object(objects.InstanceList, 'get_by_filters')
def _test_cleanup_incomplete_migrations(self, inst_host,
mock_inst_get_by_filters,
mock_migration_get_by_filters,
mock_save, mock_obj_as_admin):
def fake_inst(context, uuid, host):
inst = objects.Instance(context)
inst.uuid = uuid
inst.host = host
return inst
def fake_migration(uuid, status, inst_uuid, src_host, dest_host):
migration = objects.Migration()
migration.uuid = uuid
migration.status = status
migration.instance_uuid = inst_uuid
migration.source_compute = src_host
migration.dest_compute = dest_host
return migration
fake_instances = [fake_inst(self.context, uuids.instance_1, inst_host),
fake_inst(self.context, uuids.instance_2, inst_host)]
fake_migrations = [fake_migration('123', 'error',
uuids.instance_1,
'fake-host', 'fake-mini'),
fake_migration('456', 'error',
uuids.instance_2,
'fake-host', 'fake-mini')]
mock_migration_get_by_filters.return_value = fake_migrations
mock_inst_get_by_filters.return_value = fake_instances
with mock.patch.object(self.compute.driver, 'delete_instance_files'):
self.compute._cleanup_incomplete_migrations(self.context)
# Ensure that migration status is set to 'failed' after instance
# files deletion for those instances whose instance.host is not
# same as compute host where periodic task is running.
for inst in fake_instances:
for mig in fake_migrations:
if inst.uuid == mig.instance_uuid:
self.assertEqual('failed', mig.status)
# Make sure we filtered the instances by host in the DB query.
self.assertEqual(CONF.host,
mock_inst_get_by_filters.call_args[0][1]['host'])
for instance in mock_inst_get_by_filters.return_value:
self.assertEqual(CONF.host,
instance.host)
def test_cleanup_incomplete_migrations_dest_node(self):
"""Test to ensure instance files are deleted from destination node.
If instance gets deleted during resizing/revert-resizing operation,
in that case instance files gets deleted from instance.host (source
host here), but there is possibility that instance files could be
present on destination node.
This test ensures that `_cleanup_incomplete_migration` periodic
task deletes orphaned instance files from destination compute node.
"""
self.flags(host='fake-mini')
self._test_cleanup_incomplete_migrations('fake-host')
3. I add this code in "_test_cleanup_incomplete_migrations" function
for instance in mock_inst_get_by_filters.return_value:
self.assertEqual(CONF.host,
instance.host)
4. objects.InstanceList.get_by_filters will result instance.host==CONF.host
inst_filters = {'deleted': True, 'soft_deleted': False,
'uuid': inst_uuid_from_migrations, 'host': CONF.host}
instances = objects.InstanceList.get_by_filters(
context, inst_filters, expected_attrs=attrs, use_slave=True)
5. Then error is occur
/usr/bin/python2.7 /usr/local/pycharm/helpers/pycharm/utrunner.py /opt/stack/nova/nova/tests/unit/compute/test_compute_mgr.py::ComputeManagerUnitTestCase::test_cleanup_incomplete_migrations_dest_node true
Testing started at 上午10:14 ...
Failure
_StringException: pythonlogging:'': {{{2016-06-05 10:15:17,733 INFO [nova.virt.driver] Loading compute driver 'fake.SmallFakeDriver'}}}
Traceback (most recent call last):
File "/opt/stack/nova/nova/tests/unit/compute/test_compute_mgr.py", line 1638, in test_cleanup_incomplete_migrations_dest_node
self._test_cleanup_incomplete_migrations('fake-host')
File "/usr/local/lib/python2.7/dist-packages/mock/mock.py", line 1305, in patched
return func(*args, **keywargs)
File "/opt/stack/nova/nova/tests/unit/compute/test_compute_mgr.py", line 1625, in _test_cleanup_incomplete_migrations
instance.host)
File "/usr/local/lib/python2.7/dist-packages/testtools/testcase.py", line 362, in assertEqual
self.assertThat(observed, matcher, message)
File "/usr/local/lib/python2.7/dist-packages/testtools/testcase.py", line 447, in assertThat
raise mismatch_error
testtools.matchers._impl.MismatchError: 'fake-mini' != u'fake-host'
6. unit test scene was set error by this code
fake_instances = [fake_inst(self.context, uuids.instance_1, inst_host),
fake_inst(self.context, uuids.instance_2, inst_host)]
mock_inst_get_by_filters.return_value = fake_instances
7. so this might be right unit test scene
fake_instances = [fake_inst(self.context, uuids.instance_1, CONF.host),
fake_inst(self.context, uuids.instance_2, CONF.host)]
** Affects: nova
Importance: Undecided
Assignee: Charlotte Han (hanrong)
Status: New
** Changed in: nova
Assignee: (unassigned) => Charlotte Han (hanrong)
--
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to OpenStack Compute (nova).
https://bugs.launchpad.net/bugs/1589181
Title:
Unit test scene of test_cleanup_incomplete_migrations_dest_node is set
error.
Status in OpenStack Compute (nova):
New
Bug description:
1. version
tecs@tecs-Aspire-4740:/opt/stack/nova/nova/compute$ git log -1
commit 545d8d8666389f33601b0b003dec844004694919
Merge: a224d5e f5c9ebd
Author: Jenkins <jenkins@xxxxxxxxxxxxxxxxxxxx>
Date: Fri Jun 3 19:25:23 2016 +0000
Merge "Fall back to flat config drive if not found in rbd"
2. code
@mock.patch.object(objects.Migration, 'obj_as_admin')
@mock.patch.object(objects.Migration, 'save')
@mock.patch.object(objects.MigrationList, 'get_by_filters')
@mock.patch.object(objects.InstanceList, 'get_by_filters')
def _test_cleanup_incomplete_migrations(self, inst_host,
mock_inst_get_by_filters,
mock_migration_get_by_filters,
mock_save, mock_obj_as_admin):
def fake_inst(context, uuid, host):
inst = objects.Instance(context)
inst.uuid = uuid
inst.host = host
return inst
def fake_migration(uuid, status, inst_uuid, src_host, dest_host):
migration = objects.Migration()
migration.uuid = uuid
migration.status = status
migration.instance_uuid = inst_uuid
migration.source_compute = src_host
migration.dest_compute = dest_host
return migration
fake_instances = [fake_inst(self.context, uuids.instance_1, inst_host),
fake_inst(self.context, uuids.instance_2, inst_host)]
fake_migrations = [fake_migration('123', 'error',
uuids.instance_1,
'fake-host', 'fake-mini'),
fake_migration('456', 'error',
uuids.instance_2,
'fake-host', 'fake-mini')]
mock_migration_get_by_filters.return_value = fake_migrations
mock_inst_get_by_filters.return_value = fake_instances
with mock.patch.object(self.compute.driver, 'delete_instance_files'):
self.compute._cleanup_incomplete_migrations(self.context)
# Ensure that migration status is set to 'failed' after instance
# files deletion for those instances whose instance.host is not
# same as compute host where periodic task is running.
for inst in fake_instances:
for mig in fake_migrations:
if inst.uuid == mig.instance_uuid:
self.assertEqual('failed', mig.status)
# Make sure we filtered the instances by host in the DB query.
self.assertEqual(CONF.host,
mock_inst_get_by_filters.call_args[0][1]['host'])
for instance in mock_inst_get_by_filters.return_value:
self.assertEqual(CONF.host,
instance.host)
def test_cleanup_incomplete_migrations_dest_node(self):
"""Test to ensure instance files are deleted from destination node.
If instance gets deleted during resizing/revert-resizing operation,
in that case instance files gets deleted from instance.host (source
host here), but there is possibility that instance files could be
present on destination node.
This test ensures that `_cleanup_incomplete_migration` periodic
task deletes orphaned instance files from destination compute node.
"""
self.flags(host='fake-mini')
self._test_cleanup_incomplete_migrations('fake-host')
3. I add this code in "_test_cleanup_incomplete_migrations" function
for instance in mock_inst_get_by_filters.return_value:
self.assertEqual(CONF.host,
instance.host)
4. objects.InstanceList.get_by_filters will result instance.host==CONF.host
inst_filters = {'deleted': True, 'soft_deleted': False,
'uuid': inst_uuid_from_migrations, 'host': CONF.host}
instances = objects.InstanceList.get_by_filters(
context, inst_filters, expected_attrs=attrs, use_slave=True)
5. Then error is occur
/usr/bin/python2.7 /usr/local/pycharm/helpers/pycharm/utrunner.py /opt/stack/nova/nova/tests/unit/compute/test_compute_mgr.py::ComputeManagerUnitTestCase::test_cleanup_incomplete_migrations_dest_node true
Testing started at 上午10:14 ...
Failure
_StringException: pythonlogging:'': {{{2016-06-05 10:15:17,733 INFO [nova.virt.driver] Loading compute driver 'fake.SmallFakeDriver'}}}
Traceback (most recent call last):
File "/opt/stack/nova/nova/tests/unit/compute/test_compute_mgr.py", line 1638, in test_cleanup_incomplete_migrations_dest_node
self._test_cleanup_incomplete_migrations('fake-host')
File "/usr/local/lib/python2.7/dist-packages/mock/mock.py", line 1305, in patched
return func(*args, **keywargs)
File "/opt/stack/nova/nova/tests/unit/compute/test_compute_mgr.py", line 1625, in _test_cleanup_incomplete_migrations
instance.host)
File "/usr/local/lib/python2.7/dist-packages/testtools/testcase.py", line 362, in assertEqual
self.assertThat(observed, matcher, message)
File "/usr/local/lib/python2.7/dist-packages/testtools/testcase.py", line 447, in assertThat
raise mismatch_error
testtools.matchers._impl.MismatchError: 'fake-mini' != u'fake-host'
6. unit test scene was set error by this code
fake_instances = [fake_inst(self.context, uuids.instance_1, inst_host),
fake_inst(self.context, uuids.instance_2, inst_host)]
mock_inst_get_by_filters.return_value = fake_instances
7. so this might be right unit test scene
fake_instances = [fake_inst(self.context, uuids.instance_1, CONF.host),
fake_inst(self.context, uuids.instance_2, CONF.host)]
To manage notifications about this bug go to:
https://bugs.launchpad.net/nova/+bug/1589181/+subscriptions
Follow ups