Skip to content

Commit

Permalink
fixed issues from comments, unnecessary code mogged
Browse files Browse the repository at this point in the history
  • Loading branch information
david-mclain committed Nov 26, 2024
1 parent 37fc03e commit 0f8db0d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 38 deletions.
21 changes: 5 additions & 16 deletions landscape/client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,8 @@ def registration_sent(config):
"""
Return whether the client has sent a registration request to the server.
For now does same thing as is_registered as to make function name more
clear with what is performed.
clear with what is performed. This is the legacy behaviour of
--is-registered and the name will be changed in a future release.
"""
persist_filename = os.path.join(
config.data_path,
Expand All @@ -812,17 +813,6 @@ def actively_registered(config):
return False


def is_registered(config):
"""Return whether the client is already registered."""
persist_filename = os.path.join(
config.data_path,
f"{BrokerService.service_name}.bpickle",
)
persist = Persist(filename=persist_filename, user=USER, group=GROUP)
identity = Identity(config, persist)
return bool(identity.secure_id)


def registration_info_text(config, registration_status):
"""
A simple output displaying whether the client is registered or not, the
Expand Down Expand Up @@ -899,7 +889,7 @@ def main(args, print=print): # noqa: C901
"and force registration together.",
)

already_registered = is_registered(config)
already_registered = registration_sent(config)

if config.is_registered or config.registration_sent:

Expand All @@ -913,11 +903,10 @@ def main(args, print=print): # noqa: C901
else:
sys.exit(EXIT_NOT_REGISTERED)

currently_registered = actively_registered(config)
if config.actively_registered:
registration_status = currently_registered
currently_registered = actively_registered(config)

info_text = registration_info_text(config, registration_status)
info_text = registration_info_text(config, currently_registered)
print(info_text)

if registration_status:
Expand Down
30 changes: 11 additions & 19 deletions landscape/client/tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from landscape.client.configuration import EXIT_NOT_REGISTERED
from landscape.client.configuration import get_secure_id
from landscape.client.configuration import ImportOptionError
from landscape.client.configuration import is_registered
from landscape.client.configuration import LandscapeSetupConfiguration
from landscape.client.configuration import LandscapeSetupScript
from landscape.client.configuration import main
Expand Down Expand Up @@ -1183,7 +1182,7 @@ def test_main_register_if_needed_silent(
mock_input.assert_not_called()

@mock.patch(
"landscape.client.configuration.is_registered",
"landscape.client.configuration.registration_sent",
return_value=True,
)
@mock.patch("landscape.client.configuration.restart_client")
Expand Down Expand Up @@ -2241,29 +2240,17 @@ def setUp(self):
persist_file = os.path.join(self.config.data_path, "broker.bpickle")
self.persist = Persist(filename=persist_file)

def test_is_registered_false(self):
"""
If the client hasn't previously registered, is_registered returns False
"""
self.assertFalse(is_registered(self.config))

def test_is_registered_true(self):
"""
If the client has previously registered, is_registered returns True.
"""
self.persist.set("registration.secure-id", "super-secure")
self.persist.save()
self.assertTrue(is_registered(self.config))

def test_registration_sent_false(self):
"""
If the client hasn't previously registered, is_registered returns False
If the client hasn't previously sent a registration request,
registration_sent returns False
"""
self.assertFalse(registration_sent(self.config))

def test_registration_sent_true(self):
"""
If the client has previously registered, is_registered returns True.
If the client has previously sent a registration request,
registration_sent returns True.
"""
self.persist.set("registration.secure-id", "super-secure")
self.persist.save()
Expand All @@ -2290,7 +2277,12 @@ def test_actively_registered_false(self):

def test_actively_registered_false_only_test(self):
"""
If the client is not actively registered with the server returns False
If the client is not actively registered with the server returns False.
Here we check add only test to the accepted types as it is always an
accepted type by the server. In the actively_registered function we
check to see if the len(accepted_types) > 1 to make sure there are more
accepted types than just the test. This test case makes sure that we
fail the test case of only test if provided in accepted types
"""
self.persist.set("message-store.accepted-types", ["test"])
self.persist.save()
Expand Down
10 changes: 7 additions & 3 deletions man/landscape-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ OPTIONS
--disable Stop running clients and disable start at boot.
--init Set up the client directories structure and exit.
--is-registered Exit with code 0 (success) if client
is registered else returns 5. Display
registration info.
has sent registration request else returns 5.
Display registration sent info.
(NOTE: use --actively-registered to detect if
registration has been accepted server-side)
--registration-sent Exit with code 0 (success) if client
has sent registration request else returns 5.
has sent registration request else returns 5.
Display registration sent info.
(NOTE: use --actively-registered to detect if
registration has been accepted server-side)
--actively-registered Exit with code 0 (success) if client
is registered else returns 5. Display
registration info.
Expand Down

0 comments on commit 0f8db0d

Please sign in to comment.