summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZane Bitter <zbitter@redhat.com>2016-05-26 13:40:53 -0400
committerZane Bitter <zbitter@redhat.com>2017-05-18 11:20:23 -0400
commitc52fdbb7d68bb0814843f3fec9b2d966239bab40 (patch)
treecc2201eb0615e684402689425462ee2ff1a840b1
parent65339f57ca56113b9b17a57119aac1804269333d (diff)
Corrected max secs for concurrent trans retries
This was most likely meant as a max 2s delay here, not a max 2ms delay. Also includes a related change: when retries for metadata updates are attempted, make sure we do not have a stale value of the atomic_key (otherwise we'll just inevitably hit the ConcurrentTransaction issue). Conflicts: heat/engine/service_software_config.py heat/objects/resource.py Co-Authored-By: Crag Wolfe <cwolfe@redhat.com> Partial-Bug: #1651768 Change-Id: Ie56e0e4ff93633db1f4752859d2b2a9506922911 (cherry picked from commit e37d9fab8fe2e779ae8c0e2311de2601b66c66b6)
Notes
Notes (review): Code-Review+1: Thomas Herve <therve@redhat.com> Code-Review+1: Rico Lin <rico.lin@easystack.cn> Code-Review+2: huangtianhua <huangtianhua@huawei.com> Workflow+1: huangtianhua <huangtianhua@huawei.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 14 Jun 2017 16:10:42 +0000 Reviewed-on: https://review.openstack.org/466008 Project: openstack/heat Branch: refs/heads/stable/newton
-rw-r--r--heat/engine/service_software_config.py1
-rw-r--r--heat/objects/resource.py3
-rw-r--r--heat/tests/engine/service/test_software_config.py35
3 files changed, 23 insertions, 16 deletions
diff --git a/heat/engine/service_software_config.py b/heat/engine/service_software_config.py
index d309393..a32e8f7 100644
--- a/heat/engine/service_software_config.py
+++ b/heat/engine/service_software_config.py
@@ -101,6 +101,7 @@ class SoftwareConfigService(service.Service):
101 rs = db_api.resource_get_by_physical_resource_id(cnxt, server_id) 101 rs = db_api.resource_get_by_physical_resource_id(cnxt, server_id)
102 if not rs: 102 if not rs:
103 return 103 return
104 cnxt.session.refresh(rs)
104 deployments = self.metadata_software_deployments(cnxt, server_id) 105 deployments = self.metadata_software_deployments(cnxt, server_id)
105 md = rs.rsrc_metadata or {} 106 md = rs.rsrc_metadata or {}
106 md['deployments'] = deployments 107 md['deployments'] = deployments
diff --git a/heat/objects/resource.py b/heat/objects/resource.py
index 69cfd51..9ade3eb 100644
--- a/heat/objects/resource.py
+++ b/heat/objects/resource.py
@@ -38,8 +38,9 @@ cfg.CONF.import_opt('encrypt_parameters_and_properties', 'heat.common.config')
38def retry_on_conflict(func): 38def retry_on_conflict(func):
39 def is_conflict(ex): 39 def is_conflict(ex):
40 return isinstance(ex, exception.ConcurrentTransaction) 40 return isinstance(ex, exception.ConcurrentTransaction)
41
41 wrapper = retrying.retry(stop_max_attempt_number=11, 42 wrapper = retrying.retry(stop_max_attempt_number=11,
42 wait_random_min=0.0, wait_random_max=2.0, 43 wait_random_min=0, wait_random_max=2000,
43 retry_on_exception=is_conflict) 44 retry_on_exception=is_conflict)
44 return wrapper(func) 45 return wrapper(func)
45 46
diff --git a/heat/tests/engine/service/test_software_config.py b/heat/tests/engine/service/test_software_config.py
index 6e27d31..0dcb41c 100644
--- a/heat/tests/engine/service/test_software_config.py
+++ b/heat/tests/engine/service/test_software_config.py
@@ -635,8 +635,9 @@ class SoftwareConfigServiceTest(common.HeatTestCase):
635 'deployments': {'deploy': 'this'} 635 'deployments': {'deploy': 'this'}
636 } 636 }
637 637
638 self.engine.software_config._push_metadata_software_deployments( 638 with mock.patch.object(self.ctx.session, 'refresh'):
639 self.ctx, '1234', None) 639 self.engine.software_config._push_metadata_software_deployments(
640 self.ctx, '1234', None)
640 res_upd.assert_called_once_with( 641 res_upd.assert_called_once_with(
641 self.ctx, '1234', {'rsrc_metadata': result_metadata}, 1) 642 self.ctx, '1234', {'rsrc_metadata': result_metadata}, 1)
642 put.side_effect = Exception('Unexpected requests.put') 643 put.side_effect = Exception('Unexpected requests.put')
@@ -660,12 +661,14 @@ class SoftwareConfigServiceTest(common.HeatTestCase):
660 deployments = {'deploy': 'this'} 661 deployments = {'deploy': 'this'}
661 md_sd.return_value = deployments 662 md_sd.return_value = deployments
662 663
663 self.assertRaises( 664 with mock.patch.object(self.ctx.session, 'refresh'):
664 exception.ConcurrentTransaction, 665 f = self.engine.software_config._push_metadata_software_deployments
665 self.engine.software_config._push_metadata_software_deployments, 666 self.assertRaises(
666 self.ctx, 667 exception.ConcurrentTransaction,
667 '1234', 668 f,
668 None) 669 self.ctx,
670 '1234',
671 None)
669 # retry ten times then the final failure 672 # retry ten times then the final failure
670 self.assertEqual(11, res_upd.call_count) 673 self.assertEqual(11, res_upd.call_count)
671 put.assert_not_called() 674 put.assert_not_called()
@@ -695,9 +698,9 @@ class SoftwareConfigServiceTest(common.HeatTestCase):
695 'original': 'metadata', 698 'original': 'metadata',
696 'deployments': {'deploy': 'this'} 699 'deployments': {'deploy': 'this'}
697 } 700 }
698 701 with mock.patch.object(self.ctx.session, 'refresh'):
699 self.engine.software_config._push_metadata_software_deployments( 702 self.engine.software_config._push_metadata_software_deployments(
700 self.ctx, '1234', None) 703 self.ctx, '1234', None)
701 res_upd.assert_called_once_with( 704 res_upd.assert_called_once_with(
702 self.ctx, '1234', {'rsrc_metadata': result_metadata}, 1) 705 self.ctx, '1234', {'rsrc_metadata': result_metadata}, 1)
703 706
@@ -734,8 +737,9 @@ class SoftwareConfigServiceTest(common.HeatTestCase):
734 'deployments': {'deploy': 'this'} 737 'deployments': {'deploy': 'this'}
735 } 738 }
736 739
737 self.engine.software_config._push_metadata_software_deployments( 740 with mock.patch.object(self.ctx.session, 'refresh'):
738 self.ctx, '1234', 'project1') 741 self.engine.software_config._push_metadata_software_deployments(
742 self.ctx, '1234', 'project1')
739 res_upd.assert_called_once_with( 743 res_upd.assert_called_once_with(
740 self.ctx, '1234', {'rsrc_metadata': result_metadata}, 1) 744 self.ctx, '1234', {'rsrc_metadata': result_metadata}, 1)
741 745
@@ -903,8 +907,9 @@ class SoftwareConfigServiceTest(common.HeatTestCase):
903 zaqar_client.queue.return_value = queue 907 zaqar_client.queue.return_value = queue
904 queue.pop.return_value = [mock.Mock(body='ok')] 908 queue.pop.return_value = [mock.Mock(body='ok')]
905 909
906 deployment = self._create_software_deployment( 910 with mock.patch.object(self.ctx.session, 'refresh'):
907 status='IN_PROGRESS', config_id=config['id']) 911 deployment = self._create_software_deployment(
912 status='IN_PROGRESS', config_id=config['id'])
908 913
909 deployment_id = deployment['id'] 914 deployment_id = deployment['id']
910 self.assertEqual( 915 self.assertEqual(