Skip to content

Commit

Permalink
add snap-http as a submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
st3v3nmw committed Jan 19, 2024
1 parent d2847f6 commit 07318b2
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 410 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ jobs:
matrix:
os: ["ubuntu-22.04", "ubuntu-20.04"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true
- run: |
make depends
# -common seems a catch-22, but this is just a shortcut to
# initialize user and dirs, some used through tests.
sudo apt-get -y install landscape-common
# add submodules
- run: make check TRIAL=/usr/bin/trial3
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true
- run: make depends
- run: make lint
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "snap-http"]
path = snap-http
url = https://github.com/Perfect5th/snap-http
19 changes: 5 additions & 14 deletions landscape/client/manager/snapmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@

from twisted.internet import task

from landscape.client import snap_http
from landscape.client.manager.plugin import FAILED
from landscape.client.manager.plugin import ManagerPlugin
from landscape.client.manager.plugin import SUCCEEDED

try:
import snap_http
from snap_http import INCOMPLETE_STATUSES
from snap_http import SnapdHttpException
from snap_http import SUCCESS_STATUSES
except ImportError:
from landscape.client.snap.http import INCOMPLETE_STATUSES
from landscape.client.snap.http import SnapdHttpException
from landscape.client.snap.http import SnapHttp
from landscape.client.snap.http import SUCCESS_STATUSES

snap_http = SnapHttp()
from landscape.client.snap_http import INCOMPLETE_STATUSES
from landscape.client.snap_http import SnapdHttpException
from landscape.client.snap_http import SUCCESS_STATUSES


class SnapManager(ManagerPlugin):
Expand Down Expand Up @@ -263,7 +254,7 @@ def _respond(self, snap_results, opid, errors):

def _send_installed_snap_update(self):
try:
installed_snaps = snap_http.list()
installed_snaps = snap_http.list().result
except SnapdHttpException as e:
logging.error(
f"Unable to list installed snaps after snap change: {e}",
Expand Down
68 changes: 44 additions & 24 deletions landscape/client/manager/tests/test_snapmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
from landscape.client.manager.manager import FAILED
from landscape.client.manager.manager import SUCCEEDED
from landscape.client.manager.snapmanager import SnapManager
from landscape.client.snap_http import SnapdHttpException
from landscape.client.snap_http import SnapdResponse
from landscape.client.tests.helpers import LandscapeTest
from landscape.client.tests.helpers import ManagerHelper

try:
from snap_http import SnapdHttpException
except ImportError:
from landscape.client.snap.http import SnapdHttpException


class SnapManagerTest(LandscapeTest):
helpers = [ManagerHelper]
Expand Down Expand Up @@ -56,7 +53,12 @@ def install_snap(name, revision=None, channel=None, classic=False):
{"id": "2", "status": "Done"},
],
}
self.snap_http.list.return_value = {"installed": []}
self.snap_http.list.return_value = SnapdResponse(
"sync",
200,
"OK",
{"installed": []},
)

result = self.manager.dispatch_message(
{
Expand Down Expand Up @@ -94,19 +96,24 @@ def test_install_snaps_batch(self):
self.snap_http.check_changes.return_value = {
"result": [{"id": "1", "status": "Done"}],
}
self.snap_http.list.return_value = {
"installed": [
{
"name": "hello",
"id": "test",
"confinement": "strict",
"tracking-channel": "latest/stable",
"revision": "100",
"publisher": {"validation": "yep", "username": "me"},
"version": "1.2.3",
},
],
}
self.snap_http.list.return_value = SnapdResponse(
"sync",
200,
"OK",
{
"installed": [
{
"name": "hello",
"id": "test",
"confinement": "strict",
"tracking-channel": "latest/stable",
"revision": "100",
"publisher": {"validation": "yep", "username": "me"},
"version": "1.2.3",
},
],
},
)

result = self.manager.dispatch_message(
{
Expand Down Expand Up @@ -139,7 +146,12 @@ def test_install_snap_immediate_error(self):
self.snap_http.install_all.side_effect = SnapdHttpException(
b'{"result": "whoops"}',
)
self.snap_http.list.return_value = {"installed": []}
self.snap_http.list.return_value = SnapdResponse(
"sync",
200,
"OK",
{"installed": []},
)

result = self.manager.dispatch_message(
{
Expand Down Expand Up @@ -170,7 +182,9 @@ def got_result(r):
def test_install_snap_no_status(self):
self.snap_http.install_all.return_value = {"change": "1"}
self.snap_http.check_changes.return_value = {"result": []}
self.snap_http.list.return_value = {"installed": []}
self.snap_http.list.return_value = SnapdResponse(
"sync", 200, "OK", {"installed": []}
)

result = self.manager.dispatch_message(
{
Expand Down Expand Up @@ -199,7 +213,9 @@ def got_result(r):
def test_install_snap_check_error(self):
self.snap_http.install_all.return_value = {"change": "1"}
self.snap_http.check_changes.side_effect = SnapdHttpException("whoops")
self.snap_http.list.return_value = {"installed": []}
self.snap_http.list.return_value = SnapdResponse(
"sync", 200, "OK", {"installed": []}
)

result = self.manager.dispatch_message(
{
Expand Down Expand Up @@ -232,7 +248,9 @@ def test_remove_snap(self):
self.snap_http.check_changes.return_value = {
"result": [{"id": "1", "status": "Done"}],
}
self.snap_http.list.return_value = {"installed": []}
self.snap_http.list.return_value = SnapdResponse(
"sync", 200, "OK", {"installed": []}
)

result = self.manager.dispatch_message(
{
Expand Down Expand Up @@ -263,7 +281,9 @@ def test_set_config(self):
self.snap_http.check_changes.return_value = {
"result": [{"id": "1", "status": "Done"}],
}
self.snap_http.list.return_value = {"installed": []}
self.snap_http.list.return_value = SnapdResponse(
"sync", 200, "OK", {"installed": []}
)

result = self.manager.dispatch_message(
{
Expand Down
13 changes: 3 additions & 10 deletions landscape/client/monitor/snapmonitor.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import logging

from landscape.client import snap_http
from landscape.client.monitor.plugin import DataWatcher
from landscape.client.snap_http import SnapdHttpException
from landscape.message_schemas.server_bound import SNAPS

try:
import snap_http
from snap_http import SnapdHttpException
except ImportError:
from landscape.client.snap.http import SnapHttp
from landscape.client.snap.http import SnapdHttpException

snap_http = SnapHttp()


class SnapMonitor(DataWatcher):

Expand All @@ -37,7 +30,7 @@ def get_data(self):
for i in range(len(snaps)):
try:
config = snap_http.get_conf(snaps[i]["name"])
except SnapdHttpException as e:
except SnapdHttpException:
config = {}

snaps[i]["config"] = config
Expand Down
8 changes: 2 additions & 6 deletions landscape/client/monitor/tests/test_snapmonitor.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from unittest.mock import patch

from landscape.client.monitor.snapmonitor import SnapMonitor
from landscape.client.snap_http import SnapdHttpException
from landscape.client.snap_http import SnapdResponse
from landscape.client.tests.helpers import LandscapeTest
from landscape.client.tests.helpers import MonitorHelper

try:
from snap_http import SnapdHttpException
from snap_http import SnapdResponse
except ImportError:
from landscape.client.snap.http import SnapdHttpException


class SnapMonitorTest(LandscapeTest):
"""Snap plugin tests."""
Expand Down
Empty file removed landscape/client/snap/__init__.py
Empty file.
Loading

0 comments on commit 07318b2

Please sign in to comment.