Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add optional installation_request_id parameter to registration … #282

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion landscape/client/broker/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Configuration class for the broker."""

import os

from landscape.client.deployment import Configuration
Expand Down Expand Up @@ -101,6 +100,13 @@ def make_parser(self):
"managed by Landscape, in which case set it to be the uid that "
"Landscape assigned to the host machine.",
)
parser.add_argument(
wck0 marked this conversation as resolved.
Show resolved Hide resolved
"--installation-request-id",
help="Only set this value if this computer is a child instance "
"managed by Landscape, in which case set it to be the request id "
"that Landscape assigned to the installation activity for the "
"host machine.",
)

return parser

Expand Down
4 changes: 4 additions & 0 deletions landscape/client/broker/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Identity:
tags = config_property("tags")
access_group = config_property("access_group")
hostagent_uid = config_property("hostagent_uid")
installation_request_id = config_property("installation_request_id")

def __init__(self, config, persist):
self._config = config
Expand Down Expand Up @@ -192,6 +193,7 @@ def _handle_pre_exchange(self):
group = identity.access_group
registration_key = identity.registration_key
hostagent_uid = identity.hostagent_uid
installation_request_id = identity.installation_request_id

self._message_store.delete_all_messages()

Expand Down Expand Up @@ -221,6 +223,8 @@ def _handle_pre_exchange(self):
message["access_group"] = group
if hostagent_uid:
message["hostagent_uid"] = hostagent_uid
if installation_request_id:
message["installation_request_id"] = installation_request_id

server_api = self._message_store.get_server_api()
# If we have juju data to send and if the server is recent enough to
Expand Down
29 changes: 29 additions & 0 deletions landscape/client/broker/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,32 @@ def test_missing_hostagent_uid_is_none(self):
configuration.load(["--config", filename, "--url", "whatever"])

self.assertIsNone(configuration.hostagent_uid)

def test_installation_request_id_handling(self):
"""
The 'installation_request_id' value specified in the configuration
file is passed through.
"""
filename = self.makeFile(
"[client]\ninstallation_request_id = installed-according-to-plan",
)

configuration = BrokerConfiguration()
configuration.load(["--config", filename, "--url", "whatever"])

self.assertEqual(
configuration.installation_request_id,
"installed-according-to-plan",
)

def test_missing_installation_request_id_is_none(self):
"""
Test that if we don't explicitly pass a installation_request_id,
then this value is None.
"""
filename = self.makeFile("[client]\n")

configuration = BrokerConfiguration()
configuration.load(["--config", filename, "--url", "whatever"])

self.assertIsNone(configuration.installation_request_id)
41 changes: 41 additions & 0 deletions landscape/client/broker/tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,47 @@ def test_queue_message_on_exchange_with_none_hostagent_uid(self):
messages = self.mstore.get_pending_messages()
self.assertNotIn("hostagent_uid", messages[0])

def test_queue_message_on_exchange_with_installation_request_id(self):
"""
If the admin has defined a installation_request_id for this computer,
we send it to the server.
"""
self.mstore.set_accepted_types(["register"])
self.mstore.set_server_api(b"3.3")
self.config.account_name = "account_name"
self.config.installation_request_id = "installed-according-to-plan"
self.config.tags = "server,london"
self.reactor.fire("pre-exchange")
messages = self.mstore.get_pending_messages()
self.assertEqual(
"installed-according-to-plan",
messages[0]["installation_request_id"],
)

def test_queue_message_on_exchange_and_empty_installation_request_id(self):
"""
If the installation_request_id is "", then the outgoing message
does not define an "installation_request_id" key.
"""
self.mstore.set_accepted_types(["register"])
self.mstore.set_server_api(b"3.3")
self.config.installation_request_id = ""
self.reactor.fire("pre-exchange")
messages = self.mstore.get_pending_messages()
self.assertNotIn("installation_request_id", messages[0])

def test_queue_message_on_exchange_with_none_installation_request_id(self):
"""
If the installation_request_id is None, then the outgoing message
does not define an "installation_request_id" key.
"""
self.mstore.set_accepted_types(["register"])
self.mstore.set_server_api(b"3.3")
self.config.installation_request_id = None
self.reactor.fire("pre-exchange")
messages = self.mstore.get_pending_messages()
self.assertNotIn("installation_request_id", messages[0])

def test_queueing_registration_message_resets_message_store(self):
"""
When a registration message is queued, the store is reset
Expand Down
2 changes: 2 additions & 0 deletions landscape/client/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ClientRegistrationInfo:

container_info: Optional[str] = None
hostagent_uid: Optional[str] = None
installation_request_id: Optional[str] = None
hostname: Optional[str] = None
juju_info: None = None # We don't send Juju info currently.
registration_password: Optional[str] = None
Expand All @@ -54,6 +55,7 @@ def from_identity(
identity.computer_title,
container_info=get_container_info(),
hostagent_uid=identity.hostagent_uid,
installation_request_id=identity.installation_request_id,
hostname=get_fqdn(),
registration_password=identity.registration_key,
tags=identity.tags,
Expand Down
2 changes: 2 additions & 0 deletions landscape/message_schemas/server_bound.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@
"clone_secure_id": Any(Unicode(), Constant(None)),
"ubuntu_pro_info": Unicode(),
"hostagent_uid": Unicode(),
"installation_request_id": Unicode(),
},
api=b"3.3",
optional=[
Expand All @@ -375,6 +376,7 @@
"clone_secure_id",
"ubuntu_pro_info",
"hostagent_uid",
"installation_request_id",
],
)

Expand Down
Loading