Merge lp:~gocept/landscape-client/bytes-versioning into lp:~landscape/landscape-client/trunk

Proposed by Steffen Allner
Status: Merged
Approved by: Данило Шеган
Approved revision: 964
Merged at revision: 964
Proposed branch: lp:~gocept/landscape-client/bytes-versioning
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 119 lines (+23/-16)
4 files modified
landscape/__init__.py (+3/-3)
landscape/broker/exchange.py (+1/-1)
landscape/lib/tests/test_versioning.py (+5/-5)
landscape/lib/versioning.py (+14/-7)
To merge this branch: bzr merge lp:~gocept/landscape-client/bytes-versioning
Reviewer Review Type Date Requested Status
Daniel Havlik (community) Approve
Данило Шеган (community) Approve
🤖 Landscape Builder test results Approve
Review via email: mp+320494@code.launchpad.net

Commit message

Only allow bytestrings in landscape.lib.versioning is_version_higher() and sort_versions() functions: this is what Landscape uses in exchanged messages.

Description of the change

To consistently compare software versions, the helper method now only accepts bytes, as the version can come from a message which in turn results from a bpickled stream. To ensure backward compatibility to Python 2.7 versions of the landscape-server we have to keep them as bytes.

The constants defined throughout the project had to be adapted.

To post a comment you must log in.
Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: TRIAL_ARGS=-j4 make check
Result: Success
Revno: 964
Branch: lp:~gocept/landscape-client/bytes-versioning
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3642/

review: Approve (test results)
Revision history for this message
Данило Шеган (danilo) wrote :

Looks good, thanks for splitting this up into a separate branch.

review: Approve
Revision history for this message
Daniel Havlik (nilo) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/__init__.py'
2--- landscape/__init__.py 2017-03-02 09:36:25 +0000
3+++ landscape/__init__.py 2017-03-21 13:06:07 +0000
4@@ -4,7 +4,7 @@
5
6 # The minimum server API version that all Landscape servers are known to speak
7 # and support. It can serve as fallback in case higher versions are not there.
8-DEFAULT_SERVER_API = "3.2"
9+DEFAULT_SERVER_API = b"3.2"
10
11 # The highest server API version that the client is capable of speaking. The
12 # client will use it, unless the server declares to support only a lower
13@@ -22,7 +22,7 @@
14 # 3.3:
15 # * Add new schema for the "registration" message, providing Juju information
16 #
17-SERVER_API = "3.3"
18+SERVER_API = b"3.3"
19
20 # The "client-api" field of outgoing messages will be set to this value, and
21 # used by the server to know which schema do the message types accepted by the
22@@ -54,4 +54,4 @@
23 # "info" field of the response payload for a fail registration, in case the
24 # account has too many pending computers.
25 #
26-CLIENT_API = "3.8"
27+CLIENT_API = b"3.8"
28
29=== modified file 'landscape/broker/exchange.py'
30--- landscape/broker/exchange.py 2017-01-05 11:19:41 +0000
31+++ landscape/broker/exchange.py 2017-03-21 13:06:07 +0000
32@@ -771,7 +771,7 @@
33
34 # Extract the server API from the payload. If it's not there it must
35 # be 3.2, because it's the one that didn't have this field.
36- server_api = result.get("server-api", "3.2")
37+ server_api = result.get("server-api", b"3.2")
38
39 if is_version_higher(server_api, message_store.get_server_api()):
40 # The server can handle a message API that is higher than the one
41
42=== modified file 'landscape/lib/tests/test_versioning.py'
43--- landscape/lib/tests/test_versioning.py 2014-08-22 08:25:25 +0000
44+++ landscape/lib/tests/test_versioning.py 2017-03-21 13:06:07 +0000
45@@ -10,21 +10,21 @@
46 The C{is_version_higher} function returns C{True} if the first
47 version is greater than the second.
48 """
49- self.assertTrue(is_version_higher("3.2", "3.1"))
50+ self.assertTrue(is_version_higher(b"3.2", b"3.1"))
51
52 def test_equal(self):
53 """
54 The C{is_version_higher} function returns C{True} if the first
55 version is the same as the second.
56 """
57- self.assertTrue(is_version_higher("3.1", "3.1"))
58+ self.assertTrue(is_version_higher(b"3.1", b"3.1"))
59
60 def test_lower(self):
61 """
62 The C{is_version_higher} function returns C{False} if the first
63 version is lower than the second.
64 """
65- self.assertFalse(is_version_higher("3.1", "3.2"))
66+ self.assertFalse(is_version_higher(b"3.1", b"3.2"))
67
68
69 class SortVersionsTest(TestCase):
70@@ -34,5 +34,5 @@
71 The C{sort_versions} function sorts the given versions from the
72 highest to the lowest.
73 """
74- versions = ["3.2", "3.3", "3.1"]
75- self.assertEqual(["3.3", "3.2", "3.1"], sort_versions(versions))
76+ versions = [b"3.2", b"3.3", b"3.1"]
77+ self.assertEqual([b"3.3", b"3.2", b"3.1"], sort_versions(versions))
78
79=== modified file 'landscape/lib/versioning.py'
80--- landscape/lib/versioning.py 2014-08-22 08:25:25 +0000
81+++ landscape/lib/versioning.py 2017-03-21 13:06:07 +0000
82@@ -6,23 +6,30 @@
83 def is_version_higher(version1, version2):
84 """Check if a version is higher than another.
85
86- This takes two software versions in the usual "x.y" form
87+ This takes two software versions in the usual b"x.y" form
88 and split them on the decimal character, converting both parts
89- to ints, e.g. "3.2" becomes (3, 2).
90+ to ints, e.g. b"3.2" becomes (3, 2).
91
92 It then does a comparison of the two tuples, and returns C{True} if
93 C{version1} is greater than or equal to C{version2}.
94
95- @param version1: The first version to compare.
96- @param version2: The second version to compare.
97+ @param version1: The first version to compare as C{bytes}.
98+ @param version2: The second version to compare as C{bytes}.
99 @return: C{True} if the first version is greater than or equal to
100 the second.
101 """
102+ version1 = version1.decode("ascii")
103+ version2 = version2.decode("ascii")
104 return StrictVersion(version1) >= StrictVersion(version2)
105
106
107 def sort_versions(versions):
108- """Sort a list of software versions from the highest to the lowest."""
109+ """Sort a list of software versions in from the highest to the lowest.
110+
111+ @param version: a C{list} of C{bytes} describing a version.
112+ """
113 strict_versions = sorted(
114- [StrictVersion(version) for version in versions], reverse=True)
115- return [str(strict_version) for strict_version in strict_versions]
116+ [StrictVersion(version.decode("ascii")) for version in versions],
117+ reverse=True)
118+ return [str(strict_version).encode("ascii")
119+ for strict_version in strict_versions]

Subscribers

People subscribed via source and target branches

to all changes: