diff --git a/playbooks/python-tempestconf-tempest-devstack.yaml b/playbooks/python-tempestconf-tempest-devstack.yaml index b81f4bbe..a03dad1c 100644 --- a/playbooks/python-tempestconf-tempest-devstack.yaml +++ b/playbooks/python-tempestconf-tempest-devstack.yaml @@ -24,6 +24,9 @@ - name: ACL devstack files include_role: name: acl-devstack-files + - name: Edit clouds.yaml file + include_role: + name: tempestconf-workaround-auth-url - name: Generate tempest configuration file include_role: name: generate-tempestconf-file diff --git a/playbooks/python-tempestconf-tempest-packstack.yaml b/playbooks/python-tempestconf-tempest-packstack.yaml index 33429683..a9b8bf77 100644 --- a/playbooks/python-tempestconf-tempest-packstack.yaml +++ b/playbooks/python-tempestconf-tempest-packstack.yaml @@ -30,6 +30,12 @@ - name: Prepare keystonerc credentials generated by packstack include_role: name: create-keystonerc-files + - name: Create clouds.yaml file + include_role: + name: create-clouds-yaml-file + vars: + cloudname: "packstack-admin" + source_credentials_commands: "source {{ ansible_user_dir }}/keystonerc_admin" - name: Generate configuration file for python-tempestconf include_role: name: generate-tempestconf-file diff --git a/roles/create-clouds-yaml-file/README.rst b/roles/create-clouds-yaml-file/README.rst new file mode 100644 index 00000000..1b9d34d3 --- /dev/null +++ b/roles/create-clouds-yaml-file/README.rst @@ -0,0 +1,28 @@ +Creates clouds.yaml file + +Source credentials and create a clouds.yaml file. If the clouds.yaml +file in the defined location exists, it will be overwritten. +Note: If there is a file int the location, where clouds_file_path points, called +openstack, it will be removed and directory called openstack will be created. + +**Role Variables** + +.. zuul:rolevar:: clouds_file_path + :type: string + :default: /etc/openstack/clouds.yaml + + A path to the clouds.yaml file. + +.. zuul:rolevar:: source_credentials_commands + :type: string + :default: None + + A file or command to be sourced for obtaining credentials. + +.. zuul:rolevar:: cloudname + :type: string + :default: None + + A cloudname under which will be sourced credentials saved + in clouds.yaml file + diff --git a/roles/create-clouds-yaml-file/defaults/main.yaml b/roles/create-clouds-yaml-file/defaults/main.yaml new file mode 100644 index 00000000..56bd97e5 --- /dev/null +++ b/roles/create-clouds-yaml-file/defaults/main.yaml @@ -0,0 +1 @@ +clouds_file_path: "/etc/openstack/clouds.yaml" diff --git a/roles/create-clouds-yaml-file/tasks/main.yaml b/roles/create-clouds-yaml-file/tasks/main.yaml new file mode 100644 index 00000000..3f1030b8 --- /dev/null +++ b/roles/create-clouds-yaml-file/tasks/main.yaml @@ -0,0 +1,49 @@ + - name: get cloud variables + shell: | + for key in $( set | awk '{FS="="} /^OS_/ {print $1}' ); do unset $key ; done + {{ source_credentials_commands }} + echo -n "{{cloudname}}: \ + {'auth': \ + { 'auth-url': '$OS_AUTH_URL', \ + 'username': '$OS_USERNAME', \ + 'password': '$OS_PASSWORD', \ + $(if [ -n "$OS_USER_DOMAIN_NAME" ]; then echo "'user_domain_name': '${OS_USER_DOMAIN_NAME}',"; fi) \ + $(if [ -n "$OS_PROJECT_DOMAIN_NAME" ]; then echo "'project_domain_name': '${OS_PROJECT_DOMAIN_NAME}',"; fi) \ + 'project-name': '${OS_PROJECT_NAME:-$OS_TENANT_NAME}' \ + } $(if [ -n "$OS_IDENTITY_API_VERSION" ]; then echo ", 'identity_api_version': '${OS_IDENTITY_API_VERSION}'"; fi) }" + register: cloud_details + args: + executable: /bin/bash + + - debug: + msg: "{{ cloud_details }}" + + - name: Remove the file if it exists + become: yes + file: + path: "{{ clouds_file_path | dirname}}" + state: absent + + - name: Create directory for clouds.yaml + become: yes + file: + path: "{{ clouds_file_path | dirname}}" + state: directory + mode: 0755 + + - name: Create clouds.yaml + become: yes + copy: + content: "" + dest: "{{ clouds_file_path }}" + force: yes + mode: 0666 + + - name: Insert cloud parameters + become: yes + lineinfile: + path: "{{ clouds_file_path }}" + line: "{{ item }}" + with_items: + - "{{ cloud_details.stdout|from_yaml|to_nice_yaml(indent=4) }}" + diff --git a/roles/generate-tempestconf-file-cloud/tasks/main.yaml b/roles/generate-tempestconf-file-cloud/tasks/main.yaml index 3596c7e2..eb617a0d 100644 --- a/roles/generate-tempestconf-file-cloud/tasks/main.yaml +++ b/roles/generate-tempestconf-file-cloud/tasks/main.yaml @@ -23,30 +23,6 @@ virtualenv: "{{ virtualenvs.tempestconf }}" chdir: "{{ tempestconf_src_relative_path }}" - - name: Cat clouds.yaml file - shell: | - set -ex - cat /etc/openstack/clouds.yaml - ignore_errors: True - args: - executable: /bin/bash - - - name: "Workaround for AUTH URL in clouds.yaml" - replace: - path: /etc/openstack/clouds.yaml - regexp: "auth_url:.*" - replace: "auth_url: http://{{ ansible_default_ipv4.address }}/identity/v3" - become: true - ignore_errors: True - - - name: Cat edited clouds.yaml file - shell: | - set -ex - cat /etc/openstack/clouds.yaml - ignore_errors: True - args: - executable: /bin/bash - - name: Generate tempest configuration file shell: | set -ex diff --git a/roles/tempestconf-workaround-auth-url/README.rst b/roles/tempestconf-workaround-auth-url/README.rst new file mode 100644 index 00000000..88d4f27b --- /dev/null +++ b/roles/tempestconf-workaround-auth-url/README.rst @@ -0,0 +1,14 @@ +Workaround clouds.yaml file + +Workaround for AUTH URL in clouds.yaml file. +auth_url needs to be edited in devstack environment so that +it contains "/v3" as a suffix. + +**Role Variables** + +.. zuul:rolevar:: clouds_file_path + :type: string + :default: /etc/openstack/clouds.yaml + + A path to the clouds.yaml file. + diff --git a/roles/tempestconf-workaround-auth-url/defaults/main.yaml b/roles/tempestconf-workaround-auth-url/defaults/main.yaml new file mode 100644 index 00000000..56bd97e5 --- /dev/null +++ b/roles/tempestconf-workaround-auth-url/defaults/main.yaml @@ -0,0 +1 @@ +clouds_file_path: "/etc/openstack/clouds.yaml" diff --git a/roles/tempestconf-workaround-auth-url/tasks/main.yaml b/roles/tempestconf-workaround-auth-url/tasks/main.yaml new file mode 100644 index 00000000..580e42d6 --- /dev/null +++ b/roles/tempestconf-workaround-auth-url/tasks/main.yaml @@ -0,0 +1,23 @@ + - name: Cat clouds.yaml file + shell: | + set -ex + cat {{ clouds_file_path }} + ignore_errors: True + args: + executable: /bin/bash + + - name: Workaround for AUTH URL in clouds.yaml + replace: + path: "{{ clouds_file_path }}" + regexp: "auth_url:.*" + replace: "auth_url: http://{{ ansible_default_ipv4.address }}/identity/v3" + become: true + ignore_errors: True + + - name: Cat edited clouds.yaml file + shell: | + set -ex + cat {{ clouds_file_path }} + ignore_errors: True + args: + executable: /bin/bash