1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240 |
- #!/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.
- '''
- import json
- 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
- from resource_management.libraries import functions
- from resource_management.libraries.providers.hdfs_resource import WebHDFSUtil
- import hashlib
- md5_mock = MagicMock()
- md5_mock.hexdigest.return_value = "abc123hash"
- @patch("platform.linux_distribution", new = MagicMock(return_value="Linux"))
- @patch.object(hashlib, "md5", new=MagicMock(return_value=md5_mock))
- @patch.object(WebHDFSUtil, "run_command", new=MagicMock(return_value={}))
- 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 setUp(self):
- self.maxDiff = None
- 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()
- def test_configure_default_mysql(self):
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer",
- command = "configure",
- config_file="default_oozie_mysql.json",
- hdp_stack_version = self.STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES
- )
- self.assertResourceCalled('HdfsResource', '/user/oozie',
- security_enabled = False,
- hadoop_bin_dir = '/usr/bin',
- keytab = UnknownConfigurationMock(),
- kinit_path_local = '/usr/bin/kinit',
- user = 'hdfs',
- owner = 'oozie',
- hadoop_conf_dir = '/etc/hadoop/conf',
- type = 'directory',
- action = ['create_on_execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name=UnknownConfigurationMock(), default_fs='hdfs://c6401.ambari.apache.org:8020',
- mode = 0775,
- )
- self.assertResourceCalled('HdfsResource', None,
- security_enabled = False,
- hadoop_bin_dir = '/usr/bin',
- keytab = UnknownConfigurationMock(),
- kinit_path_local = '/usr/bin/kinit',
- user = 'hdfs',
- action = ['execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name=UnknownConfigurationMock(), default_fs='hdfs://c6401.ambari.apache.org:8020',
- hadoop_conf_dir = '/etc/hadoop/conf',
- )
- self.assertResourceCalled('Directory', '/etc/oozie/conf',
- owner = 'oozie',
- group = 'hadoop',
- recursive = True,
- )
- self.assertResourceCalled('XmlConfig', 'oozie-site.xml',
- group = 'hadoop',
- conf_dir = '/etc/oozie/conf',
- mode = 0664,
- configuration_attributes = {u'final': {u'oozie.service.CallableQueueService.queue.size': u'true',
- u'oozie.service.PurgeService.purge.interval': u'true'}},
- owner = 'oozie',
- configurations = self.getConfig()['configurations']['oozie-site'],
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/oozie-env.sh',
- content = InlineTemplate(self.getConfig()['configurations']['oozie-env']['content']),
- owner = 'oozie',
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/oozie-log4j.properties',
- content = 'log4jproperties\nline2',
- owner = 'oozie',
- group = 'hadoop',
- mode = 0644,
- )
- self.assertResourceCalled('File', '/etc/oozie/conf/adminusers.txt',
- owner = 'oozie',
- group = 'hadoop',
- )
- self.assertResourceCalled('File', '/usr/lib/ambari-agent/DBConnectionVerification.jar',
- content = DownloadSource('http://c6401.ambari.apache.org:8080/resources/DBConnectionVerification.jar'),
- )
- 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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
- )
- self.assertResourceCalled('Directory', '/usr/lib/oozie//var/tmp/oozie',
- owner = 'oozie',
- cd_access = 'a',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- )
- self.assertResourceCalled('Directory', '/var/run/oozie',
- owner = 'oozie',
- cd_access = 'a',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- )
- self.assertResourceCalled('Directory', '/var/log/oozie',
- owner = 'oozie',
- cd_access = 'a',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- )
- self.assertResourceCalled('Directory', '/var/tmp/oozie',
- owner = 'oozie',
- cd_access = 'a',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- )
- self.assertResourceCalled('Directory', '/hadoop/oozie/data',
- owner = 'oozie',
- cd_access = 'a',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- )
- self.assertResourceCalled('Directory', '/var/lib/oozie',
- owner = 'oozie',
- cd_access = 'a',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- )
- self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/webapps/',
- owner = 'oozie',
- cd_access = 'a',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- )
- self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/conf',
- owner = 'oozie',
- cd_access = 'a',
- group = 'hadoop',
- recursive = True,
- mode = 0755,
- )
- self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server',
- owner = 'oozie',
- recursive = True,
- group = 'hadoop',
- 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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1' || test -f /usr/lib/oozie/.hashcode && test -d /usr/lib/oozie/share && [[ `cat /usr/lib/oozie/.hashcode` == 'abc123hash' ]]",
- sudo = True,
- )
- self.assertResourceCalled('Execute', ('cp', '/usr/share/HDP-oozie/ext-2.2.zip', '/usr/lib/oozie/libext'),
- not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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('File', '/tmp/mysql-connector-java.jar',
- content = DownloadSource('http://c6401.ambari.apache.org:8080/resources//mysql-jdbc-driver.jar'),
- )
- self.assertResourceCalled('Execute', ('cp',
- '--remove-destination',
- '/tmp/mysql-connector-java.jar',
- '/usr/lib/oozie/libext/mysql-connector-java.jar'),
- path = ['/bin', '/usr/bin/'],
- sudo = True,
- )
- self.assertResourceCalled('File', '/usr/lib/oozie/libext/mysql-connector-java.jar',
- owner = 'oozie',
- group = 'hadoop',
- )
- self.assertResourceCalled('Execute', 'ambari-sudo.sh cp /usr/lib/falcon/oozie/ext/falcon-oozie-el-extension-*.jar /usr/lib/oozie/libext',
- not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1' || test -f /usr/lib/oozie/.hashcode && test -d /usr/lib/oozie/share && [[ `cat /usr/lib/oozie/.hashcode` == 'abc123hash' ]] && test -f /usr/lib/oozie/.prepare_war_cmd && [[ `cat /usr/lib/oozie/.prepare_war_cmd` == 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war ' ]]",
- user = 'oozie',
- )
- self.assertResourceCalled('File', '/usr/lib/oozie/.hashcode',
- content = 'abc123hash',
- mode = 0644,
- )
- self.assertResourceCalled('File', '/usr/lib/oozie/.prepare_war_cmd',
- content = 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war ',
- mode = 0644,
- )
- self.assertResourceCalled('Execute', ('chown', '-R', u'oozie:hadoop', '/var/lib/oozie/oozie-server'),
- sudo = True,
- )
- @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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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',
- path = ['/usr/bin:/usr/bin'],
- user = 'oozie',
- )
- self.assertResourceCalled('HdfsResource', '/user/oozie/share',
- security_enabled = False,
- hadoop_bin_dir = '/usr/bin',
- keytab = UnknownConfigurationMock(),
- default_fs = 'hdfs://c6401.ambari.apache.org:8020',
- user = 'hdfs',
- hdfs_site = self.getConfig()['configurations']['hdfs-site'],
- kinit_path_local = '/usr/bin/kinit',
- principal_name = UnknownConfigurationMock(),
- recursive_chmod = True,
- action = ['create_on_execute'],
- hadoop_conf_dir = '/etc/hadoop/conf',
- type = 'directory',
- mode = 0755,
- )
- self.assertResourceCalled('HdfsResource', None,
- security_enabled = False,
- hadoop_bin_dir = '/usr/bin',
- keytab = UnknownConfigurationMock(),
- default_fs = 'hdfs://c6401.ambari.apache.org:8020',
- hdfs_site = self.getConfig()['configurations']['hdfs-site'],
- kinit_path_local = '/usr/bin/kinit',
- principal_name = UnknownConfigurationMock(),
- user = 'hdfs',
- action = ['execute'],
- hadoop_conf_dir = '/etc/hadoop/conf',
- )
- self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-start.sh',
- environment = {'OOZIE_CONFIG': '/etc/oozie/conf'},
- not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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',
- environment = {'OOZIE_CONFIG': '/etc/oozie/conf'},
- only_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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;',
- user = 'oozie',
- )
- self.assertResourceCalled('Execute', 'hadoop --config /etc/hadoop/conf dfs -put /usr/lib/oozie/share /user/oozie',
- path = ['/usr/bin:/usr/bin'],
- user = 'oozie',
- )
- self.assertResourceCalled('HdfsResource', '/user/oozie/share',
- security_enabled = True,
- hadoop_bin_dir = '/usr/bin',
- keytab = '/etc/security/keytabs/hdfs.headless.keytab',
- default_fs = 'hdfs://c6401.ambari.apache.org:8020',
- user = 'hdfs',
- hdfs_site = self.getConfig()['configurations']['hdfs-site'],
- kinit_path_local = '/usr/bin/kinit',
- principal_name = 'hdfs',
- recursive_chmod = True,
- action = ['create_on_execute'],
- hadoop_conf_dir = '/etc/hadoop/conf',
- type = 'directory',
- mode = 0755,
- )
- self.assertResourceCalled('HdfsResource', None,
- security_enabled = True,
- hadoop_bin_dir = '/usr/bin',
- keytab = '/etc/security/keytabs/hdfs.headless.keytab',
- default_fs = 'hdfs://c6401.ambari.apache.org:8020',
- hdfs_site = self.getConfig()['configurations']['hdfs-site'],
- kinit_path_local = '/usr/bin/kinit',
- principal_name = 'hdfs',
- user = 'hdfs',
- action = ['execute'],
- hadoop_conf_dir = '/etc/hadoop/conf',
- )
- self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-start.sh',
- environment = {'OOZIE_CONFIG': '/etc/oozie/conf'},
- not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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',
- environment = {'OOZIE_CONFIG': '/etc/oozie/conf'},
- only_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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('HdfsResource', '/user/oozie',
- security_enabled = False,
- hadoop_conf_dir = '/etc/hadoop/conf',
- keytab = UnknownConfigurationMock(),
- kinit_path_local = '/usr/bin/kinit',
- user = 'hdfs',
- owner = 'oozie',
- hadoop_bin_dir = '/usr/bin',
- type = 'directory',
- action = ['create_on_execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name=UnknownConfigurationMock(), default_fs='hdfs://c6401.ambari.apache.org:8020',
- mode = 0775,
- )
- self.assertResourceCalled('HdfsResource', None,
- security_enabled = False,
- hadoop_bin_dir = '/usr/bin',
- keytab = UnknownConfigurationMock(),
- kinit_path_local = '/usr/bin/kinit',
- user = 'hdfs',
- action = ['execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name=UnknownConfigurationMock(), default_fs='hdfs://c6401.ambari.apache.org:8020',
- hadoop_conf_dir = '/etc/hadoop/conf',
- )
- 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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1' || test -f /usr/lib/oozie/.hashcode && test -d /usr/lib/oozie/share && [[ `cat /usr/lib/oozie/.hashcode` == 'abc123hash' ]]",
- sudo = True,
- )
- self.assertResourceCalled('Execute', ('cp', '/usr/share/HDP-oozie/ext-2.2.zip', '/usr/lib/oozie/libext'),
- not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1' || test -f /usr/lib/oozie/.hashcode && test -d /usr/lib/oozie/share && [[ `cat /usr/lib/oozie/.hashcode` == 'abc123hash' ]] && test -f /usr/lib/oozie/.prepare_war_cmd && [[ `cat /usr/lib/oozie/.prepare_war_cmd` == 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war ' ]]",
- user = 'oozie',
- )
- self.assertResourceCalled('File', '/usr/lib/oozie/.hashcode',
- content = 'abc123hash',
- mode = 0644,
- )
- self.assertResourceCalled('File', '/usr/lib/oozie/.prepare_war_cmd',
- content = 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war ',
- mode = 0644,
- )
- self.assertResourceCalled('Execute', ('chown', '-R', u'oozie:hadoop', '/var/lib/oozie/oozie-server'),
- sudo = True,
- )
- def assert_configure_secured(self):
- self.assertResourceCalled('HdfsResource', '/user/oozie',
- security_enabled = True,
- hadoop_conf_dir = '/etc/hadoop/conf',
- keytab = '/etc/security/keytabs/hdfs.headless.keytab',
-
- kinit_path_local = '/usr/bin/kinit',
- user = 'hdfs',
- owner = 'oozie',
- hadoop_bin_dir = '/usr/bin',
- type = 'directory',
- action = ['create_on_execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name='hdfs', default_fs='hdfs://c6401.ambari.apache.org:8020',
- mode = 0775,
- )
- self.assertResourceCalled('HdfsResource', None,
- security_enabled = True,
- hadoop_bin_dir = '/usr/bin',
- keytab = '/etc/security/keytabs/hdfs.headless.keytab',
-
- kinit_path_local = '/usr/bin/kinit',
- user = 'hdfs',
- action = ['execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name='hdfs', default_fs='hdfs://c6401.ambari.apache.org:8020',
- hadoop_conf_dir = '/etc/hadoop/conf',
- )
- 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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1' || test -f /usr/lib/oozie/.hashcode && test -d /usr/lib/oozie/share && [[ `cat /usr/lib/oozie/.hashcode` == 'abc123hash' ]]",
- sudo = True,
- )
- self.assertResourceCalled('Execute', ('cp', '/usr/share/HDP-oozie/ext-2.2.zip', '/usr/lib/oozie/libext'),
- not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]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 -secure',
- not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1' || test -f /usr/lib/oozie/.hashcode && test -d /usr/lib/oozie/share && [[ `cat /usr/lib/oozie/.hashcode` == 'abc123hash' ]] && test -f /usr/lib/oozie/.prepare_war_cmd && [[ `cat /usr/lib/oozie/.prepare_war_cmd` == 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war -secure' ]]",
- user = 'oozie',
- )
- self.assertResourceCalled('File', '/usr/lib/oozie/.hashcode',
- content = 'abc123hash',
- mode = 0644,
- )
- self.assertResourceCalled('File', '/usr/lib/oozie/.prepare_war_cmd',
- content = 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war -secure',
- mode = 0644,
- )
- self.assertResourceCalled('Execute', ('chown', '-R', u'oozie:hadoop', '/var/lib/oozie/oozie-server'),
- sudo = True,
- )
- 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
- )
- get_params_mock.assert_called_with("/etc/oozie/conf", {'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('/usr/bin/kinit',
- self.config_dict['configurations']['oozie-env']['oozie_user'],
- security_params['oozie-site']['oozie.service.HadoopAccessorService.keytab.file'],
- security_params['oozie-site']['oozie.service.HadoopAccessorService.kerberos.principal'],
- self.config_dict['hostname'],
- '/tmp')
- # 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 = {
- '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.copy2", new = MagicMock())
- def test_upgrade(self, glob_mock, chmod_mock, remove_mock,
- isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
- def exists_mock_side_effect(path):
- if path == '/tmp/oozie-upgrade-backup/oozie-conf-backup.tar':
- return True
- return False
- exists_mock.side_effect = exists_mock_side_effect
- isdir_mock.return_value = 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"""
- 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,
- call_mocks = [(0, prepare_war_stdout)]
- )
- # 2 calls to tarfile.open (1 directories, read + write)
- self.assertTrue(tarfile_open_mock.called)
- self.assertEqual(tarfile_open_mock.call_count,2)
- # check the call args for creation of the tarfile
- call_args = tarfile_open_mock.call_args_list[0]
- call_argument_tarfile = call_args[0][0]
- call_kwargs = call_args[1]
- self.assertTrue("oozie-upgrade-backup/oozie-conf-backup.tar" in call_argument_tarfile)
- self.assertEquals(True, call_kwargs["dereference"])
- 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'), sudo=True,)
- 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("glob.iglob")
- @patch("shutil.copy2", new = MagicMock())
- def test_upgrade_23(self, glob_mock, chmod_mock, remove_mock,
- isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
- def exists_mock_side_effect(path):
- if path == '/tmp/oozie-upgrade-backup/oozie-conf-backup.tar':
- return True
- return False
- isdir_mock.return_value = True
- exists_mock.side_effect = exists_mock_side_effect
- 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"""
- config_file = self.get_src_folder()+"/test/python/stacks/2.2/configs/oozie-upgrade.json"
- with open(config_file, "r") as f:
- json_content = json.load(f)
- version = '2.3.0.0-1234'
- json_content['commandParams']['version'] = version
- mocks_dict = {}
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
- classname = "OozieServer", command = "pre_rolling_restart", config_dict = json_content,
- hdp_stack_version = self.UPGRADE_STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES,
- call_mocks = [(0, None), (0, prepare_war_stdout)],
- mocks_dict = mocks_dict
- )
- # 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.3.0.0-1234/hadoop/lib/hadoop-lzo*.jar')
- self.assertResourceCalled('Execute', ('hdp-select', 'set', 'oozie-server', '2.3.0.0-1234'), sudo=True)
- self.assertNoMoreResources()
- self.assertEquals(2, mocks_dict['call'].call_count)
- self.assertEquals(1, mocks_dict['checked_call'].call_count)
- self.assertEquals(
- ('conf-select', 'set-conf-dir', '--package', 'oozie', '--stack-version', '2.3.0.0-1234', '--conf-version', '0'),
- mocks_dict['checked_call'].call_args_list[0][0][0])
- self.assertEquals(
- ('conf-select', 'create-conf-dir', '--package', 'oozie', '--stack-version', '2.3.0.0-1234', '--conf-version', '0'),
- mocks_dict['call'].call_args_list[0][0][0])
- @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.copy2", new = MagicMock())
- def test_downgrade_no_compression_library_copy(self, chmod_mock, remove_mock,
- isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
- isdir_mock.return_value = True
- exists_mock.return_value = False
- 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"""
- 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,
- call_mocks = [(0, prepare_war_stdout)])
- # 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'), sudo=True)
- 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("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.copy2")
- def test_upgrade_failed_prepare_war(self, shutil_copy_mock, chmod_mock, remove_mock,
- isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
- isdir_mock.return_value = True
- exists_mock.return_value = False
- isfile_mock.return_value = True
- 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
- def test_upgrade_database_sharelib(self):
- """
- Tests that the upgrade script runs the proper commands before the
- actual upgrade begins.
- :return:
- """
- config_file = self.get_src_folder()+"/test/python/stacks/2.2/configs/oozie-upgrade.json"
- with open(config_file, "r") as f:
- json_content = json.load(f)
- version = '2.3.0.0-1234'
- json_content['commandParams']['version'] = version
- json_content['hostLevelParams']['stack_name'] = "HDP"
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server_upgrade.py",
- classname = "OozieUpgrade", command = "upgrade_oozie_database_and_sharelib",
- config_dict = json_content,
- hdp_stack_version = self.UPGRADE_STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES )
- self.assertResourceCalled('Execute', '/usr/hdp/2.3.0.0-1234/oozie/bin/ooziedb.sh upgrade -run',
- user = 'oozie', logoutput = True )
- self.assertResourceCalled('HdfsResource', '/user/oozie/share',
- security_enabled = False,
- hadoop_bin_dir = '/usr/hdp/2.3.0.0-1234/hadoop/bin',
- keytab = UnknownConfigurationMock(),
- default_fs = 'hdfs://c6401.ambari.apache.org:8020',
- user = 'hdfs',
- hdfs_site = UnknownConfigurationMock(),
- kinit_path_local = '/usr/bin/kinit',
- principal_name = UnknownConfigurationMock(),
- recursive_chmod = True,
- owner = 'oozie',
- group = 'hadoop',
- hadoop_conf_dir = '/usr/hdp/current/hadoop-client/conf',
- type = 'directory',
- action = ['create_on_execute'],
- mode = 0755 )
- self.assertResourceCalled('HdfsResource', None,
- security_enabled = False,
- hadoop_bin_dir = '/usr/hdp/2.3.0.0-1234/hadoop/bin',
- keytab = UnknownConfigurationMock(),
- default_fs = 'hdfs://c6401.ambari.apache.org:8020',
- hdfs_site = UnknownConfigurationMock(),
- kinit_path_local = '/usr/bin/kinit',
- principal_name = UnknownConfigurationMock(),
- user = 'hdfs',
- action = ['execute'],
- hadoop_conf_dir = '/usr/hdp/current/hadoop-client/conf' )
- self.assertResourceCalled('Execute', '/usr/hdp/2.3.0.0-1234/oozie/bin/oozie-setup.sh sharelib create -fs hdfs://c6401.ambari.apache.org:8020',
- user='oozie', logoutput = True)
- def test_upgrade_database_sharelib_existing_mysql(self):
- """
- Tests that the upgrade script runs the proper commands before the
- actual upgrade begins when Oozie is using and external database. This
- should ensure that the JDBC JAR is copied.
- :return:
- """
- config_file = self.get_src_folder()+"/test/python/stacks/2.2/configs/oozie-upgrade.json"
- with open(config_file, "r") as f:
- json_content = json.load(f)
- version = '2.3.0.0-1234'
- json_content['commandParams']['version'] = version
- json_content['hostLevelParams']['stack_name'] = "HDP"
- # use mysql external database
- json_content['configurations']['oozie-site']['oozie.service.JPAService.jdbc.driver'] = "com.mysql.jdbc.Driver"
- self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server_upgrade.py",
- classname = "OozieUpgrade", command = "upgrade_oozie_database_and_sharelib",
- config_dict = json_content,
- hdp_stack_version = self.UPGRADE_STACK_VERSION,
- target = RMFTestCase.TARGET_COMMON_SERVICES )
- self.assertResourceCalled('File', '/tmp/mysql-connector-java.jar',
- content = DownloadSource('http://c6401.ambari.apache.org:8080/resources//mysql-jdbc-driver.jar') )
- self.assertResourceCalled('Execute', ('cp', '--remove-destination', '/tmp/mysql-connector-java.jar',
- '/usr/hdp/2.3.0.0-1234/oozie/libext/mysql-connector-java.jar'),
- path = ['/bin', '/usr/bin/'], sudo = True)
- self.assertResourceCalled('File', '/usr/hdp/2.3.0.0-1234/oozie/libext/mysql-connector-java.jar',
- owner = 'oozie', group = 'hadoop' )
- self.assertResourceCalled('Execute', '/usr/hdp/2.3.0.0-1234/oozie/bin/ooziedb.sh upgrade -run',
- user = 'oozie', logoutput = True )
- self.assertResourceCalled('HdfsResource', '/user/oozie/share',
- security_enabled = False,
- hadoop_bin_dir = '/usr/hdp/2.3.0.0-1234/hadoop/bin',
- keytab = UnknownConfigurationMock(),
- default_fs = 'hdfs://c6401.ambari.apache.org:8020',
- user = 'hdfs',
- hdfs_site = UnknownConfigurationMock(),
- kinit_path_local = '/usr/bin/kinit',
- principal_name = UnknownConfigurationMock(),
- recursive_chmod = True,
- owner = 'oozie',
- group = 'hadoop',
- hadoop_conf_dir = '/usr/hdp/current/hadoop-client/conf',
- type = 'directory',
- action = ['create_on_execute'],
- mode = 0755 )
- self.assertResourceCalled('HdfsResource', None,
- security_enabled = False,
- hadoop_bin_dir = '/usr/hdp/2.3.0.0-1234/hadoop/bin',
- keytab = UnknownConfigurationMock(),
- default_fs = 'hdfs://c6401.ambari.apache.org:8020',
- hdfs_site = UnknownConfigurationMock(),
- kinit_path_local = '/usr/bin/kinit',
- principal_name = UnknownConfigurationMock(),
- user = 'hdfs',
- action = ['execute'],
- hadoop_conf_dir = '/usr/hdp/current/hadoop-client/conf' )
- self.assertResourceCalled('Execute', '/usr/hdp/2.3.0.0-1234/oozie/bin/oozie-setup.sh sharelib create -fs hdfs://c6401.ambari.apache.org:8020',
- user='oozie', logoutput = True)
|