X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2Fhoneycomb%2FHcPersistence.py;h=e1b827f9c9c0f758389c3224e8cb1f87d972bcfc;hp=3bbc52fa911cb48e3f1e0d5ab64f772ac12ad83a;hb=3d279e4d68bbd94024bf739e71c872f18822a65d;hpb=19c91adadd57bfc4e7514993b2a711a826d52e04 diff --git a/resources/libraries/python/honeycomb/HcPersistence.py b/resources/libraries/python/honeycomb/HcPersistence.py index 3bbc52fa91..e1b827f9c9 100644 --- a/resources/libraries/python/honeycomb/HcPersistence.py +++ b/resources/libraries/python/honeycomb/HcPersistence.py @@ -83,3 +83,60 @@ class HcPersistence(object): if ret_code != 0: raise HoneycombError("Failed to modify persistence file on node" " {0}, {1}".format(node, stderr)) + + @staticmethod + def log_persisted_configuration(node): + """Read contents of Honeycomb persistence files and print them to log. + + :param node: Honeycomb node. + :type node: dict + """ + + commands = [ + "cat {0}/config/data.json".format(Const.REMOTE_HC_PERSIST), + "cat {0}/context/data.json".format(Const.REMOTE_HC_PERSIST), + ] + + ssh = SSH() + ssh.connect(node) + for command in commands: + (_, _, _) = ssh.exec_command_sudo(command) + + @staticmethod + def configure_persistence(node, state): + """Enable or disable Honeycomb configuration data persistence. + + :param node: Honeycomb node. + :param state: Enable or Disable. + :type node: dict + :type state: str + :raises ValueError: If the state argument is incorrect. + :raises HoneycombError: If the operation fails. + """ + + state = state.lower() + if state == "enable": + state = "true" + elif state == "disable": + state = "false" + else: + raise ValueError("Unexpected value of state argument:" + " {0} provided. Must be enable or disable." + .format(state)) + + for setting in ("persist-config", "persist-context"): + # find the setting, replace entire line with 'setting: state' + find = '\\"{setting}\\":'.format(setting=setting) + replace = '\\"{setting}\\": \\"{state}\\",'.format( + setting=setting, state=state) + + argument = '"/{0}/c\\ {1}"'.format(find, replace) + path = "{0}/config/honeycomb.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 configuration on " + "node {0}, {1}".format(node, stderr))