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

made empty deployments go to deployed state upon release. #979

Merged
merged 3 commits into from
Feb 28, 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
v 2018.4 (2018-12-xx)
Changes in this release:
- Various bugfixes and performance enhancements (#873, #772, #958, #959, #955)
- Modified log format, added replace file name with logger name
- Various bugfixes and performance enhancements (#873, #772, #958, #959)
- Dependency updates
- Minimal python version is now python 3.6
- Removal of snapshot and restore functionality from the server (#789)
Expand Down
10 changes: 10 additions & 0 deletions src/inmanta/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,16 @@ def get_skipped_for_undeployable(self):
{"$set": {"skipped_for_undeployable": self.skipped_for_undeployable}})
return self.skipped_for_undeployable

@gen.coroutine
def mark_done(self):
""" mark this deploy as done """
result = const.VersionState.success
for state in self.status.values():
if state["status"] != "deployed":
result = const.VersionState.failed

yield self.update_fields(deployed=True, result=result)

@gen.coroutine
def get_increment(self, negative: bool=False):
"""
Expand Down
11 changes: 5 additions & 6 deletions src/inmanta/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,10 @@ def release_version(self, env, version_id, push, agent_trigger_method=None):

yield model.update_fields(released=True, result=const.VersionState.deploying)

if model.total == 0:
yield model.mark_done()
return 200, {"model": model}

# Already mark undeployable resources as deployed to create a better UX (change the version counters)
undep = yield model.get_undeployable()
undep = [rid + ",v=%s" % version_id for rid in undep]
Expand Down Expand Up @@ -1274,12 +1278,7 @@ def resource_action_update(self, env, resource_ids, action_id, action, started,
model = yield data.ConfigurationModel.get_version(env.id, model_version)

if model.done == model.total:
result = const.VersionState.success
for state in model.status.values():
if state["status"] != "deployed":
result = const.VersionState.failed

yield model.update_fields(deployed=True, result=result)
yield model.mark_done()

waiting_agents = set([(Id.parse_id(prov).get_agent_name(), res.resource_version_id)
for res in resources for prov in res.provides])
Expand Down
45 changes: 45 additions & 0 deletions tests/test_server_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@
logger = logging.getLogger("inmanta.test.server_agent")


async def get_agent(server, environment, *endpoints, hostname="nodes1"):
agentmanager = server.get_slice(SLICE_AGENT_MANAGER)
agent = Agent(
hostname=hostname,
environment=environment,
agent_map={agent: "localhost" for agent in endpoints},
code_loader=False)
for agentname in endpoints:
agent.add_end_point_name(agentname)
await agent.start()
await retry_limited(lambda: len(agentmanager.sessions) == 1, 10)
return agent


def log_contains(caplog, loggerpart, level, msg):
for logger_name, log_level, message in caplog.record_tuples:
if loggerpart in logger_name and level == log_level and msg in message:
Expand Down Expand Up @@ -689,6 +703,37 @@ async def test_dryrun_and_deploy(server_multi, client_multi, resource_container)
await agent.stop()


@pytest.mark.asyncio(timeout=150)
async def test_deploy_empty(server, client, resource_container, environment):
"""
Test deployment of empty model
"""
agent = await get_agent(server, environment, "agent1")

version = int(time.time())

resources = []

result = await client.put_version(
tid=environment,
version=version,
resources=resources,
resource_state={},
unknowns=[],
version_info={})
assert result.code == 200

# do a deploy
result = await client.release_version(environment, version, True, const.AgentTriggerMethod.push_full_deploy)
assert result.code == 200
assert result.result["model"]["deployed"]
assert result.result["model"]["released"]
assert result.result["model"]["total"] == 0
assert result.result["model"]["result"] == const.VersionState.success.name

await agent.stop()


@pytest.mark.asyncio(timeout=100)
async def test_deploy_with_undefined(server_multi, client_multi, resource_container):
"""
Expand Down