Fix: ServerProfile._validate_volume_type() missing 1 required positional argument: 'name_or_id'

Pass `obj` param to `_validate_volume_type` method call in `_resolve_bdm` method.
Add missing param `ignore_missing` in `volume_type_get` of `cinder_v2` driver

Closes-bug: #2048726
Depends-On: https://review.opendev.org/c/openstack/senlin/+/905555
Change-Id: I667e2bf1ae5dbabbb9e75d59f10c56b4a355cb44
This commit is contained in:
Pham Le Gia Dai 2024-01-09 13:32:42 +07:00
parent 29f2e885e7
commit 3aa3959e08
5 changed files with 33 additions and 15 deletions

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixed a bug where exception raised in the `_resolve_bdm` method of the
`senlin.profile.os.nova.server` profile would cause cluster cannot create
new nodes.

View File

@ -50,8 +50,9 @@ class CinderClient(base.DriverBase):
return self.conn.block_store.get_snapshot(snapshot)
@sdk.translate_exception
def volume_type_get(self, volume_type):
return self.conn.block_store.get_type(volume_type)
def volume_type_get(self, volume_type, ignore_missing=True):
return self.conn.block_store.find_type(volume_type,
ignore_missing=ignore_missing)
@sdk.translate_exception
def volume_type_create(self, **attr):

View File

@ -508,8 +508,9 @@ class ServerProfile(base.Profile):
if bd[key] is None:
del bd[key]
if 'volume_type' in bd:
bd['volume_type'] = self._validate_volume_type(
bd['volume_type'])
volume_type = self._validate_volume_type(obj,
bd['volume_type'])
bd['volume_type'] = volume_type.name
if 'uuid' in bd and 'source_type' in bd:
if bd['source_type'] == 'image':
self._validate_image(obj, bd['uuid'], reason)
@ -1104,7 +1105,7 @@ class ServerProfile(base.Profile):
"""Check if there is a new name to be assigned to the server.
:param obj: The node object to operate on.
:param new_profile: The new profile which may contain a name for
:param profile: The new profile which may contain a name for
the server instance.
:return: A tuple consisting a boolean indicating whether the name
needs change and the server name determined.
@ -1185,8 +1186,6 @@ class ServerProfile(base.Profile):
"""Update server flavor.
:param obj: The node object to operate on.
:param old_flavor: The identity of the current flavor.
:param new_flavor: The identity of the new flavor.
:returns: Returns true if the flavor was updated or false otherwise.
:raises: `EResourceUpdate` when operation was a failure.
"""
@ -1347,7 +1346,7 @@ class ServerProfile(base.Profile):
# If network properties didn't contain floating ip,
# then we should better not make a port with floating ip
# as candidate.
if (floating and not floating_network and not floating_ip_address):
if floating and not floating_network and not floating_ip_address:
continue
port_id = net.get(self.PORT, None)
if port_id and p['id'] != port_id:
@ -1412,8 +1411,8 @@ class ServerProfile(base.Profile):
obj.data['internal_ports'] = internal_ports
node_obj.Node.update(self.context, obj.id, {'data': obj.data})
def _nw_compare(self, n1, n2, property):
return n1.get(property, None) == n2.get(property, None)
def _nw_compare(self, n1, n2, attribute):
return n1.get(attribute, None) == n2.get(attribute, None)
def _update_network_update_port(self, obj, networks):
"""Update existing port in network from the node.
@ -1845,7 +1844,7 @@ class ServerProfile(base.Profile):
id=obj.physical_id,
message=str(ex))
if (server is None or server.status != consts.VS_ACTIVE):
if server is None or server.status != consts.VS_ACTIVE:
return False
return True

View File

@ -102,4 +102,5 @@ class TestCinderV2(base.SenlinTestCase):
def test_volume_type_get(self):
self.vo.volume_type_get('foo')
self.volume.get_type.assert_called_once_with('foo')
self.volume.find_type.assert_called_once_with('foo',
ignore_missing=True)

View File

@ -98,8 +98,12 @@ class TestNovaServerBasic(base.SenlinTestCase):
res
)
def _stubout_profile(self, profile, mock_image=False, mock_flavor=False,
mock_keypair=False, mock_net=False):
def _stubout_profile(self, profile,
mock_image=False,
mock_flavor=False,
mock_keypair=False,
mock_net=False,
mock_volume_type=False):
if mock_image:
image = mock.Mock(id='FAKE_IMAGE_ID')
self.patchobject(profile, '_validate_image', return_value=image)
@ -127,6 +131,12 @@ class TestNovaServerBasic(base.SenlinTestCase):
}]
self.patchobject(profile, '_create_ports_from_properties',
return_value=fake_ports)
if mock_volume_type:
fake_volume_type = mock.Mock()
fake_volume_type.id = '588854a9'
fake_volume_type.name = 'FAKE_VOLUME_TYPE'
self.patchobject(profile, '_validate_volume_type',
return_value=fake_volume_type)
def test_do_create(self):
cc = mock.Mock()
@ -656,7 +666,8 @@ class TestNovaServerBasic(base.SenlinTestCase):
profile._computeclient = cc
profile._networkclient = nc
self._stubout_profile(profile, mock_image=True, mock_flavor=True,
mock_keypair=True, mock_net=True)
mock_keypair=True, mock_net=True,
mock_volume_type=True)
mock_zone_info = self.patchobject(profile, '_update_zone_info')
node_obj = mock.Mock(id='NODE_ID', cluster_id='', index=-1, data={})
node_obj.name = None