3
3
4
4
import mock
5
5
from mock import patch
6
+ from requests import RequestException
6
7
from tests import TestCase
7
8
8
9
import requests_mock
@@ -103,7 +104,7 @@ def test_get_resource_endpoint(self):
103
104
104
105
endpoint = hadoop_conf .get_resource_manager_endpoint ()
105
106
106
- self .assertEqual ('example.com:8022' , endpoint )
107
+ self .assertEqual ('http:// example.com:8022' , endpoint )
107
108
parse_mock .assert_called_with (hadoop_conf_path + 'yarn-site.xml' ,
108
109
'yarn.resourcemanager.webapp.address' )
109
110
@@ -122,7 +123,7 @@ def test_get_resource_endpoint_with_ha(self, check_is_active_rm_mock, parse_mock
122
123
check_is_active_rm_mock .return_value = True
123
124
endpoint = hadoop_conf .get_resource_manager_endpoint ()
124
125
125
- self .assertEqual ('example.com:8022' , endpoint )
126
+ self .assertEqual ('http:// example.com:8022' , endpoint )
126
127
parse_mock .assert_called_with (hadoop_conf_path + 'yarn-site.xml' ,
127
128
'yarn.resourcemanager.webapp.address.rm1' )
128
129
@@ -171,23 +172,21 @@ def test_check_is_active_rm(self, is_https_only_mock):
171
172
172
173
# Emulate requests library exception (socket timeout, etc)
173
174
with requests_mock .mock () as requests_get_mock :
174
- requests_get_mock .side_effect = Exception ('error' )
175
- # requests_get_mock.get('https://example2:8022/cluster', status_code=200)
176
- requests_get_mock .return_value = None
177
- self .assertFalse (hadoop_conf .check_is_active_rm ('https://example2:8022' ))
175
+ requests_get_mock .get ('example2:8022/cluster' , exc = RequestException )
176
+ self .assertFalse (hadoop_conf .check_is_active_rm ('example2:8022' ))
178
177
179
178
def test_get_resource_manager (self ):
180
179
with patch ('yarn_api_client.hadoop_conf.parse' ) as parse_mock :
181
180
parse_mock .return_value = 'example.com:8022'
182
181
183
182
endpoint = hadoop_conf ._get_resource_manager (hadoop_conf .CONF_DIR , None )
184
183
185
- self .assertEqual ('example.com:8022' , endpoint )
184
+ self .assertEqual ('http:// example.com:8022' , endpoint )
186
185
parse_mock .assert_called_with (hadoop_conf_path + 'yarn-site.xml' , 'yarn.resourcemanager.webapp.address' )
187
186
188
187
endpoint = hadoop_conf ._get_resource_manager (hadoop_conf .CONF_DIR , 'rm1' )
189
188
190
- self .assertEqual (('example.com:8022' ), endpoint )
189
+ self .assertEqual (('http:// example.com:8022' ), endpoint )
191
190
parse_mock .assert_called_with (hadoop_conf_path + 'yarn-site.xml' , 'yarn.resourcemanager.webapp.address.rm1' )
192
191
193
192
parse_mock .reset_mock ()
0 commit comments