def test_template_imports(self):
     """
 Testing Template additional imports
 """
     try:
         with Environment("/base") as env:
             template = InlineTemplate(
                 "{{test_arg1}} template content {{os.path.join(path[0],path[1])}}",
                 [],
                 test_arg1="test",
                 path=["/one", "two"],
             )
             content = template.get_content()
             self.fail("Template.get_content should fail when evaluating unknown import")
     except UndefinedError:
         pass
     with Environment("/base") as env:
         template = InlineTemplate(
             "{{test_arg1}} template content {{os.path.join(path[0],path[1])}}",
             [os],
             test_arg1="test",
             path=["/one", "two"],
         )
         content = template.get_content()
     self.assertEqual(u"test template content /one/two\n", content)
  def action_create(self):
    with Environment.get_instance_copy() as env:
      repo_file_name = self.resource.repo_file_name
      repo_dir = get_repo_dir()
      new_content = InlineTemplate(self.resource.repo_template, repo_id=self.resource.repo_id, repo_file_name=self.resource.repo_file_name,
                             base_url=self.resource.base_url, mirror_list=self.resource.mirror_list)
      repo_file_path = format("{repo_dir}/{repo_file_name}.repo")

      if os.path.isfile(repo_file_path):
        existing_content_str = sudo.read_file(repo_file_path)
        new_content_str = new_content.get_content()
        if existing_content_str != new_content_str and OSCheck.is_suse_family():
          # We need to reset package manager's cache when we replace base urls
          # at existing repo. That is a case at least under SLES
          Logger.info("Flushing package manager cache since repo file content is about to change")
          checked_call(self.update_cmd, sudo=True)
        if self.resource.append_to_file:
          content = existing_content_str + '\n' + new_content_str
        else:
          content = new_content_str
      else: # If repo file does not exist yet
        content = new_content

      File(repo_file_path,
           content=content
      )
  def _expand_hadoop_classpath_prefix(self, hadoop_classpath_prefix_template, configurations):
    import resource_management

    hadoop_classpath_prefix_obj = InlineTemplate(hadoop_classpath_prefix_template, configurations_dict=configurations,
                                                 extra_imports=[resource_management, resource_management.core,
                                                                resource_management.core.source])
    hadoop_classpath_prefix = hadoop_classpath_prefix_obj.get_content()
    return hadoop_classpath_prefix
Example #4
0
  def test_inline_template(self):
    """
    Testing InlineTemplate
    """
    with Environment("/base") as env:
      template = InlineTemplate("{{test_arg1}} template content", [], test_arg1 = "test")
      content = template.get_content()

    self.assertEqual(u'test template content\n', content)
class DummyTemplate(object):

  def __init__(self, name, extra_imports=[], **kwargs):
    self._template = InlineTemplate(DummyTemplate._inline_text, extra_imports, **kwargs)
    self.context = self._template.context
    self.name = name

  def get_content(self):
    self.content = self._template.get_content()
    return self.content

  @classmethod
  def create(cls, text):
    cls._inline_text = text
    return cls
 def __init__(self, name, extra_imports=[], **kwargs):
   self._template = InlineTemplate(DummyTemplate._inline_text, extra_imports, **kwargs)
   self.context = self._template.context
   self.name = name
Example #7
0
    def configure(self, env):
        import params
        import status_params
        env.set_params(params)
        env.set_params(status_params)
        self.create_zeppelin_log_dir(env)
        self.create_zeppelin_notebook_dir(env)

        # create the pid and zeppelin dirs
        Directory([params.zeppelin_pid_dir, params.zeppelin_dir],
                  owner=params.zeppelin_user,
                  group=params.zeppelin_group,
                  cd_access="a",
                  create_parents=True,
                  mode=0755)
        self.chown_zeppelin_pid_dir(env)

        XmlConfig(
            "zeppelin-site.xml",
            conf_dir=params.conf_dir,
            configurations=params.config['configurations']['zeppelin-site'],
            owner=params.zeppelin_user,
            group=params.zeppelin_group)
        # write out zeppelin-env.sh
        env_content = InlineTemplate(params.zeppelin_env_content)
        File(format("{params.conf_dir}/zeppelin-env.sh"),
             content=env_content,
             owner=params.zeppelin_user,
             group=params.zeppelin_group)

        # write out shiro.ini
        shiro_ini_content = InlineTemplate(params.shiro_ini_content)
        File(format("{params.conf_dir}/shiro.ini"),
             content=shiro_ini_content,
             owner=params.zeppelin_user,
             group=params.zeppelin_group)

        # write out log4j.properties
        File(format("{params.conf_dir}/log4j.properties"),
             content=params.log4j_properties_content,
             owner=params.zeppelin_user,
             group=params.zeppelin_group)

        self.create_zeppelin_hdfs_conf_dir(env)

        generate_logfeeder_input_config(
            'zeppelin',
            Template("input.config-zeppelin.json.j2", extra_imports=[default]))

        if len(params.hbase_master_hosts) > 0 and params.is_hbase_installed:
            # copy hbase-site.xml
            XmlConfig(
                "hbase-site.xml",
                conf_dir=params.external_dependency_conf,
                configurations=params.config['configurations']['hbase-site'],
                configuration_attributes=params.
                config['configurationAttributes']['hbase-site'],
                owner=params.zeppelin_user,
                group=params.zeppelin_group,
                mode=0644)

            XmlConfig(
                "hdfs-site.xml",
                conf_dir=params.external_dependency_conf,
                configurations=params.config['configurations']['hdfs-site'],
                configuration_attributes=params.
                config['configurationAttributes']['hdfs-site'],
                owner=params.zeppelin_user,
                group=params.zeppelin_group,
                mode=0644)

            XmlConfig(
                "core-site.xml",
                conf_dir=params.external_dependency_conf,
                configurations=params.config['configurations']['core-site'],
                configuration_attributes=params.
                config['configurationAttributes']['core-site'],
                owner=params.zeppelin_user,
                group=params.zeppelin_group,
                mode=0644,
                xml_include_file=params.
                mount_table_xml_inclusion_file_full_path)

            if params.mount_table_content:
                File(params.mount_table_xml_inclusion_file_full_path,
                     owner=params.zeppelin_user,
                     group=params.zeppelin_group,
                     content=params.mount_table_content,
                     mode=0644)