Merge lp:~blake-rouse/maas/is-importing into lp:maas/trunk

Proposed by Blake Rouse on 2016-12-06
Status: Merged
Approved by: Blake Rouse on 2016-12-06
Approved revision: 5590
Merged at revision: 5591
Proposed branch: lp:~blake-rouse/maas/is-importing
Merge into: lp:maas/trunk
Diff against target: 43 lines (+16/-0)
2 files modified
src/maasserver/api/boot_resources.py (+6/-0)
src/maasserver/api/tests/test_boot_resources.py (+10/-0)
To merge this branch: bzr merge lp:~blake-rouse/maas/is-importing
Reviewer Review Type Date Requested Status
Mike Pontillo (community) 2016-12-06 Approve on 2016-12-06
Review via email: mp+312591@code.launchpad.net

Commit message

Add is_importing call to boot resources API.

To post a comment you must log in.
Mike Pontillo (mpontillo) wrote :

LGTM!

review: Approve
Brendan Donegan (brendan-donegan) wrote :

I know this is merged, and thanks - but wouldn't it be nicer if this returned JSON? I'll make do in the meantime but writing something like:

if output == 'false':

is just... wrong

Gavin Panella (allenap) wrote :

That is JSON:

  >>> import json
  >>> json.loads("false")
  False

Brendan Donegan (brendan-donegan) wrote :

Oops, thanks

On Wed, 7 Dec 2016 at 10:22 Gavin Panella <email address hidden>
wrote:

> That is JSON:
>
> >>> import json
> >>> json.loads("false")
> False
>
> --
> https://code.launchpad.net/~blake-rouse/maas/is-importing/+merge/312591
> You are subscribed to branch lp:maas.
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/api/boot_resources.py'
2--- src/maasserver/api/boot_resources.py 2016-09-29 16:53:21 +0000
3+++ src/maasserver/api/boot_resources.py 2016-12-06 17:28:08 +0000
4@@ -25,6 +25,7 @@
5 from maasserver.api.utils import get_optional_param
6 from maasserver.bootresources import (
7 import_resources,
8+ is_import_resources_running,
9 stop_import_resources,
10 )
11 from maasserver.enum import (
12@@ -236,6 +237,11 @@
13 "Import of boot resources is being stopped",
14 content_type=("text/plain; charset=%s" % settings.DEFAULT_CHARSET))
15
16+ @operation(idempotent=True)
17+ def is_importing(self, request):
18+ """Return import status."""
19+ return is_import_resources_running()
20+
21 @classmethod
22 def resource_uri(cls, *args, **kwargs):
23 return ('boot_resources_handler', [])
24
25=== modified file 'src/maasserver/api/tests/test_boot_resources.py'
26--- src/maasserver/api/tests/test_boot_resources.py 2016-09-29 16:53:21 +0000
27+++ src/maasserver/api/tests/test_boot_resources.py 2016-12-06 17:28:08 +0000
28@@ -404,6 +404,16 @@
29 self.assertEqual(http.client.OK, response.status_code)
30 self.assertThat(mock_stop, MockCalledOnceWith())
31
32+ def test_is_importing_returns_import_status(self):
33+ mock_running = self.patch(
34+ boot_resources, "is_import_resources_running")
35+ mock_running.return_value = factory.pick_bool()
36+ response = self.client.get(
37+ reverse('boot_resources_handler'), {'op': 'is_importing'})
38+ self.assertEqual(http.client.OK, response.status_code)
39+ self.assertEqual(
40+ mock_running.return_value, json_load_bytes(response.content))
41+
42
43 class TestBootResourceAPI(APITestCase.ForUser):
44