Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] pkgrepo.managed fails with "'SourceEntry' object has no attribute 'repo_line'" #62546

Closed
smitelli opened this issue Aug 25, 2022 · 4 comments · Fixed by #62555
Closed
Assignees
Labels
Bug broken, incorrect, or confusing behavior debian affects this operating system needs-triage package-repo Phosphorus v3005.0 Release code name and version Regression The issue is a bug that breaks functionality known to work in previous releases.

Comments

@smitelli
Copy link

Description
After upgrading to Salt 3005, a previously working pkgrepo.managed state now fails with the error "'SourceEntry' object has no attribute 'repo_line'."

The apparent cause is in salt/modules/aptpkg.py, either in mod_repo() or expand_repo_def(). Each of these lines assumes the locally-defined SourceEntry class is used, which defines a repo_line() method. However on my system, apparently, HAS_APT is True and a vendor-provided implementation of the SourceEntry class without repo_line() is being used. (I can dig more into that later if desired.)

Setup
Example state:

linode-longview-repo:
  pkgrepo.managed:
    - humanname: Linode Longview Repository
    - name: deb https://apt-longview.linode.com/ bullseye main
    - file: /etc/apt/sources.list.d/linode-longview.list
    - key_url: https://apt-longview.linode.com/linode.gpg

Running on an up-to-date Debian 11 machine on Linode. Reproducible in a local VirtualBox VM.

Steps to Reproduce the behavior

$ salt-call -l trace --local state.apply
...
[INFO    ] Running state [deb https://apt-longview.linode.com/ bullseye main] at time 21:10:13.192374
[INFO    ] Executing state pkgrepo.managed for [deb https://apt-longview.linode.com/ bullseye main]
[DEBUG   ] Source https://repo.saltproject.io/py3/debian/11/amd64/latest will be included although is marked invalid
[DEBUG   ] Requesting URL https://apt-longview.linode.com/linode.gpg using GET method
[DEBUG   ] Using backend: tornado
[INFO    ] Executing command apt-key in directory '/root'
[DEBUG   ] stdout: OK
[DEBUG   ] stderr: Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
[ERROR   ] Failed to configure repo 'deb https://apt-longview.linode.com/ bullseye main': 'SourceEntry' object has no attribute 'repo_line'
[INFO    ] Completed state [deb https://apt-longview.linode.com/ bullseye main] at time 21:10:14.018375 (duration_in_ms=826.001)
...
----------
          ID: linode-longview-repo
    Function: pkgrepo.managed
        Name: deb https://apt-longview.linode.com/ bullseye main
      Result: False
     Comment: Failed to configure repo 'deb https://apt-longview.linode.com/ bullseye main': 'SourceEntry' object has no attribute 'repo_line'
     Started: 21:10:13.192374
    Duration: 826.001 ms
     Changes:
----------
...

Expected behavior
In my specific case, this state should succeed with no changes since the Apt repo already exists. In other situations, I would expect it to create/update the repo as warranted.

Versions Report

$ salt-call --versions-report
Salt Version:
          Salt: 3005

Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.11.3
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.0
  msgpack-pure: Not Installed
  mysql-python: 1.4.4
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: 3.9.7
        pygit2: Not Installed
        Python: 3.9.2 (default, Feb 28 2021, 17:03:44)
  python-gnupg: Not Installed
        PyYAML: 5.3.1
         PyZMQ: 20.0.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: debian 11 bullseye
        locale: utf-8
       machine: x86_64
       release: 5.10.0-17-amd64
        system: Linux
       version: Debian GNU/Linux 11 bullseye
@smitelli smitelli added Bug broken, incorrect, or confusing behavior needs-triage labels Aug 25, 2022
@smitelli
Copy link
Author

So, the behavior is a little more nuanced than my initial report suggests.

When I try to apply this state on a pristine, untouched Debian installation, it succeeds in creating the apt repo and this error does not occur. I investigated the two environments to try to determine what is different between them.

Contents of /etc/apt/sources.list.d/linode-longview.list on WORKING host:

deb https://apt-longview.linode.com/ bullseye main

Contents of /etc/apt/sources.list.d/linode-longview.list on BROKEN host:

deb https://apt-longview.linode.com bullseye main

It looks as though the omission of that trailing slash is the cause of this failure. I manually edited linode-longview.list on the broken host to add a /, and Salt runs all my states without error.

This might actually be a bug in the previous version of Salt that originally created this file, as my state's name: field contains that trailing slash, yet the file on disk was not written with one.

@svenseeberg
Copy link
Contributor

Interestingly, I see a different error for pkgrepo.managed on 3 different Salt infrastructures after upgrading to 3005:

          ID: repo_influxdb
    Function: pkgrepo.managed
        Name: deb https://repos.influxdata.com/debian focal stable
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python3/dist-packages/salt/state.py", line 2276, in call
                  ret = self.states[cdata["full"]](
                File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1228, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1243, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1276, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/states/pkgrepo.py", line 439, in managed
                  pre = __salt__["pkg.get_repo"](repo=repo, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1228, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1243, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/modules/aptpkg.py", line 1975, in get_repo
                  repos = list_repos()
                File "/usr/lib/python3/dist-packages/salt/modules/aptpkg.py", line 1921, in list_repos
                  signedby = _get_opts(line=source.line)["signedby"].get("value", "")
                File "/usr/lib/python3/dist-packages/salt/modules/aptpkg.py", line 1746, in _get_opts
                  ret[other_opt]["value"] = opt.split("=", 1)[1]
              IndexError: list index out of range

@OrangeDog OrangeDog added Regression The issue is a bug that breaks functionality known to work in previous releases. Phosphorus v3005.0 Release code name and version debian affects this operating system package-repo labels Aug 26, 2022
@sticky-note
Copy link

sticky-note commented Aug 27, 2022

@svenseeberg

Interestingly, I see a different error for pkgrepo.managed on 3 different Salt infrastructures after upgrading to 3005:

          ID: repo_influxdb
    Function: pkgrepo.managed
        Name: deb https://repos.influxdata.com/debian focal stable
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python3/dist-packages/salt/state.py", line 2276, in call
                  ret = self.states[cdata["full"]](
                File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1228, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1243, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1276, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/states/pkgrepo.py", line 439, in managed
                  pre = __salt__["pkg.get_repo"](repo=repo, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1228, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1243, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/modules/aptpkg.py", line 1975, in get_repo
                  repos = list_repos()
                File "/usr/lib/python3/dist-packages/salt/modules/aptpkg.py", line 1921, in list_repos
                  signedby = _get_opts(line=source.line)["signedby"].get("value", "")
                File "/usr/lib/python3/dist-packages/salt/modules/aptpkg.py", line 1746, in _get_opts
                  ret[other_opt]["value"] = opt.split("=", 1)[1]
              IndexError: list index out of range

This one is related to this issue #62474, Removing deb cdrom: line is a working workaround
Thanks for reporting this one too, will save me a lot of time

@Ch3LL
Copy link
Contributor

Ch3LL commented Aug 29, 2022

Can you test this fix #62555

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior debian affects this operating system needs-triage package-repo Phosphorus v3005.0 Release code name and version Regression The issue is a bug that breaks functionality known to work in previous releases.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants