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

Commit

Permalink
stop setting extra capabilities
Browse files Browse the repository at this point in the history
Only one of the three current disk driver capabilities is also
supposed to be a capability of the virt driver, yet all of them
were being copied onto the virt driver. This corrects that so
that only has_imagecache appears in both places.

It also fixes how we test capabilities, which was a) incomplete and
b) only passing coincidentally for has_imagecache (i.e., not testing
what it intended to be testing). This required making capabilities
an instance property instead of a class property, so that when one
test sets a capability that doesn't bleed over into other tests.

Change-Id: I66928342c9dc8c2735b739d1b96f0d5b187b9e8c
  • Loading branch information
edmondsw authored and Eric Fried committed Feb 22, 2018
1 parent f54ab51 commit cc75645
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 28 deletions.
62 changes: 47 additions & 15 deletions nova_powervm/tests/virt/powervm/test_driver.py
Expand Up @@ -53,17 +53,59 @@
logging.basicConfig()


@mock.patch('nova_powervm.virt.powervm.mgmt.mgmt_uuid', new=mock.Mock())
class TestPowerVMDriverInit(test.NoDBTestCase):
"""A test class specifically for the driver setup.
Handles testing the configuration of the agent with the backing REST API.
"""

def setUp(self):
super(TestPowerVMDriverInit, self).setUp()

def test_driver_capabilities_defaults(self):
"""Test the default capabilities."""
test_driver = driver.PowerVMDriver(fake.FakeVirtAPI())
self.assertTrue(test_driver.capabilities['supports_recreate'])
self.assertFalse(
test_driver.capabilities['supports_migrate_to_same_host'])
self.assertTrue(test_driver.capabilities['supports_attach_interface'])
self.assertFalse(test_driver.capabilities['supports_device_tagging'])
self.assertFalse(
test_driver.capabilities['supports_tagged_attach_interface'])
self.assertFalse(
test_driver.capabilities['supports_tagged_attach_volume'])
self.assertTrue(test_driver.capabilities['supports_extend_volume'])
self.assertFalse(test_driver.capabilities['supports_multiattach'])
self.assertNotIn('has_imagecache', test_driver.capabilities)
self.assertEqual(8, len(test_driver.capabilities))

@mock.patch('pypowervm.tasks.storage.find_vg',
new=mock.Mock(return_value=(mock.Mock(), mock.Mock())))
def test_driver_capabilities_from_localdisk_adapter(self):
"""Test dynamic capabilities from localdisk adapter."""
self.flags(disk_driver='localdisk', group='powervm')
self.flags(host='host1', my_ip='127.0.0.1')
self.flags(volume_group_name='foovg', group='powervm')
test_driver = driver.PowerVMDriver(fake.FakeVirtAPI())
test_driver.adapter = mock.Mock()
test_driver.host_uuid = mock.Mock()
test_driver._setup_disk_adapter()
# Localdisk driver has the image cache capability
self.assertTrue(test_driver.capabilities['has_imagecache'])
self.assertEqual(9, len(test_driver.capabilities))

@mock.patch('nova_powervm.virt.powervm.disk.ssp.SSPDiskAdapter.'
'_fetch_cluster', new=mock.Mock())
@mock.patch('nova_powervm.virt.powervm.disk.ssp.SSPDiskAdapter.'
'_ssp', new=mock.Mock())
@mock.patch('nova_powervm.virt.powervm.disk.ssp.SSPDiskAdapter.'
'_tier', new=mock.Mock())
def test_driver_capabilities_from_ssp_disk_adapter(self):
"""Test dynamic capabilities from SSP disk adapter."""
self.flags(disk_driver='ssp', group='powervm')
test_driver = driver.PowerVMDriver(fake.FakeVirtAPI())
test_driver.adapter = mock.Mock()
test_driver.host_uuid = mock.Mock()
test_driver._setup_disk_adapter()
# SSP driver doesn't have image cache capability
self.assertFalse(test_driver.capabilities['has_imagecache'])
self.assertEqual(9, len(test_driver.capabilities))

@mock.patch('nova_powervm.virt.powervm.event.PowerVMNovaEventHandler')
@mock.patch('pypowervm.adapter.Adapter')
Expand Down Expand Up @@ -142,16 +184,6 @@ def test_get_available_nodes(self):
self.flags(host='hostname')
self.assertEqual(['hostname'], self.drv.get_available_nodes('node'))

def test_driver_capabilities(self):
"""Test the default capabilities."""
test_driver = driver.PowerVMDriver(fake.FakeVirtAPI())
self.assertFalse(test_driver.capabilities['has_imagecache'])
self.assertTrue(test_driver.capabilities['supports_recreate'])
self.assertFalse(
test_driver.capabilities['supports_migrate_to_same_host'])
self.assertTrue(test_driver.capabilities['supports_attach_interface'])
self.assertFalse(test_driver.capabilities['supports_device_tagging'])

def _setup_lpm(self):
"""Setup the lpm environment.
Expand Down
26 changes: 13 additions & 13 deletions nova_powervm/virt/powervm/driver.py
Expand Up @@ -90,19 +90,18 @@ class PowerVMDriver(driver.ComputeDriver):

"""PowerVM Implementation of Compute Driver."""

capabilities = {
"has_imagecache": False,
"supports_recreate": True,
"supports_migrate_to_same_host": False,
"supports_attach_interface": True,
"supports_device_tagging": False,
"supports_tagged_attach_interface": False,
"supports_tagged_attach_volume": False,
"supports_extend_volume": True,
"supports_multiattach": False,
}

def __init__(self, virtapi):
self.capabilities = {
# NOTE(edmondsw): 'has_imagecache' will be set dynamically
"supports_recreate": True,
"supports_migrate_to_same_host": False,
"supports_attach_interface": True,
"supports_device_tagging": False,
"supports_tagged_attach_interface": False,
"supports_tagged_attach_volume": False,
"supports_extend_volume": True,
"supports_multiattach": False,
}
super(PowerVMDriver, self).__init__(virtapi)

def init_host(self, host):
Expand Down Expand Up @@ -177,7 +176,8 @@ def _setup_disk_adapter(self):
self.disk_dvr = importutils.import_object_ns(
DISK_ADPT_NS, DISK_ADPT_MAPPINGS[CONF.powervm.disk_driver.lower()],
self.adapter, self.host_uuid)
self.capabilities.update(self.disk_dvr.capabilities)
has_imagecache = self.disk_dvr.capabilities['has_imagecache']
self.capabilities['has_imagecache'] = has_imagecache

def manage_image_cache(self, context, all_instances):
self.disk_dvr.manage_image_cache(context, all_instances)
Expand Down

0 comments on commit cc75645

Please sign in to comment.