Walter A. Boring IV | b725e62 | 2013-07-11 17:21:33 -0700 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # (c) Copyright 2013 Hewlett-Packard Development Company, L.P. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
| 17 | import signal |
| 18 | import sys |
| 19 | |
| 20 | |
| 21 | class StressAction(object): |
| 22 | |
| 23 | def __init__(self, manager, logger): |
| 24 | self.manager = manager |
| 25 | self.logger = logger |
| 26 | self.runs = 0 |
| 27 | |
| 28 | def _shutdown_handler(self, signal, frame): |
| 29 | self.tearDown() |
| 30 | sys.exit(0) |
| 31 | |
| 32 | def setUp(self, **kwargs): |
| 33 | """This method is called before the run method |
| 34 | to help the test initiatlize any structures. |
| 35 | kwargs contains arguments passed in from the |
| 36 | configuration json file. |
| 37 | |
| 38 | setUp doesn't count against the time duration. |
| 39 | """ |
| 40 | self.logger.debug("setUp") |
| 41 | |
| 42 | def tearDown(self): |
| 43 | """This method is called to do any cleanup |
| 44 | after the test is complete. |
| 45 | """ |
| 46 | self.logger.debug("tearDown") |
| 47 | |
| 48 | def execute(self): |
| 49 | """This is the main execution entry point called |
| 50 | by the driver. We register a signal handler to |
| 51 | allow us to gracefull tearDown, and then exit. |
| 52 | We also keep track of how many runs we do. |
| 53 | """ |
| 54 | signal.signal(signal.SIGHUP, self._shutdown_handler) |
| 55 | signal.signal(signal.SIGTERM, self._shutdown_handler) |
| 56 | while True: |
| 57 | self.run() |
| 58 | self.runs = self.runs + 1 |
| 59 | |
| 60 | def run(self): |
| 61 | """This method is where the stress test code runs.""" |
| 62 | raise NotImplemented() |