From d41835e7463d52151d8be63334d6f3187d3246d5 Mon Sep 17 00:00:00 2001 From: Samir Faci <samir@es.net> Date: Tue, 26 Oct 2021 09:09:46 -0400 Subject: [PATCH] Adding CI/CD --- .drone.yml | 28 ++++++++++++++++++++++++++++ test/db.py | 2 +- test/test_config.py | 2 +- test/test_multiple.py | 2 +- test/test_ncsvpn.py | 2 +- util/integration-config.json | 7 +++++++ util/pg-test-run | 3 ++- 7 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 .drone.yml create mode 100644 util/integration-config.json diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 00000000..76794166 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,28 @@ +kind: pipeline +name: default + +steps: + - name: build + image: python:3.9 + environment: + POSTGRES_HOST: database + commands: + - apt update && apt-get install -y postgresql-client + - cat datafiles/schema.sql | PGPASSWORD="w1gWIn7NDGXjXMguiI2Qe05X" psql -U opennsa -h database -d opennsatest + - python3 -m pip install -r requirements.txt + - cp util/integration-config.json .opennsa-test.json + - cp config/opennsa.conf.template config/opennsa.conf + - PYTHONPATH=. trial test + +services: +- name: database + image: postgres:12-alpine + environment: + POSTGRES_USER: opennsa + POSTGRES_PASSWORD: w1gWIn7NDGXjXMguiI2Qe05X + POSTGRES_DB: opennsatest + +trigger: + event: + - push + - pull_request diff --git a/test/db.py b/test/db.py index f28ec977..a3880c76 100644 --- a/test/db.py +++ b/test/db.py @@ -15,6 +15,6 @@ def setupDatabase(config_file=CONFIG_FILE): tc = json.load( open(config_file) ) - database.setupDatabase( tc['database'], tc['user'], tc['password'], host='127.0.0.1') + database.setupDatabase( tc['database'], tc['user'], tc['password'], host=tc['hostname']) diff --git a/test/test_config.py b/test/test_config.py index 22195075..3993ddec 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -123,7 +123,7 @@ class ConfigTest(unittest.TestCase): self.database = tc['database'] self.db_user = tc['user'] self.db_password = tc['password'] - self.db_host = '127.0.0.1' + self.db_host = tc['hostname'] def _generate_temp_file(self, buffer): """ diff --git a/test/test_multiple.py b/test/test_multiple.py index 7a30ae68..fefd9ec5 100644 --- a/test/test_multiple.py +++ b/test/test_multiple.py @@ -117,7 +117,7 @@ class MultipleInstancesTestMultipleInstancesTest(unittest.TestCase): self.database = tc['database'] self.db_user = tc['user'] self.db_password = tc['password'] - self.db_host = '127.0.0.1' + self.db_host = tc['hostname'] # make temporary files for nrm map files diff --git a/test/test_ncsvpn.py b/test/test_ncsvpn.py index 8cedaf15..1c75f0da 100644 --- a/test/test_ncsvpn.py +++ b/test/test_ncsvpn.py @@ -32,7 +32,7 @@ class NCSVPNBackendTest(unittest.TestCase): self.backend.startService() - database.setupDatabase( tc['database'], tc['database-user'], tc['database-password']) + database.setupDatabase(tc['database'], tc['database-user'], tc['database-password'], host=tc['hostname']) self.requester_nsa = nsa.NetworkServiceAgent('test-requester', 'http://example.org/nsa-test-requester') self.provider_nsa = nsa.NetworkServiceAgent('test-provider', 'http://example.org/nsa-test-provider') diff --git a/util/integration-config.json b/util/integration-config.json new file mode 100644 index 00000000..91f79fdd --- /dev/null +++ b/util/integration-config.json @@ -0,0 +1,7 @@ +{ + "container" : "opennsa-test-database", + "database" : "opennsatest", + "user" : "opennsa", + "hostname" : "database", + "password" : "w1gWIn7NDGXjXMguiI2Qe05X" +} diff --git a/util/pg-test-run b/util/pg-test-run index 040aee44..a84c2f9d 100755 --- a/util/pg-test-run +++ b/util/pg-test-run @@ -21,7 +21,8 @@ echo "{ \"container\" : \"$container\", \"database\" : \"$database\", \"user\" : \"$user\", - \"password\" : \"$password\" + \"password\" : \"$password\", + \"hostname\" : \"127.0.0.1\" }" > "$configfile" -- GitLab