-
Notifications
You must be signed in to change notification settings - Fork 51
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
(WIP) Added Validation to Packer Binary Wrapper #27
Conversation
@Hrily this is a great start! I'll leave you some comments for this PR. thanks for your effort! |
@mayn
Okay, then I'll remove them from
Sure 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Hrily here is some feedback.
let me know your thoughts!
src/packerlicious/packer.py
Outdated
packer_path += "/" | ||
self.packer_path = packer_path | ||
self.template = template | ||
self._vars = _vars |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vars
are already an attribute of template
and should be accesible via template. variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do this 👍
src/packerlicious/packer.py
Outdated
if len(packer_path) > 0 and packer_path[-1] != '/': | ||
packer_path += "/" | ||
self.packer_path = packer_path | ||
self.template = template |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see template
as just a method parameter vs an instance variable. and Packer
class as stateless
so it is easy to use:
packer.validate(my_template)
packer.validate(my_template2)
or whatever without having to re-initial a packer
object.
what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay 👍
So each method will require template
as parameter.
Also Should the packer
binary path be the parameter for each method?
I did it because, I did not make assumption whether user has updated path variable w.r.t. packer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So each method will require template as parameter.
correct
Also Should the packer binary path be the parameter for each method?
I understand. I think it is fine the way it is as a class variable. A future enhancement could be to look at os.env
variable or something if it is useful
For now I think this is a fair expectation that the user know where packer is on their system and provide the location if necessary.
The check_available
method should catch if packer isn't found in the location
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay
So each method will require template as parameter.
I think we won't require Packer
class. All methods will be part of packer
.
But in this case, packer_path
should be a parameter for each method, since we don't have class.
What do you think?
Correct me if I'm wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try it out, can always change it back. so long as you aren't making packer_path
required for the user to provide i think it should be fine.
src/packerlicious/packer.py
Outdated
for key in self._vars: | ||
validate_command += "-var '" + key + "=" + self._vars[key] + "' " | ||
template_file, template_filename = tempfile.mkstemp() | ||
os.write(template_file, self.template.to_json()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally this would pipe directly to packer without creating a tmp file.
if you keep the tmp file writing, please add error handling
if you don't change it on this pr, please create an issue about this so the idea doesn't get lost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not find a way to pipe it directly without creating file.
If you have a way, plz tell me so I can update accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be able to do it via stdin of the popen.communicate
. see hashicorp/packer#2914 for an example. looks like there is a trailing -
they pass to the cmd.
Also more info here hashicorp/packer#4132
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, did it 👍
Thanks :)
src/packerlicious/packer.py
Outdated
proc = subprocess.Popen(shlex.split(validate_command), stdout=subprocess.PIPE) | ||
out = proc.communicate()[0] | ||
os.remove(template_filename) | ||
return proc.returncode, out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice to handle return by converting to a python object we can interact with.
please create an issue so we don't loose this thought ( don't expect as part of initial submission)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do this 👍
src/packerlicious/packer.py
Outdated
os.write(template_file, self.template.to_json()) | ||
os.close(template_file) | ||
validate_command += template_filename | ||
proc = subprocess.Popen(shlex.split(validate_command), stdout=subprocess.PIPE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should capture and return stderr also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do this 👍
I did the mentioned changes, please review. Sorry for late push, was travelling yesterday. Also, Can you tell me how would I pass this coverage test? |
thanks @Hrily! Will review over next day... |
Could you give me some test cases for I think I have written some wrong test case... 🙈 |
Hie @mayn Sorry for a real late reply. The build test on travis is failing with this output
Can I get help regarding this??? I'm using the same Templates used by example. |
@mayn |
@Hrily apologies for the delay, I think you are getting the error because the example template doesn't actually have ec2 credentials in it. |
Build an alternate implementation as standalone repo https://github.com/mayn/packer.py |
PR for #21
I was unsure if I'm going in right direction.
I have just implemented validation part, please have a look and tell if this is good.
PS: Are we taking care of
-var
in Template itself???