123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730 |
- #!/usr/bin/env python
- '''
- 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 mock.mock import MagicMock, call, patch
- from stacks.utils.RMFTestCase import *
- from resource_management.core import shell
- from resource_management.core.exceptions import Fail
- class TestOozieServer(RMFTestCase):
- COMMON_SERVICES_PACKAGE_DIR = "OOZIE/4.0.0.2.0/package"
- STACK_VERSION = "2.0.6"
- UPGRADE_STACK_VERSION = "2.2"
- def test_configure_default(self):
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer",
- command = "configure",
- config_file="default.json",
- hdp_stack_version = self.STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES
- )
- self.assert_configure_default()
- self.assertNoMoreResources()
- @patch("os.path.isfile")
- def test_start_default(self, isfile_mock):
- isfile_mock.return_value = True
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer",
- command = "start",
- config_file="default.json",
- hdp_stack_version = self.STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES
- )
- self.assert_configure_default()
- self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/ooziedb.sh create -sqlfile oozie.sql -run',
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- ignore_failures = True,
- user = 'oozie',
- )
- self.assertResourceCalled('Execute', ' hadoop --config /etc/hadoop/conf dfs -put /usr/lib/oozie/share /user/oozie ; hadoop --config /etc/hadoop/conf dfs -chmod -R 755 /user/oozie/share',
- not_if = " hadoop --config /etc/hadoop/conf dfs -ls /user/oozie/share | awk 'BEGIN {count=0;} /share/ {count++} END {if (count > 0) {exit 0} else {exit 1}}'",
- user = 'oozie',
- path = ['/usr/bin:/usr/bin'],
- )
- self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-start.sh',
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- user = 'oozie',
- )
- self.assertNoMoreResources()
- def test_stop_default(self):
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer",
- command = "stop",
- config_file="default.json",
- hdp_stack_version = self.STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES
- )
- self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-stop.sh',
- only_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- user = 'oozie',
- )
- self.assertResourceCalled('File', '/var/run/oozie/oozie.pid',
- action = ['delete'],
- )
- self.assertNoMoreResources()
- def test_configure_secured(self):
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer",
- command = "configure",
- config_file="secured.json",
- hdp_stack_version = self.STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES
- )
- self.assert_configure_secured()
- self.assertNoMoreResources()
- @patch("os.path.isfile")
- def test_start_secured(self, isfile_mock):
- isfile_mock.return_value = True
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer",
- command = "start",
- config_file="secured.json",
- hdp_stack_version = self.STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES
- )
- self.assert_configure_secured()
- self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/ooziedb.sh create -sqlfile oozie.sql -run',
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- ignore_failures = True,
- user = 'oozie',
- )
- self.assertResourceCalled('Execute', '/usr/bin/kinit -kt /etc/security/keytabs/oozie.service.keytab oozie/c6402.ambari.apache.org@EXAMPLE.COM; hadoop --config /etc/hadoop/conf dfs -put /usr/lib/oozie/share /user/oozie ; hadoop --config /etc/hadoop/conf dfs -chmod -R 755 /user/oozie/share',
- not_if = "/usr/bin/kinit -kt /etc/security/keytabs/oozie.service.keytab oozie/c6402.ambari.apache.org@EXAMPLE.COM; hadoop --config /etc/hadoop/conf dfs -ls /user/oozie/share | awk 'BEGIN {count=0;} /share/ {count++} END {if (count > 0) {exit 0} else {exit 1}}'",
- user = 'oozie',
- path = ['/usr/bin:/usr/bin'],
- )
- self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-start.sh',
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- user = 'oozie',
- )
- self.assertNoMoreResources()
- def test_stop_secured(self):
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer",
- command = "stop",
- config_file="secured.json",
- hdp_stack_version = self.STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES
- )
- self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-stop.sh',
- only_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- user = 'oozie',
- )
- self.assertResourceCalled('File', '/var/run/oozie/oozie.pid',
- action = ['delete'],
- )
- self.assertNoMoreResources()
- def assert_configure_default(self):
- self.assertResourceCalled('HdfsDirectory', '/user/oozie',
- security_enabled = False,
- keytab = UnknownConfigurationMock(),
- conf_dir = '/etc/hadoop/conf',
- hdfs_user = 'hdfs',
- kinit_path_local = '/usr/bin/kinit',
- mode = 0775,
- owner = 'oozie',
- bin_dir = '/usr/bin',
- action = ['create'],
- )
- self.assertResourceCalled('Directory', '/etc/oozie/conf',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True
- )
- self.assertResourceCalled('XmlConfig', 'oozie-site.xml',
- owner = 'oozie',
- group = 'hadoop',
- mode = 0664,
- conf_dir = '/etc/oozie/conf',
- configurations = self.getConfig()['configurations']['oozie-site'],
- configuration_attributes = self.getConfig()['configuration_attributes']['oozie-site']
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/oozie-env.sh',
- owner = 'oozie',
- content = InlineTemplate(self.getConfig()['configurations']['oozie-env']['content'])
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/oozie-log4j.properties',
- owner = 'oozie',
- group = 'hadoop',
- mode = 0644,
- content = 'log4jproperties\nline2'
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/adminusers.txt',
- owner = 'oozie',
- group = 'hadoop',
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/hadoop-config.xml',
- owner = 'oozie',
- group = 'hadoop',
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/oozie-default.xml',
- owner = 'oozie',
- group = 'hadoop',
- )
- self.assertResourceCalled('Directory', '/etc/oozie/conf/action-conf',
- owner = 'oozie',
- group = 'hadoop',
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/action-conf/hive.xml',
- owner = 'oozie',
- group = 'hadoop',
- )
- self.assertResourceCalled('File', '/var/run/oozie/oozie.pid',
- action=["delete"],
- not_if="ls {pid_file} >/dev/null 2>&1 && !(ps `cat {pid_file}` >/dev/null 2>&1)"
- )
- self.assertResourceCalled('Directory', '/usr/lib/oozie//var/tmp/oozie',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/var/run/oozie',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/var/log/oozie',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/var/tmp/oozie',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/hadoop/oozie/data',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/var/lib/oozie',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/webapps/',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/conf',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/usr/lib/oozie/libext',
- recursive = True,
- )
- self.assertResourceCalled('Execute', ('tar', '-xvf', '/usr/lib/oozie/oozie-sharelib.tar.gz', '-C', '/usr/lib/oozie'),
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- sudo = True,
- )
- self.assertResourceCalled('Execute', ('cp', '/usr/share/HDP-oozie/ext-2.2.zip', '/usr/lib/oozie/libext'),
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- sudo = True,
- )
- self.assertResourceCalled('Execute', ('chown', u'oozie:hadoop', '/usr/lib/oozie/libext/ext-2.2.zip'),
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- sudo = True,
- )
- self.assertResourceCalled('Execute', ('chown', '-RL', u'oozie:hadoop', '/var/lib/oozie/oozie-server/conf'),
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- sudo = True,
- )
- self.assertResourceCalled('Execute', 'ambari-sudo.sh cp /usr/lib/falcon/oozie/ext/falcon-oozie-el-extension-*.jar /usr/lib/oozie/libext',
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- )
- self.assertResourceCalled('Execute', 'ambari-sudo.sh chown oozie:hadoop /usr/lib/oozie/libext/falcon-oozie-el-extension-*.jar',
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- )
- self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war',
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- user = 'oozie',
- )
- def assert_configure_secured(self):
- self.assertResourceCalled('HdfsDirectory', '/user/oozie',
- security_enabled = True,
- keytab = '/etc/security/keytabs/hdfs.headless.keytab',
- conf_dir = '/etc/hadoop/conf',
- hdfs_user = 'hdfs',
- kinit_path_local = '/usr/bin/kinit',
- mode = 0775,
- owner = 'oozie',
- bin_dir = '/usr/bin',
- action = ['create'],
- )
- self.assertResourceCalled('Directory', '/etc/oozie/conf',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True
- )
- self.assertResourceCalled('XmlConfig', 'oozie-site.xml',
- owner = 'oozie',
- group = 'hadoop',
- mode = 0664,
- conf_dir = '/etc/oozie/conf',
- configurations = self.getConfig()['configurations']['oozie-site'],
- configuration_attributes = self.getConfig()['configuration_attributes']['oozie-site']
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/oozie-env.sh',
- owner = 'oozie',
- content = InlineTemplate(self.getConfig()['configurations']['oozie-env']['content'])
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/oozie-log4j.properties',
- owner = 'oozie',
- group = 'hadoop',
- mode = 0644,
- content = 'log4jproperties\nline2'
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/adminusers.txt',
- owner = 'oozie',
- group = 'hadoop',
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/hadoop-config.xml',
- owner = 'oozie',
- group = 'hadoop',
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/oozie-default.xml',
- owner = 'oozie',
- group = 'hadoop',
- )
- self.assertResourceCalled('Directory', '/etc/oozie/conf/action-conf',
- owner = 'oozie',
- group = 'hadoop',
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/action-conf/hive.xml',
- owner = 'oozie',
- group = 'hadoop',
- )
- self.assertResourceCalled('File', '/var/run/oozie/oozie.pid',
- action=["delete"],
- not_if="ls {pid_file} >/dev/null 2>&1 && !(ps `cat {pid_file}` >/dev/null 2>&1)"
- )
- self.assertResourceCalled('Directory', '/usr/lib/oozie//var/tmp/oozie',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/var/run/oozie',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/var/log/oozie',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/var/tmp/oozie',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/hadoop/oozie/data',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/var/lib/oozie',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/webapps/',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/conf',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- cd_access='a'
- )
- self.assertResourceCalled('Directory', '/usr/lib/oozie/libext',
- recursive = True,
- )
- self.assertResourceCalled('Execute', ('tar', '-xvf', '/usr/lib/oozie/oozie-sharelib.tar.gz', '-C', '/usr/lib/oozie'),
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- sudo = True,
- )
- self.assertResourceCalled('Execute', ('cp', '/usr/share/HDP-oozie/ext-2.2.zip', '/usr/lib/oozie/libext'),
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- sudo = True,
- )
- self.assertResourceCalled('Execute', ('chown', u'oozie:hadoop', '/usr/lib/oozie/libext/ext-2.2.zip'),
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- sudo = True,
- )
- self.assertResourceCalled('Execute', ('chown', '-RL', u'oozie:hadoop', '/var/lib/oozie/oozie-server/conf'),
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- sudo = True,
- )
- self.assertResourceCalled('Execute', 'ambari-sudo.sh cp /usr/lib/falcon/oozie/ext/falcon-oozie-el-extension-*.jar /usr/lib/oozie/libext',
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- )
- self.assertResourceCalled('Execute', 'ambari-sudo.sh chown oozie:hadoop /usr/lib/oozie/libext/falcon-oozie-el-extension-*.jar',
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- )
- self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war',
- not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
- user = 'oozie',
- )
- def test_configure_default_hdp22(self):
- config_file = "stacks/2.0.6/configs/default.json"
- with open(config_file, "r") as f:
- default_json = json.load(f)
- default_json['hostLevelParams']['stack_version']= '2.2'
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer",
- command = "configure",
- config_file="default.json",
- hdp_stack_version = self.STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES
- )
- self.assert_configure_default()
- self.assertResourceCalled('Directory', '/etc/oozie/conf/action-conf/hive',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True
- )
- self.assertResourceCalled('XmlConfig', 'hive-site',
- owner = 'oozie',
- group = 'hadoop',
- mode = 0664,
- conf_dir = '/etc/oozie/conf/action-conf/hive',
- configurations = self.getConfig()['configurations']['hive-site'],
- configuration_attributes = self.getConfig()['configuration_attributes']['hive-site']
- )
- self.assertResourceCalled('XmlConfig', 'tez-site',
- owner = 'oozie',
- group = 'hadoop',
- mode = 0664,
- conf_dir = '/etc/oozie/conf/action-conf/hive',
- configurations = self.getConfig()['configurations']['tez-site'],
- configuration_attributes = self.getConfig()['configuration_attributes']['tez-site']
- )
- self.assertNoMoreResources()
- @patch("resource_management.libraries.functions.security_commons.build_expectations")
- @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem")
- @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties")
- @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor")
- @patch("resource_management.libraries.script.Script.put_structured_out")
- def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock):
- # Test that function works when is called with correct parameters
- security_params = {
- "oozie-site": {
- "oozie.authentication.type": "kerberos",
- "oozie.service.AuthorizationService.security.enabled": "true",
- "oozie.service.HadoopAccessorService.kerberos.enabled": "true",
- "local.realm": "EXAMPLE.COM",
- "oozie.authentication.kerberos.principal": "principal",
- "oozie.authentication.kerberos.keytab": "/path/to_keytab",
- "oozie.service.HadoopAccessorService.kerberos.principal": "principal",
- "oozie.service.HadoopAccessorService.keytab.file": "/path/to_keytab"}
- }
- result_issues = []
- props_value_check = {"oozie.authentication.type": "kerberos",
- "oozie.service.AuthorizationService.security.enabled": "true",
- "oozie.service.HadoopAccessorService.kerberos.enabled": "true"}
- props_empty_check = [ "local.realm",
- "oozie.authentication.kerberos.principal",
- "oozie.authentication.kerberos.keytab",
- "oozie.service.HadoopAccessorService.kerberos.principal",
- "oozie.service.HadoopAccessorService.keytab.file"]
- props_read_check = None
- get_params_mock.return_value = security_params
- validate_security_config_mock.return_value = result_issues
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer",
- command = "security_status",
- config_file="secured.json",
- hdp_stack_version = self.STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES
- )
- import status_params
- get_params_mock.assert_called_with(status_params.conf_dir, {'oozie-site.xml': 'XML'})
- build_exp_mock.assert_called_with('oozie-site', props_value_check, props_empty_check, props_read_check)
- put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"})
- self.assertTrue(cached_kinit_executor_mock.call_count, 2)
- cached_kinit_executor_mock.assert_called_with(status_params.kinit_path_local,
- status_params.oozie_user,
- security_params['oozie-site']['oozie.service.HadoopAccessorService.keytab.file'],
- security_params['oozie-site']['oozie.service.HadoopAccessorService.kerberos.principal'],
- status_params.hostname,
- status_params.tmp_dir)
- # Testing that the exception throw by cached_executor is caught
- cached_kinit_executor_mock.reset_mock()
- cached_kinit_executor_mock.side_effect = Exception("Invalid command")
- try:
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer",
- command = "security_status",
- config_file="secured.json",
- hdp_stack_version = self.STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES
- )
- except:
- self.assertTrue(True)
- # Testing with a security_params which doesn't contains oozie-site
- empty_security_params = {}
- cached_kinit_executor_mock.reset_mock()
- get_params_mock.reset_mock()
- put_structured_out_mock.reset_mock()
- get_params_mock.return_value = empty_security_params
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer",
- command = "security_status",
- config_file="secured.json",
- hdp_stack_version = self.STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES
- )
- put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."})
- # Testing with not empty result_issues
- result_issues_with_params = {}
- result_issues_with_params['oozie-site']="Something bad happened"
- validate_security_config_mock.reset_mock()
- get_params_mock.reset_mock()
- validate_security_config_mock.return_value = result_issues_with_params
- get_params_mock.return_value = security_params
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer",
- command = "security_status",
- config_file="secured.json",
- hdp_stack_version = self.STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES
- )
- put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"})
- # Testing with security_enable = false
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer",
- command = "security_status",
- config_file="default.json",
- hdp_stack_version = self.STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES
- )
- put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"})
- @patch("tarfile.open")
- @patch("os.path.isdir")
- @patch("os.path.exists")
- @patch("os.path.isfile")
- @patch("os.remove")
- @patch("os.chmod")
- @patch("shutil.rmtree", new = MagicMock())
- @patch("glob.iglob")
- @patch("shutil.copy", new = MagicMock())
- @patch.object(shell, "call")
- def test_upgrade(self, call_mock, glob_mock, chmod_mock, remove_mock,
- isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
- isdir_mock.return_value = True
- exists_mock.side_effect = [False,False,True]
- isfile_mock.return_value = True
- glob_mock.return_value = ["/usr/hdp/2.2.1.0-2187/hadoop/lib/hadoop-lzo-0.6.0.2.2.1.0-2187.jar"]
- prepare_war_stdout = """INFO: Adding extension: libext/mysql-connector-java.jar
- New Oozie WAR file with added 'JARs' at /var/lib/oozie/oozie-server/webapps/oozie.war"""
- call_mock.return_value = (0, prepare_war_stdout)
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer", command = "pre_rolling_restart", config_file = "oozie-upgrade.json",
- hdp_stack_version = self.UPGRADE_STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES )
- # 2 calls to tarfile.open (1 directories, read + write)
- self.assertTrue(tarfile_open_mock.called)
- self.assertEqual(tarfile_open_mock.call_count,2)
- self.assertTrue(chmod_mock.called)
- self.assertEqual(chmod_mock.call_count,1)
- chmod_mock.assert_called_once_with('/usr/hdp/current/oozie-server/libext-customer', 511)
- self.assertTrue(isfile_mock.called)
- self.assertEqual(isfile_mock.call_count,3)
- isfile_mock.assert_called_with('/usr/share/HDP-oozie/ext-2.2.zip')
- self.assertTrue(glob_mock.called)
- self.assertEqual(glob_mock.call_count,1)
- glob_mock.assert_called_with('/usr/hdp/2.2.1.0-2135/hadoop/lib/hadoop-lzo*.jar')
- self.assertResourceCalled('Execute', 'hdp-select set oozie-server 2.2.1.0-2135')
- self.assertResourceCalled('Execute', 'hdfs dfs -chown oozie:hadoop /user/oozie/share', user='oozie')
- self.assertResourceCalled('Execute', 'hdfs dfs -chmod -R 755 /user/oozie/share', user='oozie')
- self.assertResourceCalled('Execute', '/usr/hdp/current/oozie-server/bin/ooziedb.sh upgrade -run', user='oozie')
- self.assertResourceCalled('Execute', '/usr/hdp/current/oozie-server/bin/oozie-setup.sh sharelib create -fs hdfs://c6401.ambari.apache.org:8020', user='oozie')
- self.assertNoMoreResources()
- @patch("tarfile.open")
- @patch("os.path.isdir")
- @patch("os.path.exists")
- @patch("os.path.isfile")
- @patch("os.remove")
- @patch("os.chmod")
- @patch("shutil.rmtree", new = MagicMock())
- @patch("shutil.copy", new = MagicMock())
- @patch.object(shell, "call")
- def test_downgrade_no_compression_library_copy(self, call_mock, chmod_mock, remove_mock,
- isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
- isdir_mock.return_value = True
- exists_mock.side_effect = [False,False,True]
- isfile_mock.return_value = True
- prepare_war_stdout = """INFO: Adding extension: libext/mysql-connector-java.jar
- New Oozie WAR file with added 'JARs' at /var/lib/oozie/oozie-server/webapps/oozie.war"""
- call_mock.return_value = (0, prepare_war_stdout)
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer", command = "pre_rolling_restart", config_file = "oozie-downgrade.json",
- hdp_stack_version = self.UPGRADE_STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES )
- # 2 calls to tarfile.open (1 directories, read + write)
- self.assertTrue(tarfile_open_mock.called)
- self.assertEqual(tarfile_open_mock.call_count,2)
- self.assertTrue(chmod_mock.called)
- self.assertEqual(chmod_mock.call_count,1)
- chmod_mock.assert_called_once_with('/usr/hdp/current/oozie-server/libext-customer', 511)
- self.assertTrue(isfile_mock.called)
- self.assertEqual(isfile_mock.call_count,2)
- isfile_mock.assert_called_with('/usr/share/HDP-oozie/ext-2.2.zip')
- self.assertResourceCalled('Execute', 'hdp-select set oozie-server 2.2.0.0-0000')
- self.assertResourceCalled('Execute', 'hdfs dfs -chown oozie:hadoop /user/oozie/share', user='oozie')
- self.assertResourceCalled('Execute', 'hdfs dfs -chmod -R 755 /user/oozie/share', user='oozie')
- self.assertResourceCalled('Execute', '/usr/hdp/current/oozie-server/bin/ooziedb.sh upgrade -run', user='oozie')
- self.assertResourceCalled('Execute', '/usr/hdp/current/oozie-server/bin/oozie-setup.sh sharelib create -fs hdfs://c6401.ambari.apache.org:8020', user='oozie')
- @patch("tarfile.open")
- @patch("os.path.isdir")
- @patch("os.path.exists")
- @patch("os.path.isfile")
- @patch("os.remove")
- @patch("os.chmod")
- @patch("shutil.rmtree", new = MagicMock())
- @patch("glob.iglob", new = MagicMock(return_value=["/usr/hdp/2.2.1.0-2187/hadoop/lib/hadoop-lzo-0.6.0.2.2.1.0-2187.jar"]))
- @patch("shutil.copy")
- @patch.object(shell, "call")
- def test_upgrade_failed_prepare_war(self, call_mock, shutil_copy_mock, chmod_mock, remove_mock,
- isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
- isdir_mock.return_value = True
- exists_mock.side_effect = [False,False,True]
- isfile_mock.return_value = True
- call_mock.return_value = (0, 'Whoops, you messed up the WAR.')
- try:
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer", command = "pre_rolling_restart", config_file = "oozie-upgrade.json",
- hdp_stack_version = self.UPGRADE_STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES )
- self.fail("An invalid WAR preparation should have caused an error")
- except Fail,f:
- pass
|