Skip to content

Commit

Permalink
fixes #138 Merge branch 'release/2.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijeetkaurav1st committed Nov 2, 2020
2 parents 87d2e27 + a65ef4a commit 27c7a14
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Context info includes server, project and log configuration for dsl operations.

### Application
- List apps: `calm get apps`. Use `calm get apps -q` to show only application names.
- Create app: `calm create app -f <file>`. Command will create blueprint and launch it to get application. Please look at `calm create app -h`.
- Describe app: `calm describe app <app_name>`. It will print a summary of the application and the current application state. Use `calm describe app <name> 2>/dev/null --out json | jq '.["status"]'` to get fields from the app json. More info on how to use `jq` [here](https://stedolan.github.io/jq/tutorial/).
- Delete app: `calm delete app <app_name>`. You can delete multiple apps using: `calm get apps -q | xargs -I {} calm delete app {}`.
- Run action on application: `calm run action <action_name> --app <application_name>`
Expand Down
1 change: 1 addition & 0 deletions calm/dsl/cli/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def _create_app(
\b
Command consumes a dsl blueprint file and creates a blueprint from it.
If created blueprint is in ACTIVE state, then it got launched to create an application.
Blueprint is deleted after launching it.
"""

create_app(
Expand Down
15 changes: 9 additions & 6 deletions calm/dsl/cli/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,8 @@ def create_app(
LOG.error("User blueprint not found in {}".format(bp_file))
sys.exit(-1)

if bp_payload["spec"]["resources"].get("type", "") != "BROWNFIELD":
LOG.error(
"Command only allowed for brownfield application. Please use 'calm create bp' and 'calm launch bp' for USER applications"
)
sys.exit(-1)
# Get the blueprint type
bp_type = bp_payload["spec"]["resources"].get("type", "")

# Create blueprint from dsl file
bp_name = "Blueprint{}".format(str(uuid.uuid4())[:10])
Expand Down Expand Up @@ -296,9 +293,15 @@ def create_app(
profile_name=profile_name,
patch_editables=patch_editables,
launch_params=launch_params,
is_brownfield=True,
is_brownfield=True if bp_type == "BROWNFIELD" else False,
)

if bp_type != "BROWNFIELD":
# Delete the blueprint
res, err = client.blueprint.delete(bp_uuid)
if err:
raise Exception("[{}] - {}".format(err["code"], err["error"]))


class RunlogNode(NodeMixin):
def __init__(self, runlog, parent=None, children=None):
Expand Down
30 changes: 30 additions & 0 deletions tests/cli/test_app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
import json
import sys
import uuid
import traceback
from click.testing import CliRunner

Expand Down Expand Up @@ -338,6 +339,35 @@ def _test_dsl_bp_delete(self):
)
LOG.info("Success")

def test_app_create(self):
runner = CliRunner()

self.created_app_name = "Application{}".format(str(uuid.uuid4())[:10])
LOG.info("Creating App '{}'".format(self.created_app_name))
result = runner.invoke(
cli,
[
"create",
"app",
"--file={}".format(DSL_BP_FILEPATH),
"--name={}".format(self.created_app_name),
],
)
if result.exit_code:
cli_res_dict = {"Output": result.output, "Exception": str(result.exception)}
LOG.debug(
"Cli Response: {}".format(
json.dumps(cli_res_dict, indent=4, separators=(",", ": "))
)
)
LOG.debug(
"Traceback: \n{}".format(
"".join(traceback.format_tb(result.exc_info[2]))
)
)
LOG.info("Success")
self._test_app_delete()


if __name__ == "__main__":
tester = TestAppCommands()

0 comments on commit 27c7a14

Please sign in to comment.