PageRenderTime 196ms CodeModel.GetById 18ms RepoModel.GetById 2ms app.codeStats 0ms

/master/buildbot/test/unit/test_steps_shellsequence.py

https://gitlab.com/murder187ss/buildbot
Python | 149 lines | 117 code | 17 blank | 15 comment | 1 complexity | 42513402be69d9e63afa1e14ea45c889 MD5 | raw file
  1. # This file is part of Buildbot. Buildbot is free software: you can
  2. # redistribute it and/or modify it under the terms of the GNU General Public
  3. # License as published by the Free Software Foundation, version 2.
  4. #
  5. # This program is distributed in the hope that it will be useful, but WITHOUT
  6. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  7. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  8. # details.
  9. #
  10. # You should have received a copy of the GNU General Public License along with
  11. # this program; if not, write to the Free Software Foundation, Inc., 51
  12. # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  13. #
  14. # Copyright Buildbot Team Members
  15. from twisted.trial import unittest
  16. from buildbot.process.properties import WithProperties
  17. from buildbot.process.results import EXCEPTION
  18. from buildbot.process.results import FAILURE
  19. from buildbot.process.results import SUCCESS
  20. from buildbot.process.results import WARNINGS
  21. from buildbot.steps import shellsequence
  22. from buildbot.test.fake.remotecommand import Expect
  23. from buildbot.test.fake.remotecommand import ExpectShell
  24. from buildbot.test.util import config as configmixin
  25. from buildbot.test.util import steps
  26. class DynamicRun(shellsequence.ShellSequence):
  27. def run(self):
  28. return self.runShellSequence(self.dynamicCommands)
  29. class TestOneShellCommand(steps.BuildStepMixin, unittest.TestCase, configmixin.ConfigErrorsMixin):
  30. def setUp(self):
  31. return self.setUpBuildStep()
  32. def tearDown(self):
  33. return self.tearDownBuildStep()
  34. def testShellArgInput(self):
  35. self.assertRaisesConfigError(
  36. "the 'command' parameter of ShellArg must not be None",
  37. lambda: shellsequence.ShellArg(command=None))
  38. arg1 = shellsequence.ShellArg(command=1)
  39. self.assertRaisesConfigError(
  40. "1 is an invalid command, it must be a string or a list",
  41. lambda: arg1.validateAttributes())
  42. arg2 = shellsequence.ShellArg(command=["make", 1])
  43. self.assertRaisesConfigError(
  44. "['make', 1] must only have strings in it",
  45. lambda: arg2.validateAttributes())
  46. for goodcmd in ["make p1", ["make", "p1"]]:
  47. arg = shellsequence.ShellArg(command=goodcmd)
  48. arg.validateAttributes()
  49. def testShellArgsAreRendered(self):
  50. arg1 = shellsequence.ShellArg(command=WithProperties('make %s', 'project'),
  51. logfile=WithProperties('make %s', 'project'))
  52. self.setupStep(
  53. shellsequence.ShellSequence(commands=[arg1],
  54. workdir='build'))
  55. self.properties.setProperty("project", "BUILDBOT-TEST", "TEST")
  56. self.expectCommands(ExpectShell(workdir='build', command='make BUILDBOT-TEST',
  57. usePTY="slave-config")
  58. + 0 + Expect.log('stdio make BUILDBOT-TEST'))
  59. # TODO: need to factor command-summary stuff into a utility method and use it here
  60. self.expectOutcome(result=SUCCESS, state_string="'make BUILDBOT-TEST'")
  61. return self.runStep()
  62. def createDynamicRun(self, commands):
  63. DynamicRun.dynamicCommands = commands
  64. return DynamicRun()
  65. def testSanityChecksAreDoneInRuntimeWhenDynamicCmdIsNone(self):
  66. self.setupStep(self.createDynamicRun(None))
  67. self.expectOutcome(result=EXCEPTION,
  68. state_string="finished (exception)")
  69. return self.runStep()
  70. def testSanityChecksAreDoneInRuntimeWhenDynamicCmdIsString(self):
  71. self.setupStep(self.createDynamicRun(["one command"]))
  72. self.expectOutcome(result=EXCEPTION,
  73. state_string='finished (exception)')
  74. return self.runStep()
  75. def testSanityChecksAreDoneInRuntimeWhenDynamicCmdIsInvalidShellArg(self):
  76. self.setupStep(self.createDynamicRun([shellsequence.ShellArg(command=1)]))
  77. self.expectOutcome(result=EXCEPTION,
  78. state_string='finished (exception)')
  79. return self.runStep()
  80. def testMultipleCommandsAreRun(self):
  81. arg1 = shellsequence.ShellArg(command='make p1')
  82. arg2 = shellsequence.ShellArg(command='deploy p1', logfile='deploy')
  83. self.setupStep(
  84. shellsequence.ShellSequence(commands=[arg1, arg2],
  85. workdir='build'))
  86. self.expectCommands(ExpectShell(workdir='build', command='make p1',
  87. usePTY="slave-config") + 0,
  88. ExpectShell(workdir='build', command='deploy p1',
  89. usePTY="slave-config") + 0 +
  90. Expect.log('stdio deploy p1'))
  91. self.expectOutcome(result=SUCCESS, state_string="'deploy p1'")
  92. return self.runStep()
  93. def testSkipWorks(self):
  94. arg1 = shellsequence.ShellArg(command='make p1')
  95. arg2 = shellsequence.ShellArg(command='')
  96. arg3 = shellsequence.ShellArg(command='deploy p1')
  97. self.setupStep(
  98. shellsequence.ShellSequence(commands=[arg1, arg2, arg3],
  99. workdir='build'))
  100. self.expectCommands(ExpectShell(workdir='build', command='make p1',
  101. usePTY="slave-config") + 0,
  102. ExpectShell(workdir='build', command='deploy p1',
  103. usePTY="slave-config") + 0)
  104. self.expectOutcome(result=SUCCESS, state_string="'deploy p1'")
  105. return self.runStep()
  106. def testWarningWins(self):
  107. arg1 = shellsequence.ShellArg(command='make p1',
  108. warnOnFailure=True,
  109. flunkOnFailure=False)
  110. arg2 = shellsequence.ShellArg(command='deploy p1')
  111. self.setupStep(
  112. shellsequence.ShellSequence(commands=[arg1, arg2],
  113. workdir='build'))
  114. self.expectCommands(ExpectShell(workdir='build', command='make p1',
  115. usePTY="slave-config") + 1,
  116. ExpectShell(workdir='build', command='deploy p1',
  117. usePTY="slave-config") + 0)
  118. self.expectOutcome(result=WARNINGS, state_string="'deploy p1'")
  119. return self.runStep()
  120. def testSequenceStopsOnHaltOnFailure(self):
  121. arg1 = shellsequence.ShellArg(command='make p1', haltOnFailure=True)
  122. arg2 = shellsequence.ShellArg(command='deploy p1')
  123. self.setupStep(
  124. shellsequence.ShellSequence(commands=[arg1, arg2],
  125. workdir='build'))
  126. self.expectCommands(ExpectShell(workdir='build', command='make p1',
  127. usePTY="slave-config") + 1)
  128. self.expectOutcome(result=FAILURE, state_string="'make p1'")
  129. return self.runStep()