Bug 629718 - If locale is C pulp-admin and pulp-client fail with exception
Summary: If locale is C pulp-admin and pulp-client fail with exception
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Pulp
Classification: Retired
Component: z_other
Version: unspecified
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
: Sprint 23
Assignee: Jason Connor
QA Contact: wes hayutin
URL:
Whiteboard:
Depends On:
Blocks: verified-to-close
TreeView+ depends on / blocked
 
Reported: 2010-09-02 19:24 UTC by Mike McCune
Modified: 2014-03-31 01:38 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2011-08-16 14:20:39 UTC


Attachments (Terms of Use)
patch to resolve issue (685 bytes, patch)
2011-04-21 21:26 UTC, Mike McCune
no flags Details | Diff

Description Mike McCune 2010-09-02 19:24:02 UTC
Puppet sets the locale for running scripts to be "C" which is the Posix default.  From Python's getdefaultlocale() method:

        According to POSIX, a program which has not called
        setlocale(LC_ALL, "") runs using the portable 'C' locale.
        Calling setlocale(LC_ALL, "") lets it use the default locale as
        defined by the LANG variable. Since we don't want to interfere
        with the current locale setting we thus emulate the behavior
        in the way described above.

which causes getdefaultlocale() to return None.


Reproduce:

$ export LANG=C
$ pulp-admin repo list -u admin -p admin
AttributeError: 'NoneType' object has no attribute 'lower'

Fix is to check if we got None back and not try to munge the locale if so.

Comment 1 Preethi Thomas 2010-09-21 18:02:38 UTC
verified

[root@preethi ~]# export LANG=C
[root@preethi ~]# pulp-admin repo list -u admin -p admin
+-------------------------------------------+
    List of Available Repositories 
+-------------------------------------------+

Label                   f12_i386-5               
Name                    f12                      
Feed                    {u'url': u'file:///var/mypackages/', u'type': u'local', u'supported_types': [u'yum', u'local', u'rhn']}
Arch                    i386                     
Sync Schedule           None                     
Packages                0                        
Files                   0                        


Label                   local-repo               
Name                    f12                      
Feed                    {u'url': u'file:///var/mypackages/', u'type': u'local', u'supported_types': [u'yum', u'local', u'rhn']}
Arch                    i386                     
Sync Schedule           None                     
Packages                0                        
Files                   0                        


Label                   local-repo-1             
Name                    local                    
Feed                    {u'url': u'file:///root/rpm-dir/', u'type': u'local', u'supported_types': [u'yum', u'local', u'rhn']}
Arch                    noarch                   
Sync Schedule           None                     
Packages                0                        
Files                   0                        


Label                   f13                      
Name                    f13                      
Feed                    {u'url': u'http://download.devel.redhat.com/released/F-13/GOLD/Fedora/x86_64/os/', u'type': u'yum', u'supported_types': [u'yum', u'local', u'rhn']}
Arch                    x86_64                   
Sync Schedule           None                     
Packages                3102                     
Files                   8                        


Label                   f12_x86_64               
Name                    f12                      
Feed                    {u'url': u'http://download.devel.redhat.com/released/F-12/GOLD/Fedora/x86_64/os/', u'type': u'yum', u'supported_types': [u'yum', u'local', u'rhn']}
Arch                    x86_64                   
Sync Schedule           None                     
Packages                2998                     
Files                   8

Comment 2 Preethi Thomas 2010-10-20 16:11:41 UTC
Closed after review.

Comment 3 Mike McCune 2011-04-21 21:24:01 UTC
This is happening again, we aren't being defensive if there is no locale set:

otice: /Stage[main]//Service[pulp-server]/ensure: ensure changed 'stopped' to 'running'
notice: /Stage[main]//Exec[pulp-auth-2]/returns: executed successfully
notice: /Stage[main]//Exec[pulp-create-f13-repo]/returns: Traceback (most recent call last):
notice: /Stage[main]//Exec[pulp-create-f13-repo]/returns:   File "/usr/bin/pulp-admin", line 170, in <module>
notice: /Stage[main]//Exec[pulp-create-f13-repo]/returns:     admin.main()
notice: /Stage[main]//Exec[pulp-create-f13-repo]/returns:   File "/usr/lib/python2.7/site-packages/pulp/client/cli/base.py", line 135, in main
notice: /Stage[main]//Exec[pulp-create-f13-repo]/returns:     self.setup_server()
notice: /Stage[main]//Exec[pulp-create-f13-repo]/returns:   File "/usr/lib/python2.7/site-packages/pulp/client/cli/base.py", line 107, in setup_server
notice: /Stage[main]//Exec[pulp-create-f13-repo]/returns:     self._server = server.PulpServer(host, int(port), scheme, path)
notice: /Stage[main]//Exec[pulp-create-f13-repo]/returns:   File "/usr/lib/python2.7/site-packages/pulp/client/server.py", line 182, in __init__
notice: /Stage[main]//Exec[pulp-create-f13-repo]/returns:     default_locale = locale.getdefaultlocale()[0].lower().replace('_', '-')
notice: /Stage[main]//Exec[pulp-create-f13-repo]/returns: AttributeError: 'NoneType' object has no attribute 'lower'
err: /Stage[main]//Exec[pulp-create-f13-repo]/returns: change from notrun to 0 failed: /usr/bin/pulp-admin repo create --id f13-x86_64 --feed yum:http://mirror.uoregon.edu/fedora/linux/releases/14/Fedora/x86_64/os/ returned 1 instead of one of [0] at /cloud/configure/recipes/aeolus_recipe/manifests/pulp.pp:32
notice: Finished catalog run in 1.76 seconds


Note the code in server.py:

        default_locale = locale.getdefaultlocale()[0].lower().replace('_', '-')

this bug was fixed earlier with:

+        default_locale = locale.getdefaultlocale()[0]
+        if default_locale:
+            default_locale = default_locale.lower().replace('_', '-')

in sha: b58d871628d77cd290a70ffb6afa3ff2f3a10ab0

Comment 4 Mike McCune 2011-04-21 21:26:52 UTC
Created attachment 494005 [details]
patch to resolve issue

Patch to resolve the issue

Comment 5 Richard Su 2011-04-21 22:13:43 UTC
Thanks Mike. After applying patch I am seeing this. Still related to MISSING lang.

Traceback (most recent call last):
  File "/usr/bin/pulp-admin", line 170, in <module>
    admin.main()
  File "/usr/lib/python2.7/site-packages/pulp/client/cli/base.py", line 137, in main
    command.main(args[1:])
  File "/usr/lib/python2.7/site-packages/pulp/client/core/base.py", line 118, in main
    action.main(args[1:])
  File "/usr/lib/python2.7/site-packages/pulp/client/core/base.py", line 226, in main
    self.run()
  File "/usr/lib/python2.7/site-packages/pulp/client/core/auth.py", line 46, in run
    cert_dict = self.user_api.admin_certificate()
  File "/usr/lib/python2.7/site-packages/pulp/client/api/user.py", line 53, in admin_certificate
    return self.server.GET(path)[1]
  File "/usr/lib/python2.7/site-packages/pulp/client/server.py", line 291, in GET
    return self._request('GET', path, queries)
  File "/usr/lib/python2.7/site-packages/pulp/client/server.py", line 243, in _request
    connection.request(method, url, body=body, headers=self.headers)
  File "/usr/lib64/python2.7/httplib.py", line 946, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib64/python2.7/httplib.py", line 986, in _send_request
    self.putheader(hdr, value)
  File "/usr/lib64/python2.7/httplib.py", line 924, in putheader
    str = '%s: %s' % (header, '\r\n\t'.join(values))
TypeError: sequence item 0: expected string, NoneType found

Comment 6 Richard Su 2011-04-26 01:26:46 UTC
Just FYI, I had to add a couple more lines to the patch above to get myself unstuck. Needed to set default_locale to something, or the error in comment 5 would be thrown.

        default_locale = locale.getdefaultlocale()[0]
        if default_locale:
            default_locale = default_locale.lower().replace('_', '-')
        else:
            default_locale = "us-en"

Comment 7 Jay Dobies 2011-04-28 17:36:50 UTC
Fixed in commit:

commit	db1a98790221bfb96a3648de4924f508696b6c0b
tree	13313e35be78b7426d0093bd212c61ad39b4beda


629718 - adding sane default language encoding


src/pulp/client/server.py

Comment 8 Jeff Ortel 2011-05-04 15:41:53 UTC
build: 0.173

Comment 9 Preethi Thomas 2011-05-05 18:56:00 UTC
[root@preethi ~]# rpm -q pulp
pulp-0.0.173-1.fc14.noarch

[root@preethi ~]# export LANG=C
[root@preethi ~]# 
[root@preethi ~]# pulp-admin repo  list
+------------------------------------------+
       List of Available Repositories
+------------------------------------------+

Id                 	f13-original             
Name               	f13-original             
Feed URL           	http://download.devel.redhat.com/released/F-13/GOLD/Fedora/x86_64/os/
Feed Type          	yum                      
Feed Certs         	No                       
Consumer Certs     	No                       
Architecture       	x86_64                   
Sync Schedule      	None                     
Packages           	3102                     
Files              	0                        
Distributions      	ks-f13-original-x86_64   
Publish            	True                     
Clones             	[]                       
Groups             	None                     
Filters            	[]                       
Notes              	{}

Comment 10 Preethi Thomas 2011-08-16 14:20:39 UTC
Closing with Community Release 15

pulp-0.0.223-4.


Note You need to log in before you can comment on or make changes to this bug.