Add retry to rename func

This change adds a retry to the overall rename operation.  The CI
testing has found a few etag issues from the REST API when this is
invoked and this change will provide some additional retries to ensure
that the overall rename goes through.

Change-Id: Ib68bfb72fd0b755fe065c36153c4dceffc117ebc
Closes-Bug: 1570927
This commit is contained in:
Drew Thorstensen
2016-04-18 22:50:30 -04:00
parent f53ee398e1
commit dd776b9a7d
2 changed files with 14 additions and 4 deletions

View File

@@ -444,16 +444,20 @@ class TestVM(test.TestCase):
self.assertEqual('NewEntry', new_entry)
self.san_lpar_name.assert_called_with(name)
@mock.patch('pypowervm.utils.transaction.entry_transaction')
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper')
def test_rename(self, mock_get_inst):
def test_rename(self, mock_get_inst, mock_entry_transaction):
instance = objects.Instance(**powervm.TEST_INSTANCE)
mock_entry_transaction.side_effect = lambda x: x
entry = mock.Mock()
entry.update.return_value = 'NewEntry'
new_entry = vm.rename(self.apt, 'mock_host_uuid', instance, 'new_name',
entry=entry)
self.assertEqual('new_name', entry.name)
entry.update.assert_called_once_with()
mock_entry_transaction.assert_called_once_with(mock.ANY)
self.assertEqual('NewEntry', new_entry)
self.san_lpar_name.assert_called_with('new_name')
self.san_lpar_name.reset_mock()

View File

@@ -31,6 +31,7 @@ from pypowervm.tasks import power
from pypowervm.tasks import vterm
from pypowervm import util as pvm_util
from pypowervm.utils import lpar_builder as lpar_bldr
from pypowervm.utils import transaction as pvm_trans
from pypowervm.utils import uuid as pvm_uuid
from pypowervm.utils import validation as vldn
from pypowervm.wrappers import base_partition as pvm_bp
@@ -600,12 +601,17 @@ def rename(adapter, host_uuid, instance, name, entry=None):
be fetched.
:returns: The updated LPAR wrapper.
"""
if not entry:
entry = get_instance_wrapper(adapter, instance, host_uuid)
entry.name = pvm_util.sanitize_partition_name_for_api(name)
return entry.update()
hyp_name = pvm_util.sanitize_partition_name_for_api(name)
@pvm_trans.entry_transaction
def _rename(entry):
entry.name = hyp_name
return entry.update()
return _rename(entry)
def dlt_lpar(adapter, lpar_uuid):