فهرست منبع

[core] Update sample install user's username if needed

The sample user is not always 'hue' with id 1100713 in a new install, all the defaults are with that in old installs, we consolidate the install user by renaming 'sample' username to 'hue'
Jenny Kim 10 سال پیش
والد
کامیت
7836bf3795
4فایلهای تغییر یافته به همراه16 افزوده شده و 10 حذف شده
  1. 2 2
      apps/pig/src/pig/models.py
  2. 3 2
      apps/pig/src/pig/tests.py
  3. 10 5
      apps/useradmin/src/useradmin/models.py
  4. 1 1
      desktop/core/src/desktop/models.py

+ 2 - 2
apps/pig/src/pig/models.py

@@ -25,7 +25,7 @@ from django.core.urlresolvers import reverse
 from django.utils.translation import ugettext as _, ugettext_lazy as _t
 
 from desktop.lib.exceptions_renderable import PopupException
-from desktop.models import Document as Doc
+from desktop.models import Document as Doc, SAMPLE_USER_ID
 from hadoop.fs.hadoopfs import Hdfs
 
 
@@ -93,7 +93,7 @@ class PigScript(Document):
 def create_or_update_script(id, name, script, user, parameters, resources, hadoopProperties, is_design=True):
   try:
     pig_script = PigScript.objects.get(id=id)
-    if id == '1100713': # Special case for the Example, just create an history
+    if id == str(SAMPLE_USER_ID): # Special case for the Example, just create an history
       is_design = False
       raise PigScript.DoesNotExist()
     pig_script.doc.get().can_write_or_exception(user)

+ 3 - 2
apps/pig/src/pig/tests.py

@@ -27,6 +27,7 @@ from nose.tools import assert_true, assert_equal, assert_false
 
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.test_utils import grant_access
+from desktop.models import SAMPLE_USER_ID
 from hadoop import pseudo_hdfs4
 from hadoop.pseudo_hdfs4 import is_live_cluster
 from liboozie.oozie_api_tests import OozieServerProvider
@@ -218,7 +219,7 @@ class TestWithHadoop(OozieBase):
     if is_live_cluster():
       raise SkipTest('HUE-2909: Skipping because test is not reentrant')
 
-    script = PigScript.objects.get(id=1100713)
+    script = PigScript.objects.get(id=SAMPLE_USER_ID)
     script_dict = script.dict
 
     post_data = {
@@ -238,7 +239,7 @@ class TestWithHadoop(OozieBase):
     self.wait_until_completion(job_id)
 
   def test_stop(self):
-    script = PigScript.objects.get(id=1100713)
+    script = PigScript.objects.get(id=SAMPLE_USER_ID)
     script_dict = script.dict
 
     post_data = {

+ 10 - 5
apps/useradmin/src/useradmin/models.py

@@ -53,14 +53,14 @@ import logging
 from datetime import datetime
 from enum import Enum
 
-from django.db import connection, models
+from django.db import connection, models, transaction
 from django.contrib.auth import models as auth_models
 from django.core.cache import cache
 from django.utils.translation import ugettext_lazy as _t
 
 from desktop import appmanager
 from desktop.lib.exceptions_renderable import PopupException
-from desktop.models import SAMPLE_USER_INSTALL
+from desktop.models import SAMPLE_USER_ID, SAMPLE_USER_INSTALL
 from hadoop import cluster
 
 import useradmin.conf
@@ -299,16 +299,21 @@ def install_sample_user():
   """
   user = None
   try:
-    user = auth_models.User.objects.get(id=1100713)
+    user = auth_models.User.objects.get(id=SAMPLE_USER_ID)
     LOG.info('Sample user found: %s' % user.username)
+    if user.username != SAMPLE_USER_INSTALL:
+      with transaction.atomic():
+        user = auth_models.User.objects.filter(id=SAMPLE_USER_ID).select_for_update()[0]
+        user.username = SAMPLE_USER_INSTALL
+        user.save()
   except auth_models.User.DoesNotExist:
     user, created = auth_models.User.objects.get_or_create(
       username=SAMPLE_USER_INSTALL,
       password='!',
       is_active=False,
       is_superuser=False,
-      id=1100713,
-      pk=1100713)
+      id=SAMPLE_USER_ID,
+      pk=SAMPLE_USER_ID)
 
     if created:
       LOG.info('Installed a user called "%s"' % SAMPLE_USER_INSTALL)

+ 1 - 1
desktop/core/src/desktop/models.py

@@ -38,7 +38,7 @@ from desktop.lib.exceptions_renderable import PopupException
 
 LOG = logging.getLogger(__name__)
 
-
+SAMPLE_USER_ID = 1100713
 SAMPLE_USER_INSTALL = 'hue'
 SAMPLE_USER_OWNERS = ['hue', 'sample']