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 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
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ DEPRECATIONS:
- The config option agent-interval, agent-splay, autostart_agent_interval and autostart_splay are
deprecated in favour of agent-deploy-interval, agent-deploy-splay-time, autostart_agent_deploy_interval
and autostart_agent_deploy_splay_time respectively. The deprecated options will be removed in release 2019.2
- 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.

v 2018.3 (2018-12-07)
Changes in this release:
Expand Down
4 changes: 2 additions & 2 deletions src/inmanta/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ def export(options):
conn = protocol.SyncClient("compiler")
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)
agent_trigger_method = const.AgentTriggerMethod.get_agent_trigger_method(options.full_deploy)
conn.release_version(tid, version, True, agent_trigger_method)


log_levels = {
Expand Down
11 changes: 4 additions & 7 deletions src/inmanta/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,12 @@ class ResourceAction(Enum):


class AgentTriggerMethod(Enum):
no_push = 1
push_incremental_deploy = 2
push_full_deploy = 3
push_incremental_deploy = 1
push_full_deploy = 2

@classmethod
def get_agent_trigger_method(cls, push, is_full_deploy):
if not push:
return cls.no_push
elif is_full_deploy:
def get_agent_trigger_method(cls, is_full_deploy):
if is_full_deploy:
return cls.push_full_deploy
else:
return cls.push_incremental_deploy
Expand Down
9 changes: 6 additions & 3 deletions src/inmanta/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ def convert_agent_map(value):


def convert_agent_trigger_method(value):
if isinstance(value, const.AgentTriggerMethod):
return value
value = str(value)
valid_values = [x.name for x in const.AgentTriggerMethod]
if value not in valid_values:
Expand Down Expand Up @@ -576,12 +578,13 @@ class Environment(BaseDocument):
doc="When this boolean is set to true, the orchestrator will automatically release a new version "
"that was compiled by the orchestrator itself.", validator=convert_boolean),
PUSH_ON_AUTO_DEPLOY: Setting(name=PUSH_ON_AUTO_DEPLOY, typ="bool", default=False,
doc="[DEPRECATED] Push a new version when it has been autodeployed.",
doc="Push a new version when it has been autodeployed.",
validator=convert_boolean),
AGENT_TRIGGER_METHOD_ON_AUTO_DEPLOY: Setting(name=AGENT_TRIGGER_METHOD_ON_AUTO_DEPLOY, typ="str",
default=const.AgentTriggerMethod.no_push.name,
default=const.AgentTriggerMethod.push_full_deploy.name,
validator=convert_agent_trigger_method,
doc="The agent trigger method to use when " + AUTO_DEPLOY + " is enabled"),
doc="The agent trigger method to use when "
+ PUSH_ON_AUTO_DEPLOY + " is enabled"),
AUTOSTART_SPLAY: Setting(name=AUTOSTART_SPLAY, typ="int", default=10,
doc="[DEPRECATED] Splay time for autostarted agents.", validator=convert_int),
AUTOSTART_AGENT_DEPLOY_INTERVAL: Setting(name=AUTOSTART_AGENT_DEPLOY_INTERVAL, typ="int", default=600,
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=True,
agent_trigger_method=const.AgentTriggerMethod.push_full_deploy)
self.progress_deploy_report(version)

Expand Down
5 changes: 3 additions & 2 deletions src/inmanta/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,9 @@ def version_list(client: Client, environment: str) -> None:
def version_release(client: Client, environment: str, push: bool, full: bool, version: str) -> None:
env_id = client.to_environment_id(environment)
if push:
trigger_method = AgentTriggerMethod.get_agent_trigger_method(push, full)
x = client.get_dict("release_version", "model", dict(tid=env_id, id=version, agent_trigger_method=trigger_method))
trigger_method = AgentTriggerMethod.get_agent_trigger_method(full)
x = client.get_dict("release_version", "model", dict(tid=env_id, id=version, push=True,
agent_trigger_method=trigger_method))
else:
x = client.get_dict("release_version", "model", dict(tid=env_id, id=version))

Expand Down
8 changes: 4 additions & 4 deletions src/inmanta/protocol/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,15 @@ 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 = None):
"""
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 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
:param push: Notify all agents to deploy the version
:param agent_trigger_method Indicates whether the agents should perform a full or an incremental deploy when
push is true.
"""


Expand Down
22 changes: 8 additions & 14 deletions src/inmanta/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from uuid import UUID
import uuid
import shutil
import warnings

import dateutil
import pymongo
Expand Down Expand Up @@ -957,20 +956,13 @@ def safe_get(input, key, default):
push_on_auto_deploy = yield env.get(data.PUSH_ON_AUTO_DEPLOY)
agent_trigger_method_on_autodeploy = yield env.get(data.AGENT_TRIGGER_METHOD_ON_AUTO_DEPLOY)
agent_trigger_method_on_autodeploy = const.AgentTriggerMethod[agent_trigger_method_on_autodeploy]

# Ensure backward compatibility
if push_on_auto_deploy and agent_trigger_method_on_autodeploy is const.AgentTriggerMethod.no_push:
warnings.warn("Config option %s is deprecated. Use %s instead." % (data.PUSH_ON_AUTO_DEPLOY,
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, push_on_auto_deploy, 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=None):
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,17 +998,19 @@ 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

if trigger_agent:
if push:
# fetch all resource in this cm and create a list of distinct agents
agents = yield data.ConfigurationModel.get_agents(env.id, version_id)
yield self.agentmanager._ensure_agents(env, agents)

for agent in agents:
client = self.get_agent_client(env.id, agent)
if client is not None:
incremental_deploy = agent_trigger_method is const.AgentTriggerMethod.push_incremental_deploy
if not agent_trigger_method:
# Ensure backward compatibility
incremental_deploy = False
else:
incremental_deploy = agent_trigger_method is const.AgentTriggerMethod.push_incremental_deploy
future = client.trigger(env.id, agent, incremental_deploy)
self.add_future(future)
else:
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)
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)
assert result == 200

resource_ids = [x["id"] for x in resources]
Expand Down
14 changes: 7 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)
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)
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)
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)
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)
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)
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)
assert result.code == 200

now = datetime.now()
Expand Down
Loading