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

Make sure that the release_version() API call is backwards compatible. #950

Merged
merged 5 commits into from
Feb 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ and autostart_agent_deploy_splay_time respectively. The deprecated options will
- The environment setting push_on_auto_deploy is deprecated. It will be replaced with the setting
agent_trigger_method_on_auto_deploy, which allows you to specify whether the agents should receive a push notification
for the new deployment and whether the agents should perform an incremental or a full deployment when they receive a trigger
from the autodeploy.
from the autodeploy. The deprecated option will be removed in release 2019.2
- The push option in the release_version() API call to the Inmanta server is deprecated. It will be replaced with the
agent_trigger_method option. The deprecated option will be removed in release 2019.2
wouterdb marked this conversation as resolved.
Show resolved Hide resolved

v 2018.3 (2018-12-07)
Changes in this release:
Expand Down
2 changes: 1 addition & 1 deletion src/inmanta/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def export(options):
LOGGER.info("Triggering deploy for version %d" % version)
tid = cfg_env.get()
agent_trigger_method = const.AgentTriggerMethod.get_agent_trigger_method(options.deploy, options.full_deploy)
conn.release_version(tid, version, agent_trigger_method)
conn.release_version(tid, version, False, agent_trigger_method)


log_levels = {
Expand Down
2 changes: 1 addition & 1 deletion src/inmanta/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def deploy(self, dry_run):

# release the version!
if not dry_run:
self._client.release_version(tid=self._environment_id, id=version,
self._client.release_version(tid=self._environment_id, id=version, push=False,
agent_trigger_method=const.AgentTriggerMethod.push_full_deploy)
self.progress_deploy_report(version)

Expand Down
4 changes: 3 additions & 1 deletion src/inmanta/protocol/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,14 @@ def put_version(


@method(method_name="version", operation="POST", id=True, arg_options=ENV_OPTS, client_types=["api", "compiler"])
def release_version(tid: uuid.UUID, id: int, agent_trigger_method: const.AgentTriggerMethod = const.AgentTriggerMethod.no_push):
def release_version(tid: uuid.UUID, id: int, push: bool = False,
agent_trigger_method: const.AgentTriggerMethod = const.AgentTriggerMethod.no_push):
"""
Release version of the configuration model for deployment.

:param tid: The id of the environment
:param id: The version of the CM to deploy
:param push: [DEPRECATED] Notify all agents to deploy the version
:param agent_trigger_method Indicates whether the agents should receive a push notification for the deployment and
how the agents should perform the deploy (incremental deploy vs full deploy) when a push
notification was requested
Expand Down
12 changes: 9 additions & 3 deletions src/inmanta/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,13 +964,13 @@ def safe_get(input, key, default):
data.AGENT_TRIGGER_METHOD_ON_AUTO_DEPLOY))
agent_trigger_method_on_autodeploy = const.AgentTriggerMethod.push_full_deploy

yield self.release_version(env, version, agent_trigger_method_on_autodeploy)
yield self.release_version(env, version, False, agent_trigger_method_on_autodeploy)

return 200

@protocol.handle(methods.release_version, version_id="id", env="tid")
@gen.coroutine
def release_version(self, env, version_id, agent_trigger_method=const.AgentTriggerMethod.no_push):
def release_version(self, env, version_id, push, agent_trigger_method=const.AgentTriggerMethod.no_push):
model = yield data.ConfigurationModel.get_version(env.id, version_id)
if model is None:
return 404, {"message": "The request version does not exist."}
Expand Down Expand Up @@ -1006,7 +1006,13 @@ def release_version(self, env, version_id, agent_trigger_method=const.AgentTrigg
action=const.ResourceAction.deploy, changes={}, messages=[logline],
change=const.Change.nochange, send_events=False)

trigger_agent = agent_trigger_method is not None and agent_trigger_method is not const.AgentTriggerMethod.no_push
# Ensure backward compatibility
if push and agent_trigger_method is const.AgentTriggerMethod.no_push:
warnings.warn("The push option in the release_version() API call is deprecated. "
"Use the agent_trigger_method option instead.")
trigger_agent = True
else:
trigger_agent = agent_trigger_method is not None and agent_trigger_method is not const.AgentTriggerMethod.no_push

if trigger_agent:
# fetch all resource in this cm and create a list of distinct agents
Expand Down
4 changes: 2 additions & 2 deletions tests/server/test_incremental_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async def setup(self, serverdirect: Server, env: UUID):
)
assert res == 200

result, _ = await serverdirect.release_version(env, version, const.AgentTriggerMethod.no_push)
result, _ = await serverdirect.release_version(env, version, False, const.AgentTriggerMethod.no_push)
assert result == 200
for rid, state in self.states.items():
# Start the deploy
Expand Down Expand Up @@ -226,7 +226,7 @@ def make_resources(version):
)
assert res == 200

result, _ = await serverdirect.release_version(env, version, const.AgentTriggerMethod.no_push)
result, _ = await serverdirect.release_version(env, version, False, const.AgentTriggerMethod.no_push)
assert result == 200

resource_ids = [x["id"] for x in resources]
Expand Down
48 changes: 41 additions & 7 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ async def test_get_resource_for_agent(motor, server_multi, client_multi, environ
assert result.code == 200
assert result.result["count"] == 1

result = await client_multi.release_version(environment, version, const.AgentTriggerMethod.no_push)
result = await client_multi.release_version(environment, version, False, const.AgentTriggerMethod.no_push)
assert result.code == 200

result = await client_multi.get_version(environment, version)
Expand Down Expand Up @@ -336,7 +336,7 @@ async def test_resource_update(client, server, environment):
res = await client.put_version(tid=environment, version=version, resources=resources, unknowns=[], version_info={})
assert(res.code == 200)

result = await client.release_version(environment, version, const.AgentTriggerMethod.no_push)
result = await client.release_version(environment, version, False, const.AgentTriggerMethod.no_push)
assert result.code == 200

resource_ids = [x["id"] for x in resources]
Expand Down Expand Up @@ -520,7 +520,7 @@ async def test_purge_on_delete_requires(client, server, environment):
assert res.code == 200

# Release the model and set all resources as deployed
result = await client.release_version(environment, version, const.AgentTriggerMethod.no_push)
result = await client.release_version(environment, version, False, const.AgentTriggerMethod.no_push)
assert result.code == 200

now = datetime.now()
Expand Down Expand Up @@ -652,7 +652,7 @@ async def test_purge_on_delete_compile_failed(client, server, environment):
assert result.code == 200

# Release the model and set all resources as deployed
result = await client.release_version(environment, version, const.AgentTriggerMethod.no_push)
result = await client.release_version(environment, version, False, const.AgentTriggerMethod.no_push)
assert result.code == 200

now = datetime.now()
Expand Down Expand Up @@ -741,7 +741,7 @@ async def test_purge_on_delete(client, server, environment):
assert res.code == 200

# Release the model and set all resources as deployed
result = await client.release_version(environment, version, const.AgentTriggerMethod.no_push)
result = await client.release_version(environment, version, False, const.AgentTriggerMethod.no_push)
assert result.code == 200

now = datetime.now()
Expand Down Expand Up @@ -827,7 +827,7 @@ async def test_purge_on_delete_ignore(client, server, environment):
assert res.code == 200

# Release the model and set all resources as deployed
result = await client.release_version(environment, version, const.AgentTriggerMethod.no_push)
result = await client.release_version(environment, version, False, const.AgentTriggerMethod.no_push)
assert result.code == 200

now = datetime.now()
Expand Down Expand Up @@ -863,7 +863,7 @@ async def test_purge_on_delete_ignore(client, server, environment):
assert res.code == 200

# Release the model and set all resources as deployed
result = await client.release_version(environment, version, const.AgentTriggerMethod.no_push)
result = await client.release_version(environment, version, False, const.AgentTriggerMethod.no_push)
assert result.code == 200

now = datetime.now()
Expand Down Expand Up @@ -1055,3 +1055,37 @@ async def test_resource_action_log(motor, server_multi, client_multi, environmen
resource_action_log = os.path.join(opt.log_dir.get(), opt.server_resource_action_log.get())
assert os.path.isfile(resource_action_log)
assert os.stat(resource_action_log).st_size != 0


@pytest.mark.parametrize("push,agent_trigger_method", [(True, const.AgentTriggerMethod.no_push),
(True, const.AgentTriggerMethod.push_incremental_deploy),
(True, const.AgentTriggerMethod.push_full_deploy),
(False, const.AgentTriggerMethod.no_push),
(False, const.AgentTriggerMethod.push_incremental_deploy),
(False, const.AgentTriggerMethod.push_full_deploy)])
@pytest.mark.asyncio(timeout=30)
async def test_backwards_compatibility_release_version_api_call(server, client, environment, caplog, push,
agent_trigger_method):
version = 1
resources = [{'group': 'root',
'hash': '89bf880a0dc5ffc1156c8d958b4960971370ee6a',
'id': 'std::File[vm1.dev.inmanta.com,path=/etc/sysconfig/network],v=%d' % version,
'owner': 'root',
'path': '/etc/sysconfig/network',
'permissions': 644,
'purged': False,
'reload': False,
'requires': [],
'version': version}]
res = await client.put_version(tid=environment, version=version, resources=resources, unknowns=[], version_info={})
assert res.code == 200
result = await client.release_version(environment, version, push, agent_trigger_method)
assert result.code == 200

log_lines = '\n'.join(caplog.messages)
target_line = "The push option in the release_version() API call is deprecated. " \
"Use the agent_trigger_method option instead."
if push and agent_trigger_method == const.AgentTriggerMethod.no_push:
assert target_line in log_lines
else:
assert target_line not in log_lines
Loading