ambari-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alejandro Fernandez (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (AMBARI-13271) Error: str() function only 1 takes parameter
Date Sun, 06 Mar 2016 01:40:40 GMT

    [ https://issues.apache.org/jira/browse/AMBARI-13271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15181941#comment-15181941
] 

Alejandro Fernandez commented on AMBARI-13271:
----------------------------------------------

[~kvasko], thank you for your contribution.
Please change 
{code}
... % (str(filePath, e)))
{code}
to
{code}
% (str(filePath), str(e)))
{code}

Also, you can assign the Jira to yourself and set the Fix Version to 2.4.0
You patch is small enough that you shouldn't need to write unit tests.

If you still do, take a look at "TestHostCleanup.py"
We typically don't make assertions on log statements, but you can mock the Logger and assert
that it was called with certain arguments. Because your patch is when an exception is thrown
in shutil.copyfile, you're also going to have to mock that class and make it throw an exception.

> Error: str() function only 1 takes parameter
> --------------------------------------------
>
>                 Key: AMBARI-13271
>                 URL: https://issues.apache.org/jira/browse/AMBARI-13271
>             Project: Ambari
>          Issue Type: Bug
>          Components: ambari-agent
>    Affects Versions: 2.1.1
>         Environment: CentOS 7.0
>            Reporter: Kevin Vasko
>            Priority: Minor
>         Attachments: AMBARI-13271.patch, patch.diff
>
>
> In the file
> /usr/lib/python2.6/site-packages/ambari_agent/HostCleanup.py
> and in the backup_file function I was getting an error staying Error: str() only takes
1 parameter but 2 were passed type error.
> # Copy file and save with file.# (timestamp)
> def backup_file(filePath):
>   if filePath is not None and os.path.exists(filePath):
>     timestamp = datetime.datetime.now()
>     format = '%Y%m%d%H%M%S'
>     try:
>       shutil.copyfile(filePath, filePath + "." + timestamp.strftime(format))
>     except (Exception), e:
>       logger.warn('Could not backup file "%s": %s' % (str(filePath, e)))
>   return 0 
> I do believe the exception handling line is incorrect and should be change from:
> logger.warn('Could not backup file "%s": %s' % (str(filePath, e)))
> to:
> logger.warn('Could not backup file "%s": %s' % (str(filePath), e))



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message