Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
    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)
Пример #4
0
  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
      )
Пример #5
0
  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
Пример #6
0
  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
Пример #7
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)
Пример #8
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', content)
Пример #9
0
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
Пример #10
0
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
Пример #11
0
 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 self.resource.append_to_file and os.path.isfile(repo_file_path):
       content = sudo.read_file(repo_file_path) + '\n' + new_content.get_content()
     else:
       content = new_content
       
     File(repo_file_path, 
          content=content
     )