def test_strip_el(self): exp_func = 'concat("abc", "def")' exp_var = "hostname" el_func1 = '${concat("abc", "def")}' el_var1 = "${hostname}" el_func2 = '${ concat("abc", "def") }' el_var2 = "${ hostname }" self.assertEqual(el_utils.strip_el(el_func1), exp_func) self.assertEqual(el_utils.strip_el(el_func2), exp_func) self.assertEqual(el_utils.strip_el(el_var1), exp_var) self.assertEqual(el_utils.strip_el(el_var2), exp_var)
def get_host_key(self) -> str: host = self.oozie_node.find("host") if host is None or not host.text: raise Exception("Missing host node in SSH action: {}".format(self.oozie_node)) host_key = el_utils.strip_el(host.text) # the <user> node is formatted like [USER]@[HOST] if host_key in self.props.merged: host_key = self.props.merged[host_key] return host_key
def __init__( self, oozie_node: Element, name: str, trigger_rule: str = TriggerRule.ALL_SUCCESS, params: Dict[str, str] = None, template: str = "ssh.tpl", **kwargs, ): ActionMapper.__init__(self, oozie_node=oozie_node, name=name, trigger_rule=trigger_rule, **kwargs) if params is None: params = {} self.template = template cmd_node = self.oozie_node.find("command") arg_nodes = self.oozie_node.findall("args") if cmd_node is None or not cmd_node.text: raise Exception( "Missing or empty command node in SSH action {}".format( self.oozie_node)) cmd = cmd_node.text args = (x.text if x.text else "" for x in arg_nodes) cmd = " ".join(shlex.quote(x) for x in [cmd, *args]) self.command = el_utils.convert_el_to_jinja(cmd, quote=True) host = self.oozie_node.find("host") if host is None: raise Exception("Missing host node in SSH action: {}".format( self.oozie_node)) host_key = el_utils.strip_el(host.text) # the <user> node is formatted like [USER]@[HOST] if host_key in params: host_key = params[host_key] # Since ariflow separates user and host, we can't use jinja templating. # We must check if it is in params. user_host = host_key.split("@") self.user = user_host[0] self.host = user_host[1]