
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


---
# juju-finish/tasks/main.yml

# run another time, so services will be in juju_services list
- name: Obtain Juju Facts after service creation
  juju_facts:
  register: result
  until: result | success
  retries: 3
  delay: 15

# 1800s = 30m. Usually takes 10-12m on cloudlab for relations to come up
# Only checks for first port in list
- name: Wait for juju services to have open ports
  wait_for:
    host={{ item.name }}
    port={{ item.forwarded_ports[0].int }}
    timeout=1800
  with_items: "{{ head_lxd_list | selectattr('forwarded_ports', 'defined') | list }}"

# secondary wait, as waiting on ports isn't enough. Probably only need one of these...
# 160*15s = 2400s = 40m max wait
- name: Wait for juju services to start
  command: juju status --format=summary
  register: juju_summary
  until: juju_summary.stdout.find("pending:") == -1
  retries: 160
  delay: 15
  tags:
   - skip_ansible_lint # checking/waiting on a system to be up

