Merge lp:~ack/landscape-client/landscape-config-no-reregister-by-default into lp:~landscape/landscape-client/trunk

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: 948
Merged at revision: 939
Proposed branch: lp:~ack/landscape-client/landscape-config-no-reregister-by-default
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 102 lines (+43/-4)
2 files modified
landscape/configuration.py (+12/-1)
landscape/tests/test_configuration.py (+31/-3)
To merge this branch: bzr merge lp:~ack/landscape-client/landscape-config-no-reregister-by-default
Reviewer Review Type Date Requested Status
Free Ekanayaka (community) Approve
🤖 Landscape Builder test results Approve
Eric Snow (community) Approve
Review via email: mp+319179@code.launchpad.net

Commit message

Default to "N" as answer to "request registration now" at the end of landscape-config runs if a prvevious registration has been sent.

Description of the change

Default to "N" as answer to "request registration now" at the end of landscape-config runs if a prvevious registration has been sent.

Testing instructions:

- run landscape-config a first time, request a registration
- run landscape-config again, see that by default "N" is selected at the registration question.

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: Fail
Revno: 947
Branch: lp:~ack/landscape-client/landscape-config-no-reregister-by-default
Jenkins: https://ci.lscape.net/job/latch-test-precise/889/

review: Needs Fixing (test results)
Revision history for this message
Eric Snow (ericsnowcurrently) wrote :

LGTM

review: Approve
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: Fail
Revno: 947
Branch: lp:~ack/landscape-client/landscape-config-no-reregister-by-default
Jenkins: https://ci.lscape.net/job/latch-test-precise/890/

review: Needs Fixing (test results)
948. By Alberto Donato

Fix tests.

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: 948
Branch: lp:~ack/landscape-client/landscape-config-no-reregister-by-default
Jenkins: https://ci.lscape.net/job/latch-test-precise/891/

review: Approve (test results)
Revision history for this message
Free Ekanayaka (free.ekanayaka) 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/configuration.py'
2--- landscape/configuration.py 2017-03-03 12:36:55 +0000
3+++ landscape/configuration.py 2017-03-07 16:47:31 +0000
4@@ -741,6 +741,15 @@
5 return 2 # An error happened
6
7
8+def is_registered(config):
9+ """Return whether the client is already registered."""
10+ persist_filename = os.path.join(
11+ config.data_path, "{}.bpickle".format(BrokerService.service_name))
12+ persist = Persist(filename=persist_filename)
13+ identity = Identity(config, persist)
14+ return bool(identity.secure_id)
15+
16+
17 def main(args, print=print):
18 """Interact with the user and the server to set up client configuration."""
19
20@@ -779,8 +788,10 @@
21 report_registration_outcome(result, print=print)
22 sys.exit(determine_exit_code(result))
23 else:
24+ default_answer = not is_registered(config)
25 answer = prompt_yes_no(
26- "\nRequest a new registration for this computer now?")
27+ "\nRequest a new registration for this computer now?",
28+ default=default_answer)
29 if answer:
30 result = register(config, reactor)
31 report_registration_outcome(result, print=print)
32
33=== modified file 'landscape/tests/test_configuration.py'
34--- landscape/tests/test_configuration.py 2017-03-03 12:35:28 +0000
35+++ landscape/tests/test_configuration.py 2017-03-07 16:47:31 +0000
36@@ -11,7 +11,8 @@
37 from twisted.internet.defer import succeed, fail, Deferred
38
39 from landscape.broker.registration import RegistrationError
40-from landscape.broker.tests.helpers import RemoteBrokerHelper
41+from landscape.broker.tests.helpers import (
42+ RemoteBrokerHelper, BrokerConfigurationHelper)
43 from landscape.configuration import (
44 print_text, LandscapeSetupScript, LandscapeSetupConfiguration,
45 register, setup, main, setup_init_script_and_start_client,
46@@ -19,9 +20,10 @@
47 ImportOptionError, store_public_key_data,
48 bootstrap_tree, got_connection, success, failure, exchange_failure,
49 handle_registration_errors, done, got_error, report_registration_outcome,
50- determine_exit_code)
51+ determine_exit_code, is_registered)
52 from landscape.lib.amp import MethodCallError
53 from landscape.lib.fetch import HTTPCodeError, PyCurlError
54+from landscape.lib.persist import Persist
55 from landscape.sysvconfig import ProcessError
56 from landscape.tests.helpers import FakeBrokerServiceHelper
57 from landscape.tests.helpers import LandscapeTest, EnvironSaverHelper
58@@ -1239,13 +1241,15 @@
59 printed)
60
61 def make_working_config(self):
62+ data_path = self.makeFile()
63 return self.makeFile("[client]\n"
64 "computer_title = Old Title\n"
65 "account_name = Old Name\n"
66 "registration_key = Old Password\n"
67 "http_proxy = http://old.proxy\n"
68 "https_proxy = https://old.proxy\n"
69- "url = http://url\n")
70+ "data_path = {}\n"
71+ "url = http://url\n".format(data_path))
72
73 @mock.patch("__builtin__.raw_input", return_value="")
74 @mock.patch("landscape.configuration.register")
75@@ -2170,3 +2174,27 @@
76 for code in failure_codes:
77 result = determine_exit_code(code)
78 self.assertEqual(2, result)
79+
80+
81+class IsRegisteredTest(LandscapeTest):
82+
83+ helpers = [BrokerConfigurationHelper]
84+
85+ def setUp(self):
86+ super(IsRegisteredTest, self).setUp()
87+ persist_file = os.path.join(self.config.data_path, "broker.bpickle")
88+ self.persist = Persist(filename=persist_file)
89+
90+ def test_is_registered_false(self):
91+ """
92+ If the client hasn't previouly registered, is_registered returns False.
93+ """
94+ self.assertFalse(is_registered(self.config))
95+
96+ def test_is_registered_true(self):
97+ """
98+ If the client has previouly registered, is_registered returns True.
99+ """
100+ self.persist.set("registration.secure-id", "super-secure")
101+ self.persist.save()
102+ self.assertTrue(is_registered(self.config))

Subscribers

People subscribed via source and target branches

to all changes: