Browse Source

AMBARI-11214. Duplicate repo_suse_rhel.j2 templates (aonishuk)

Andrew Onishuk 10 years ago
parent
commit
49ecd6b2e9

+ 74 - 69
ambari-agent/src/test/python/resource_management/TestRepositoryResource.py

@@ -43,7 +43,7 @@ class DummyTemplate(object):
 
 DEBIAN_DEFAUTL_TEMPLATE = "{{package_type}} {{base_url}} {{components}}\n"
 RHEL_SUSE_DEFAULT_TEMPLATE ="""[{{repo_id}}]
-name={{repo_file_name}}
+name={{repo_id}}
 {% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}
 
 path=/
@@ -65,31 +65,32 @@ class TestRepositoryResource(TestCase):
         is_suse_family.return_value = False
         with Environment('/') as env:
           with patch.object(repository,"Template", new=DummyTemplate.create(RHEL_SUSE_DEFAULT_TEMPLATE)):
-            Repository('hadoop',
-                       base_url='http://download.base_url.org/rpm/',
-                       mirror_list='https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
-                       repo_file_name='Repository',
-                       repo_template='dummy.j2')
-
-            self.assertTrue('hadoop' in env.resources['Repository'])
-            defined_arguments = env.resources['Repository']['hadoop'].arguments
-            expected_arguments = {'repo_template': 'dummy.j2',
-                                  'base_url': 'http://download.base_url.org/rpm/',
-                                  'mirror_list': 'https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
-                                  'repo_file_name': 'Repository'}
-            expected_template_arguments = {'base_url': 'http://download.base_url.org/rpm/',
-                                  'mirror_list': 'https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
-                                  'repo_file_name': 'Repository'}
-
-            self.assertEqual(defined_arguments, expected_arguments)
-            self.assertEqual(file_mock.call_args[0][0], '/etc/yum.repos.d/Repository.repo')
-
-            template_item = file_mock.call_args[1]['content']
-            template = str(template_item.name)
-            expected_template_arguments.update({'repo_id': 'hadoop'})
-
-            self.assertEqual(expected_template_arguments, template_item.context._dict)
-            self.assertEqual('dummy.j2', template)
+            with patch.object(repository, "__file__", new='/ambari/test/repo/dummy/path/file'):
+              Repository('hadoop',
+                         base_url='http://download.base_url.org/rpm/',
+                         mirror_list='https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
+                         repo_file_name='Repository',
+                         repo_template='dummy.j2')
+
+              self.assertTrue('hadoop' in env.resources['Repository'])
+              defined_arguments = env.resources['Repository']['hadoop'].arguments
+              expected_arguments = {'repo_template': 'dummy.j2',
+                                    'base_url': 'http://download.base_url.org/rpm/',
+                                    'mirror_list': 'https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
+                                    'repo_file_name': 'Repository'}
+              expected_template_arguments = {'base_url': 'http://download.base_url.org/rpm/',
+                                    'mirror_list': 'https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
+                                    'repo_file_name': 'Repository'}
+
+              self.assertEqual(defined_arguments, expected_arguments)
+              self.assertEqual(file_mock.call_args[0][0], '/etc/yum.repos.d/Repository.repo')
+
+              template_item = file_mock.call_args[1]['content']
+              template = str(template_item.name)
+              expected_template_arguments.update({'repo_id': 'hadoop'})
+
+              self.assertEqual(expected_template_arguments, template_item.context._dict)
+              self.assertEqual('/ambari/test/repo/dummy/path/../data/dummy.j2', template)
 
 
     @patch.object(OSCheck, "is_suse_family")
@@ -104,31 +105,32 @@ class TestRepositoryResource(TestCase):
         is_suse_family.return_value = True
         with Environment('/') as env:
           with patch.object(repository,"Template", new=DummyTemplate.create(RHEL_SUSE_DEFAULT_TEMPLATE)):
-            Repository('hadoop',
-                       base_url='http://download.base_url.org/rpm/',
-                       mirror_list='https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
-                       repo_template = "dummy.j2",
-                       repo_file_name='Repository')
-
-            self.assertTrue('hadoop' in env.resources['Repository'])
-            defined_arguments = env.resources['Repository']['hadoop'].arguments
-            expected_arguments = {'repo_template': 'dummy.j2',
-                                  'mirror_list': 'https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
-                                  'base_url': 'http://download.base_url.org/rpm/',
-                                  'repo_file_name': 'Repository'}
-            expected_template_arguments = {'mirror_list': 'https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
-                                  'base_url': 'http://download.base_url.org/rpm/',
-                                  'repo_file_name': 'Repository'}
-
-            self.assertEqual(defined_arguments, expected_arguments)
-            self.assertEqual(file_mock.call_args[0][0], '/etc/zypp/repos.d/Repository.repo')
-
-            template_item = file_mock.call_args[1]['content']
-            template = str(template_item.name)
-            expected_template_arguments.update({'repo_id': 'hadoop'})
-
-            self.assertEqual(expected_template_arguments, template_item.context._dict)
-            self.assertEqual('dummy.j2', template)
+            with patch.object(repository, "__file__", new='/ambari/test/repo/dummy/path/file'):
+              Repository('hadoop',
+                         base_url='http://download.base_url.org/rpm/',
+                         mirror_list='https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
+                         repo_template = "dummy.j2",
+                         repo_file_name='Repository')
+
+              self.assertTrue('hadoop' in env.resources['Repository'])
+              defined_arguments = env.resources['Repository']['hadoop'].arguments
+              expected_arguments = {'repo_template': 'dummy.j2',
+                                    'mirror_list': 'https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
+                                    'base_url': 'http://download.base_url.org/rpm/',
+                                    'repo_file_name': 'Repository'}
+              expected_template_arguments = {'mirror_list': 'https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
+                                    'base_url': 'http://download.base_url.org/rpm/',
+                                    'repo_file_name': 'Repository'}
+
+              self.assertEqual(defined_arguments, expected_arguments)
+              self.assertEqual(file_mock.call_args[0][0], '/etc/zypp/repos.d/Repository.repo')
+
+              template_item = file_mock.call_args[1]['content']
+              template = str(template_item.name)
+              expected_template_arguments.update({'repo_id': 'hadoop'})
+
+              self.assertEqual(expected_template_arguments, template_item.context._dict)
+              self.assertEqual('/ambari/test/repo/dummy/path/../data/dummy.j2', template)
     
     @patch.object(OSCheck, "is_suse_family")
     @patch.object(OSCheck, "is_ubuntu_family")
@@ -152,12 +154,13 @@ class TestRepositoryResource(TestCase):
       
       with Environment('/') as env:
         with patch.object(repository,"Template", new=DummyTemplate.create(DEBIAN_DEFAUTL_TEMPLATE)):
-          Repository('HDP',
-                     base_url='http://download.base_url.org/rpm/',
-                     repo_file_name='HDP',
-                     repo_template = "dummy.j2",
-                     components = ['a','b','c']
-          )
+          with patch.object(repository, "__file__", new='/ambari/test/repo/dummy/path/file'):
+            Repository('HDP',
+                       base_url='http://download.base_url.org/rpm/',
+                       repo_file_name='HDP',
+                       repo_template = "dummy.j2",
+                       components = ['a','b','c']
+            )
 
       call_content = file_mock.call_args_list[0]
       template_name = call_content[0][0]
@@ -193,12 +196,13 @@ class TestRepositoryResource(TestCase):
 
       with Environment('/') as env:
         with patch.object(repository,"Template", new=DummyTemplate.create(DEBIAN_DEFAUTL_TEMPLATE)):
-          Repository('HDP',
-                     base_url='http://download.base_url.org/rpm/',
-                     repo_file_name='HDP',
-                     repo_template = "dummy.j2",
-                     components = ['a','b','c']
-          )
+          with patch.object(repository, "__file__", new='/ambari/test/repo/dummy/path/file'):
+            Repository('HDP',
+                       base_url='http://download.base_url.org/rpm/',
+                       repo_file_name='HDP',
+                       repo_template = "dummy.j2",
+                       components = ['a','b','c']
+            )
 
       call_content = file_mock.call_args_list[0]
       template_name = call_content[0][0]
@@ -227,12 +231,13 @@ class TestRepositoryResource(TestCase):
       
       with Environment('/') as env:
         with patch.object(repository,"Template", new=DummyTemplate.create(DEBIAN_DEFAUTL_TEMPLATE)):
-          Repository('HDP',
-                     base_url='http://download.base_url.org/rpm/',
-                     repo_file_name='HDP',
-                     repo_template = "dummy.j2",
-                     components = ['a','b','c']
-          )
+          with patch.object(repository, "__file__", new='/ambari/test/repo/dummy/path/file'):
+            Repository('HDP',
+                       base_url='http://download.base_url.org/rpm/',
+                       repo_file_name='HDP',
+                       repo_template = "dummy.j2",
+                       components = ['a','b','c']
+            )
 
       call_content = file_mock.call_args_list[0]
       template_name = call_content[0][0]

+ 0 - 0
ambari-server/src/main/resources/custom_actions/templates/repo_suse_rhel.j2 → ambari-common/src/main/python/resource_management/libraries/data/repo_suse_rhel.j2


+ 0 - 0
ambari-server/src/main/resources/custom_actions/templates/repo_ubuntu.j2 → ambari-common/src/main/python/resource_management/libraries/data/repo_ubuntu.j2


+ 5 - 2
ambari-common/src/main/python/resource_management/libraries/providers/repository.py

@@ -34,12 +34,14 @@ from resource_management.core.environment import Environment
 from resource_management.core.shell import checked_call
 import re
 
+REPO_TEMPLATE_FOLDER = 'data'
+
 class RhelSuseRepositoryProvider(Provider):
   def action_create(self):
     with Environment.get_instance_copy() as env:
       repo_file_name = self.resource.repo_file_name
       repo_dir = get_repo_dir()
-      repo_template = self.resource.repo_template
+      repo_template = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', REPO_TEMPLATE_FOLDER, self.resource.repo_template)
       new_content = Template(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")
@@ -76,8 +78,9 @@ class UbuntuRepositoryProvider(Provider):
       with tempfile.NamedTemporaryFile() as tmpf:
         repo_file_name = format("{repo_file_name}.list",repo_file_name = self.resource.repo_file_name)
         repo_file_path = format("{repo_dir}/{repo_file_name}", repo_dir = self.repo_dir)
+        repo_template = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', REPO_TEMPLATE_FOLDER, self.resource.repo_template)
 
-        new_content = Template(self.resource.repo_template, package_type=self.package_type,
+        new_content = Template(repo_template, package_type=self.package_type,
                                       base_url=self.resource.base_url,
                                       components=' '.join(self.resource.components)).get_content()
         old_content = ''

+ 0 - 7
ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_suse_rhel.j2

@@ -1,7 +0,0 @@
-[{{repo_id}}]
-name={{repo_file_name}}
-{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}
-
-path=/
-enabled=1
-gpgcheck=0

+ 0 - 1
ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_ubuntu.j2

@@ -1 +0,0 @@
-{{package_type}} {{base_url}} {{components}}