예제 #1
0
    def test_all_cli_options_are_collected_when_enabling_sso(
            self, is_root_mock, is_server_runing_mock, get_silent_mock,
            get_ambari_properties_mock, update_properties_mock,
            perform_changes_via_rest_api_mock):
        out = StringIO.StringIO()
        sys.stdout = out

        is_root_mock.return_value = True
        is_server_runing_mock.return_value = (True, 0)
        get_silent_mock.return_value = False

        properties = Properties()
        get_ambari_properties_mock.return_value = properties

        sso_enabled = 'true'
        sso_enabled_services = 'Ambari, SERVICE1, SERVICE2'
        sso_provider_url = 'https://c7402.ambari.apache.org:8443/gateway/knoxsso/api/v1/websso'
        sso_public_cert_file = '/test/file/path'
        sso_jwt_cookie_name = 'test_cookie'
        sso_jwt_audience_list = 'test, audience, list'
        options = self._create_empty_options_mock()
        options.sso_enabled = sso_enabled
        options.sso_provider_url = sso_provider_url
        options.sso_public_cert_file = sso_public_cert_file
        options.sso_jwt_cookie_name = sso_jwt_cookie_name
        options.sso_jwt_audience_list = sso_jwt_audience_list
        options.sso_enabled_services = sso_enabled_services

        setup_sso(options)

        self.assertTrue(update_properties_mock.called)
        self.assertEqual(properties.get_property(JWT_AUTH_ENBABLED),
                         sso_enabled)
        self.assertEqual(properties.get_property(JWT_AUTH_PROVIDER_URL),
                         sso_provider_url)
        self.assertEqual(properties.get_property(JWT_PUBLIC_KEY),
                         sso_public_cert_file)
        self.assertEqual(properties.get_property(JWT_COOKIE_NAME),
                         sso_jwt_cookie_name)
        self.assertEqual(properties.get_property(JWT_AUDIENCES),
                         sso_jwt_audience_list)
        self.assertTrue(perform_changes_via_rest_api_mock.called)

        sys.stdout = sys.__stdout__
        pass
예제 #2
0
    def test_all_cli_options_are_collected_when_enabling_sso(
            self, is_root_mock, get_silent_mock, get_ambari_properties_mock,
            update_properties_mock):
        out = StringIO.StringIO()
        sys.stdout = out

        is_root_mock.return_value = True
        get_silent_mock.return_value = False

        properties = Properties()
        get_ambari_properties_mock.return_value = properties

        sso_enabled = 'true'
        sso_provider_url = 'http://testHost:8080'
        sso_public_cert_file = '/test/file/path'
        sso_jwt_cookie_name = 'test_cookie'
        sso_jwt_audience_list = 'test, audience, list'
        options = self._create_empty_options_mock()
        options.sso_enabled = sso_enabled
        options.sso_provider_url = sso_provider_url
        options.sso_public_cert_file = sso_public_cert_file
        options.sso_jwt_cookie_name = sso_jwt_cookie_name
        options.sso_jwt_audience_list = sso_jwt_audience_list

        setup_sso(options)

        self.assertTrue(update_properties_mock.called)
        self.assertEqual(properties.get_property(JWT_AUTH_ENBABLED),
                         sso_enabled)
        self.assertEqual(properties.get_property(JWT_AUTH_PROVIDER_URL),
                         sso_provider_url)
        self.assertEqual(properties.get_property(JWT_PUBLIC_KEY),
                         sso_public_cert_file)
        self.assertEqual(properties.get_property(JWT_COOKIE_NAME),
                         sso_jwt_cookie_name)
        self.assertEqual(properties.get_property(JWT_AUDIENCES),
                         sso_jwt_audience_list)

        sys.stdout = sys.__stdout__
        pass
예제 #3
0
    def test_only_sso_enabled_cli_option_is_collected_when_disabling_sso(
            self, is_root_mock, is_server_runing_mock, get_silent_mock,
            get_ambari_properties_mock, update_properties_mock, urlopen_mock):
        out = StringIO.StringIO()
        sys.stdout = out

        is_root_mock.return_value = True
        is_server_runing_mock.return_value = (True, 0)
        get_silent_mock.return_value = False

        properties = Properties()
        get_ambari_properties_mock.return_value = properties

        sso_enabled = 'false'
        sso_provider_url = 'http://testHost:8080'
        sso_public_cert_file = '/test/file/path'
        sso_jwt_cookie_name = 'test_cookie'
        sso_jwt_audience_list = 'test, audience, list'
        options = self._create_empty_options_mock()
        options.sso_enabled = sso_enabled
        options.sso_provider_url = sso_provider_url
        options.sso_public_cert_file = sso_public_cert_file
        options.sso_jwt_cookie_name = sso_jwt_cookie_name
        options.sso_jwt_audience_list = sso_jwt_audience_list

        response = MagicMock()
        response.getcode.return_value = 200
        urlopen_mock.return_value = response

        setup_sso(options)

        self.assertTrue(update_properties_mock.called)
        self.assertEqual(properties.get_property(JWT_AUTH_ENBABLED),
                         sso_enabled)
        self.assertTrue(
            JWT_AUTH_PROVIDER_URL not in properties.propertyNames())
        self.assertTrue(JWT_PUBLIC_KEY not in properties.propertyNames())
        self.assertTrue(JWT_COOKIE_NAME not in properties.propertyNames())
        self.assertTrue(JWT_AUDIENCES not in properties.propertyNames())

        sys.stdout = sys.__stdout__
        pass
예제 #4
0
            if ("agent.fqdn.service.url" == prop_key):
                #BUG-7179 what is agent.fqdn property in ambari.props?
                new_properties.process_pair(GET_FQDN_SERVICE_URL, prop_value)
            elif ("server.os_type" == prop_key):
                new_properties.process_pair(OS_TYPE_PROPERTY,
                                            OS_FAMILY + OS_VERSION)
            else:
                new_properties.process_pair(prop_key, prop_value)

        # Adding custom user name property if it is absent
        # In previous versions without custom user support server was started as
        # "root" anyway so it's a reasonable default
        if not NR_USER_PROPERTY in new_properties.keys():
            new_properties.process_pair(NR_USER_PROPERTY, "root")

        isJDK16Installed = new_properties.get_property(
            JAVA_HOME_PROPERTY) == DEFAULT_JDK16_LOCATION
        if not JDK_NAME_PROPERTY in new_properties.keys() and isJDK16Installed:
            new_properties.process_pair(JDK_NAME_PROPERTY, JDK_NAMES[1])

        if not JCE_NAME_PROPERTY in new_properties.keys() and isJDK16Installed:
            new_properties.process_pair(JCE_NAME_PROPERTY,
                                        JCE_POLICY_FILENAMES[1])

        if not OS_FAMILY_PROPERTY in new_properties.keys():
            new_properties.process_pair(OS_FAMILY_PROPERTY,
                                        OS_FAMILY + OS_VERSION)

        new_properties.store(open(conf_file, 'w'))

    except Exception, e:
        print 'Could not write "%s": %s' % (conf_file, e)
예제 #5
0
    for prop_key, prop_value in old_properties.getPropertyDict().items():
      if ("agent.fqdn.service.url" == prop_key):
        #BUG-7179 what is agent.fqdn property in tbds.props?
        new_properties.process_pair(GET_FQDN_SERVICE_URL, prop_value)
      elif ("server.os_type" == prop_key):
        new_properties.process_pair(OS_TYPE_PROPERTY, OS_FAMILY + OS_VERSION)
      else:
        new_properties.process_pair(prop_key, prop_value)

    # Adding custom user name property if it is absent
    # In previous versions without custom user support server was started as
    # "root" anyway so it's a reasonable default
    if not NR_USER_PROPERTY in new_properties.keys():
      new_properties.process_pair(NR_USER_PROPERTY, "root")

    isJDK16Installed = new_properties.get_property(JAVA_HOME_PROPERTY) == DEFAULT_JDK16_LOCATION
    if not JDK_NAME_PROPERTY in new_properties.keys() and isJDK16Installed:
      new_properties.process_pair(JDK_NAME_PROPERTY, JDK_NAMES[1])

    if not JCE_NAME_PROPERTY in new_properties.keys() and isJDK16Installed:
      new_properties.process_pair(JCE_NAME_PROPERTY, JCE_POLICY_FILENAMES[1])

    if not OS_FAMILY_PROPERTY in new_properties.keys():
      new_properties.process_pair(OS_FAMILY_PROPERTY, OS_FAMILY + OS_VERSION)

    new_properties.store(open(conf_file, 'w'))

  except Exception, e:
    print 'Could not write "%s": %s' % (conf_file, e)
    return -1