Complete implementation, add test
This commit is contained in:
parent
fe2e92889d
commit
7f28d78297
@ -261,6 +261,16 @@ def init(ctx, config, output, map_ports_to_host):
|
|||||||
yaml.dump(spec_file_content, output_file)
|
yaml.dump(spec_file_content, output_file)
|
||||||
|
|
||||||
|
|
||||||
|
def _write_config_file(spec_file: Path, config_env_file: Path):
|
||||||
|
spec_content = get_parsed_deployment_spec(spec_file)
|
||||||
|
if spec_content["config"]:
|
||||||
|
config_vars = spec_content["config"]
|
||||||
|
if config_vars:
|
||||||
|
with open(config_env_file, "w") as output_file:
|
||||||
|
for variable_name, variable_value in config_vars.items():
|
||||||
|
output_file.write(f"{variable_name}={variable_value}\n")
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option("--spec-file", required=True, help="Spec file to use to create this deployment")
|
@click.option("--spec-file", required=True, help="Spec file to use to create this deployment")
|
||||||
@click.option("--deployment-dir", help="Create deployment files in this directory")
|
@click.option("--deployment-dir", help="Create deployment files in this directory")
|
||||||
@ -285,6 +295,8 @@ def create(ctx, spec_file, deployment_dir, network_dir, initial_peers):
|
|||||||
# Copy spec file and the stack file into the deployment dir
|
# Copy spec file and the stack file into the deployment dir
|
||||||
copyfile(spec_file, os.path.join(deployment_dir, os.path.basename(spec_file)))
|
copyfile(spec_file, os.path.join(deployment_dir, os.path.basename(spec_file)))
|
||||||
copyfile(stack_file, os.path.join(deployment_dir, os.path.basename(stack_file)))
|
copyfile(stack_file, os.path.join(deployment_dir, os.path.basename(stack_file)))
|
||||||
|
# Copy any config varibles from the spec file into an env file suitable for compose
|
||||||
|
_write_config_file(spec_file, os.path.join(deployment_dir, "config.env"))
|
||||||
# Copy the pod files into the deployment dir, fixing up content
|
# Copy the pod files into the deployment dir, fixing up content
|
||||||
pods = parsed_stack['pods']
|
pods = parsed_stack['pods']
|
||||||
destination_compose_dir = os.path.join(deployment_dir, "compose")
|
destination_compose_dir = os.path.join(deployment_dir, "compose")
|
||||||
|
@ -77,7 +77,7 @@ $TEST_TARGET_SO --stack test deploy down --delete-volumes
|
|||||||
# Basic test of creating a deployment
|
# Basic test of creating a deployment
|
||||||
test_deployment_dir=$CERC_REPO_BASE_DIR/test-deployment-dir
|
test_deployment_dir=$CERC_REPO_BASE_DIR/test-deployment-dir
|
||||||
test_deployment_spec=$CERC_REPO_BASE_DIR/test-deployment-spec.yml
|
test_deployment_spec=$CERC_REPO_BASE_DIR/test-deployment-spec.yml
|
||||||
$TEST_TARGET_SO --stack test deploy init --output $test_deployment_spec
|
$TEST_TARGET_SO --stack test deploy init --output $test_deployment_spec --config CERC_TEST_PARAM_1=PASSED
|
||||||
# Check the file now exists
|
# Check the file now exists
|
||||||
if [ ! -f "$test_deployment_spec" ]; then
|
if [ ! -f "$test_deployment_spec" ]; then
|
||||||
echo "deploy init test: spec file not present"
|
echo "deploy init test: spec file not present"
|
||||||
@ -110,13 +110,20 @@ echo "deploy create output file test: passed"
|
|||||||
# Try to start the deployment
|
# Try to start the deployment
|
||||||
$TEST_TARGET_SO deployment --dir $test_deployment_dir start
|
$TEST_TARGET_SO deployment --dir $test_deployment_dir start
|
||||||
# Check logs command works
|
# Check logs command works
|
||||||
log_output_2=$( $TEST_TARGET_SO deployment --dir $test_deployment_dir logs )
|
log_output_3=$( $TEST_TARGET_SO deployment --dir $test_deployment_dir logs )
|
||||||
if [[ "$log_output_2" == *"Filesystem is fresh"* ]]; then
|
if [[ "$log_output_3" == *"Filesystem is fresh"* ]]; then
|
||||||
echo "deployment logs test: passed"
|
echo "deployment logs test: passed"
|
||||||
else
|
else
|
||||||
echo "deployment logs test: FAILED"
|
echo "deployment logs test: FAILED"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
# Check the config variable CERC_TEST_PARAM_1 was passed correctly
|
||||||
|
if [[ "$log_output_3" == *"Test-param-1: PPASSED"* ]]; then
|
||||||
|
echo "deployment config test: passed"
|
||||||
|
else
|
||||||
|
echo "deployment config test: FAILED"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
# Stop and clean up
|
# Stop and clean up
|
||||||
$TEST_TARGET_SO deployment --dir $test_deployment_dir stop --delete-volumes
|
$TEST_TARGET_SO deployment --dir $test_deployment_dir stop --delete-volumes
|
||||||
echo "Test passed"
|
echo "Test passed"
|
||||||
|
Loading…
Reference in New Issue
Block a user