Return-Path: X-Original-To: apmail-ambari-commits-archive@www.apache.org Delivered-To: apmail-ambari-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1B1B719D11 for ; Fri, 4 Mar 2016 23:20:07 +0000 (UTC) Received: (qmail 7316 invoked by uid 500); 4 Mar 2016 23:20:07 -0000 Delivered-To: apmail-ambari-commits-archive@ambari.apache.org Received: (qmail 7286 invoked by uid 500); 4 Mar 2016 23:20:07 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 7277 invoked by uid 99); 4 Mar 2016 23:20:07 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Mar 2016 23:20:07 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A8F3FE795B; Fri, 4 Mar 2016 23:20:06 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mithmatt@apache.org To: commits@ambari.apache.org Date: Fri, 04 Mar 2016 23:20:07 -0000 Message-Id: <22a3dafaea7e49caa6e5fa5122c73b20@git.apache.org> In-Reply-To: <907b837be1894ad980d08377eaf614d7@git.apache.org> References: <907b837be1894ad980d08377eaf614d7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] ambari git commit: AMBARI-13439: Unit tests for the HAWQ service under common-services (Newton Alex via mithmatt) AMBARI-13439: Unit tests for the HAWQ service under common-services (Newton Alex via mithmatt) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/34cc05b8 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/34cc05b8 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/34cc05b8 Branch: refs/heads/branch-2.2 Commit: 34cc05b8145299d8a53d7066359bd12367f6201d Parents: 4705a06 Author: Matt Authored: Fri Mar 4 15:19:17 2016 -0800 Committer: Matt Committed: Fri Mar 4 15:19:17 2016 -0800 ---------------------------------------------------------------------- .../HAWQ/2.0.0/package/scripts/__init__.py | 19 + .../HAWQ/2.0.0/package/scripts/params.py | 4 +- .../python/stacks/2.3/HAWQ/test_hawqmaster.py | 292 ++++ .../python/stacks/2.3/HAWQ/test_hawqsegment.py | 160 +++ .../python/stacks/2.3/HAWQ/test_hawqstandby.py | 200 +++ .../python/stacks/2.3/configs/hawq_default.json | 1324 ++++++++++++++++++ 6 files changed, 1997 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/34cc05b8/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/__init__.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/__init__.py b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/__init__.py new file mode 100644 index 0000000..5561e10 --- /dev/null +++ b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/__init__.py @@ -0,0 +1,19 @@ +#!/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. + +""" http://git-wip-us.apache.org/repos/asf/ambari/blob/34cc05b8/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/params.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/params.py b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/params.py index 7633731..50a8fda 100644 --- a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/params.py +++ b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/params.py @@ -51,9 +51,9 @@ hawq_password = unicode(config['configurations']['hawq-env']['hawq_password']) # HAWQ Hostnames hawqmaster_host = __get_component_host('hawqmaster_hosts') hawqstandby_host = __get_component_host('hawqstandby_hosts') -hawqsegment_hosts = default('/clusterHostInfo/hawqsegment_hosts', []) +hawqsegment_hosts = sorted(default('/clusterHostInfo/hawqsegment_hosts', [])) hawq_master_hosts = [host for host in hawqmaster_host, hawqstandby_host if host] -hawq_all_hosts = set(hawq_master_hosts + hawqsegment_hosts) +hawq_all_hosts = sorted(set(hawq_master_hosts + hawqsegment_hosts)) # HDFS http://git-wip-us.apache.org/repos/asf/ambari/blob/34cc05b8/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqmaster.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqmaster.py b/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqmaster.py new file mode 100644 index 0000000..7bd50ea --- /dev/null +++ b/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqmaster.py @@ -0,0 +1,292 @@ +#!/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 * +import resource_management.libraries.functions + +@patch.object(resource_management.libraries.functions, 'check_process_status', new = MagicMock()) +class TestHawqMaster(RMFTestCase): + COMMON_SERVICES_PACKAGE_DIR = 'HAWQ/2.0.0/package' + STACK_VERSION = '2.3' + GPADMIN = 'gpadmin' + + def __asserts_for_configure(self): + + self.assertResourceCalled('Group', self.GPADMIN, + ignore_failures = True + ) + + self.assertResourceCalled('User', self.GPADMIN, + gid = self.GPADMIN, + groups = ['gpadmin', u'hadoop'], + ignore_failures = True, + password = 'saNIJ3hOyqasU' + ) + + self.assertResourceCalled('Execute', 'chown -R gpadmin:gpadmin /usr/local/hawq/', + timeout = 600 + ) + + self.assertResourceCalled('XmlConfig', 'hdfs-client.xml', + conf_dir = '/usr/local/hawq/etc/', + configurations = self.getConfig()['configurations']['hdfs-client'], + configuration_attributes = self.getConfig()['configuration_attributes']['hdfs-client'], + group = self.GPADMIN, + owner = self.GPADMIN, + mode = 0644 + ) + + self.assertResourceCalled('XmlConfig', 'yarn-client.xml', + conf_dir = '/usr/local/hawq/etc/', + configurations = self.getConfig()['configurations']['yarn-client'], + configuration_attributes = self.getConfig()['configuration_attributes']['yarn-client'], + group = self.GPADMIN, + owner = self.GPADMIN, + mode = 0644 + ) + + self.assertResourceCalled('XmlConfig', 'hawq-site.xml', + conf_dir = '/usr/local/hawq/etc/', + configurations = self.getConfig()['configurations']['hawq-site'], + configuration_attributes = self.getConfig()['configuration_attributes']['hawq-site'], + group = self.GPADMIN, + owner = self.GPADMIN, + mode = 0644 + ) + + self.assertResourceCalled('File', '/usr/local/hawq/etc/hawq_check.cnf', + content = self.getConfig()['configurations']['hawq-check-env']['content'], + owner = self.GPADMIN, + group = self.GPADMIN, + mode=0644 + ) + + self.assertResourceCalled('File', '/usr/local/hawq/etc/slaves', + content = InlineTemplate('c6401.ambari.apache.org\nc6402.ambari.apache.org\nc6403.ambari.apache.org\n\n'), + group = self.GPADMIN, + owner = self.GPADMIN, + mode = 0644 + ) + + self.assertResourceCalled('File', '/usr/local/hawq/etc/hawq_hosts', + content = InlineTemplate('c6401.ambari.apache.org\nc6402.ambari.apache.org\nc6403.ambari.apache.org\n\n'), + group = self.GPADMIN, + owner = self.GPADMIN, + mode = 0644 + ) + + self.assertResourceCalled('Directory', '/data/hawq/master', + group = self.GPADMIN, + owner = self.GPADMIN, + recursive = True + ) + + self.assertResourceCalled('Directory', '/tmp', + group = self.GPADMIN, + owner = self.GPADMIN, + recursive = True + ) + + self.assertResourceCalled('Execute', 'chmod 700 /data/hawq/master', + user = 'root', + timeout = 600 + ) + + + @patch ('hawqmaster.common.__set_osparams') + def test_configure_default(self, set_osparams_mock): + + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + '/scripts/hawqmaster.py', + classname = 'HawqMaster', + command = 'configure', + config_file ='hawq_default.json', + hdp_stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES + ) + + self.__asserts_for_configure() + self.assertNoMoreResources() + + + @patch ('hawqmaster.common.__set_osparams') + def test_install_default(self, set_osparams_mock): + + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + '/scripts/hawqmaster.py', + classname = 'HawqMaster', + command = 'install', + config_file ='hawq_default.json', + hdp_stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES + ) + + self.__asserts_for_configure() + self.assertNoMoreResources() + + + @patch ('hawqmaster.common.__set_osparams') + @patch ('hawqmaster.master_helper.__is_active_master') + @patch ('hawqmaster.master_helper.__is_local_initialized') + def test_start_default(self, is_local_initialized_mock, active_master_mock, set_osparams_mock): + active_master_mock.return_value = True + is_local_initialized_mock.return_value = False + + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + '/scripts/hawqmaster.py', + classname = 'HawqMaster', + command = 'start', + config_file ='hawq_default.json', + hdp_stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES + ) + + self.__asserts_for_configure() + + self.assertResourceCalled('Execute', 'source /usr/local/hawq/greenplum_path.sh && hawq ssh-exkeys -f /usr/local/hawq/etc/hawq_hosts -p gpadmin', + logoutput = True, + not_if = None, + only_if = None, + user = self.GPADMIN, + timeout = 900 + ) + + self.assertResourceCalled('HdfsResource', '/hawq_default', + default_fs = u'hdfs://c6401.ambari.apache.org:8020', + hdfs_site = self.getConfig()['configurations']['hdfs-site'], + type = 'directory', + action = ['create_on_execute'], + owner = self.GPADMIN, + group = self.GPADMIN, + user = u'hdfs', + mode = 493, + security_enabled = False, + kinit_path_local = '/usr/bin/kinit', + recursive_chown = True, + keytab = UnknownConfigurationMock(), + principal_name = UnknownConfigurationMock(), + ) + + self.assertResourceCalled('HdfsResource', None, + default_fs = u'hdfs://c6401.ambari.apache.org:8020', + hdfs_site = self.getConfig()['configurations']['hdfs-site'], + action = ['execute'], + user = u'hdfs', + security_enabled = False, + kinit_path_local = '/usr/bin/kinit', + keytab = UnknownConfigurationMock(), + principal_name = UnknownConfigurationMock() + ) + + self.assertResourceCalled('Execute', 'source /usr/local/hawq/greenplum_path.sh && hawq init master -a -v', + logoutput = True, + not_if = None, + only_if = None, + user = self.GPADMIN, + timeout = 900 + ) + + self.assertNoMoreResources() + + + @patch ('hawqmaster.common.__set_osparams') + @patch ('hawqmaster.master_helper.__is_active_master') + @patch ('hawqmaster.master_helper.__is_local_initialized') + def test_start_localmaster(self, is_local_initialized_mock, active_master_mock, set_osparams_mock): + active_master_mock.return_value = True + is_local_initialized_mock.return_value = True + + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + '/scripts/hawqmaster.py', + classname = 'HawqMaster', + command = 'start', + config_file ='hawq_default.json', + hdp_stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES + ) + + self.__asserts_for_configure() + + self.assertResourceCalled('Execute', 'source /usr/local/hawq/greenplum_path.sh && hawq ssh-exkeys -f /usr/local/hawq/etc/hawq_hosts -p gpadmin', + logoutput = True, + not_if = None, + only_if = None, + user = self.GPADMIN, + timeout = 900 + ) + + self.assertResourceCalled('HdfsResource', '/hawq_default', + default_fs = u'hdfs://c6401.ambari.apache.org:8020', + hdfs_site = self.getConfig()['configurations']['hdfs-site'], + type = 'directory', + action = ['create_on_execute'], + owner = self.GPADMIN, + group = self.GPADMIN, + user = u'hdfs', + mode = 493, + security_enabled = False, + kinit_path_local = '/usr/bin/kinit', + recursive_chown = True, + keytab = UnknownConfigurationMock(), + principal_name = UnknownConfigurationMock(), + ) + + self.assertResourceCalled('HdfsResource', None, + default_fs = u'hdfs://c6401.ambari.apache.org:8020', + hdfs_site = self.getConfig()['configurations']['hdfs-site'], + action = ['execute'], + user = u'hdfs', + security_enabled = False, + kinit_path_local = '/usr/bin/kinit', + keytab = UnknownConfigurationMock(), + principal_name = UnknownConfigurationMock() + ) + + self.assertResourceCalled('Execute', 'source /usr/local/hawq/greenplum_path.sh && hawq start master -a -v', + logoutput = True, + not_if = "netstat -tupln | egrep ':5432\\s' | egrep postgres", + only_if = None, + user = self.GPADMIN, + timeout = 900 + ) + + self.assertNoMoreResources() + + + @patch ('hawqmaster.common.__set_osparams') + @patch ('hawqmaster.master_helper.__is_active_master') + def test_stop_default(self, active_master_mock, set_osparams_mock): + active_master_mock.return_value = True + + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + '/scripts/hawqmaster.py', + classname = 'HawqMaster', + command = 'stop', + config_file ='hawq_default.json', + hdp_stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES + ) + + self.assertResourceCalled('Execute', 'source /usr/local/hawq/greenplum_path.sh && hawq stop master -M fast -a -v', + logoutput = True, + not_if = None, + only_if = "netstat -tupln | egrep ':5432\\s' | egrep postgres", + user = self.GPADMIN, + timeout = 900 + ) + + self.assertNoMoreResources() + http://git-wip-us.apache.org/repos/asf/ambari/blob/34cc05b8/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqsegment.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqsegment.py b/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqsegment.py new file mode 100644 index 0000000..6ca83b7 --- /dev/null +++ b/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqsegment.py @@ -0,0 +1,160 @@ +#!/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 * + +class TestHawqSegment(RMFTestCase): + COMMON_SERVICES_PACKAGE_DIR = 'HAWQ/2.0.0/package' + STACK_VERSION = '2.3' + GPADMIN = 'gpadmin' + + def __asserts_for_configure(self): + + self.assertResourceCalled('Group', self.GPADMIN, + ignore_failures = True + ) + + self.assertResourceCalled('User', self.GPADMIN, + gid = self.GPADMIN, + groups = [self.GPADMIN, u'hadoop'], + ignore_failures = True, + password = 'saNIJ3hOyqasU' + ) + + self.assertResourceCalled('Execute', 'chown -R gpadmin:gpadmin /usr/local/hawq/', + timeout = 600 + ) + + self.assertResourceCalled('XmlConfig', 'hdfs-client.xml', + conf_dir = '/usr/local/hawq/etc/', + configurations = self.getConfig()['configurations']['hdfs-client'], + configuration_attributes = self.getConfig()['configuration_attributes']['hdfs-client'], + group = self.GPADMIN, + owner = self.GPADMIN, + mode = 0644 + ) + + self.assertResourceCalled('XmlConfig', 'yarn-client.xml', + conf_dir = '/usr/local/hawq/etc/', + configurations = self.getConfig()['configurations']['yarn-client'], + configuration_attributes = self.getConfig()['configuration_attributes']['yarn-client'], + group = self.GPADMIN, + owner = self.GPADMIN, + mode = 0644 + ) + + self.assertResourceCalled('XmlConfig', 'hawq-site.xml', + conf_dir = '/usr/local/hawq/etc/', + configurations = self.getConfig()['configurations']['hawq-site'], + configuration_attributes = self.getConfig()['configuration_attributes']['hawq-site'], + group = self.GPADMIN, + owner = self.GPADMIN, + mode = 0644 + ) + + + + @patch ('hawqsegment.common.__set_osparams') + def test_configure_default(self, set_osparams_mock): + + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + '/scripts/hawqsegment.py', + classname = 'HawqSegment', + command = 'configure', + config_file ='hawq_default.json', + hdp_stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES + ) + + self.__asserts_for_configure() + self.assertNoMoreResources() + + + @patch ('hawqsegment.common.__set_osparams') + def test_install_default(self, set_osparams_mock): + + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + '/scripts/hawqsegment.py', + classname = 'HawqSegment', + command = 'install', + config_file ='hawq_default.json', + hdp_stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES + ) + + self.__asserts_for_configure() + self.assertNoMoreResources() + + + @patch ('hawqsegment.common.__set_osparams') + def test_start_default(self, set_osparams_mock): + + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + '/scripts/hawqsegment.py', + classname = 'HawqSegment', + command = 'start', + config_file ='hawq_default.json', + hdp_stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES + ) + + self.__asserts_for_configure() + + self.assertResourceCalled('Directory', '/data/hawq/segment', + owner = self.GPADMIN, + group = self.GPADMIN, + recursive = True + ) + + self.assertResourceCalled('Directory', '/tmp', + owner = self.GPADMIN, + group = self.GPADMIN, + recursive = True + ) + + self.assertResourceCalled('Execute', 'source /usr/local/hawq/greenplum_path.sh && hawq init segment -a -v', + logoutput = True, + not_if = None, + only_if = None, + user = self.GPADMIN, + timeout = 900 + ) + + self.assertNoMoreResources() + + + def test_stop_default(self): + + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + '/scripts/hawqsegment.py', + classname = 'HawqSegment', + command = 'stop', + config_file ='hawq_default.json', + hdp_stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES + ) + + self.assertResourceCalled('Execute', 'source /usr/local/hawq/greenplum_path.sh && hawq stop segment -M fast -a -v', + logoutput = True, + not_if = None, + only_if = "netstat -tupln | egrep ':40000\\s' | egrep postgres", + user = self.GPADMIN, + timeout = 900 + ) + + self.assertNoMoreResources() + http://git-wip-us.apache.org/repos/asf/ambari/blob/34cc05b8/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqstandby.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqstandby.py b/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqstandby.py new file mode 100644 index 0000000..eaba496 --- /dev/null +++ b/ambari-server/src/test/python/stacks/2.3/HAWQ/test_hawqstandby.py @@ -0,0 +1,200 @@ +#!/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 * + + +class TestHawqStandby(RMFTestCase): + COMMON_SERVICES_PACKAGE_DIR = 'HAWQ/2.0.0/package' + STACK_VERSION = '2.3' + GPADMIN = 'gpadmin' + + def __asserts_for_configure(self): + + self.assertResourceCalled('Group', self.GPADMIN, + ignore_failures = True + ) + + self.assertResourceCalled('User', self.GPADMIN, + gid = self.GPADMIN, + groups = [self.GPADMIN, u'hadoop'], + ignore_failures = True, + password = 'saNIJ3hOyqasU' + ) + + self.assertResourceCalled('Execute', 'chown -R gpadmin:gpadmin /usr/local/hawq/', + timeout = 600 + ) + + self.assertResourceCalled('XmlConfig', 'hdfs-client.xml', + conf_dir = '/usr/local/hawq/etc/', + configurations = self.getConfig()['configurations']['hdfs-client'], + configuration_attributes = self.getConfig()['configuration_attributes']['hdfs-client'], + group = self.GPADMIN, + owner = self.GPADMIN, + mode = 0644 + ) + + self.assertResourceCalled('XmlConfig', 'yarn-client.xml', + conf_dir = '/usr/local/hawq/etc/', + configurations = self.getConfig()['configurations']['yarn-client'], + configuration_attributes = self.getConfig()['configuration_attributes']['yarn-client'], + group = self.GPADMIN, + owner = self.GPADMIN, + mode = 0644 + ) + + self.assertResourceCalled('XmlConfig', 'hawq-site.xml', + conf_dir = '/usr/local/hawq/etc/', + configurations = self.getConfig()['configurations']['hawq-site'], + configuration_attributes = self.getConfig()['configuration_attributes']['hawq-site'], + group = self.GPADMIN, + owner = self.GPADMIN, + mode = 0644 + ) + + self.assertResourceCalled('File', '/usr/local/hawq/etc/hawq_check.cnf', + content = self.getConfig()['configurations']['hawq-check-env']['content'], + owner = self.GPADMIN, + group = self.GPADMIN, + mode = 0644 + ) + + self.assertResourceCalled('File', '/usr/local/hawq/etc/slaves', + content = InlineTemplate('c6401.ambari.apache.org\nc6402.ambari.apache.org\nc6403.ambari.apache.org\n\n'), + group = self.GPADMIN, + owner = self.GPADMIN, + mode = 0644 + ) + + self.assertResourceCalled('File', '/usr/local/hawq/etc/hawq_hosts', + content = InlineTemplate('c6401.ambari.apache.org\nc6402.ambari.apache.org\nc6403.ambari.apache.org\n\n'), + group = self.GPADMIN, + owner = self.GPADMIN, + mode = 0644 + ) + + self.assertResourceCalled('Directory', '/data/hawq/master', + group = self.GPADMIN, + owner = self.GPADMIN, + recursive = True + ) + + self.assertResourceCalled('Directory', '/tmp', + group = self.GPADMIN, + owner = self.GPADMIN, + recursive = True + ) + + self.assertResourceCalled('Execute', 'chmod 700 /data/hawq/master', + user = 'root', + timeout = 600 + ) + + + @patch ('hawqstandby.common.__set_osparams') + def test_configure_default(self, set_osparams_mock): + + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + '/scripts/hawqstandby.py', + classname = 'HawqStandby', + command = 'configure', + config_file ='hawq_default.json', + hdp_stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES + ) + + self.__asserts_for_configure() + self.assertNoMoreResources() + + + @patch ('hawqstandby.common.__set_osparams') + def test_install_default(self, set_osparams_mock): + + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + '/scripts/hawqstandby.py', + classname = 'HawqStandby', + command = 'install', + config_file ='hawq_default.json', + hdp_stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES + ) + + self.__asserts_for_configure() + self.assertNoMoreResources() + + + + @patch ('hawqstandby.common.__set_osparams') + @patch ('hawqstandby.master_helper.__is_active_master') + @patch ('hawqstandby.master_helper.__is_standby_host') + def test_start_default(self, standby_host_mock, active_master_mock, set_osparams_mock): + standby_host_mock.return_value = True + active_master_mock.return_value = False + + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + '/scripts/hawqstandby.py', + classname = 'HawqStandby', + command = 'start', + config_file ='hawq_default.json', + hdp_stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES + ) + + self.__asserts_for_configure() + + self.assertResourceCalled('Execute', 'source /usr/local/hawq/greenplum_path.sh && hawq ssh-exkeys -f /usr/local/hawq/etc/hawq_hosts -p gpadmin', + logoutput = True, + not_if = None, + only_if = None, + user = self.GPADMIN, + timeout = 900 + ) + + self.assertResourceCalled('Execute', 'source /usr/local/hawq/greenplum_path.sh && hawq init standby -a -v', + logoutput = True, + not_if = None, + only_if = None, + user = self.GPADMIN, + timeout = 900 + ) + self.assertNoMoreResources() + + + @patch ('hawqstandby.common.__set_osparams') + @patch ('hawqstandby.master_helper.__is_active_master') + def test_stop_default(self, active_master_mock, set_osparams_mock): + active_master_mock.return_value = False + + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + '/scripts/hawqstandby.py', + classname = 'HawqStandby', + command = 'stop', + config_file ='hawq_default.json', + hdp_stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES + ) + + self.assertResourceCalled('Execute', 'source /usr/local/hawq/greenplum_path.sh && hawq stop standby -M fast -a -v', + logoutput = True, + not_if = None, + only_if = "netstat -tupln | egrep ':5432\\s' | egrep gpsyncmaster", + user = self.GPADMIN, + timeout = 900 + ) + + self.assertNoMoreResources()