def test_install_packages(self, package_provider_mock): no_such_entry_config = {} empty_config = {'hostLevelParams': {'package_list': ''}} dummy_config = { 'hostLevelParams': { 'package_list': "[{\"type\":\"rpm\",\"name\":\"hbase\"}," "{\"type\":\"rpm\",\"name\":\"yet-another-package\"}]" } } # Testing config without any keys with Environment(".") as env: script = Script() Script.config = no_such_entry_config script.install_packages(env) self.assertEquals(len(env.resource_list), 0) # Testing empty package list with Environment(".") as env: script = Script() Script.config = empty_config script.install_packages(env) self.assertEquals(len(env.resource_list), 0) # Testing installing of a list of packages with Environment(".") as env: Script.config = dummy_config script.install_packages("env") resource_dump = pprint.pformat(env.resource_list) self.assertEqual(resource_dump, "[Package['hbase'], Package['yet-another-package']]")
def test_install_packages(self, package_provider_mock): no_packages_config = { 'hostLevelParams': { 'repo_info': "[{\"baseUrl\":\"http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0\",\"osType\":\"centos6\",\"repoId\":\"HDP-2.0._\",\"repoName\":\"HDP\",\"defaultBaseUrl\":\"http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0\"}]", 'agent_stack_retry_count': '5', 'agent_stack_retry_on_unavailability': 'false' } } empty_config = { 'hostLevelParams': { 'package_list': '', 'repo_info': "[{\"baseUrl\":\"http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0\",\"osType\":\"centos6\",\"repoId\":\"HDP-2.0._\",\"repoName\":\"HDP\",\"defaultBaseUrl\":\"http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0\"}]", 'agent_stack_retry_count': '5', 'agent_stack_retry_on_unavailability': 'false' } } dummy_config = { 'hostLevelParams': { 'package_list': "[{\"type\":\"rpm\",\"name\":\"hbase\", \"condition\": \"\"}," "{\"type\":\"rpm\",\"name\":\"yet-another-package\", \"condition\": \"\"}]", 'repo_info': "[{\"baseUrl\":\"http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0\",\"osType\":\"centos6\",\"repoId\":\"HDP-2.0._\",\"repoName\":\"HDP\",\"defaultBaseUrl\":\"http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0\"}]", 'service_repo_info': "[{\"mirrorsList\":\"abc\",\"osType\":\"centos6\",\"repoId\":\"HDP-2.0._\",\"repoName\":\"HDP\",\"defaultBaseUrl\":\"http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0\"}]", 'agent_stack_retry_count': '5', 'agent_stack_retry_on_unavailability': 'false' } } # Testing config without any keys with Environment(".", test_mode=True) as env: script = Script() Script.config = no_packages_config script.install_packages(env) resource_dump = pprint.pformat(env.resource_list) self.assertEquals(resource_dump, "[]") # Testing empty package list with Environment(".", test_mode=True) as env: script = Script() Script.config = empty_config script.install_packages(env) resource_dump = pprint.pformat(env.resource_list) self.assertEquals(resource_dump, "[]") # Testing installing of a list of packages with Environment(".", test_mode=True) as env: script = Script() Script.config = dummy_config script.install_packages("env") resource_dump = pprint.pformat(env.resource_list) self.assertEqual( resource_dump, '[Package[\'hbase\'], Package[\'yet-another-package\']]')
def test_status_commands_clear_structured_out(self, open_mock): """ Tests that status commands will clear and stored structured output from prior status commands. :param open_mock: :return: """ class MagicFile(object): def read(self): return "{}" def write(self, data): pass def __exit__(self, exc_type, exc_val, exc_tb): pass def __enter__(self): return self sys.argv = ["", "status", "foo.py", "", "", "INFO", ""] open_mock.side_effect = [MagicFile()] try: with Environment(".", test_mode=True) as env: script = Script() Script.structuredOut = {"version": "old_version"} script.execute() except: pass self.assertTrue(open_mock.called) self.assertEquals({}, Script.structuredOut)
def test_set_version(self, get_stack_to_component_mock): good_config = { 'hostLevelParams': { 'stack_name': "HDP", 'stack_version': "2.2" }, 'commandParams': { 'version': "2.2.0.0-2041" } } get_stack_to_component_mock.return_value = {"HDP": "kafka-broker"} # Testing default workflow with Environment(".", test_mode=True) as env: script = Script() Script.config = good_config script.set_version() resource_dump = pprint.pformat(env.resource_list) self.assertEquals( resource_dump, '[Execute[\'(\'/usr/bin/hdp-select\', \'set\', \'kafka-broker\', \'2.2.0.0-2041\')\']]' ) # Component does not provide mapping get_stack_to_component_mock.return_value = {} with Environment(".", test_mode=True) as env: script = Script() Script.config = good_config script.set_version() resource_dump = pprint.pformat(env.resource_list) self.assertEquals(resource_dump, '[]') # Component provided mapping, but configuration is not complete (testing fallback) get_stack_to_component_mock.return_value = {"HDP": "kafka-broker"} bad_config = {} with Environment(".", test_mode=True) as env: script = Script() Script.config = bad_config script.set_version() resource_dump = pprint.pformat(env.resource_list) self.assertEquals(resource_dump, '[]')
def test_struct_out(self): from resource_management.libraries.script import Script configs_path = os.path.join(RMFTestCase._getSrcFolder(), "test/python/stacks", self.STACK_VERSION, "configs") script = Script() script.stroutfile = os.path.join(configs_path, "structured-out-status.json") script.load_structured_out() self.assertFalse("version" in script.structuredOut)
def test_bad_struct_out(self): from resource_management.libraries.script import Script from resource_management.core.logger import Logger configs_path = os.path.join(RMFTestCase.get_src_folder(), "test/python/stacks", self.STACK_VERSION, "configs") Logger.initialize_logger() script = Script() script.stroutfile = os.path.join(configs_path, "structured-out-status-bad.json") script.load_structured_out() self.assertTrue(script.structuredOut == {})
def test_bad_struct_out(self, logger_mock): from resource_management.libraries.script import Script logger_mock.warn = MagicMock() configs_path = os.path.join(RMFTestCase.get_src_folder(), "test/python/stacks", self.STACK_VERSION, "configs") script = Script() script.stroutfile = os.path.join(configs_path, "structured-out-status-bad.json") script.load_structured_out() self.assertTrue(logger_mock.warn.called) self.assertTrue(script.structuredOut == {})
def test_save_version_structured_out_stack_select(self, pso_mock): """ Tests that when writing out the version of the component to the structure output, if all else fails, we'll invoke the stack-select tool to see if there are any versions reported. :param pso_mock: :return: """ script = Script() script.stroutfile = '' script.save_component_version_to_structured_out("start") self.assertEqual(pso_mock.call_count, 1) self.assertEquals(pso_mock.call_args[0][0], {'version': '2.6.0.0-1234'})
def test_structured_out(self, open_mock): script = Script() script.stroutfile = '' self.assertEqual(Script.structuredOut, {}) script.put_structured_out({"1": "1"}) self.assertEqual(Script.structuredOut, {"1": "1"}) self.assertTrue(open_mock.called) script.put_structured_out({"2": "2"}) self.assertEqual(open_mock.call_count, 2) self.assertEqual(Script.structuredOut, {"1": "1", "2": "2"}) #Overriding script.put_structured_out({"1": "3"}) self.assertEqual(open_mock.call_count, 3) self.assertEqual(Script.structuredOut, {"1": "3", "2": "2"})