github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/script/stackenv (about)

     1  #!/bin/bash
     2  #
     3  # Prep the testing environment by creating the required testing resources and
     4  # environment variables. This env is used for the CI jobs and you might need
     5  # to modify this according to your setup
     6  
     7  set -euxo pipefail
     8  
     9  DEVSTACK_PATH=${DEVSTACK_PATH:-/opt/stack/new/devstack}
    10  
    11  pushd "$DEVSTACK_PATH"
    12  
    13  set +u
    14  # shellcheck disable=SC1091
    15  source openrc admin admin
    16  set -u
    17  
    18  if [[ "${USE_SYSTEM_SCOPE:-}" == "true" ]]; then
    19      # use system-scoped tokens
    20      echo export OS_SYSTEM_SCOPE=all >> openrc
    21  fi
    22  # TODO: This should only be set when using project-scoped tokens (and we should
    23  # unsetting things like OS_PROJECT_NAME and OS_PROJECT_DOMAIN_ID when not using
    24  # these) but our tests require both which means we need to export both. This
    25  # causes OSC to (correctly) fail since keystoneauth (which is handling
    26  # authentication for OSC and most other clients) can't tell if we want project-
    27  # or system-scoped tokens. As such, post running this script, the 'openrc' file
    28  # will no longer be usable with OSC or other clients.
    29  #
    30  # The long-term fix for this likely involves a mechanism to switch between
    31  # different sets of auth info on a test-by-test basis. Achieving this almost
    32  # certainly means switching our tests to use clouds.yaml with well-known cloud
    33  # names rather than openrc file currently used.
    34  echo export OS_DOMAIN_ID=default >> openrc
    35  
    36  _FLAVOR_ID=99
    37  _FLAVOR_ALT_ID=98
    38  openstack flavor create m1.acctest --id "$_FLAVOR_ID" --ram 512 --disk 10 --vcpu 1 --ephemeral 10
    39  openstack flavor create m1.resize --id "$_FLAVOR_ALT_ID" --ram 512 --disk 11 --vcpu 1 --ephemeral 10
    40  openstack keypair create magnum
    41  _NETWORK_ID=$(openstack network show private -c id -f value)
    42  _SUBNET_ID=$(openstack subnet show private-subnet -c id -f value)
    43  _EXTGW_ID=$(openstack network show public -c id -f value)
    44  _IMAGE=$(openstack image list | grep -i cirros | head -n 1)
    45  _IMAGE_ID=$(echo "$_IMAGE" | awk -F\| '{print $2}' | tr -d ' ')
    46  _IMAGE_NAME=$(echo "$_IMAGE" | awk -F\| '{print $3}' | tr -d ' ')
    47  
    48  cat >> "openrc" <<EOL
    49  
    50  # gophercloud-specific configuration
    51  
    52  export OS_IMAGE_NAME="$_IMAGE_NAME"
    53  export OS_IMAGE_ID="$_IMAGE_ID"
    54  export OS_NETWORK_ID="$_NETWORK_ID"
    55  export OS_SUBNET_ID="$_SUBNET_ID"
    56  export OS_EXTGW_ID="$_EXTGW_ID"
    57  export OS_POOL_NAME="public"
    58  export OS_FLAVOR_ID="$_FLAVOR_ID"
    59  export OS_FLAVOR_ID_RESIZE="$_FLAVOR_ALT_ID"
    60  EOL
    61  
    62  if _=$(openstack service list | grep container-infra); then
    63      _MAGNUM_IMAGE_ID=$(openstack image list --format value -c Name -c ID | grep coreos | cut -d ' ' -f 1)
    64      if [ -z "$_MAGNUM_IMAGE_ID" ]; then
    65          _MAGNUM_IMAGE_ID=$(openstack image list --format value -c Name -c ID | grep -i atomic | cut -d ' ' -f 1)
    66      fi
    67      cat >> "openrc" <<EOL
    68  export OS_MAGNUM_IMAGE_ID="$_MAGNUM_IMAGE_ID"
    69  export OS_MAGNUM_KEYPAIR=magnum
    70  EOL
    71  fi
    72  
    73  set +u
    74  # shellcheck disable=SC1091
    75  source openrc admin admin
    76  set -u
    77  
    78  popd