diff options
author | selias <samelias@cisco.com> | 2016-05-25 17:16:11 +0200 |
---|---|---|
committer | Jan Gelety <jgelety@cisco.com> | 2016-06-07 20:19:50 +0000 |
commit | ce469c1a7d56c2be639e5cecde961c4ef6354fb5 (patch) | |
tree | 617a03045adb8426c59ac2758d5075fb3096d054 /resources/libraries/python/honeycomb/HcPersistence.py | |
parent | 6000b2abc3d6b8bb8ff2941aacf005a04a33be60 (diff) |
Add Honeycomb persistence tests
JIRA: CSIT-121
- add honeycomb persistence test suite
- add keywords used by persistence tests
- add methods for working with Honeycomb persistence files
- make suite setup clear persisted data before Honeycomb startup
Change-Id: Ief61c12b730d58a456566c4683c0091e08a09b56
Signed-off-by: selias <samelias@cisco.com>
Diffstat (limited to 'resources/libraries/python/honeycomb/HcPersistence.py')
-rw-r--r-- | resources/libraries/python/honeycomb/HcPersistence.py | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/resources/libraries/python/honeycomb/HcPersistence.py b/resources/libraries/python/honeycomb/HcPersistence.py new file mode 100644 index 0000000000..adb55f5477 --- /dev/null +++ b/resources/libraries/python/honeycomb/HcPersistence.py @@ -0,0 +1,87 @@ +# Copyright (c) 2016 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Implementation of keywords for managing Honeycomb persistence files.""" + +from robot.api import logger + +from resources.libraries.python.constants import Constants as Const +from resources.libraries.python.honeycomb.HoneycombUtil import HoneycombError +from resources.libraries.python.ssh import SSH +from resources.libraries.python.topology import NodeType + + +class HcPersistence(object): + """Implements keywords for managing Honeycomb persistence files. + + The keywords implemented in this class make possible to: + - find and replace strings in config.json persistence file + """ + + def __init__(self): + pass + + @staticmethod + def clear_persisted_honeycomb_config(*nodes): + """Remove configuration data persisted from last Honeycomb session. + Default configuration will be used instead. + + :param nodes: List of DUTs to execute on. + :type nodes: list + :raises HoneycombError: If persisted configuration could not be removed. + """ + cmd = "rm {0}/etc/opendaylight/honeycomb/*".format( + Const.REMOTE_HC_DIR) + for node in nodes: + if node['type'] == NodeType.DUT: + ssh = SSH() + ssh.connect(node) + (ret_code, _, stderr) = ssh.exec_command_sudo(cmd) + if ret_code != 0: + if "No such file or directory" not in stderr: + raise HoneycombError('Could not clear persisted ' + 'configuration on node {0}, {1}' + .format(node['host'], stderr)) + else: + logger.info("Persistence data was not present on node" + " {0}".format(node['host'])) + else: + logger.info("Persistence files removed on node {0}" + .format(node['host'])) + + @staticmethod + def modify_persistence_files(node, find, replace): + """Searches contents of persistence file config.json for the provided + string, and replaces all occurrences with another string. + + :param node: Honeycomb node. + :param find: Text to find in file. + :param replace: String to replace anything found with. + :type node: dict + :type find: string + :type replace: string + :raises HoneycombError: If persistent configuration couldn't be + modified. + """ + + argument = "\"s/{0}/{1}/g\"".format(find, replace) + path = "{0}/etc/opendaylight/honeycomb/config.json".format( + Const.REMOTE_HC_DIR) + command = "sed -i {0} {1}".format(argument, path) + + ssh = SSH() + ssh.connect(node) + (ret_code, _, stderr) = ssh.exec_command_sudo(command) + if ret_code != 0: + raise HoneycombError("Failed to modify persistence file on node" + " {0}, {1}".format(node, stderr)) |