Browse code

Add swift user and project in non-default domain

Swift has functional tests that check access controls
between users and projects in differing domains. Those tests
are currently skipped by default since swift tests are
configured to use keystone v2 API. In order for those
tests to pass when using keystone v3 API, a user and
project must be setup in a non-default domain.

This patch creates a domain, and a user and project in
that domain, in support of swift functional tests moving
to using keystone v3 API.

Changes:
lib/swift
- create a new domain, project and user for
swift testing
- add new project and user credentials to swift
test config file
- set correct identity service url in swift test
config file according to kesytone API version

functions-common
- add function get_or_create_domain
- modify get_or_create_user and get_or_create_project
functions to optionally specify a domain

Change-Id: I557de01bf196075f2f3adcdf4dd1b43756d8a0ae

Alistair Coles authored on 2014/10/16 02:57:59
Showing 2 changed files
... ...
@@ -790,38 +790,70 @@ function policy_add {
790 790
     mv ${tmpfile} ${policy_file}
791 791
 }
792 792
 
793
+# Gets or creates a domain
794
+# Usage: get_or_create_domain <name> <description>
795
+function get_or_create_domain {
796
+    local os_url="$KEYSTONE_SERVICE_URI/v3"
797
+    # Gets domain id
798
+    local domain_id=$(
799
+        # Gets domain id
800
+        openstack --os-token=$OS_TOKEN --os-url=$os_url \
801
+            --os-identity-api-version=3 domain show $1 \
802
+            -f value -c id 2>/dev/null ||
803
+        # Creates new domain
804
+        openstack --os-token=$OS_TOKEN --os-url=$os_url \
805
+            --os-identity-api-version=3 domain create $1 \
806
+            --description "$2" \
807
+            -f value -c id
808
+    )
809
+    echo $domain_id
810
+}
811
+
793 812
 # Gets or creates user
794
-# Usage: get_or_create_user <username> <password> <project> [<email>]
813
+# Usage: get_or_create_user <username> <password> <project> [<email> [<domain>]]
795 814
 function get_or_create_user {
796 815
     if [[ ! -z "$4" ]]; then
797 816
         local email="--email=$4"
798 817
     else
799 818
         local email=""
800 819
     fi
820
+    local os_cmd="openstack"
821
+    local domain=""
822
+    if [[ ! -z "$5" ]]; then
823
+        domain="--domain=$5"
824
+        os_cmd="$os_cmd --os-url=$KEYSTONE_SERVICE_URI/v3 --os-identity-api-version=3"
825
+    fi
801 826
     # Gets user id
802 827
     local user_id=$(
803 828
         # Gets user id
804
-        openstack user show $1 -f value -c id 2>/dev/null ||
829
+        $os_cmd user show $1 $domain -f value -c id 2>/dev/null ||
805 830
         # Creates new user
806
-        openstack user create \
831
+        $os_cmd user create \
807 832
             $1 \
808 833
             --password "$2" \
809 834
             --project $3 \
810 835
             $email \
836
+            $domain \
811 837
             -f value -c id
812 838
     )
813 839
     echo $user_id
814 840
 }
815 841
 
816 842
 # Gets or creates project
817
-# Usage: get_or_create_project <name>
843
+# Usage: get_or_create_project <name> [<domain>]
818 844
 function get_or_create_project {
819 845
     # Gets project id
846
+    local os_cmd="openstack"
847
+    local domain=""
848
+    if [[ ! -z "$2" ]]; then
849
+        domain="--domain=$2"
850
+        os_cmd="$os_cmd --os-url=$KEYSTONE_SERVICE_URI/v3 --os-identity-api-version=3"
851
+    fi
820 852
     local project_id=$(
821 853
         # Gets project id
822
-        openstack project show $1 -f value -c id 2>/dev/null ||
854
+        $os_cmd project show $1 $domain -f value -c id 2>/dev/null ||
823 855
         # Creates new project if not exists
824
-        openstack project create $1 -f value -c id
856
+        $os_cmd project create $1 $domain -f value -c id
825 857
     )
826 858
     echo $project_id
827 859
 }
... ...
@@ -468,12 +468,21 @@ EOF
468 468
     iniset ${testfile} func_test username3 swiftusertest3
469 469
     iniset ${testfile} func_test account2 swifttenanttest2
470 470
     iniset ${testfile} func_test username2 swiftusertest2
471
+    iniset ${testfile} func_test account4 swifttenanttest4
472
+    iniset ${testfile} func_test username4 swiftusertest4
473
+    iniset ${testfile} func_test password4 testing4
474
+    iniset ${testfile} func_test domain4 swift_test
471 475
 
472 476
     if is_service_enabled key;then
473 477
         iniuncomment ${testfile} func_test auth_version
478
+        local auth_vers=$(iniget ${testfile} func_test auth_version)
474 479
         iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
475 480
         iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
476
-        iniset ${testfile} func_test auth_prefix /v2.0/
481
+        if [[ $auth_vers == "3" ]]; then
482
+            iniset ${testfile} func_test auth_prefix /v3/
483
+        else
484
+            iniset ${testfile} func_test auth_prefix /v2.0/
485
+        fi
477 486
     fi
478 487
 
479 488
     local swift_log_dir=${SWIFT_DATA_DIR}/logs
... ...
@@ -548,12 +557,13 @@ function create_swift_disk {
548 548
 # since we want to make it compatible with tempauth which use
549 549
 # underscores for separators.
550 550
 
551
-# Tenant               User       Roles
551
+# Tenant             User               Roles          Domain
552 552
 # ------------------------------------------------------------------
553
-# service            swift              service
554
-# swifttenanttest1   swiftusertest1     admin
555
-# swifttenanttest1   swiftusertest3     anotherrole
556
-# swifttenanttest2   swiftusertest2     admin
553
+# service            swift              service        default
554
+# swifttenanttest1   swiftusertest1     admin          default
555
+# swifttenanttest1   swiftusertest3     anotherrole    default
556
+# swifttenanttest2   swiftusertest2     admin          default
557
+# swifttenanttest4   swiftusertest4     admin          swift_test
557 558
 
558 559
 function create_swift_accounts {
559 560
     # Defines specific passwords used by tools/create_userrc.sh
... ...
@@ -562,6 +572,7 @@ function create_swift_accounts {
562 562
     export swiftusertest1_password=testing
563 563
     export swiftusertest2_password=testing2
564 564
     export swiftusertest3_password=testing3
565
+    export swiftusertest4_password=testing4
565 566
 
566 567
     KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
567 568
 
... ...
@@ -603,6 +614,16 @@ function create_swift_accounts {
603 603
         "$swift_tenant_test2" "test2@example.com")
604 604
     die_if_not_set $LINENO swift_user_test2 "Failure creating swift_user_test2"
605 605
     get_or_add_user_role $admin_role $swift_user_test2 $swift_tenant_test2
606
+
607
+    local swift_domain=$(get_or_create_domain swift_test 'Used for swift functional testing')
608
+    die_if_not_set $LINENO swift_domain "Failure creating swift_test domain"
609
+
610
+    local swift_tenant_test4=$(get_or_create_project swifttenanttest4 $swift_domain)
611
+    die_if_not_set $LINENO swift_tenant_test4 "Failure creating swift_tenant_test4"
612
+    local swift_user_test4=$(get_or_create_user swiftusertest4 $swiftusertest4_password \
613
+        $swift_tenant_test4 "test4@example.com" $swift_domain)
614
+    die_if_not_set $LINENO swift_user_test4 "Failure creating swift_user_test4"
615
+    get_or_add_user_role $admin_role $swift_user_test4 $swift_tenant_test4
606 616
 }
607 617
 
608 618
 # init_swift() - Initialize rings