Пример #1
0
  def test_execution(self, cache_mock, get_config_mock, get_tmp_dir_mock, get_config_file_mock, os_path_exists_mock, call_mock):
    # Mock the config objects
    json_file_path = os.path.join(self.get_custom_actions_dir(), "ru_execute_tasks_namenode_prepare.json")
    self.assertTrue(os.path.isfile(json_file_path))
    with open(json_file_path, "r") as json_file:
      json_payload = json.load(json_file)

    config_dict = ConfigDictionary(json_payload)

    cache_mock.return_value = "/var/lib/ambari-agent/cache/common-services/HDFS/2.1.0.2.0/package"
    get_config_mock.return_value = config_dict
    get_tmp_dir_mock.return_value = "/tmp"
    ambari_agent_ini_file_path = os.path.join(self.get_src_folder(), "../../ambari-agent/conf/unix/ambari-agent.ini")
    self.assertTrue(os.path.isfile(ambari_agent_ini_file_path))
    get_config_file_mock.return_value = ambari_agent_ini_file_path

    # Mock os calls
    os_path_exists_mock.return_value = True
    call_mock.side_effect = fake_call   # echo the command

    # Ensure that the json file was actually read.
    stack_name = default("/hostLevelParams/stack_name", None)
    stack_version = default("/hostLevelParams/stack_version", None)
    service_package_folder = default('/roleParams/service_package_folder', None)

    self.assertEqual(stack_name, "HDP")
    self.assertEqual(stack_version, 2.2)
    self.assertEqual(service_package_folder, "common-services/HDFS/2.1.0.2.0/package")

    # Begin the test
    ru_execute = ExecuteUpgradeTasks()
    ru_execute.actionexecute(None)

    call_mock.assert_called_with("source /var/lib/ambari-agent/ambari-env.sh ; /usr/bin/ambari-python-wrap /var/lib/ambari-agent/cache/common-services/HDFS/2.1.0.2.0/package/scripts/namenode.py prepare_rolling_upgrade /tmp", logoutput=True, quiet=True)
Пример #2
0
    def test_execution_custom_action(self, cache_mock, get_config_mock,
                                     get_tmp_dir_mock, get_config_file_mock,
                                     os_path_exists_mock, call_mock):
        # Mock the config objects
        json_file_path = os.path.join(
            self.get_custom_actions_dir(),
            "ru_execute_tasks_namenode_prepare.json")
        self.assertTrue(os.path.isfile(json_file_path))
        with open(json_file_path, "r") as json_file:
            json_payload = json.load(json_file)

        del json_payload['roleParams']['service_package_folder']
        del json_payload['roleParams']['hooks_folder']

        config_dict = ConfigDictionary(json_payload)

        cache_mock.return_value = "/var/lib/ambari-agent/cache/custom_actions"
        get_config_mock.return_value = config_dict
        get_tmp_dir_mock.return_value = "/tmp"

        ambari_agent_ini_file_path = os.path.join(
            self.get_src_folder(),
            "../../ambari-agent/conf/unix/ambari-agent.ini")
        self.assertTrue(os.path.isfile(ambari_agent_ini_file_path))
        get_config_file_mock.return_value = ambari_agent_ini_file_path

        # Mock os calls
        os_path_exists_mock.return_value = True
        call_mock.side_effect = fake_call  # echo the command

        # Ensure that the json file was actually read.
        stack_name = default("/hostLevelParams/stack_name", None)
        stack_version = default("/hostLevelParams/stack_version", None)
        service_package_folder = default('/roleParams/service_package_folder',
                                         None)

        self.assertEqual(stack_name, "HDP")
        self.assertEqual(stack_version, 2.2)
        self.assertEqual(service_package_folder, None)

        # Begin the test
        ru_execute = ExecuteUpgradeTasks()
        ru_execute.actionexecute(None)

        call_mock.assert_called_with(
            "/usr/bin/ambari-python-wrap /var/lib/ambari-agent/cache/custom_actions"
            + os.sep + "scripts/namenode.py prepare_rolling_upgrade /tmp",
            logoutput=True,
            quiet=True)
        pass
Пример #3
0
    def test_execution(self, cache_mock, get_config_mock, get_tmp_dir_mock,
                       get_config_file_mock, os_path_exists_mock, call_mock):
        # Mock the config objects
        json_file_path = os.path.join(
            self.get_custom_actions_dir(),
            "ru_execute_tasks_namenode_prepare.json")
        self.assertTrue(os.path.isfile(json_file_path))
        with open(json_file_path, "r") as json_file:
            json_payload = json.load(json_file)

        config_dict = ConfigDictionary(json_payload)

        cache_mock.return_value = self.CACHE_MOCK_DIR
        get_config_mock.return_value = config_dict
        get_tmp_dir_mock.return_value = "/tmp"

        ambari_agent_ini_file_path = self.AGENT_INI_FILE_PATH
        self.assertTrue(os.path.isfile(ambari_agent_ini_file_path))
        get_config_file_mock.return_value = ambari_agent_ini_file_path

        # Mock os calls
        os_path_exists_mock.return_value = True
        call_mock.side_effect = fake_call  # echo the command

        # Ensure that the json file was actually read.
        stack_name = default("/clusterLevelParams/stack_name", None)
        stack_version = default("/clusterLevelParams/stack_version", None)
        service_package_folder = default('/roleParams/service_package_folder',
                                         None)

        self.assertEqual(stack_name, "HDP")
        self.assertEqual(stack_version, '2.2')
        self.assertEqual(service_package_folder,
                         "common-services/HDFS/2.1.0.2.0/package")

        # Begin the test
        ru_execute = ExecuteUpgradeTasks()
        ru_execute.actionexecute(None)

        call_mock.assert_called_with(
            "source /var/lib/ambari-agent/ambari-env.sh ; /usr/bin/ambari-python-wrap /var/lib/ambari-agent/cache/common-services/HDFS/2.1.0.2.0/package"
            + os.sep + "scripts/namenode.py prepare_rolling_upgrade /tmp",
            logoutput=True,
            quiet=True)
        pass