Moshe | 0bb532c | 2018-02-26 13:39:57 +0200 | [diff] [blame] | 1 | ############################################################################## |
| 2 | # Copyright 2018 EuropeanSoftwareMarketingLtd. |
| 3 | # =================================================================== |
| 4 | # Licensed under the ApacheLicense, Version2.0 (the"License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # software distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | # See the License for the specific language governing permissions and limitations under |
| 12 | # the License |
| 13 | ############################################################################## |
| 14 | # vnftest comment: this is a modified copy of |
| 15 | # yardstick/dispatcher/file.py |
| 16 | |
| 17 | from __future__ import absolute_import |
| 18 | |
| 19 | from vnftest.dispatcher.base import Base as DispatchBase |
| 20 | from vnftest.common import constants as consts |
| 21 | from vnftest.common import utils |
| 22 | |
| 23 | |
| 24 | class FileDispatcher(DispatchBase): |
| 25 | """Dispatcher class for recording data to a file. |
| 26 | """ |
| 27 | |
| 28 | __dispatcher_type__ = "File" |
| 29 | |
| 30 | def __init__(self, conf): |
| 31 | super(FileDispatcher, self).__init__(conf) |
| 32 | self.target = conf['dispatcher_file'].get('file_path', |
| 33 | consts.DEFAULT_OUTPUT_FILE) |
| 34 | |
| 35 | def flush_result_data(self, data): |
| 36 | utils.write_json_to_file(self.target, data) |