Skip to content

Commit

Permalink
Add command to apply all hotfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeprag committed Oct 25, 2018
1 parent 4bffbb4 commit 22b1aab
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions upgrade/upgrade/UpgradeManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ def apply(self, name):
self.reboot()
return True

def applyAll(self):
for name, hotfix in self.list().items():
if hotfix['applied']:
continue
if hotfix['deployment'] != 'auto':
continue
yield name
self.apply(name)

def clearCache(self):
self.hotfixes = None

Expand Down Expand Up @@ -459,6 +468,10 @@ def runCli():
sys.stdout.write('%s %s\n' % ('*' if hfix['applied'] else ' ', hotfixName))
sys.stdout.flush()
sys.exit(0)
if hotfix == 'all':
for hotfixName in hotfixManager.applyAll():
logging.warning('Applying %s', hotfixName)
sys.exit(0)
if hotfix not in hotfixManager.list():
logging.error('Hotfix %s not found', hotfix)
sys.exit(1)
Expand Down
18 changes: 18 additions & 0 deletions upgrade/upgrade/tests/UpgradeManagerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ def testApply(self):
with open('/tmp/tests/helloworld', 'r') as fd:
self.assertEqual(fd.read(), 'Hello World!\n')

@patch.object(UpgradeManagerBase, 'reboot', reboot)
def testApplyAll(self):
autoHotfixes = ['default', 'deployAuto']
manualHotfixes = ['deployMalformed', 'deployManual', 'helloworld']
failedHotfixes = ['invalidSignature', 'scriptFailing']

self.assertEqual(self.hotfixManager.appliedHotfixes, [])
with self.assertRaises(RebootException):
for name in self.hotfixManager.applyAll():
# No manual hotfix may be applied
self.assertNotIn(name, manualHotfixes)
for name in autoHotfixes:
# Make sure all auto has been appled
self.assertIn(name, self.hotfixManager.appliedHotfixes)
for name in failedHotfixes:
# Make sure no failed has been marked as applied
self.assertNotIn(name, self.hotfixManager.appliedHotfixes)

def testDeployment(self):
self.assertEqual(self.__getHotFix('default')['deployment'], 'auto')
self.assertEqual(self.__getHotFix('deployAuto')['deployment'], 'auto')
Expand Down

0 comments on commit 22b1aab

Please sign in to comment.