From 0f231f0e76cfe9c2baf7979ed85eb875e051e236 Mon Sep 17 00:00:00 2001
From: Matthew Mosesohn <mmosesohn@mirantis.com>
Date: Sat, 9 Sep 2017 23:41:31 +0300
Subject: [PATCH] Improve method to create and wait for gce instances (#1645)

---
 tests/cloud_playbooks/create-gce.yml    | 14 +++++++++++---
 tests/testcases/010_check-apiserver.yml |  2 +-
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/tests/cloud_playbooks/create-gce.yml b/tests/cloud_playbooks/create-gce.yml
index 1a82c50d7..afa757719 100644
--- a/tests/cloud_playbooks/create-gce.yml
+++ b/tests/cloud_playbooks/create-gce.yml
@@ -34,6 +34,10 @@
         tags: "build-{{test_name}},{{kube_network_plugin}}"
       register: gce
 
+    - name: Add instances to host group
+      add_host: hostname={{item.name}} ansible_host={{item.public_ip}} groupname="waitfor_hosts"
+      with_items: '{{gce.instance_data}}'
+
     - name: Template the inventory
       template:
         src: ../templates/inventory-gce.j2
@@ -51,6 +55,10 @@
         dest: "{{ inventory_path|dirname }}/group_vars/fake_hosts.yml"
       when: mode in ['scale', 'separate-scale', 'ha-scale']
 
-    - name: Wait for SSH to come up
-      wait_for: host={{item.public_ip}} port=22 delay=30 timeout=180 state=started
-      with_items: "{{gce.instance_data}}"
+
+- name: Wait for instances
+  hosts: "waitfor_hosts"
+  gather_facts: false
+  tasks:
+    - name: Wait for SSH to come up.
+      local_action: wait_for host={{inventory_hostname}} port=22 delay=5 timeout=240 state=started
diff --git a/tests/testcases/010_check-apiserver.yml b/tests/testcases/010_check-apiserver.yml
index 82c8b23d4..5b053fd4b 100644
--- a/tests/testcases/010_check-apiserver.yml
+++ b/tests/testcases/010_check-apiserver.yml
@@ -6,6 +6,6 @@
     uri:
       url: "https://{{ access_ip | default(ansible_default_ipv4.address) }}:{{ kube_apiserver_port }}/api/v1"
       user: kube
-      password: "{{ lookup('password', '../../credentials/kube_user length=15') }}"
+      password: "{{ lookup('password', '../../credentials/kube_user length=15 chars=ascii_letters,digits') }}"
       validate_certs: no
       status_code: 200
-- 
GitLab