-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Port #51625 to master #56953
Port #51625 to master #56953
Conversation
Any idea when this will get merged ? Can I help ? @alexey-zhukovin |
@valentin2105 Hey, are you still interested/able to help with this? Currently the problem is that there aren't any tests written for this. If you're able to help, writing tests would be appreciated! If you need help getting started with tests, I run a test clinic on Tues/Thurs (check https://saltproject.io/ for more on times) |
@alexey-zhukovin Hey! Do you mind adding the Quite useful to install microk8s |
ret["comment"] = 'Failed to switch Package "{0}" to channel {1}'.format( | ||
name, channel | ||
) | ||
ret["comment"] += "\noutput:\n" + install["output"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been testing out using these modules in the packages-formula
, to replace the use of cmd.run
for snap
installations. Hit a traceback with this line:
An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/state.py", line 2179, 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 1201, 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 1216, in _run_as
return _func_or_method(*args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1249, in wrapper
return f(*args, **kwargs)
File "/var/cache/salt/minion/extmods/states/snap.py", line 84, in installed
ret["comment"] += "\noutput:\n" + install["output"]
UnboundLocalError: local variable 'install' referenced before assignment
Looking at the code, realised that this line should actually be:
ret["comment"] += "\noutput:\n" + install["output"] | |
ret["comment"] += "\noutput:\n" + refresh["output"] |
Left over from a copy-paste of L53 above, perhaps.
@lordcirth As the original PR author, would you mind confirming this suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@myii Sounds correct to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appreciate the response, @lordcirth. I've got another question, if you don't mind.
I've found that the execution module functions are returning bytes instead of string objects (where relevant). Should __salt__["cmd.run_all"]()
be used instead of subprocess.check_output()
? Checking across other modules, that seems to be the main method being used when working with command output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very experienced with Python or Saltstack internals. Your guess is probably better than mine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lordcirth OK, If I get around to pushing this to the packages-formula
, I'll try to refactor it accordingly. I'll report back here on how things work out. Thanks again for the prompt response -- and for providing these modules in the first place!
Patch to support the diff -Naur salt.orig/modules/snap.py salt/modules/snap.py
--- salt.orig/modules/snap.py 2022-03-21 10:56:38.000000000 +0700
+++ salt/modules/snap.py 2022-03-21 10:58:48.000000000 +0700
@@ -28,7 +28,7 @@
)
-def install(pkg, channel=None, refresh=False):
+def install(pkg, channel=None, refresh=False, classic=False):
"""
Install the specified snap package from the specified channel.
Returns a dictionary of "result" and "output".
@@ -42,6 +42,9 @@
refresh : False
If True, use "snap refresh" instead of "snap install".
This allows changing the channel of a previously installed package.
+
+ classic : False
+ Install a classic snap package if True
"""
args = []
ret = {"result": None, "output": ""}
@@ -54,6 +57,9 @@
if channel:
args.append("--channel=" + channel)
+ if classic:
+ args.append("--classic")
+
try:
# Try to run it, merging stderr into output
ret["output"] = subprocess.check_output(
diff -Naur salt.orig/states/snap.py salt/states/snap.py
--- salt.orig/states/snap.py 2022-03-21 10:57:50.000000000 +0700
+++ salt/states/snap.py 2022-03-21 10:58:34.000000000 +0700
@@ -24,7 +24,7 @@
)
-def installed(name, channel=None):
+def installed(name, channel=None, classic=False):
"""
Ensure that the named snap package is installed
@@ -33,6 +33,9 @@
channel
Optional. The channel to install the package from.
+
+ classic
+ Optional. Install a classic snap package if True
"""
ret = {"name": name, "changes": {}, "pchanges": {}, "result": None, "comment": ""}
@@ -45,7 +48,7 @@
ret["result"] = None
return ret
- install = __salt__["snap.install"](name, channel=channel)
+ install = __salt__["snap.install"](name, channel=channel, classic=classic)
if install["result"]:
ret["comment"] = 'Package "{0}" was installed'.format(name)
ret["changes"]["new"] = name
@@ -73,7 +76,7 @@
return ret
refresh = __salt__["snap.install"](
- name, channel=channel, refresh=True
+ name, channel=channel, refresh=True, classic=classic
)
if refresh["result"]:
ret["comment"] = 'Package "{0}" was switched to channel {1}'.format( |
There are some encoding issues here:
As suggested by @myii, going to try using |
Overall it needs more testing and polishing (e.g. proper logging), because the fixes I made were quick and dirty (and I'm not familiar with snap) |
Fixed another issue reported by Imran (via Slack):
The channel Tracking field can be truncated (see the And overall I think that multiple package managers in a single OS are breaking the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a changelog and a testcase. Also needs to have the feedback implemented.
until the pre-commit is fixed, tests are added, and a changelog added. this PR can not be merged. |
Closing this due to inactivity. Anyone should feel free to re-open it if they want to see it through to the end in one release cycle. |
For anyone that followed this, I just released a Salt extension for Snapd: https://github.com/salt-extensions/saltext-snap It should be much more comprehensive than the previous unported modules since it interfaces with the REST API in addition to the CLI, depending on the query/operation, and offers several states in addition to |
What does this PR do?
Port #51625 to master
Fixes: #58132