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

Set null value for response #61

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

gsoyka
Copy link

@gsoyka gsoyka commented Oct 11, 2017

On a non-EC2 instance, I'm seeing the following error. As best I can tell, it happens because the response variable is never set if the EC2 metadata url doesn't exist. Setting the variable to none appears to resolve the issue.

"/usr/lib/yum-plugins/s3iam.py" 463L, 17040C
        self.token = None
    return base.installPkgs(extcmds, basecmd=basecmd)
  File "/usr/share/yum-cli/cli.py", line 983, in installPkgs
    txmbrs = self.install(pattern=arg)
  File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 4825, in install
    mypkgs = self.pkgSack.returnPackages(patterns=pats,
  File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 1074, in <lambda>
    pkgSack = property(fget=lambda self: self._getSacks(),
  File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 778, in _getSacks
    self.repos.populateSack(which=repos)
  File "/usr/lib/python2.7/site-packages/yum/repos.py", line 386, in populateSack
    sack.populate(repo, mdtype, callback, cacheonly)
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 227, in populate
    if self._check_db_version(repo, mydbtype):
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 319, in _check_db_version
    return repo._check_db_version(mdtype)
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1512, in _check_db_version
    repoXML = self.repoXML
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1698, in <lambda>
    repoXML = property(fget=lambda self: self._getRepoXML(),
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1694, in _getRepoXML
    self._loadRepoXML(text=self.ui_id)
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1685, in _loadRepoXML
    return self._groupLoadRepoXML(text, self._mdpolicy2mdtypes())
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1659, in _groupLoadRepoXML
    if self._commonLoadRepoXML(text):
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1479, in _commonLoadRepoXML
    result = self._getFileRepoXML(local, text)
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1256, in _getFileRepoXML
    size=102400) # setting max size as 100K
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1022, in _getFile
    result = self.grab.urlgrab(misc.to_utf8(relative), local,
  File "/usr/lib/yum-plugins/s3iam.py", line 194, in grab
    self.grabber.get_role()
  File "/usr/lib/yum-plugins/s3iam.py", line 244, in get_role
    if response:
UnboundLocalError: local variable 'response' referenced before assignment

@gsoyka
Copy link
Author

gsoyka commented Oct 11, 2017

Setting to work in progress, root cause appears to be the timeout on the urllib request, need to investigate further

@gsoyka
Copy link
Author

gsoyka commented Oct 12, 2017

Tracked the root cause to a long timeout period when in a Non-EC2 environment. Setting the timeout lower causes it to fall back to configuring from the environment variables in a more reasonable period of time.

@mbrossard
Copy link
Collaborator

mbrossard commented Oct 20, 2017

Would it be possible for you to add a metadata_timeout configuration setting and use this value in the urllib2.urlopen call? Default value should be None in order to keep existing behavior, but people using the plugin outside EC2 will be able to lower the timeout via configuration.

@gsoyka
Copy link
Author

gsoyka commented Oct 23, 2017

I can, but I'm not sure that it's necessary. I tested the response time for the request to the metadata URL and was seeing averages under 200ms. Even at a 1 second timeout there should be plenty of time for it to get the metadata before timing out if it's running on EC2. I hesitate leaving the default as no timeout; because urllib2 has no default timeout it will just run forever until manually killed, which is not ideal.

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.

2 participants