Jira (PUP-6418) File parsing error result flushing of file content

2017-05-16 Thread Moses Mendoza (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Moses Mendoza updated an issue 
 
 
 
 
 
 
 
 
 
 

 
 
 
 
 
 
 
 Puppet /  PUP-6418 
 
 
 
  File parsing error result flushing of file content  
 
 
 
 
 
 
 
 
 

Change By:
 
 Moses Mendoza 
 
 
 

Team:
 
 Agent 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 

 
 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups "Puppet Bugs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-bugs@googlegroups.com.
Visit this group at https://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/d/optout.


Jira (PUP-6418) File parsing error result flushing of file content

2017-05-16 Thread Moses Mendoza (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Moses Mendoza updated an issue 
 
 
 
 
 
 
 
 
 
 

 
 
 
 
 
 
 
 Puppet /  PUP-6418 
 
 
 
  File parsing error result flushing of file content  
 
 
 
 
 
 
 
 
 

Change By:
 
 Moses Mendoza 
 
 
 

Labels:
 
 triaged 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 

 
 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups "Puppet Bugs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-bugs@googlegroups.com.
Visit this group at https://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/d/optout.


Jira (PUP-6418) File parsing error result flushing of file content

2016-06-18 Thread Liao Penghui (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Liao Penghui updated an issue 
 
 
 
 
 
 
 
 
 
 

 
 
 
 
 
 
 
 Puppet /  PUP-6418 
 
 
 
  File parsing error result flushing of file content  
 
 
 
 
 
 
 
 
 

Change By:
 
 Liao Penghui 
 
 
 
 
 
 
 
 
 
 When using  resource types like ssh_authorized_keys or host, Puppet will use Puppet::Util::FileParsing module for file line parsing. Specifically, Puppet will call parse for file parsing method during prefetch stage, the parse method is like:{code:ruby}  # Split a bunch of text into lines and then parse them individually.  def parse(text)count = 1lines(text).collect do |line|  count += 1  if val = parse_line(line)val  elseerror = Puppet::ResourceError.new("Could not parse line #{line.inspect}")error.line = countraise error  endend  end{code}As the code above shows, Puppet will raise a Puppet::ResourceError if some line in the file can't be parsed  correctly(May cause by wrong format) . This will lead to failure of prefetch method of a resource type. However, Puppet will still write content to the file cause the flush method in the provider of these resource types. For example, the flush method in ssh_authorized_keys provider will flush the ~/.ssh/authorized_keys file using content in @property_hash. But the flush will delete the original content in that file cause @property_hash is not set by prefetch method. See flush method below:{code:ruby}  def flush# Make sure we've got a target and name set.# If the target isn't set, then this is our first modification, so# mark it for flushing.unless @property_hash[:target]  @property_hash[:target] = @resource.should(:target) || self.class.default_target  self.class.modified(@property_hash[:target])end@resource.class.key_attributes.each do |attr|  @property_hash[attr] ||= @resource[attr]endself.class.flush(@property_hash)  end{code}As above shows ,@property_hash is set by using resource attribute when it is empty. This will lead to lose original content in the file after flush the file.How to reproduce this bug:Say the ssh authorized_keys file is like:{code:bash}$ cat ~/.ssh/authorized_keysssh-rsa ORIGINAL_KEY COMMENTA LINE THAT CAN'T PARSE BY PUPPET{code}I apply a puppet manifest like:{code:puppet}ssh_authorized_key { 'test':  user => 'root',  type => 'ssh-rsa',  key  => 'A_NEW_KEY',}{code}the authorized_keys becomes like:{code:bash}$ cat ~/.ssh/authorized_keysssh-rsa A_NEW_KEY test{code}The original content in that file lost. 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
   

Jira (PUP-6418) File parsing error result flushing of file content

2016-06-18 Thread Liao Penghui (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Liao Penghui created an issue 
 
 
 
 
 
 
 
 
 
 

 
 
 
 
 
 
 
 Puppet /  PUP-6418 
 
 
 
  File parsing error result flushing of file content  
 
 
 
 
 
 
 
 
 

Issue Type:
 
  Bug 
 
 
 

Assignee:
 
 Liao Penghui 
 
 
 

Created:
 

 2016/06/18 8:22 AM 
 
 
 

Priority:
 
  Normal 
 
 
 

Reporter:
 
 Liao Penghui 
 
 
 
 
 
 
 
 
 
 
When using resource types like ssh_authorized_keys or host, Puppet will use Puppet::Util::FileParsing module for file line parsing. Specifically, Puppet will call parse for file parsing method during prefetch stage, the parse method is like: 
 
 
 
 
 
 
  # Split a bunch of text into lines and then parse them individually. 
 
 
 
 
  def parse(text) 
 
 
 
 
count = 1 
 
 
 
 
lines(text).collect do |line|