From 46f7409bb7108623c4650c95abc2f65c6abb2b8b Mon Sep 17 00:00:00 2001
From: handreas <andreas.hamacher@monash.edu>
Date: Wed, 29 Jan 2020 00:27:59 +0000
Subject: [PATCH] fixing some issues from the first commit. mainly key handling
 and pathes

Former-commit-id: 746a1a3554281db2afb9ec588b9cb28640301f55
---
 .gitignore                            |  4 ++
 .gitlab-ci.yml                        | 81 ++++++++++++++-------------
 CICD/ansible_create_cluster_script.sh |  1 -
 3 files changed, 47 insertions(+), 39 deletions(-)

diff --git a/.gitignore b/.gitignore
index 153b6a97..4dadd585 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,8 @@
+*.swp
 *.retry
 *-openrc.sh
 gc_key.pem
+CICD/files/slurm.conf
+CICD/files/slurmdbd.conf
+CICD/files/ssh_known_hosts
 
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3b15d116..e1792faa 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -7,12 +7,21 @@ stages:
 #  - integration_test_downstream # working but unwanted here
 #  - trigger_pipeline_in_B   # working but unwanted here
   - yamllint
-#  - heat
+  - heat
   - ansible_create_cluster_stage
   - push_button_spawn_cluster
 #  - e2e
   - tests
-#  - clean # only on master
+  - clean # only on master
+
+setup:
+  stage: .pre
+  tags: 
+  - ansible
+  script: 
+  - echo $GC_KEY > gc_key.pem
+  - chmod 400 gc_key.pem
+  - echo $HPCCICD_openrc > ./$NECTAR_ALLOCATION-openrc.sh
 
 #trigger_pipeline_in_B:
 #  stage: integration_test_downstream
@@ -21,33 +30,33 @@ stages:
 #  script:
 #  - "curl --request POST --form token=${CI_JOB_TOKEN} --form ref=master https://gitlab.erc.monash.edu.au/api/v4/projects/1085/trigger/pipeline"  # ID is from pysshauthz
 
-heat_test:
-  stage: heat
-  allow_failure: false
-  tags:
-  - heat
-  before_script:
-    - source ./keys/$NECTAR_ALLOCATION-openrc.sh
-    - export HEAT_TEST_STACKNAME=_TESTING_HEAT
-    - bash -x ./heat/heatcicdwrapper.sh delete_if_exists $HEAT_TEST_STACKNAME
-    - sleep 60
-  script:
-    - echo "heat_test stage"
-    - source ./keys/$NECTAR_ALLOCATION-openrc.sh
-    - bash -x ./heat/heatcicdwrapper.sh create $HEAT_TEST_STACKNAME
-    - openstack stack list
-    - bash -x ./heat/heatcicdwrapper.sh update $HEAT_TEST_STACKNAME
-    - openstack stack list
-    - bash -x ./heat/heatcicdwrapper.sh delete_if_exists $HEAT_TEST_STACKNAME
-    - openstack stack list
-  after_script:
-    - sleep 20 # artifically wait a bit to make sure it is really dead
-  only:
-    changes: #https://docs.gitlab.com/ee/ci/yaml/#onlychangesexceptchanges
-    - "heat/heatcicdwrapper.sh"
-    - "heat/*.{yml,yaml}"
-    - schedules
-    #- CICD/.gitlab-ci.yml
+# heat_test:
+#   stage: heat
+#   allow_failure: false
+#   tags:
+#   - heat
+#   before_script:
+#     - source ./$NECTAR_ALLOCATION-openrc.sh
+#     - export HEAT_TEST_STACKNAME=_TESTING_HEAT
+#     - bash -x ./heat/heatcicdwrapper.sh delete_if_exists $HEAT_TEST_STACKNAME
+#     - sleep 60
+#   script:
+#     - echo "heat_test stage"
+#     - source ./$NECTAR_ALLOCATION-openrc.sh
+#     - bash -x ./heat/heatcicdwrapper.sh create $HEAT_TEST_STACKNAME
+#     - openstack stack list
+#     - bash -x ./heat/heatcicdwrapper.sh update $HEAT_TEST_STACKNAME
+#     - openstack stack list
+#     - bash -x ./heat/heatcicdwrapper.sh delete_if_exists $HEAT_TEST_STACKNAME
+#     - openstack stack list
+#   after_script:
+#     - sleep 20 # artifically wait a bit to make sure it is really dead
+#   only:
+#     changes: #https://docs.gitlab.com/ee/ci/yaml/#onlychangesexceptchanges
+#     - "heat/heatcicdwrapper.sh"
+#     - "heat/*.{yml,yaml}"
+#     - schedules
+#     #- CICD/.gitlab-ci.yml
 
 yamllint:
   stage: yamllint
@@ -100,7 +109,7 @@ tests:
   script:
     - echo "tests stage"
     - export ANSIBLE_HOST_KEY_CHECKING=False
-    - source ./keys/$NECTAR_ALLOCATION-openrc.sh
+    - source ./$NECTAR_ALLOCATION-openrc.sh
     - python3 dependencies/ansible_cluster_in_a_box/scripts/make_inventory.py static CICD$STACKNAME | tee ./files/cicd_inventory
     - grep -qv "I could not find any resouces tagged with project_name:" ./files/cicd_inventory   #fail if inventory file is empty
     - chmod 755 ./files/cicd_inventory
@@ -131,7 +140,7 @@ manual_cluster_spawn:
     - echo I still need to handle os password
     - echo $MANUAL_STACKNAME
   script:
-    - source ./keys/$NECTAR_ALLOCATION-openrc.sh
+    - source ./$NECTAR_ALLOCATION-openrc.sh
     - bash -x ./heat/heatcicdwrapper.sh create $MANUAL_STACKNAME
     - git submodule update --init --remote --merge
     - openstack stack list
@@ -154,10 +163,6 @@ clean:
     - echo "cleanup master"
     - sleep 30
   script:
-    - source ./keys/$NECTAR_ALLOCATION-openrc.sh
-    - bash -x ./heat/heatcicdwrapper.sh delete_if_exists _reporefmaster # hardcoding master stackname on purpose here
-  only:
-    refs:
-      - "master"
-    changes:
-    - schedules
+    - source ./$NECTAR_ALLOCATION-openrc.sh
+    - bash -x ./heat/heatcicdwrapper.sh delete_if_exists $STACKNAME
+
diff --git a/CICD/ansible_create_cluster_script.sh b/CICD/ansible_create_cluster_script.sh
index bf753fd7..a1499f72 100755
--- a/CICD/ansible_create_cluster_script.sh
+++ b/CICD/ansible_create_cluster_script.sh
@@ -9,7 +9,6 @@ cd CICD
 echo "[ansible_create_cluster_script] Prefixing the Stackname with CICD because heatcicdwrapper does he same"
 python3 ../scripts/make_inventory.py static CICD$STACKNAME | tee ./files/inventory.$STACKNAME && chmod 755 ./files/inventory.$STACKNAME
 grep -qv "I could not find any resouces tagged with project_name:" ./files/inventory.$STACKNAME   #fail if inventory file is empty
-chmod 400 ../gc_key.pem
 ansible -m ping -i files/inventory.$STACKNAME --key-file ../gc_key.pem all
 ansible -i files/inventory.$STACKNAME --key-file ../gc_key.pem -a "sudo ls" all
 
-- 
GitLab