You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ao...@apache.org on 2015/05/18 18:09:02 UTC
ambari git commit: AMBARI-11214. Duplicate repo_suse_rhel.j2
templates (aonishuk)
Repository: ambari
Updated Branches:
refs/heads/trunk 2dd80b903 -> 49ecd6b2e
AMBARI-11214. Duplicate repo_suse_rhel.j2 templates (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/49ecd6b2
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/49ecd6b2
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/49ecd6b2
Branch: refs/heads/trunk
Commit: 49ecd6b2e9ad872a47324960150157e6d928e17f
Parents: 2dd80b9
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Mon May 18 19:08:50 2015 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Mon May 18 19:08:50 2015 +0300
----------------------------------------------------------------------
.../TestRepositoryResource.py | 143 ++++++++++---------
.../libraries/data/repo_suse_rhel.j2 | 8 ++
.../libraries/data/repo_ubuntu.j2 | 1 +
.../libraries/providers/repository.py | 7 +-
.../custom_actions/templates/repo_suse_rhel.j2 | 8 --
.../custom_actions/templates/repo_ubuntu.j2 | 1 -
.../before-INSTALL/templates/repo_suse_rhel.j2 | 7 -
.../before-INSTALL/templates/repo_ubuntu.j2 | 1 -
8 files changed, 88 insertions(+), 88 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/49ecd6b2/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py b/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
index c31cc20..0a849f3 100644
--- a/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
+++ b/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]
http://git-wip-us.apache.org/repos/asf/ambari/blob/49ecd6b2/ambari-common/src/main/python/resource_management/libraries/data/repo_suse_rhel.j2
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/data/repo_suse_rhel.j2 b/ambari-common/src/main/python/resource_management/libraries/data/repo_suse_rhel.j2
new file mode 100644
index 0000000..1cb687f
--- /dev/null
+++ b/ambari-common/src/main/python/resource_management/libraries/data/repo_suse_rhel.j2
@@ -0,0 +1,8 @@
+[{{repo_id}}]
+name={{repo_id}}
+{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}
+
+path=/
+enabled=1
+gpgcheck=0
+
http://git-wip-us.apache.org/repos/asf/ambari/blob/49ecd6b2/ambari-common/src/main/python/resource_management/libraries/data/repo_ubuntu.j2
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/data/repo_ubuntu.j2 b/ambari-common/src/main/python/resource_management/libraries/data/repo_ubuntu.j2
new file mode 100644
index 0000000..52d4c9a
--- /dev/null
+++ b/ambari-common/src/main/python/resource_management/libraries/data/repo_ubuntu.j2
@@ -0,0 +1 @@
+{{package_type}} {{base_url}} {{components}}
http://git-wip-us.apache.org/repos/asf/ambari/blob/49ecd6b2/ambari-common/src/main/python/resource_management/libraries/providers/repository.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/providers/repository.py b/ambari-common/src/main/python/resource_management/libraries/providers/repository.py
index 85ad83e..139cd68 100644
--- a/ambari-common/src/main/python/resource_management/libraries/providers/repository.py
+++ b/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 = ''
http://git-wip-us.apache.org/repos/asf/ambari/blob/49ecd6b2/ambari-server/src/main/resources/custom_actions/templates/repo_suse_rhel.j2
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_actions/templates/repo_suse_rhel.j2 b/ambari-server/src/main/resources/custom_actions/templates/repo_suse_rhel.j2
deleted file mode 100644
index 1cb687f..0000000
--- a/ambari-server/src/main/resources/custom_actions/templates/repo_suse_rhel.j2
+++ /dev/null
@@ -1,8 +0,0 @@
-[{{repo_id}}]
-name={{repo_id}}
-{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}
-
-path=/
-enabled=1
-gpgcheck=0
-
http://git-wip-us.apache.org/repos/asf/ambari/blob/49ecd6b2/ambari-server/src/main/resources/custom_actions/templates/repo_ubuntu.j2
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_actions/templates/repo_ubuntu.j2 b/ambari-server/src/main/resources/custom_actions/templates/repo_ubuntu.j2
deleted file mode 100644
index 52d4c9a..0000000
--- a/ambari-server/src/main/resources/custom_actions/templates/repo_ubuntu.j2
+++ /dev/null
@@ -1 +0,0 @@
-{{package_type}} {{base_url}} {{components}}
http://git-wip-us.apache.org/repos/asf/ambari/blob/49ecd6b2/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_suse_rhel.j2
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_suse_rhel.j2 b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_suse_rhel.j2
deleted file mode 100644
index d486f89..0000000
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_suse_rhel.j2
+++ /dev/null
@@ -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
http://git-wip-us.apache.org/repos/asf/ambari/blob/49ecd6b2/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_ubuntu.j2
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_ubuntu.j2 b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_ubuntu.j2
deleted file mode 100644
index 52d4c9a..0000000
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_ubuntu.j2
+++ /dev/null
@@ -1 +0,0 @@
-{{package_type}} {{base_url}} {{components}}