tests.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python
  2. # Licensed to Cloudera, Inc. under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. Cloudera, Inc. licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. import sys
  18. import aws
  19. from nose.tools import assert_true, assert_false, assert_equal, assert_not_equal, assert_raises
  20. from desktop.lib.django_test_util import make_logged_in_client
  21. if sys.version_info[0] > 2:
  22. from unittest.mock import patch, Mock
  23. else:
  24. from mock import patch, Mock
  25. def test_config_check():
  26. with patch('beeswax.hive_site.get_metastore_warehouse_dir') as get_metastore_warehouse_dir:
  27. with patch('aws.s3.s3fs.S3FileSystem._stats') as s3_stat:
  28. with patch('aws.conf.is_enabled') as is_s3_enabled:
  29. reset = aws.conf.AWS_ACCOUNTS.set_for_testing({
  30. 'default': {
  31. 'region': 'us-east-1',
  32. 'access_key_id': 'access_key_id',
  33. 'secret_access_key':'secret_access_key'
  34. }
  35. }),
  36. warehouse = 's3a://yingsdx0602/data1/warehouse/tablespace/managed/hive'
  37. get_metastore_warehouse_dir.return_value = warehouse
  38. is_s3_enabled.return_value = True
  39. s3_stat.return_value = Mock(
  40. DIR_MODE=16895,
  41. FILE_MODE=33206,
  42. aclBit=False,
  43. atime=None,
  44. group='',
  45. isDir=True,
  46. mode=16895,
  47. mtime=None,
  48. name='hive',
  49. path='s3a://yingchensdx/data1/warehouse/tablespace/managed/hive/',
  50. size=0,
  51. type='DIRECTORY',
  52. user=''
  53. )
  54. try:
  55. cli = make_logged_in_client()
  56. resp = cli.get('/desktop/debug/check_config')
  57. s3_stat.assert_called()
  58. err_msg = 'Failed to access Hive warehouse: %s' % warehouse
  59. if not isinstance(err_msg, bytes):
  60. err_msg = err_msg.encode('utf-8')
  61. assert_false(err_msg in resp.content, resp)
  62. finally:
  63. for old_conf in reset:
  64. old_conf()