Changes between Version 24 and Version 25 of OracleTestSetup
- Timestamp:
- Sep 24, 2015, 2:21:05 PM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
OracleTestSetup
v24 v25 10 10 =============================================== 11 11 12 Oracle provides pre-built virtual machine images with Oracle Database 1 1g Release 2 Enterprise Editionfor developers in form of an OVA archive which can be imported by VirtualBox. The archive can be downloaded `here`__ (or alternately a different one can be chosen from `this list`__) after signing up for an *Oracle Developer Network* account.12 Oracle provides pre-built virtual machine images with Oracle Database 12c Release 1 Enterprise Edition (12.1.0.2.0) for developers in form of an OVA archive which can be imported by VirtualBox. The archive can be downloaded `here`__ (or alternately a different one can be chosen from `this list`__) after signing up for an *Oracle Developer Network* account. 13 13 14 14 .. __: http://www.oracle.com/technetwork/database/enterprise-edition/databaseappdev-vm-161299.html … … 17 17 The server will probably be somewhat slower than if you install it directly on the host machine, but using a VM has a slightly simpler setup, there's a somewhat smaller chance you'll pollute your host system completely and in case something goes wrong, you can always just remove the virtual machine, import a fresh copy and start again. 18 18 19 #. Download the OVA file from http://www.oracle.com/technetwork/database/enterprise-edition/databaseappdev-vm-161299.html and import it into VirtualBox . You'll have to accept an extensive license agreement.19 #. Download the OVA file from http://www.oracle.com/technetwork/database/enterprise-edition/databaseappdev-vm-161299.html and import it into VirtualBox (File -> Import Appliance). You'll have to accept an extensive license agreement. 20 20 21 #. By default, the VM will be configured to have one NAT network interface . The database server itself starts automatically and listens on port 1521. You'll have to set up port forwarding in VirtualBox in order to access the server. Open the settings of the emulated network adapter and under *Advanced* open *Port Forwarding*. Insert a new rule with host IP set to 127.0.0.1, host port and destination port 1521 and an empty guest IP.21 #. By default, the VM will be configured to have one NAT network interface and active port forwarding on port 1521. The database server itself starts automatically and listens on port 1521 (which is the default port for the Oracle listener), therefore you can connect to Oracle server using ``127.0.0.1:1521``. VM image uses ``cdb1`` as Oracle *SID* and ``oracle`` as pluggable DB. 22 22 23 #. The server comes with a number of user accounts created beforehand but I only found out how to access two of them. There's ``sys``, which is a "sysdba" account (whatever that means), and ``system``. The password for both of these is ``oracle`` and both have full privileges. Since the ``sys`` account is "sysdba", I'm not sure it can be used to run the tests (it spits out an error message on login attempt) but ``system`` seems to work just fine.23 #. The server comes with more than thirty user accounts created beforehand. Password for all accounts is ``oracle``. Crucial users are ``sys`` and ``system`` because both of them have "*sysdba*" privilege (which means full control over DB and privileges to do everything). You can use them to create new test accounts in ``orcl`` container. 24 24 25 25 As for other credentials on the virtual machine, if you want to login as a regular user, just use ``oracle``/``oracle``, the root password is ``oracle`` as well. However, in order to run the test suite, you just need to boot the machine up, you don't need to start anything manually. 26 26 27 #. Install *instantclient* on your host system (the one where you'll be running the test suite). On Gentoo there is an ebuild, which means it is just a matter of ``emerge -av oracle-instantclient-basic`` and fetching the appropriate zip archives from the Oracle download site as instructed.27 #. Install *instantclient* on your host system (the one where you'll be running the test suite). On Debian or Ubuntu you can download the RPM packages ("Instant Client Package - Basic", "Instant Client Package - SDK" and "Instant Client Package - SQL*Plus" for 12.1.0.2.0) from http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html and install using alien:: 28 28 29 On Debian or Ubuntu you can download the RPM package ("Instant Client Package - Basic"), convert it to a DEB package and install using alien:: 29 $ sudo alien -i oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm 30 $ sudo alien -i oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm 31 $ sudo alien -i oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm 30 32 31 $ sudo alien -i oracle-instantclient-basic*.rpm33 After installing the client, you need to add links to Oracle shared libraries and ``sqlplus``:: 32 34 33 After installing the client, you will need to install the "Instant Client Package - SDK". After downloading, unzip and copy it to the client install directory:: 34 35 $ unzip instantclient-sdk-linux.x64-*.zip 36 $ sudo cp -R instantclient_11_2/* /usr/lib/oracle/11.2/client64/ 35 $ sudo echo "/usr/lib/oracle/12.1/client64/lib/" > /etc/ld.so.conf.d/oracle.conf 36 $ ldconfig 37 $ ln -s /usr/bin/sqlplus64 /usr/bin/sqlplus 37 38 38 #. Start a new shell and install cx_Oraclein your testing virtualenv::39 #. Next install ``cx_Oracle`` in your testing virtualenv:: 39 40 40 41 $ pip install cx_Oracle 41 42 42 The new shell is necessary because the *instantclient* package sets various environment variables required to build the adapter. On Debian/Ubuntu, you'll need to set the variables manually::43 #. Create test user:: 43 44 44 $ export ORACLE_HOME=/usr/lib/oracle/11.2/client64/ 45 $ sqlplus sys/oracle@localhost/cdb1 as sysdba 46 SQL> ALTER SESSION SET CONTAINER=orcl; 47 SQL> CREATE USER djangotest IDENTIFIED BY djangotest; 48 SQL> GRANT DBA TO djangotest; 49 SQL> QUIT 45 50 46 If you get an error installing cx_oracle (``/usr/bin/ld: cannot find -lclntsh``), you may also need to create this link:: 47 48 $ sudo ln -s /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1 /usr/lib/oracle/11.2/client64/lib/libclntsh.so 49 50 #. Create a settings file, the following example seems to work for me:: 51 #. Fill ``DATABASES`` in settings file:: 51 52 52 53 DATABASES = { 53 54 'default': { 54 55 'ENGINE': 'django.db.backends.oracle', 55 'HOST': '127.0.0.1', 56 'PORT': '1521', 57 'NAME': 'orcl', 58 'USER': 'system', 59 'PASSWORD': 'oracle', 60 'TEST': { 61 'USER': 'django', 62 'TBLSPACE': 'django_test', 63 'TBLSPACE_TMP': 'django_test_tmp', 64 }, 65 }, 66 'other': { 67 'ENGINE': 'django.db.backends.oracle', 68 'HOST': '127.0.0.1', 69 'PORT': '1521', 70 'NAME': 'orcl', 71 'USER': 'system', 72 'PASSWORD': 'oracle', 73 'TEST': { 74 'USER': 'other', 75 'TBLSPACE': 'other_test', 76 'TBLSPACE_TMP': 'other_test_tmp', 77 }, 56 'NAME': '127.0.0.1:1521/orcl', 57 'USER': 'djangotest', 58 'PASSWORD': 'djangotest', 78 59 }, 79 60 } 80 61 81 SECRET_KEY = "django_tests_secret_key" 62 #. Run tests:: 82 63 83 As opposed to the XE server whose installation is outlined above, the server provided on the VM image uses ``orcl`` as its SID. 84 85 #. Profit:: 86 87 $ # may be need on Debian/Ubuntu 88 $ export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib 89 $ # for error "libaio.so.1: cannot open shared object file" 90 $ sudo apt-get install libaio1 91 92 $ ./runtests.py --settings=test_oracle 64 $ ./manage.py test 93 65 Creating test database for alias 'default'... 94 66 Creating test user... 95 Creating test database for alias 'other'...96 67 ... 97 68 ---------------------------------------------------------------------- 98 69 Ran XXX tests in XXXs 99 70 100 OK (skipped=X, expected failures=X)71 OK 101 72 Destroying test database for alias 'default'... 102 73 Destroying test user... 103 74 Destroying test database tables... 104 Destroying test database for alias 'other'...105 75 }}}