diff --git a/gdk/commands/component/PublishCommand.py b/gdk/commands/component/PublishCommand.py index 3155b774..9712a4c1 100644 --- a/gdk/commands/component/PublishCommand.py +++ b/gdk/commands/component/PublishCommand.py @@ -112,7 +112,7 @@ def create_bucket(self, bucket, region): if self.bucket_exists_in_same_region(bucket, region): logging.info("Not creating an artifacts bucket as it already exists.") return - logging.error("Cannot create the artifacts bucket '{}' as it is already owned by you in other region.") + logging.error(f"Cannot create the artifacts bucket '{bucket}' as it is already owned by you in other region.") raise Exception(e) except Exception as e: logging.error("Failed to create the bucket '{}' in region '{}'".format(bucket, region)) diff --git a/gdk/commands/component/component.py b/gdk/commands/component/component.py index 361d87e4..8dd2b174 100644 --- a/gdk/commands/component/component.py +++ b/gdk/commands/component/component.py @@ -4,7 +4,7 @@ def init(d_args): try: InitCommand(d_args).run() except Exception as e: - raise Exception(f"Could not initialze the project due to the following error.\n{e}") + raise Exception(f"Could not initialize the project due to the following error.\n{e}") def build(d_args): diff --git a/integration_tests/gdk/components/test_integ_InitCommand.py b/integration_tests/gdk/components/test_integ_InitCommand.py index d4df2e2e..4b635e2a 100644 --- a/integration_tests/gdk/components/test_integ_InitCommand.py +++ b/integration_tests/gdk/components/test_integ_InitCommand.py @@ -94,7 +94,7 @@ def test_init_run_with_conflicting_args(self): with pytest.raises(Exception) as e: parse_args_actions.run_command(CLIParser.cli_parser.parse_args(["component", "init", "--repository", "dummy"])) - assert "Could not initialze the project due to the following error." in e.value.args[0] + assert "Could not initialize the project due to the following error." in e.value.args[0] assert mock_is_directory_empty.call_count == 0 assert mock_init_with_template.call_count == 0 diff --git a/uat/t_utils.py b/uat/t_utils.py index 8777cd8b..c7a95269 100644 --- a/uat/t_utils.py +++ b/uat/t_utils.py @@ -4,13 +4,14 @@ import boto3 -def update_config(config_file, component_name, region, bucket, author): +def update_config(config_file, component_name, region, bucket, author, version="NEXT_PATCH"): # Update gdk-config file mandatory field like region. with open(str(config_file), "r") as f: config = json.loads(f.read()) config["component"][component_name]["author"] = author config["component"][component_name]["publish"]["region"] = region config["component"][component_name]["publish"]["bucket"] = bucket + config["component"][component_name]["version"] = version with open(str(config_file), "w") as f: f.write(json.dumps(config)) @@ -51,10 +52,9 @@ def get_version_created(recipes_path, component_name): for f in Path(recipes_path).iterdir(): if component_name in str(f.resolve()): file_name = f.name - break - split_file_name = file_name.split(f"{component_name}-") - split_for_version = split_file_name[1].split(".yaml")[0] - return split_for_version + split_file_name = file_name.split(f"{component_name}-") + split_for_version = split_file_name[1].split(".yaml")[0] + return split_for_version def create_s3_client(region): diff --git a/uat/test_uat_build.py b/uat/test_uat_build.py index 8fb317e3..b19d63e5 100644 --- a/uat/test_uat_build.py +++ b/uat/test_uat_build.py @@ -11,9 +11,7 @@ def test_build_template_zip(change_test_dir, gdk_cli): component_name = "com.example.PythonHelloWorld" region = "us-east-1" # Check if init downloads templates with necessary files. - check_init_template = gdk_cli.run( - ["component", "init", "-t", "HelloWorld", "-l", "python", "-n", "HelloWorld"] - ) + check_init_template = gdk_cli.run(["component", "init", "-t", "HelloWorld", "-l", "python", "-n", "HelloWorld"]) assert check_init_template.returncode == 0 assert Path(path_HelloWorld).joinpath("recipe.yaml").resolve().exists() config_file = Path(path_HelloWorld).joinpath("gdk-config.json").resolve() @@ -48,9 +46,7 @@ def test_build_template_zip_fail_with_no_artifact(change_test_dir, gdk_cli): component_name = "com.example.PythonHelloWorld" region = "us-east-1" # Check if init downloads templates with necessary files. - check_init_template = gdk_cli.run( - ["component", "init", "-t", "HelloWorld", "-l", "python", "-n", dir_name] - ) + check_init_template = gdk_cli.run(["component", "init", "-t", "HelloWorld", "-l", "python", "-n", dir_name]) assert check_init_template.returncode == 0 assert Path(dir_path).joinpath("recipe.yaml").resolve().exists() config_file = Path(dir_path).joinpath("gdk-config.json").resolve() @@ -78,9 +74,7 @@ def test_build_template_maven(change_test_dir, gdk_cli): component_name = "com.example.JavaHelloWorld" region = "us-east-1" # Check if init downloads templates with necessary files. - check_init_template = gdk_cli.run( - ["component", "init", "-t", "HelloWorld", "-l", "java", "-n", "HelloWorld"] - ) + check_init_template = gdk_cli.run(["component", "init", "-t", "HelloWorld", "-l", "java", "-n", "HelloWorld"]) assert check_init_template.returncode == 0 assert Path(path_HelloWorld).joinpath("recipe.yaml").resolve().exists() config_file = Path(path_HelloWorld).joinpath("gdk-config.json").resolve() diff --git a/uat/test_uat_init.py b/uat/test_uat_init.py index 04d14a4a..db4b33f3 100644 --- a/uat/test_uat_init.py +++ b/uat/test_uat_init.py @@ -18,9 +18,7 @@ def test_init_template(change_test_dir, gdk_cli): def test_init_template_with_new_directory(change_test_dir, gdk_cli): dir = "test-dir" dirpath = Path(change_test_dir).joinpath(dir) - check_init_template = gdk_cli.run( - ["component", "init", "-t", "HelloWorld", "-l", "python", "-n", dir] - ) + check_init_template = gdk_cli.run(["component", "init", "-t", "HelloWorld", "-l", "python", "-n", dir]) assert check_init_template.returncode == 0 assert Path(dirpath).joinpath("recipe.yaml").resolve().exists() assert Path(dirpath).joinpath("gdk-config.json").resolve().exists() @@ -28,9 +26,7 @@ def test_init_template_with_new_directory(change_test_dir, gdk_cli): def test_init_repository(change_test_dir, gdk_cli): dirpath = Path(change_test_dir) - check_init_repo = gdk_cli.run( - ["component", "init", "-r", "aws-greengrass-labs-database-influxdb"] - ) + check_init_repo = gdk_cli.run(["component", "init", "-r", "aws-greengrass-labs-database-influxdb"]) assert check_init_repo.returncode == 0 assert Path(dirpath).joinpath("recipe.yaml").exists() assert Path(dirpath).joinpath("gdk-config.json").exists() @@ -39,9 +35,30 @@ def test_init_repository(change_test_dir, gdk_cli): def test_init_repository_with_new_dir(change_test_dir, gdk_cli): dir = "test-dir" dirpath = Path(change_test_dir).joinpath(dir) - check_init_repo = gdk_cli.run( - ["component", "init", "-r", "aws-greengrass-labs-database-influxdb", "-n", dir] - ) + check_init_repo = gdk_cli.run(["component", "init", "-r", "aws-greengrass-labs-database-influxdb", "-n", dir]) assert check_init_repo.returncode == 0 assert Path(dirpath).joinpath("recipe.yaml").exists() assert Path(dirpath).joinpath("gdk-config.json").exists() + + +def test_init_repository_not_exists(change_test_dir, gdk_cli): + check_init_repo = gdk_cli.run(["component", "init", "-r", "repo-not-exists"]) + assert check_init_repo.returncode == 1 + assert ( + "Could not find the component repository 'repo-not-exists' in Greengrass Software Catalog." in check_init_repo.output + ) + + +def test_init_template_not_exists(change_test_dir, gdk_cli): + check_init_temp = gdk_cli.run(["component", "init", "-t", "temp-not-exists", "-l", "python"]) + assert check_init_temp.returncode == 1 + assert ( + "Could not find the component template 'temp-not-exists-python' in Greengrass Software Catalog." + in check_init_temp.output + ) + + +def test_init_incomplete_args(change_test_dir, gdk_cli): + check_init = gdk_cli.run(["component", "init"]) + assert check_init.returncode == 1 + assert "Could not initialize the project as the arguments passed are invalid." in check_init.output diff --git a/uat/test_uat_list.py b/uat/test_uat_list.py index 7b2caa76..a6837cfe 100644 --- a/uat/test_uat_list.py +++ b/uat/test_uat_list.py @@ -7,3 +7,9 @@ def test_list_template(gdk_cli): def test_list_repository(gdk_cli): check_list_template = gdk_cli.run(["component", "list", "--repository"]) assert "aws-greengrass-labs-database-influxdb" in check_list_template.output + + +def test_list_incomplete_args(gdk_cli): + check_list_template = gdk_cli.run(["component", "list"]) + assert check_list_template.returncode == 1 + assert "Could not list the components as the command arguments are invalid." in check_list_template.output diff --git a/uat/test_uat_publish.py b/uat/test_uat_publish.py index cc346098..3d7de872 100644 --- a/uat/test_uat_publish.py +++ b/uat/test_uat_publish.py @@ -12,9 +12,7 @@ def test_publish_template_zip(change_test_dir, gdk_cli): bucket = "gdk-cli-uat" author = "gdk-cli-uat" # Check if init downloads templates with necessary files. - check_init_template = gdk_cli.run( - ["component", "init", "-t", "HelloWorld", "-l", "python", "-n", "HelloWorld"] - ) + check_init_template = gdk_cli.run(["component", "init", "-t", "HelloWorld", "-l", "python", "-n", "HelloWorld"]) assert check_init_template.returncode == 0 assert Path(path_HelloWorld).joinpath("recipe.yaml").resolve().exists() config_file = Path(path_HelloWorld).joinpath("gdk-config.json").resolve() @@ -44,7 +42,7 @@ def test_publish_template_zip(change_test_dir, gdk_cli): t_utils.clean_up_aws_resources(component_name, t_utils.get_version_created(recipes_path, component_name), region) -def test_publish_without_build_template_zip(change_test_dir, gdk_cli): +def test_publish_without_build_template_zip_with_bucket_arg(change_test_dir, gdk_cli): # Recipe contains HelloWorld.zip artifact. So, create HelloWorld directory inside temporary directory. path_HelloWorld = Path(change_test_dir).joinpath("HelloWorld") component_name = "com.example.PythonHelloWorld" @@ -52,9 +50,7 @@ def test_publish_without_build_template_zip(change_test_dir, gdk_cli): bucket = "gdk-cli-uat" author = "gdk-cli-uat" # Check if init downloads templates with necessary files. - check_init_template = gdk_cli.run( - ["component", "init", "-t", "HelloWorld", "-l", "python", "-n", "HelloWorld"] - ) + check_init_template = gdk_cli.run(["component", "init", "-t", "HelloWorld", "-l", "python", "-n", "HelloWorld"]) assert check_init_template.returncode == 0 assert Path(path_HelloWorld).joinpath("recipe.yaml").resolve().exists() config_file = Path(path_HelloWorld).joinpath("gdk-config.json").resolve() @@ -64,8 +60,9 @@ def test_publish_without_build_template_zip(change_test_dir, gdk_cli): t_utils.update_config(config_file, component_name, region, bucket, author) os.chdir(path_HelloWorld) - - check_publish_component = gdk_cli.run(["component", "publish"]) + # Pass in bucket name as arg + bucket_arg = "{}-{}-{}".format(bucket, region, t_utils.get_acc_num(region)) + check_publish_component = gdk_cli.run(["component", "publish", "-b", bucket_arg]) assert check_publish_component.returncode == 0 assert Path(path_HelloWorld).joinpath("zip-build").resolve().exists() assert Path(path_HelloWorld).joinpath("greengrass-build").resolve().exists()