Merge ~cgrabowski/maas:maas_cli_read_boot_resource_as_bytes into maas:master

Proposed by Christian Grabowski
Status: Merged
Approved by: Christian Grabowski
Approved revision: 6b57a131afcd36adc0f67666b6649dce63e3e510
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~cgrabowski/maas:maas_cli_read_boot_resource_as_bytes
Merge into: maas:master
Diff against target: 51 lines (+7/-4)
3 files modified
src/maascli/actions/boot_resources_create.py (+2/-2)
src/maascli/actions/tests/test_boot_resources_create.py (+3/-1)
src/maascli/api.py (+2/-1)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Alberto Donato (community) Approve
Review via email: mp+408018@code.launchpad.net

Commit message

remove rb from make_Content to have the same behavior as what's actually passed to action

read boot resources as bytes

To post a comment you must log in.
Revision history for this message
Alberto Donato (ack) wrote :

+1, thanks for the fix

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b maas_cli_read_boot_resource_as_bytes lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 613ae7c058aa09bbbc25fd10eac42aeddf64589a

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

LANDING
-b maas_cli_read_boot_resource_as_bytes lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10870/consoleText

Revision history for this message
MAAS Lander (maas-lander) wrote :

LANDING
-b maas_cli_read_boot_resource_as_bytes lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10875/consoleText

Revision history for this message
MAAS Lander (maas-lander) wrote :

LANDING
-b maas_cli_read_boot_resource_as_bytes lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10876/consoleText

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b maas_cli_read_boot_resource_as_bytes lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: b33003bce4ca3ce18f5bea9acc7ba376a7d1fc1f

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b maas_cli_read_boot_resource_as_bytes lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 6b57a131afcd36adc0f67666b6649dce63e3e510

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maascli/actions/boot_resources_create.py b/src/maascli/actions/boot_resources_create.py
2index faae098..6640c3b 100644
3--- a/src/maascli/actions/boot_resources_create.py
4+++ b/src/maascli/actions/boot_resources_create.py
5@@ -118,7 +118,7 @@ class BootResourcesCreateAction(Action):
6 """Return the size and sha256 of the content."""
7 size = 0
8 sha256 = hashlib.sha256()
9- with content() as fd:
10+ with content("rb") as fd:
11 while True:
12 buf = fd.read(CHUNK_SIZE)
13 length = len(buf)
14@@ -164,7 +164,7 @@ class BootResourcesCreateAction(Action):
15
16 def upload_content(self, upload_uri, content, insecure=False):
17 """Upload the content in chunks."""
18- with content() as fd:
19+ with content("rb") as fd:
20 while True:
21 buf = fd.read(CHUNK_SIZE)
22 length = len(buf)
23diff --git a/src/maascli/actions/tests/test_boot_resources_create.py b/src/maascli/actions/tests/test_boot_resources_create.py
24index 54c40c6..8a5a76c 100644
25--- a/src/maascli/actions/tests/test_boot_resources_create.py
26+++ b/src/maascli/actions/tests/test_boot_resources_create.py
27@@ -55,7 +55,9 @@ class TestBootResourcesCreateAction(MAASTestCase):
28 stream.write(data)
29 sha256 = hashlib.sha256()
30 sha256.update(data)
31- return size, sha256.hexdigest(), partial(open, content_path, "rb")
32+ # the parser will create a partial function without "r" or "rb",
33+ # that is then passed upon calling content
34+ return size, sha256.hexdigest(), partial(open, content_path)
35
36 def test_initial_request_returns_content(self):
37 content = factory.make_name("content")
38diff --git a/src/maascli/api.py b/src/maascli/api.py
39index 0f02b37..d2494c6 100644
40--- a/src/maascli/api.py
41+++ b/src/maascli/api.py
42@@ -189,7 +189,8 @@ class Action(Command):
43 However, when `string` is of the form ``name@=value``, this
44 returns a ``name, opener`` tuple, where ``opener`` is a function
45 that will return an open file handle when called. The file will
46- be opened in binary mode for reading only.
47+ be opened for reading only, actions will open it as text by default,
48+ but may use binary mode if specified.
49 """
50 parts = re.split(r"(=|@=)", string, 1)
51 if len(parts) == 3:

Subscribers

People subscribed via source and target branches