Merge lp:~ajkavanagh/charm-helpers/fix-unit-paused-set-functions into lp:charm-helpers

Proposed by Alex Kavanagh
Status: Merged
Merged at revision: 541
Proposed branch: lp:~ajkavanagh/charm-helpers/fix-unit-paused-set-functions
Merge into: lp:charm-helpers
Diff against target: 209 lines (+68/-22)
2 files modified
charmhelpers/contrib/openstack/utils.py (+10/-6)
tests/contrib/openstack/test_openstack_utils.py (+58/-16)
To merge this branch: bzr merge lp:~ajkavanagh/charm-helpers/fix-unit-paused-set-functions
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+288395@code.launchpad.net

Description of the change

Fixes broken *_unit_paused_set() functions in contrib/openstack/utils.py that were merged by mistake.

Also fixes some PEP8 formatting in the utils.py and test_openstack_utils.py files (line lengths).

To post a comment you must log in.
Revision history for this message
Liam Young (gnuoy) wrote :

LGTM, thanks for the fixes

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/contrib/openstack/utils.py'
--- charmhelpers/contrib/openstack/utils.py 2016-03-07 16:44:43 +0000
+++ charmhelpers/contrib/openstack/utils.py 2016-03-08 12:40:42 +0000
@@ -772,7 +772,8 @@
772 os.mkdir(parent_dir)772 os.mkdir(parent_dir)
773773
774 juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch))774 juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch))
775 repo_dir = install_remote(repo, dest=parent_dir, branch=branch, depth=depth)775 repo_dir = install_remote(
776 repo, dest=parent_dir, branch=branch, depth=depth)
776777
777 venv = os.path.join(parent_dir, 'venv')778 venv = os.path.join(parent_dir, 'venv')
778779
@@ -1016,8 +1017,8 @@
1016 # Normal case relation ID exists but no related unit1017 # Normal case relation ID exists but no related unit
1017 # (joining)1018 # (joining)
1018 else:1019 else:
1019 juju_log("{} relations's interface, {}, is related but has "1020 juju_log("{} relations's interface, {}, is related but has"
1020 "no units in the relation."1021 " no units in the relation."
1021 "".format(generic_interface, related_interface),1022 "".format(generic_interface, related_interface),
1022 "INFO")1023 "INFO")
1023 # Related unit exists and data missing on the relation1024 # Related unit exists and data missing on the relation
@@ -1377,7 +1378,8 @@
1377 """Set the unit to a paused state in the local kv() store.1378 """Set the unit to a paused state in the local kv() store.
1378 This does NOT actually pause the unit1379 This does NOT actually pause the unit
1379 """1380 """
1380 with unitdata.HookData()() as kv:1381 with unitdata.HookData()() as t:
1382 kv = t[0]
1381 kv.set('unit-paused', True)1383 kv.set('unit-paused', True)
13821384
13831385
@@ -1386,7 +1388,8 @@
1386 This does NOT actually restart any services - it only clears the1388 This does NOT actually restart any services - it only clears the
1387 local state.1389 local state.
1388 """1390 """
1389 with unitdata.HookData()() as kv:1391 with unitdata.HookData()() as t:
1392 kv = t[0]
1390 kv.set('unit-paused', False)1393 kv.set('unit-paused', False)
13911394
13921395
@@ -1398,7 +1401,8 @@
1398 if it excepts, return False1401 if it excepts, return False
1399 """1402 """
1400 try:1403 try:
1401 with unitdata.HookData()() as kv:1404 with unitdata.HookData()() as t:
1405 kv = t[0]
1402 # transform something truth-y into a Boolean.1406 # transform something truth-y into a Boolean.
1403 return not(not(kv.get('unit-paused')))1407 return not(not(kv.get('unit-paused')))
1404 except:1408 except:
14051409
=== modified file 'tests/contrib/openstack/test_openstack_utils.py'
--- tests/contrib/openstack/test_openstack_utils.py 2016-03-02 13:55:54 +0000
+++ tests/contrib/openstack/test_openstack_utils.py 2016-03-08 12:40:42 +0000
@@ -2,6 +2,7 @@
2import os2import os
3import subprocess3import subprocess
4import tempfile4import tempfile
5import contextlib
5import unittest6import unittest
6from copy import copy7from copy import copy
7from testtools import TestCase8from testtools import TestCase
@@ -196,8 +197,9 @@
196 self.assertEquals(openstack.get_os_codename_install_source('distro'),197 self.assertEquals(openstack.get_os_codename_install_source('distro'),
197 'essex')198 'essex')
198 # proposed pocket199 # proposed pocket
199 self.assertEquals(openstack.get_os_codename_install_source('distro-proposed'),200 self.assertEquals(openstack.get_os_codename_install_source(
200 'essex')201 'distro-proposed'),
202 'essex')
201203
202 # various cloud archive pockets204 # various cloud archive pockets
203 src = 'cloud:precise-grizzly'205 src = 'cloud:precise-grizzly'
@@ -777,7 +779,8 @@
777 repository: 'git://git.openstack.org/openstack/requirements',779 repository: 'git://git.openstack.org/openstack/requirements',
778 branch: stable/juno}"""780 branch: stable/juno}"""
779 openstack.git_clone_and_install(git_wrong_order_1, 'keystone')781 openstack.git_clone_and_install(git_wrong_order_1, 'keystone')
780 error_out.assert_called_with('keystone git repo must be specified last')782 error_out.assert_called_with(
783 'keystone git repo must be specified last')
781784
782 git_wrong_order_2 = """785 git_wrong_order_2 = """
783 repositories:786 repositories:
@@ -785,7 +788,8 @@
785 repository: 'git://git.openstack.org/openstack/keystone',788 repository: 'git://git.openstack.org/openstack/keystone',
786 branch: stable/juno}"""789 branch: stable/juno}"""
787 openstack.git_clone_and_install(git_wrong_order_2, 'keystone')790 openstack.git_clone_and_install(git_wrong_order_2, 'keystone')
788 error_out.assert_called_with('requirements git repo must be specified first')791 error_out.assert_called_with(
792 'requirements git repo must be specified first')
789793
790 @patch('os.path.join')794 @patch('os.path.join')
791 @patch.object(openstack, 'charm_dir')795 @patch.object(openstack, 'charm_dir')
@@ -839,8 +843,8 @@
839 path_exists.return_value = False843 path_exists.return_value = False
840 install_remote.return_value = dest_dir844 install_remote.return_value = dest_dir
841845
842 openstack._git_clone_and_install_single(repo, branch, depth, parent_dir,846 openstack._git_clone_and_install_single(
843 http_proxy, False)847 repo, branch, depth, parent_dir, http_proxy, False)
844 mkdir.assert_called_with(parent_dir)848 mkdir.assert_called_with(parent_dir)
845 install_remote.assert_called_with(repo, dest=parent_dir, depth=1,849 install_remote.assert_called_with(repo, dest=parent_dir, depth=1,
846 branch=branch)850 branch=branch)
@@ -855,10 +859,9 @@
855 @patch.object(openstack, 'install_remote')859 @patch.object(openstack, 'install_remote')
856 @patch.object(openstack, 'pip_install')860 @patch.object(openstack, 'pip_install')
857 @patch.object(openstack, '_git_update_requirements')861 @patch.object(openstack, '_git_update_requirements')
858 def test_git_clone_and_install_single_with_update(self, _git_update_reqs,862 def test_git_clone_and_install_single_with_update(
859 pip_install,863 self, _git_update_reqs, pip_install, install_remote, log,
860 install_remote, log,864 path_exists, mkdir, join):
861 path_exists, mkdir, join):
862 repo = 'git://git.openstack.org/openstack/requirements.git'865 repo = 'git://git.openstack.org/openstack/requirements.git'
863 branch = 'master'866 branch = 'master'
864 depth = 1867 depth = 1
@@ -872,8 +875,8 @@
872 path_exists.return_value = False875 path_exists.return_value = False
873 install_remote.return_value = dest_dir876 install_remote.return_value = dest_dir
874877
875 openstack._git_clone_and_install_single(repo, branch, depth, parent_dir,878 openstack._git_clone_and_install_single(
876 http_proxy, True)879 repo, branch, depth, parent_dir, http_proxy, True)
877 mkdir.assert_called_with(parent_dir)880 mkdir.assert_called_with(parent_dir)
878 install_remote.assert_called_with(repo, dest=parent_dir, depth=1,881 install_remote.assert_called_with(repo, dest=parent_dir, depth=1,
879 branch=branch)882 branch=branch)
@@ -914,7 +917,8 @@
914 'identity': ['identity-service']}917 'identity': ['identity-service']}
915 expected_result = 'identity'918 expected_result = 'identity'
916919
917 result = openstack.incomplete_relation_data(configs, required_interfaces)920 result = openstack.incomplete_relation_data(
921 configs, required_interfaces)
918 self.assertTrue(expected_result in result.keys())922 self.assertTrue(expected_result in result.keys())
919923
920 @patch.object(openstack, 'juju_log')924 @patch.object(openstack, 'juju_log')
@@ -1431,6 +1435,43 @@
1431 'Services should be paused but these ports '1435 'Services should be paused but these ports '
1432 'which should be closed, but are open: 60')1436 'which should be closed, but are open: 60')
14331437
1438 @staticmethod
1439 def _unit_paused_helper(hook_data_mock):
1440 # HookData()() returns a tuple (kv, delta_config, delta_relation)
1441 # but we only want kv in the test.
1442 kv = MagicMock()
1443
1444 @contextlib.contextmanager
1445 def hook_data__call__():
1446 yield (kv, True, False)
1447
1448 hook_data__call__.return_value = (kv, True, False)
1449 hook_data_mock.return_value = hook_data__call__
1450 return kv
1451
1452 @patch('charmhelpers.contrib.openstack.utils.unitdata.HookData')
1453 def test_set_unit_paused(self, hook_data):
1454 kv = self._unit_paused_helper(hook_data)
1455 openstack.set_unit_paused()
1456 kv.set.assert_called_once_with('unit-paused', True)
1457
1458 @patch('charmhelpers.contrib.openstack.utils.unitdata.HookData')
1459 def test_clear_unit_paused(self, hook_data):
1460 kv = self._unit_paused_helper(hook_data)
1461 openstack.clear_unit_paused()
1462 kv.set.assert_called_once_with('unit-paused', False)
1463
1464 @patch('charmhelpers.contrib.openstack.utils.unitdata.HookData')
1465 def test_is_unit_paused_set(self, hook_data):
1466 kv = self._unit_paused_helper(hook_data)
1467 kv.get.return_value = True
1468 r = openstack.is_unit_paused_set()
1469 kv.get.assert_called_once_with('unit-paused')
1470 self.assertEquals(r, True)
1471 kv.get.return_value = False
1472 r = openstack.is_unit_paused_set()
1473 self.assertEquals(r, False)
1474
1434 @patch('charmhelpers.contrib.openstack.utils.service_pause')1475 @patch('charmhelpers.contrib.openstack.utils.service_pause')
1435 @patch('charmhelpers.contrib.openstack.utils.set_unit_paused')1476 @patch('charmhelpers.contrib.openstack.utils.set_unit_paused')
1436 def test_pause_unit_okay(self, set_unit_paused, service_pause):1477 def test_pause_unit_okay(self, set_unit_paused, service_pause):
@@ -1507,7 +1548,8 @@
15071548
1508 @patch('charmhelpers.contrib.openstack.utils.service_resume')1549 @patch('charmhelpers.contrib.openstack.utils.service_resume')
1509 @patch('charmhelpers.contrib.openstack.utils.clear_unit_paused')1550 @patch('charmhelpers.contrib.openstack.utils.clear_unit_paused')
1510 def test_resume_unit_service_fails(self, clear_unit_paused, service_resume):1551 def test_resume_unit_service_fails(
1552 self, clear_unit_paused, service_resume):
1511 services = ['service1', 'service2']1553 services = ['service1', 'service2']
1512 service_resume.side_effect = [True, True]1554 service_resume.side_effect = [True, True]
1513 openstack.resume_unit(None, services=services)1555 openstack.resume_unit(None, services=services)
@@ -1519,8 +1561,8 @@
1519 openstack.resume_unit(None, services=services)1561 openstack.resume_unit(None, services=services)
1520 raise Exception("resume_unit should have raised Exception")1562 raise Exception("resume_unit should have raised Exception")
1521 except Exception as e:1563 except Exception as e:
1522 self.assertEquals(e.args[0],1564 self.assertEquals(
1523 "Couldn't resume: service2 didn't start cleanly.")1565 e.args[0], "Couldn't resume: service2 didn't start cleanly.")
15241566
1525 @patch('charmhelpers.contrib.openstack.utils.service_resume')1567 @patch('charmhelpers.contrib.openstack.utils.service_resume')
1526 @patch('charmhelpers.contrib.openstack.utils.clear_unit_paused')1568 @patch('charmhelpers.contrib.openstack.utils.clear_unit_paused')

Subscribers

People subscribed via source and target branches