Skip to content

Commit

Permalink
Merge pull request #525 from Ostorlab/revert-516-Fix/Change_the_behav…
Browse files Browse the repository at this point in the history
…ior_in_the_to_fail_if_an_argument_is_present_in_the_settings_but_not_in_the_agent_definition_

Revert the change of the behavior to fail if an argument is present in the settings but not in the agent definition
  • Loading branch information
3asm authored Nov 3, 2023
2 parents 53e6694 + 305332a commit d37ad79
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
6 changes: 1 addition & 5 deletions src/ostorlab/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ class MaximumCyclicProcessReachedError(exceptions.OstorlabError):
"""The cyclic process limit is enforced and reach set value."""


class ArgumentMissingInAgentDefinitionError(exceptions.OstorlabError):
"""Argument is present in the settings but not in the agent definition."""


def _setup_logging(agent_key: str, universe: str) -> None:
gcp_logging_credential = os.environ.get(GCP_LOGGING_CREDENTIAL_ENV)
if gcp_logging_credential is not None:
Expand Down Expand Up @@ -133,12 +129,12 @@ def args(self) -> Dict[str, Any]:
for a in self.settings.args:
# Enforce that only declared arguments are accepted.
if a.name not in arguments:
# TODO(OS-5119): Change behavior to fail of the argument is missing from definition.
logger.warning(
"Argument %s is defined in the agent settings but not in the agent definition. "
"Please update your definition file or the agent will fail in the future.",
a.name,
)
raise ArgumentMissingInAgentDefinitionError()

if a.type == "binary":
arguments[a.name] = a.value
Expand Down
55 changes: 28 additions & 27 deletions tests/agent/agent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,37 +159,38 @@ class TestAgent(agent.Agent):
assert test_agent.args == {"color": "red", "speed": b"slow"}


@pytest.mark.xfail(reason="OS-5119: Awaiting deprecation.")
def testAgent_withArgMissingFromDefinition_raisesException(agent_mock):
class TestAgent(agent.Agent):
"""Test Agent"""

with pytest.raises(agent.ArgumentMissingInAgentDefinitionError):
test_agent = TestAgent(
agent_definitions.AgentDefinition(
name="start_test_agent",
out_selectors=["v3.healthcheck.ping"],
args=[
{"name": "color", "type": "string", "value": None},
{"name": "speed", "type": "string", "value": b"fast"},
],
),
runtime_definitions.AgentSettings(
key="agent/ostorlab/start_test_agent",
bus_url="amqp://guest:guest@localhost:5672/",
bus_exchange_topic="ostorlab_test",
healthcheck_port=5301,
args=[
utils_definitions.Arg(name="speed", type="binary", value=b"slow"),
utils_definitions.Arg(
name="color", type="string", value=json.dumps("red").encode()
),
utils_definitions.Arg(
name="force", type="string", value=json.dumps("strong").encode()
),
],
),
)
assert test_agent.args is None
test_agent = TestAgent(
agent_definitions.AgentDefinition(
name="start_test_agent",
out_selectors=["v3.healthcheck.ping"],
args=[
{"name": "color", "type": "string", "value": None},
{"name": "speed", "type": "string", "value": b"fast"},
],
),
runtime_definitions.AgentSettings(
key="agent/ostorlab/start_test_agent",
bus_url="amqp://guest:guest@localhost:5672/",
bus_exchange_topic="ostorlab_test",
healthcheck_port=5301,
args=[
utils_definitions.Arg(name="speed", type="binary", value=b"slow"),
utils_definitions.Arg(
name="color", type="string", value=json.dumps("red").encode()
),
utils_definitions.Arg(
name="force", type="string", value=json.dumps("strong").encode()
),
],
),
)

assert test_agent.args == {"color": "red", "speed": b"slow"}


def testEmit_whenEmitFromNoProcess_willSendTheAgentNameInControlAgents(
Expand Down

0 comments on commit d37ad79

Please sign in to comment.