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

Add root_template_path to nested stack #3237

Merged
merged 17 commits into from
Sep 10, 2021
Merged

Add root_template_path to nested stack #3237

merged 17 commits into from
Sep 10, 2021

Conversation

xazhao
Copy link
Contributor

@xazhao xazhao commented Sep 2, 2021

Which issue(s) does this change fix?

#2837

Why is this change necessary?

The current behavior is if CodeUri is a relative path, we convert it to absolute path when we normalize resource path for nested stacks. We will also try to resolve relative code path to absolute code path when we get invoke config using --docker-volume-basedir option. There is a bug here. If a customer wants to resolve the path using that option, it won't work since CodeUri is already an absolute path so it won't trying to resolve again.
To fix this issue, we need to make sure if CodeUri is relative path, we keep it relative path so that it can be resolved using --docker-volume-basedir properly. root_template_path is introduced to make sure relative path is based on root template.

How does it address the issue?

Keep relative path when we normalize resource path.

What side effects does this change have?

Checklist

  • Add input/output type hints to new functions/methods
  • Write design document (Do I need to write a design document?)
  • Write unit tests
  • Write/update functional tests
  • Write/update integration tests
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@aahung aahung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some tests involving docker-volume-basedir?

@@ -29,20 +29,26 @@ class TemplateFailedParsingException(UserException):
pass


def get_template_data(template_file):
def get_template_data(template_file, root_template_path: str = ""):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we expect root_template_path to be None or ""?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think either is fine. Just need to keep it consistent in other places. My understanding is if it is string, we prefer using "".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated it to None since it makes more sense.


Returns
-------
Template data as a dictionary
"""

# if template_file is a relative path , we use root_template_path to convert to absolute path
if not os.path.isabs(template_file) and root_template_path:
template_file = os.path.join(root_template_path, template_file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me that we need to get dirname from root_template_path before joining

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the name is misleading. I just updated it to root_template_dir

@xazhao
Copy link
Contributor Author

xazhao commented Sep 8, 2021

Added an integration test involving using --docker-volume-basedir option.

Comment on lines 49 to 51
# if template_file is a relative path , we use root_template_dir to convert to absolute path
if not os.path.isabs(template_file) and root_template_dir:
template_file = os.path.join(root_template_dir, template_file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to do this without requiring multiple variables to specify a single path?

e.g. in one location make the path absolute, and pass that around, so that callees just read from the path without caring whether it's absolute or relative

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is possible and useful. It needs a relative larger refactoring since currently we have a few places doing path checking and converting. I'd say it's out of scope for this bug and we can do this in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way to reduce the number of places where these path modifications are done?

It's already somewhat confusing as for example normalize_resource_path already does some path changes, but then further changes are done here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed elsewhere: normalize_resource_path no longer converts to absolute path only since a bug was discovered. Agreed to add comment explaining the context.

Copy link
Contributor

@aahung aahung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines -223 to +238
template_dict = get_template_data(template_file)
template_dict = get_template_data(template_file, root_template_dir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to provide root_template_dir for all usage of get_template_data()? Maybe we can make it not optional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it is used in a few other places including intrinsics resolver. I prefer not changing that part. Ideally as Chris said, we can get rid of all root_template_dir and convert all paths to absolute in a single place later.

Comment on lines 1085 to 1088
"template_file", parameter_overrides=None, global_parameter_overrides={"AWS::Region": "my-custom-region"}
"template_file",
parameter_overrides=None,
root_template_dir=os.getcwd(),
global_parameter_overrides={"AWS::Region": "my-custom-region"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put a comment at line 1087 explaining a little bit why it is os.getcwd()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants