You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2014/05/14 17:47:04 UTC

git commit: AMBARI-5757. Agent can not download modified stack files if wrong http_proxy is set up (dlysnichenko)

Repository: ambari
Updated Branches:
  refs/heads/trunk 17a4e3e9c -> d1e53b326


AMBARI-5757. Agent can not download modified stack files if wrong http_proxy is set up (dlysnichenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d1e53b32
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d1e53b32
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d1e53b32

Branch: refs/heads/trunk
Commit: d1e53b326018e3e33173d150109b588c33437da2
Parents: 17a4e3e
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Wed May 14 18:46:10 2014 +0300
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Wed May 14 18:46:10 2014 +0300

----------------------------------------------------------------------
 ambari-agent/src/main/python/ambari_agent/FileCache.py     | 6 ++++--
 ambari-agent/src/main/python/ambari_agent/security.py      | 7 ++++++-
 ambari-agent/src/test/python/ambari_agent/TestFileCache.py | 4 ++--
 ambari-agent/src/test/python/ambari_agent/TestSecurity.py  | 6 +++---
 4 files changed, 15 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d1e53b32/ambari-agent/src/main/python/ambari_agent/FileCache.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/FileCache.py b/ambari-agent/src/main/python/ambari_agent/FileCache.py
index 740e820..91ec76a 100644
--- a/ambari-agent/src/main/python/ambari_agent/FileCache.py
+++ b/ambari-agent/src/main/python/ambari_agent/FileCache.py
@@ -155,7 +155,9 @@ class FileCache():
     logger.debug("Trying to download {0}".format(url))
     try:
       memory_buffer = StringIO.StringIO()
-      u = urllib2.urlopen(url, timeout=self.SOCKET_TIMEOUT)
+      proxy_handler = urllib2.ProxyHandler({})
+      opener = urllib2.build_opener(proxy_handler)
+      u = opener.open(url, timeout=self.SOCKET_TIMEOUT)
       logger.debug("Connected with {0} with code {1}".format(u.geturl(),
                                                              u.getcode()))
       buff = u.read(self.BLOCK_SIZE)
@@ -234,4 +236,4 @@ class FileCache():
     except Exception, err:
       raise CachingException("Can not unpack zip file to "
                              "directory {0} : {1}".format(
-                            target_directory, str(err)))
\ No newline at end of file
+                            target_directory, str(err)))

http://git-wip-us.apache.org/repos/asf/ambari/blob/d1e53b32/ambari-agent/src/main/python/ambari_agent/security.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/security.py b/ambari-agent/src/main/python/ambari_agent/security.py
index 9801dec..c4cb746 100644
--- a/ambari-agent/src/main/python/ambari_agent/security.py
+++ b/ambari-agent/src/main/python/ambari_agent/security.py
@@ -189,7 +189,9 @@ class CertificateManager():
   def loadSrvrCrt(self):
     get_ca_url = self.server_url + '/cert/ca/'
     logger.info("Downloading server cert from " + get_ca_url)
-    stream = urllib2.urlopen(get_ca_url)
+    proxy_handler = urllib2.ProxyHandler({})
+    opener = urllib2.build_opener(proxy_handler)
+    stream = opener.open(get_ca_url)
     response = stream.read()
     stream.close()
     srvr_crt_f = open(self.getSrvrCrtName(), 'w+')
@@ -204,6 +206,9 @@ class CertificateManager():
     register_data = {'csr'       : agent_crt_req_content,
                     'passphrase' : passphrase}
     data = json.dumps(register_data)
+    proxy_handler = urllib2.ProxyHandler({})
+    opener = urllib2.build_opener(proxy_handler)
+    urllib2.install_opener(opener)
     req = urllib2.Request(sign_crt_req_url, data, {'Content-Type': 'application/json'})
     f = urllib2.urlopen(req)
     response = f.read()

http://git-wip-us.apache.org/repos/asf/ambari/blob/d1e53b32/ambari-agent/src/test/python/ambari_agent/TestFileCache.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestFileCache.py b/ambari-agent/src/test/python/ambari_agent/TestFileCache.py
index 023d19a..63ecced 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestFileCache.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestFileCache.py
@@ -224,7 +224,7 @@ class TestFileCache(TestCase):
         'http://localhost:8080/resources//stacks/HDP/2.1.1/hooks/archive.zip')
 
 
-  @patch("urllib2.urlopen")
+  @patch("urllib2.OpenerDirector.open")
   def test_fetch_url(self, urlopen_mock):
     fileCache = FileCache(self.config)
     remote_url = "http://dummy-url/"
@@ -367,4 +367,4 @@ class TestFileCache(TestCase):
     raise Exception("horrible_exc")
 
   def caching_exc_side_effect(self, *a):
-    raise CachingException("horrible_caching_exc")
\ No newline at end of file
+    raise CachingException("horrible_caching_exc")

http://git-wip-us.apache.org/repos/asf/ambari/blob/d1e53b32/ambari-agent/src/test/python/ambari_agent/TestSecurity.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestSecurity.py b/ambari-agent/src/test/python/ambari_agent/TestSecurity.py
index d8955cf..8b11063 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestSecurity.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestSecurity.py
@@ -250,7 +250,7 @@ class TestSecurity(unittest.TestCase):
 
 
 
-  @patch('urllib2.urlopen')
+  @patch("urllib2.OpenerDirector.open")
   @patch.object(security.CertificateManager, "getSrvrCrtName")
   def test_loadSrvrCrt(self, getSrvrCrtName_mock, urlopen_mock):
     read_mock = MagicMock(create=True)
@@ -274,7 +274,7 @@ class TestSecurity(unittest.TestCase):
   @patch.dict('os.environ', {'DUMMY_PASSPHRASE': 'dummy-passphrase'})
   @patch('json.dumps')
   @patch('urllib2.Request')
-  @patch('urllib2.urlopen')
+  @patch("urllib2.OpenerDirector.open")
   @patch('json.loads')
   def test_reqSignCrt(self, loads_mock, urlopen_mock, request_mock, dumps_mock, open_mock, hostname_mock):
     self.config.set('security', 'keysdir', '/dummy-keysdir')
@@ -348,7 +348,7 @@ class TestSecurity(unittest.TestCase):
 
   @patch("ambari_agent.hostname.hostname")
   @patch('__builtin__.open', create=True, autospec=True)
-  @patch('urllib2.urlopen')
+  @patch("urllib2.OpenerDirector.open")
   @patch.dict('os.environ', {'DUMMY_PASSPHRASE': 'dummy-passphrase'})
   def test_reqSignCrt_malformedJson(self, urlopen_mock, open_mock, hostname_mock):
     hostname_mock.return_value = "dummy-hostname"