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 2014/02/20 16:59:34 UTC
git commit: AMBARI-4746. unittest Repository resource (Vitaliy via
aonishuk)
Repository: ambari
Updated Branches:
refs/heads/trunk 34b1ccbf2 -> a864232ed
AMBARI-4746. unittest Repository resource (Vitaliy via aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a864232e
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a864232e
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a864232e
Branch: refs/heads/trunk
Commit: a864232ed6f707e5b909673bd7af6c21f2f3fa97
Parents: 34b1ccb
Author: Andrew Onischuk <ao...@hortonworks.com>
Authored: Thu Feb 20 07:53:36 2014 -0800
Committer: Andrew Onischuk <ao...@hortonworks.com>
Committed: Thu Feb 20 07:53:36 2014 -0800
----------------------------------------------------------------------
.../TestRepositoryResource.py | 131 +++++++++++++++++++
1 file changed, 131 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/a864232e/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
new file mode 100644
index 0000000..35b82ca
--- /dev/null
+++ b/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
@@ -0,0 +1,131 @@
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+'''
+
+from unittest import TestCase
+from mock.mock import patch
+
+from resource_management import *
+from resource_management.libraries.providers.repository \
+ import RepositoryProvider
+from resource_management.libraries.resources.repository \
+ import Repository
+
+
+class TestRepositoryResource(TestCase):
+ @patch.object(System, "os_family", new='redhat')
+ @patch("resource_management.libraries.providers.repository.File")
+ def test_create_repo_redhat(self, file_mock):
+ with Environment('/') as env:
+ 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')
+
+ self.assertTrue('hadoop' in env.resources['Repository'])
+ defined_arguments = env.resources['Repository']['hadoop'].arguments
+ expected_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_arguments.update({'repo_id': 'hadoop'})
+
+ self.assertEqual(expected_arguments, template_item.context._dict)
+ self.assertEqual("""[{{repo_id}}]
+name={{repo_file_name}}
+{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}
+path=/
+enabled=1
+gpgcheck=0""", template)
+
+
+ @patch.object(System, "os_family", new='suse')
+ @patch("resource_management.libraries.providers.repository.File")
+ def test_create_repo_suse(self, file_mock):
+ with Environment('/') as env:
+ 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')
+
+ self.assertTrue('hadoop' in env.resources['Repository'])
+ defined_arguments = env.resources['Repository']['hadoop'].arguments
+ expected_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/zypp/repos.d/Repository.repo')
+
+ template_item = file_mock.call_args[1]['content']
+ template = str(template_item.name)
+ expected_arguments.update({'repo_id': 'hadoop'})
+
+ self.assertEqual(expected_arguments, template_item.context._dict)
+ self.assertEqual("""[{{repo_id}}]
+name={{repo_file_name}}
+{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}
+path=/
+enabled=1
+gpgcheck=0""", template)
+
+
+ @patch.object(System, "os_family", new='redhat')
+ @patch("resource_management.libraries.providers.repository.File")
+ def test_remove_repo_redhat(self, file_mock):
+ with Environment('/') as env:
+ Repository('hadoop',
+ action='remove',
+ base_url='http://download.base_url.org/rpm/',
+ mirror_list='https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
+ repo_file_name='Repository')
+
+ self.assertTrue('hadoop' in env.resources['Repository'])
+ defined_arguments = env.resources['Repository']['hadoop'].arguments
+ expected_arguments = {'action': ['remove'],
+ '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[1]['action'], 'delete')
+ self.assertEqual(file_mock.call_args[0][0], '/etc/yum.repos.d/Repository.repo')
+
+
+ @patch.object(System, "os_family", new='suse')
+ @patch("resource_management.libraries.providers.repository.File")
+ def test_remove_repo_suse(self, file_mock):
+ with Environment('/') as env:
+ Repository('hadoop',
+ action='remove',
+ base_url='http://download.base_url.org/rpm/',
+ mirror_list='https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
+ repo_file_name='Repository')
+
+ self.assertTrue('hadoop' in env.resources['Repository'])
+ defined_arguments = env.resources['Repository']['hadoop'].arguments
+ expected_arguments = {'action': ['remove'],
+ '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[1]['action'], 'delete')
+ self.assertEqual(file_mock.call_args[0][0], '/etc/zypp/repos.d/Repository.repo')