test_client.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 os
  18. import shutil
  19. import sys
  20. import tempfile
  21. from nose.tools import assert_true, assert_equal, assert_false
  22. from sqoop.conf import SQOOP_CONF_DIR
  23. from sqoop.client.base import SqoopClient
  24. from sqoop.sqoop_properties import reset
  25. if sys.version_info[0] > 2:
  26. open_file = open
  27. else:
  28. open_file = file
  29. def test_security_plain():
  30. tmpdir = tempfile.mkdtemp()
  31. finish = SQOOP_CONF_DIR.set_for_testing(tmpdir)
  32. try:
  33. xml = sqoop_properties(authentication='SIMPLE')
  34. with open_file(os.path.join(tmpdir, 'sqoop.properties'), 'w') as f:
  35. f.write(xml)
  36. reset()
  37. client = SqoopClient('test.com', 'test')
  38. assert_false(client._security_enabled)
  39. finally:
  40. reset()
  41. finish()
  42. shutil.rmtree(tmpdir)
  43. def test_security_kerberos():
  44. tmpdir = tempfile.mkdtemp()
  45. finish = SQOOP_CONF_DIR.set_for_testing(tmpdir)
  46. try:
  47. xml = sqoop_properties(authentication='KERBEROS')
  48. with open_file(os.path.join(tmpdir, 'sqoop.properties'), 'w') as f:
  49. f.write(xml)
  50. reset()
  51. client = SqoopClient('test.com', 'test')
  52. assert_true(client._security_enabled)
  53. finally:
  54. reset()
  55. finish()
  56. shutil.rmtree(tmpdir)
  57. def sqoop_properties(authentication='SIMPLE'):
  58. return """
  59. org.apache.sqoop.repository.provider=org.apache.sqoop.repository.JdbcRepositoryProvider
  60. org.apache.sqoop.repository.jdbc.transaction.isolation=READ_COMMITTED
  61. org.apache.sqoop.repository.jdbc.maximum.connections=10
  62. org.apache.sqoop.repository.jdbc.handler=org.apache.sqoop.repository.derby.DerbyRepositoryHandler
  63. org.apache.sqoop.repository.jdbc.url=jdbc:derby:/var/lib/sqoop2/repository/db;create=true
  64. org.apache.sqoop.repository.jdbc.driver=org.apache.derby.jdbc.EmbeddedDriver
  65. org.apache.sqoop.repository.jdbc.create.schema=true
  66. org.apache.sqoop.repository.jdbc.user=sa
  67. org.apache.sqoop.repository.jdbc.password=
  68. org.apache.sqoop.repository.sysprop.derby.stream.error.file=/var/log/sqoop2/derbyrepo.log
  69. org.apache.sqoop.submission.engine=org.apache.sqoop.submission.mapreduce.MapreduceSubmissionEngine
  70. org.apache.sqoop.submission.engine.mapreduce.configuration.directory={{CMF_CONF_DIR}}/yarn-conf
  71. org.apache.sqoop.execution.engine=org.apache.sqoop.execution.mapreduce.MapreduceExecutionEngine
  72. org.apache.sqoop.security.authentication.type=%(authentication)s
  73. org.apache.sqoop.security.authentication.handler=org.apache.sqoop.security.KerberosAuthenticationHandler
  74. org.apache.sqoop.security.authentication.kerberos.principal=sqoop2/_HOST@VPC.CLOUDERA.COM
  75. org.apache.sqoop.security.authentication.kerberos.http.principal=HTTP/_HOST@VPC.CLOUDERA.COM
  76. org.apache.sqoop.security.authentication.kerberos.keytab=sqoop.keytab
  77. org.apache.sqoop.security.authentication.kerberos.http.keytab=sqoop.keytab
  78. """ % {
  79. 'authentication': authentication,
  80. }