From 8aadb2653e35eff19c42663dcb7df11806e29014 Mon Sep 17 00:00:00 2001
From: Varac <varac@varac.net>
Date: Wed, 30 Jan 2019 15:09:56 +0100
Subject: [PATCH] Add create_domain_record()

---
 .gitlab-ci.yml       |  2 +-
 test/ci-bootstrap.py |  3 +++
 test/cosmos.py       | 31 ++++++++++++++++++++++---------
 3 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 8295c5f24..51a76e453 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -22,7 +22,7 @@ bootstrap:
   script:
     - apk update
     - apk add ansible musl-dev linux-headers gcc py3-psutil openssh-client moreutils
-    - pip3 install ansible-runner requests
+    - pip3 install ansible-runner requests tabulate
     - cd test
     - eval $(ssh-agent -s)
     - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
diff --git a/test/ci-bootstrap.py b/test/ci-bootstrap.py
index 9a4f263de..d8b6740e9 100755
--- a/test/ci-bootstrap.py
+++ b/test/ci-bootstrap.py
@@ -91,6 +91,9 @@ if __name__ == "__main__":
     ip = droplet['networks']['v4'][0]['ip_address']
     name = droplet['name']
 
+    # Create domain record
+    cosmos.list_domain_records('openappstack.net')
+
     # Wait for ssh
     cosmos.wait_for_ssh(ip)
 
diff --git a/test/cosmos.py b/test/cosmos.py
index e9e78ba78..75114d5ff 100755
--- a/test/cosmos.py
+++ b/test/cosmos.py
@@ -49,18 +49,19 @@ def request_api(resource: str, request_type: str = 'GET',
 
 
 # API calls
-def get_domain_record(domain: str, id: int):
-    """Get details for given domain record."""
-    response = request_api('domains/' + domain + '/records/' + str(id))
+def create_domain_record(domain: str, name: str, data: str,
+                         record_type: str = 'A'):
+    """Create domain record."""
+    print('Creating domain record')
+    record = {
+        'name': name,
+        'data': data,
+        'type': record_type
+    }
+    response = request_api('domains/' + domain + '/records/', 'POST', record)
     return response['domain_record']
 
 
-def get_domain_records(domain: str):
-    """Get domain records for given domain."""
-    response = request_api('domains/' + domain + '/records')
-    return response['domain_records']
-
-
 def create_droplet(name: str, ssh_key_id: int, region: str = 'ams1',
                    size: int = 2048, disk: int = 20, image: int = 7):
     """Create a droplet."""
@@ -86,6 +87,18 @@ def delete_droplet(id: int):
     return response
 
 
+def get_domain_record(domain: str, id: int):
+    """Get details for given domain record."""
+    response = request_api('domains/' + domain + '/records/' + str(id))
+    return response['domain_record']
+
+
+def get_domain_records(domain: str):
+    """Get domain records for given domain."""
+    response = request_api('domains/' + domain + '/records')
+    return response['domain_records']
+
+
 def get_droplets():
     """Get all information about all droplets."""
     response = request_api('droplets')
-- 
GitLab