Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

Commit

Permalink
test: adding tests for DeploymentConfig (#54)
Browse files Browse the repository at this point in the history
* fix: rename DeploymentSpec -> DeploymentConfig

* fix: using .get()

* test: tests for deployment_config

* change name in codebase deployment_spec=>deployment_config
  • Loading branch information
jjmachan committed Dec 15, 2021
1 parent 0913fc6 commit 55b7fef
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 97 deletions.
83 changes: 43 additions & 40 deletions bentoctl/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from cloup import Section
from rich.pretty import pprint

from bentoctl.cli.interactive import deployment_spec_builder
from bentoctl.cli.interactive import deployment_config_builder
from bentoctl.cli.operator_management import get_operator_management_subcommands
from bentoctl.cli.utils import BentoctlCommandGroup
from bentoctl.deployment_config import DeploymentConfig
Expand All @@ -28,22 +28,24 @@ class BentoctlSections:
INTERACTIVE = Section("Interactive Mode")


def save_deployment_spec(deployment_spec, save_path, filename="deployment_spec.yaml"):
spec_path = Path(save_path, filename)
def save_deployment_config(
deployment_config, save_path, filename="deployment_config.yaml"
):
config_path = Path(save_path, filename)

if spec_path.exists():
if config_path.exists():
override = click.confirm(
"deployment spec file exists! Should I override?", default=True
"deployment config file exists! Should I override?", default=True
)
if override:
spec_path.unlink()
config_path.unlink()
else:
return spec_path
return config_path

with open(spec_path, "w", encoding="UTF-8") as f:
yaml.safe_dump(deployment_spec, f, default_flow_style=False, sort_keys=False)
with open(config_path, "w", encoding="UTF-8") as f:
yaml.safe_dump(deployment_config, f, default_flow_style=False, sort_keys=False)

return spec_path
return config_path


@cloup.group(
Expand All @@ -58,8 +60,8 @@ def bentoctl():
This tool helps you deploy your bentos to any cloud service you want. To start off
you have to install some operators that you need to deploy to the cloud
service of your choice, check out `bentoctl operator --help` for more details.
You can run `bentoctl generate` to start the interactive deployment spec builder or
check out the <link to deployment_spec doc> on how to write one yourself.
You can run `bentoctl generate` to start the interactive deployment config builder
or check out the <link to deployment_config doc> on how to write one yourself.
"""


Expand All @@ -85,28 +87,28 @@ def bentoctl():
"--file",
"-f",
type=click.Path(exists=True),
help="The path to the deployment spec file.",
help="The path to the deployment config file.",
)
def deploy(name, operator, bento, display_deployment_info, file):
"""
Deploy a bento to cloud either in interactive mode or with deployment_spec.
Deploy a bento to cloud either in interactive mode or with deployment_config.
1. if interactive mode. call the interactive setup manager
2. call deploy_bento
3. display results from deploy_bento
"""
try:
if file is None:
deployment_spec = deployment_spec_builder(bento, name, operator)
deployment_config = DeploymentConfig(deployment_spec)
deployment_spec_path = save_deployment_spec(
deployment_config.deployment_spec, Path.cwd()
deployment_config = deployment_config_builder(bento, name, operator)
deployment_config = DeploymentConfig(deployment_config)
deployment_config_path = save_deployment_config(
deployment_config.deployment_config, Path.cwd()
)
console.print(
"[green]deployment spec generated to: "
f"{deployment_spec_path.relative_to(Path.cwd())}[/]"
"[green]deployment config generated to: "
f"{deployment_config_path.relative_to(Path.cwd())}[/]"
)
file = deployment_spec_path
file = deployment_config_path
deploy_deployment(file)
print("Successful deployment!")
if display_deployment_info:
Expand All @@ -121,14 +123,14 @@ def deploy(name, operator, bento, display_deployment_info, file):
"--file",
"-f",
type=click.Path(exists=True),
help="The path to the deployment spec file.",
help="The path to the deployment config file.",
required=True,
)
def describe(file):
"""
Shows the properties of the deployment given a deployment_spec.
Shows the properties of the deployment given a deployment_config.
"""
info_json = describe_deployment(deployment_spec_path=file)
info_json = describe_deployment(deployment_config_path=file)
pprint(info_json)


Expand All @@ -137,7 +139,7 @@ def describe(file):
"--file",
"-f",
type=click.Path(exists=True),
help="The path to the deployment spec file.",
help="The path to the deployment config file.",
required=True,
)
@click.option(
Expand All @@ -147,9 +149,9 @@ def describe(file):
)
def update(file, display_deployment_info):
"""
Update the deployment given a deployment_spec.
Update the deployment given a deployment_config.
"""
update_deployment(deployment_spec_path=file)
update_deployment(deployment_config_path=file)
if display_deployment_info:
info_json = describe(file)
pprint(info_json)
Expand All @@ -160,7 +162,7 @@ def update(file, display_deployment_info):
"--file",
"-f",
type=click.Path(exists=True),
help="The path to the deployment spec file.",
help="The path to the deployment config file.",
required=True,
)
@click.option(
Expand All @@ -172,30 +174,31 @@ def update(file, display_deployment_info):
)
def delete(file, yes):
"""
Delete the deployment given a deployment_spec.
Delete the deployment given a deployment_config.
"""
if yes or click.confirm("Are you sure you want to delete the deployment?"):
delete_deployment(deployment_spec_path=file)
deployment_name = delete_deployment(deployment_spec_path=file)
delete_deployment(deployment_config_path=file)
deployment_name = delete_deployment(deployment_config_path=file)
click.echo(f"Deleted deployment - {deployment_name}!")


@bentoctl.command(section=BentoctlSections.INTERACTIVE)
def generate():
"""
Start the interactive deployment spec builder file.
Start the interactive deployment config builder file.
"""
deployment_spec = deployment_spec_builder()
deployment_spec_filname = console.input(
"filename for deployment_spec [[b]deployment_spec.yaml[/]]: ",
deployment_config = deployment_config_builder()
deployment_config_filname = console.input(
"filename for deployment_config [[b]deployment_config.yaml[/]]: ",
)
if deployment_spec_filname == "":
deployment_spec_filname = "deployment_spec.yaml"
spec_path = save_deployment_spec(
deployment_spec, Path.cwd(), deployment_spec_filname
if deployment_config_filname == "":
deployment_config_filname = "deployment_config.yaml"
config_path = save_deployment_config(
deployment_config, Path.cwd(), deployment_config_filname
)
console.print(
f"[green]deployment spec generated to: {spec_path.relative_to(Path.cwd())}[/]"
"[green]deployment config generated to: "
f"{config_path.relative_to(Path.cwd())}[/]"
)


Expand Down
22 changes: 11 additions & 11 deletions bentoctl/cli/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
local_operator_registry = get_local_operator_registry()


INTERACTIVE_MODE_TITLE = "[r]Bentoctl Interactive Deployment Spec Builder[/]"
INTERACTIVE_MODE_TITLE = "[r]Bentoctl Interactive Deployment Config Builder[/]"
WELCOME_MESSAGE = """
[green]Welcome![/] You are now in interactive mode.
This mode will help you setup the deployment_spec.yaml file required for
This mode will help you setup the deployment_config.yaml file required for
deployment. Fill out the appropriate values for the fields.
[dim](deployment spec will be saved to: ./deployment_spec.yaml)[/]
[dim](deployment config will be saved to: ./deployment_config.yaml)[/]
"""


Expand Down Expand Up @@ -287,11 +287,11 @@ def generate_spec(bento, schema):
return spec


def deployment_spec_builder(bento=None, name=None, operator=None):
def deployment_config_builder(bento=None, name=None, operator=None):
"""
Interactively build the deployment spec.
Interactively build the deployment config.
"""
deployment_spec = {
deployment_config = {
"api_version": "v1",
"metadata": {"name": name, "operator": operator},
"spec": {},
Expand All @@ -303,7 +303,7 @@ def deployment_spec_builder(bento=None, name=None, operator=None):
console.print("[bold]metadata: [/]")
if name is None:
name = prompt_input("name", metadata_schema.get("name"))
deployment_spec["metadata"]["name"] = name
deployment_config["metadata"]["name"] = name
intended_print(f"name: {name}", indent_level=1)
if operator is None:
available_operators = list(local_operator_registry.list())
Expand All @@ -312,12 +312,12 @@ def deployment_spec_builder(bento=None, name=None, operator=None):
operator = available_operators[0]
else:
operator = select_operator_from_list(available_operators)
deployment_spec["metadata"]["operator"] = operator
deployment_config["metadata"]["operator"] = operator
intended_print(f"operator: {operator}", indent_level=1)

console.print("[bold]spec: [/]")
operator = local_operator_registry.get(deployment_spec["metadata"]["operator"])
operator = local_operator_registry.get(deployment_config["metadata"]["operator"])
spec = generate_spec(bento, operator.operator_schema)
deployment_spec["spec"] = dict(spec)
deployment_config["spec"] = dict(spec)

return deployment_spec
return deployment_config
16 changes: 8 additions & 8 deletions bentoctl/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
local_operator_registry = get_local_operator_registry()


def deploy_deployment(deployment_spec_path):
deployment_resource = DeploymentConfig.from_file(deployment_spec_path)
def deploy_deployment(deployment_config_path):
deployment_resource = DeploymentConfig.from_file(deployment_config_path)
deployable_path = deployment_resource.operator.deploy(
bento_path=deployment_resource.bento_path,
deployment_name=deployment_resource.deployment_name,
Expand All @@ -18,8 +18,8 @@ def deploy_deployment(deployment_spec_path):
shutil.rmtree(deployable_path)


def update_deployment(deployment_spec_path):
deployment_resource = DeploymentConfig.from_file(deployment_spec_path)
def update_deployment(deployment_config_path):
deployment_resource = DeploymentConfig.from_file(deployment_config_path)
deployable_path = deployment_resource.operator.update(
bento_path=deployment_resource.bento_path,
deployment_name=deployment_resource.deployment_name,
Expand All @@ -29,16 +29,16 @@ def update_deployment(deployment_spec_path):
shutil.rmtree(deployable_path)


def describe_deployment(deployment_spec_path):
deployment_resource = DeploymentConfig.from_file(deployment_spec_path)
def describe_deployment(deployment_config_path):
deployment_resource = DeploymentConfig.from_file(deployment_config_path)
return deployment_resource.operator.describe(
deployment_name=deployment_resource.deployment_name,
deployment_spec=deployment_resource.operator_spec,
)


def delete_deployment(deployment_spec_path):
deployment_resource = DeploymentConfig.from_file(deployment_spec_path)
def delete_deployment(deployment_config_path):
deployment_resource = DeploymentConfig.from_file(deployment_config_path)
deployment_resource.operator.delete(
deployment_name=deployment_resource.deployment_name,
deployment_spec=deployment_resource.operator_spec,
Expand Down
Loading

0 comments on commit 55b7fef

Please sign in to comment.