test_client.py 3.4 KB

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