Fix unit test to have appropriate FakeHost

The unit test "test_get_host_details_without_az", which is added
in commit 8dd7a70a37, sometimes failed.

This was because another test right above
"test_get_host_details_with_invalid_host" changes the FakeHost not
to have vcpus attribute, which results in InvalidHost exceptions
in following tests. This patch fixes it.

Change-Id: Ied0b486dc61b51d717d8c0894df065026c76e99f
Closes-Bug: #1780946
This commit is contained in:
Tetsuro Nakamura 2018-07-10 19:12:13 +09:00 committed by Hiroaki Kobayashi
parent 84785b7dde
commit 756d460b8e
1 changed files with 6 additions and 2 deletions

View File

@ -538,9 +538,13 @@ class NovaInventoryTestCase(tests.TestCase):
self.inventory.get_host_details, 'wrong_name')
def test_get_host_details_with_invalid_host(self):
invalid_host = FakeNovaHypervisors.FakeHost
# Create a new class from FakeHost called `invalid_host`,
# which lacks the vcpus attribute.
invalid_host = type('invalid_host',
FakeNovaHypervisors.FakeHost.__bases__,
dict(FakeNovaHypervisors.FakeHost.__dict__))
del invalid_host.vcpus
self.hypervisors_get.return_value = invalid_host
self.hypervisors_get.side_effect = [invalid_host]
self.assertRaises(manager_exceptions.InvalidHost,
self.inventory.get_host_details, '1')