Bug 1631339 - subscription-manager and python-3.7
Summary: subscription-manager and python-3.7
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: subscription-manager
Version: 29
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: ---
Assignee: candlepin-bugs
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
: 1636654 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-09-20 11:31 UTC by Rob Sanders
Modified: 2022-08-02 08:39 UTC (History)
14 users (show)

Fixed In Version: subscription-manager-1.25.5-1.fc30 subscription-manager-1.25.9-1.fc29
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-05-21 01:09:19 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Small diff which fixes my problem (763 bytes, patch)
2018-09-20 11:31 UTC, Rob Sanders
no flags Details | Diff
utils.py fixed (3.53 KB, text/plain)
2019-02-20 14:36 UTC, Ricardo Zanini
no flags Details
files.py fixed (6.73 KB, text/plain)
2019-02-20 14:37 UTC, Ricardo Zanini
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Github candlepin subscription-manager pull 1953 0 'None' closed 1631339: Fix os.errno issue 2020-10-14 07:22:23 UTC
Python 33666 0 None None None 2018-09-20 11:31:27 UTC
Red Hat Knowledge Base (Solution) 3237101 0 None None None 2018-10-15 14:49:25 UTC

Description Rob Sanders 2018-09-20 11:31:28 UTC
Created attachment 1485108 [details]
Small diff which fixes my problem

Python 3.7 - which is shipped with F29 - removed os.errno. It seems that subscription-manager relies on it. 

From the changelog:
https://docs.python.org/3.7/whatsnew/3.7.html

"Several undocumented internal imports were removed. One example is that os.errno is no longer available; use import errno directly instead. Note that such undocumented internal imports may be removed any time without notice, even in micro version releases"


If you try to subscribe to a repository on F29, you'll get the following error:

Traceback (most recent call last):
  File "/usr/lib64/python3.7/site-packages/subscription_manager/identity.py", line 140, in reload
    self.consumer = self._get_consumer_identity()
  File "/usr/lib64/python3.7/site-packages/subscription_manager/identity.py", line 164, in _get_consumer_identity
    return ConsumerIdentity.read()
  File "/usr/lib64/python3.7/site-packages/subscription_manager/identity.py", line 53, in read
    with open(cls.keypath()) as key_file:
FileNotFoundError: [Errno 2] No such file or directory: '/etc/pki/consumer/key.pem'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/sbin/subscription-manager", line 11, in <module>
    load_entry_point('subscription-manager==1.23.3', 'console_scripts', 'subscription-manager')()
  File "/usr/lib64/python3.7/site-packages/subscription_manager/scripts/subscription_manager.py", line 85, in main
    return managercli.ManagerCLI().main()
  File "/usr/lib64/python3.7/site-packages/subscription_manager/managercli.py", line 2838, in __init__
    CLI.__init__(self, command_classes=commands)
  File "/usr/lib64/python3.7/site-packages/subscription_manager/cli.py", line 101, in __init__
    cmd = clazz()
  File "/usr/lib64/python3.7/site-packages/subscription_manager/managercli.py", line 1056, in __init__
    super(RegisterCommand, self).__init__("register", shortdesc, True)
  File "/usr/lib64/python3.7/site-packages/subscription_manager/managercli.py", line 529, in __init__
    super(UserPassCommand, self).__init__(name, shortdesc, primary)
  File "/usr/lib64/python3.7/site-packages/subscription_manager/managercli.py", line 257, in __init__
    self.identity = inj.require(inj.IDENTITY)
  File "/usr/lib64/python3.7/site-packages/subscription_manager/injection.py", line 106, in require
    return FEATURES.require(feature, *args, **kwargs)
  File "/usr/lib64/python3.7/site-packages/subscription_manager/injection.py", line 80, in require
    self.providers[feature] = provider(*args, **kwargs)
  File "/usr/lib64/python3.7/site-packages/subscription_manager/identity.py", line 133, in __init__
    self.reload()
  File "/usr/lib64/python3.7/site-packages/subscription_manager/identity.py", line 147, in reload
    if isinstance(err, IOError) and err.errno == os.errno.ENOENT:
AttributeError: module 'os' has no attribute 'errno'


I've attached a small patch which fixes it for me.

Comment 1 Kevin Howell 2018-10-15 14:49:25 UTC
*** Bug 1636654 has been marked as a duplicate of this bug. ***

Comment 2 Kevin Howell 2018-10-15 14:51:48 UTC
Rob, would you like to submit a PR for this? https://github.com/candlepin/subscription-manager. We ask that the commit message start with the bug number (ex. 1631339: Fix os.errno issue).

Would also accept a patch that git can apply via git am.

We'd like to recognize your contribution by having a commit/changelog entry if you'd like.

Comment 3 Rob Sanders 2018-10-24 22:58:10 UTC
Hi Kevin,

As per your request PR #1953 is now ready.

Comment 4 Fred van Zwieten 2018-12-04 19:35:49 UTC
When I do this:
subscription-manager register:
Username: <name>
Password: <...>
module 'os' has no attribute 'errno'

This is on a subscription-manager on Fedora 29 that has already above fix
# subscription_manager]# rpm -qa | grep -i subscription
subscription-manager-rhsm-certificates-1.24.2-1.fc29.x86_64
dnf-plugin-subscription-manager-1.24.2-1.fc29.x86_64
python3-subscription-manager-rhsm-1.24.2-1.fc29.x86_64
subscription-manager-1.24.2-1.fc29.x86_64

Comment 5 lau18 2018-12-18 18:35:57 UTC
I also saw the it, module 'os' has no attribute 'errno', while registering.

rhsm.log showed:
2018-12-18 10:24:20,189 [INFO] subscription-manager:1871:MainThread @connection.py:917 - Connection built: host=subscription.rhsm.redhat.com port=443 handler=/subscription auth=basic username=;
2018-12-18 10:24:20,190 [ERROR] subscription-manager:1871:MainThread @managercli.py:190 - Error during registration: module 'os' has no attribute 'errno'
2018-12-18 10:24:20,190 [ERROR] subscription-manager:1871:MainThread @managercli.py:191 - module 'os' has no attribute 'errno'
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/syspurpose/utils.py", line 51, in create_dir
    os.makedirs(path, mode=0o755)
  File "/usr/lib64/python3.7/os.py", line 221, in makedirs
    mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/etc/rhsm/syspurpose'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.7/site-packages/subscription_manager/managercli.py", line 1273, in _do_command
    syspurpose = syspurposelib.read_syspurpose()
  File "/usr/lib64/python3.7/site-packages/subscription_manager/syspurposelib.py", line 234, in read_syspurpose
    syspurpose = SyspurposeStore.read(USER_SYSPURPOSE).contents
  File "/usr/lib/python3.7/site-packages/syspurpose/files.py", line 187, in read
    new_store.create()
  File "/usr/lib/python3.7/site-packages/syspurpose/files.py", line 78, in create
    return create_dir(os.path.dirname(self.path)) or \
  File "/usr/lib/python3.7/site-packages/syspurpose/utils.py", line 53, in create_dir
    if e.errno == os.errno.EEXIST:
AttributeError: module 'os' has no attribute 'errno'
2018-12-18 10:33:01,547 [INFO] yum:1890:MainThread @connection.py:917 - Connection built: host=subscription.rhsm.redhat.com port=443 handler=/subscription auth=identity_cert ca_dir=/etc/rhsm/ca/ insecure=False

Comment 6 Brendan Shephard 2018-12-20 22:52:11 UTC
Looks like this is happening again on Fedora 29..

I made similar changes to:

/usr/lib/python3.7/site-packages/syspurpose/utils.py

and 

/usr/lib/python3.7/site-packages/syspurpose/files.py

import errno and  :%s/os.errno/errno/g 

This has got me past that error, but now I'm getting:
sudo subscription-manager register                           
Registering to: satellite.bne-home.net:443/rhsm
Username: admin
Password: 
Environment: Library
'dict' object has no attribute 'has_key'


Looks like this is raised when it tries to call:
if not conduit.facts.has_key('network.fqdn'):
  conduit.facts['network.fqdn'] = socket.getfqdn()

from /usr/share/rhsm-plugins/fqdn.py

I checked to make sure that socket.getfqdn() worked on it's own, which it did. So I just did this:

import socket

from subscription_manager.base_plugin import SubManPlugin

requires_api_version = "1.0"

class FactsPlugin(SubManPlugin):
    name = 'fqdn fact'

    def post_facts_collection_hook(self, conduit):
        try:
            if not conduit.facts.has_key('network.fqdn'):
               conduit.facts['network.fqdn'] = socket.getfqdn()
        except AttributeError as e:
            log.debug("Attribute error in collecting facts: %s" % e)
        conduit.facts['network.fqdn'] = socket.getfqdn()

This allows me to register the system. Probably not the greatest fix for the problem. Probably would help to identify why it couldn't get it in the first place. But my python skillz are limited and this got me out of trouble. Hopefully it provides enough information for a better solution. :)

Comment 7 Brendan Shephard 2018-12-20 23:00:18 UTC
Sorry, that log.debug section didn't actually log anything for me so I removed it and just did the try, except without logging anything. As I said, amateur Python skillz. The working one looks like this:


import socket

from subscription_manager.base_plugin import SubManPlugin

requires_api_version = "1.0"

class FactsPlugin(SubManPlugin):
    name = 'fqdn fact'

    def post_facts_collection_hook(self, conduit):
        try:
            if not conduit.facts.has_key('network.fqdn'):
               conduit.facts['network.fqdn'] = socket.getfqdn()
        except AttributeError as e:
        conduit.facts['network.fqdn'] = socket.getfqdn()



And I verified that the fact is actually available in subscription-manager as well

sudo subscription-manager facts | grep fqdn
network.fqdn: fedora-desktop.bne-home.net

python3.7
Python 3.7.1 (default, Nov 23 2018, 10:01:49) 
[GCC 8.2.1 20181105 (Red Hat 8.2.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.getfqdn()
'fedora-desktop.bne-home.net'

Comment 8 Jiri Hnidek 2019-01-02 09:10:18 UTC
Current master branch of subscription-manager does not include any 'os.errno'. It was replaced by 'errno' module.

'subscription-manager facts | grep fqdn' works for me too.

Comment 9 Wheeler Law 2019-02-19 20:56:10 UTC
Fedora 29 is still listing 1.24.2-1 as the latest version, so this is still problematic when installing subscription-manager through yum.

Comment 10 Ricardo Zanini 2019-02-20 14:34:33 UTC
I've also edited the files:

- /usr/lib/python3.7/site-packages/syspurpose/utils.py
- /usr/lib/python3.7/site-packages/syspurpose/files.py

To get rid of the "module 'os' has no attribute 'errno'" error.

I'm attaching these files if anyone needs them in the future. I've looked at the repo and it seems that it's already been corrected. It's just a matter of applying the fix for F29.

[1] https://github.com/candlepin/subscription-manager/tree/master/syspurpose/src/syspurpose

Cheers!

Comment 11 Ricardo Zanini 2019-02-20 14:36:42 UTC
Created attachment 1536711 [details]
utils.py fixed

/usr/lib/python3.7/site-packages/syspurpose/utils.py fixed

Comment 12 Ricardo Zanini 2019-02-20 14:37:26 UTC
Created attachment 1536713 [details]
files.py fixed

/usr/lib/python3.7/site-packages/syspurpose/files.py with the fixes

Comment 13 Fedora Update System 2019-05-13 15:50:02 UTC
subscription-manager-1.25.5-1.fc28 has been submitted as an update to Fedora 28. https://bodhi.fedoraproject.org/updates/FEDORA-2019-6663f52736

Comment 14 Fedora Update System 2019-05-13 15:50:09 UTC
subscription-manager-1.25.5-1.fc29 has been submitted as an update to Fedora 29. https://bodhi.fedoraproject.org/updates/FEDORA-2019-3928f88562

Comment 15 Fedora Update System 2019-05-13 15:50:16 UTC
subscription-manager-1.25.5-1.fc30 has been submitted as an update to Fedora 30. https://bodhi.fedoraproject.org/updates/FEDORA-2019-10f8c3b13d

Comment 16 Fedora Update System 2019-05-14 01:53:57 UTC
subscription-manager-1.25.5-1.fc30 has been pushed to the Fedora 30 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-10f8c3b13d

Comment 17 Fedora Update System 2019-05-14 03:36:23 UTC
subscription-manager-1.25.5-1.fc28 has been pushed to the Fedora 28 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-6663f52736

Comment 18 Fedora Update System 2019-05-14 04:26:14 UTC
subscription-manager-1.25.5-1.fc29 has been pushed to the Fedora 29 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-3928f88562

Comment 19 Fedora Update System 2019-05-21 01:09:19 UTC
subscription-manager-1.25.5-1.fc30 has been pushed to the Fedora 30 stable repository. If problems still persist, please make note of it in this bug report.

Comment 20 Fedora Update System 2019-06-17 23:16:22 UTC
FEDORA-2019-3928f88562 has been submitted as an update to Fedora 29. https://bodhi.fedoraproject.org/updates/FEDORA-2019-3928f88562

Comment 21 Fedora Update System 2019-06-18 02:16:45 UTC
subscription-manager-1.25.9-1.fc29 has been pushed to the Fedora 29 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-3928f88562

Comment 22 Fedora Update System 2019-07-30 01:45:11 UTC
subscription-manager-1.25.9-1.fc29 has been pushed to the Fedora 29 stable repository. If problems still persist, please make note of it in this bug report.


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