~openstack-charmers-next/charms/xenial/glance/trunk

« back to all changes in this revision

Viewing changes to unit_tests/test_glance_utils.py

  • Committer: Alex Kavanagh
  • Date: 2016-06-05 12:57:53 UTC
  • Revision ID: alex@ajkavanagh.co.uk-20160605125753-l5v09hqdx6xuech8
Fix for status-set race - related to bug 1588462

This change fixes the obvious race for a status_set() between
check_optional_interfaces() and assess_status() as the later calls the former
which calls status_set(), returns the status, which is then potentially set
again by the assess_status() function.  This cleans up the code so that only a
single status_set() is performed when calling assess_status().

Change-Id: I06efbcaade8f0c99b5931104e6887d24cb10e35a
Related-Bug:#1588462

Show diffs side-by-side

added added

removed removed

Lines of Context:
295
295
            asf.assert_called_once_with('test-config')
296
296
            callee.assert_called_once_with()
297
297
 
 
298
    @patch.object(utils, 'get_optional_interfaces')
298
299
    @patch.object(utils, 'REQUIRED_INTERFACES')
299
300
    @patch.object(utils, 'services')
300
301
    @patch.object(utils, 'make_assess_status_func')
301
302
    def test_assess_status_func(self,
302
303
                                make_assess_status_func,
303
304
                                services,
304
 
                                REQUIRED_INTERFACES):
 
305
                                REQUIRED_INTERFACES,
 
306
                                get_optional_interfaces):
305
307
        services.return_value = 's1'
 
308
        REQUIRED_INTERFACES.copy.return_value = {'int': ['test 1']}
 
309
        get_optional_interfaces.return_value = {'opt': ['test 2']}
306
310
        utils.assess_status_func('test-config')
307
311
        # ports=None whilst port checks are disabled.
308
312
        make_assess_status_func.assert_called_once_with(
309
 
            'test-config', REQUIRED_INTERFACES,
 
313
            'test-config',
 
314
            {'int': ['test 1'], 'opt': ['test 2']},
310
315
            charm_func=utils.check_optional_relations,
311
316
            services='s1', ports=None)
312
317