Deprecate authentication variable OS_TENANT_NAME 65/49265/7
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Tue, 19 Dec 2017 09:08:05 +0000 (09:08 +0000)
committerRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Wed, 28 Feb 2018 11:09:31 +0000 (11:09 +0000)
OS_TENANT_NAME was deprecated as authentication variable in Keystone
when moved from v2 to v3, in Icehouse (2014). Because this project doesn't
support oldest versions, by default the only identification API version
supported is v3.

JIRA: YARDSTICK-902

Change-Id: I273fb0151ba583f7c8a5a809e5e8864e92c27d31
Signed-off-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
ansible/roles/convert_openrc/tasks/main.yml
ansible/roles/create_storperf_admin_rc/tasks/main.yml
ansible/roles/create_storperf_admin_rc/templates/storperf_admin-rc.j2
docs/testing/user/userguide/04-installation.rst
docs/testing/user/userguide/05-yardstick_plugin.rst
docs/testing/user/userguide/08-api.rst
gui/app/scripts/controllers/main.js
tests/ci/prepare_storperf_admin-rc.sh
yardstick/benchmark/scenarios/networking/sfc_openstack.py
yardstick/common/openstack_utils.py

index 1606b0b..be621f0 100644 (file)
       auth_url: "{{ openrc.OS_AUTH_URL }}"
       password: "{{ openrc.OS_PASSWORD }}"
       username: "{{ openrc.OS_USERNAME }}"
-      project_name: "{{ openrc.OS_PROJECT_NAME }}"
-#      tenant_name: "{{ openrc.OS_TENANT_NAME }}"
+      project_name: "{{ openrc.OS_PROJECT_NAME|default(openrc.OS_TENANT_NAME) }}"
       project_domain_name: "{{ openrc.OS_PROJECT_DOMAIN_NAME }}"
-#      user_domain_name: "{{ openrc.OS_USER_DOMAIN_NAME }}"
-      # BUGS: We need to specify identity_api_version == 3, but we can't do it here
-      # because it is not the write place
-      # we need to set it via OS_IDENTITY_API_VERSION or clouds.yaml
-#      identity_api_version: "{{ openrc.OS_IDENTITY_API_VERSION }}"
 
 - debug: var=os_auth
 
@@ -44,7 +38,7 @@
     clouds:
         demo:
             # must specify API version here
-            identity_api_version: "{{ openrc.OS_IDENTITY_API_VERSION }}"
+            identity_api_version: "{{ openrc.OS_IDENTITY_API_VERSION|default(3) }}"
             auth: "{{ os_auth }}"
 
 - template:
index bd1418e..f63d1d8 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ---
-- name: Fetch TENANT_ID
-  os_project_facts:
-    name: admin
-  environment: "{{ openrc }}"
-
-- name: Fetch TENANT_ID
-  set_fact:
-    os_tenant_id: "{{ openstack_projects[0].id }}"
-
 - name: Create storperf_admin-rc
   template:
     src: storperf_admin-rc.j2
index 410ab24..888e871 100644 (file)
@@ -1,7 +1,5 @@
 OS_AUTH_URL="{{ openrc.OS_AUTH_URL }}"
 OS_USERNAME="{{ openrc.OS_USERNAME|default('admin') }}"
 OS_PASSWORD="{{ openrc.OS_PASSWORD|default('console') }}"
-OS_TENANT_NAME="{{ openrc.OS_TENANT_NAME|default('admin') }}"
 OS_VOLUME_API_VERSION="{{ openrc.OS_VOLUME_API_VERSION|default('2') }}"
-OS_PROJECT_NAME="{{ openrc.OS_PROJECT_NAME|default(openrc.OS_TENANT_NAME) }}"
-OS_TENANT_ID="{{ os_tenant_id }}"
+OS_PROJECT_NAME="{{ openrc.OS_PROJECT_NAME|openrc.OS_TENANT_NAME|default('admin') }}"
index 5bb64e3..cac8146 100644 (file)
@@ -172,13 +172,13 @@ Environment variables in the ``openrc`` file have to include at least::
    OS_AUTH_URL
    OS_USERNAME
    OS_PASSWORD
-   OS_TENANT_NAME
+   OS_PROJECT_NAME
    EXTERNAL_NETWORK
 
 A sample ``openrc`` file may look like this::
 
   export OS_PASSWORD=console
-  export OS_TENANT_NAME=admin
+  export OS_PROJECT_NAME=admin
   export OS_AUTH_URL=http://172.16.1.222:35357/v2.0
   export OS_USERNAME=admin
   export OS_VOLUME_API_VERSION=2
index ec0b49f..679ce79 100644 (file)
@@ -49,7 +49,7 @@ environment and other dependencies:
 3. Make sure Jump Host have access to the OpenStack Controller API.
 4. Make sure Jump Host must have internet connectivity for downloading docker image.
 5. You need to know where to get basic openstack Keystone authorization info, such as
-   OS_PASSWORD, OS_TENANT_NAME, OS_AUTH_URL, OS_USERNAME.
+   OS_PASSWORD, OS_PROJECT_NAME, OS_AUTH_URL, OS_USERNAME.
 6. To run a Storperf container, you need to have OpenStack Controller environment
    variables defined and passed to Storperf container. The best way to do this is to
    put environment variables in a "storperf_admin-rc" file. The storperf_admin-rc
@@ -58,8 +58,6 @@ environment and other dependencies:
 * OS_AUTH_URL
 * OS_USERNAME
 * OS_PASSWORD
-* OS_TENANT_ID
-* OS_TENANT_NAME
 * OS_PROJECT_NAME
 * OS_PROJECT_ID
 * OS_USER_DOMAIN_ID
@@ -76,8 +74,9 @@ test/ci/prepare_storperf_admin-rc.sh
   USERNAME=${OS_USERNAME:-admin}
   PASSWORD=${OS_PASSWORD:-console}
 
+  # OS_TENANT_NAME is still present to keep backward compatibility with legacy
+  # deployments, but should be replaced by OS_PROJECT_NAME.
   TENANT_NAME=${OS_TENANT_NAME:-admin}
-  TENANT_ID=`openstack project show admin|grep '\bid\b' |awk -F '|' '{print $3}'|sed -e 's/^[[:space:]]*//'`
   PROJECT_NAME=${OS_PROJECT_NAME:-$TENANT_NAME}
   PROJECT_ID=`openstack project show admin|grep '\bid\b' |awk -F '|' '{print $3}'|sed -e 's/^[[:space:]]*//'`
   USER_DOMAIN_ID=${OS_USER_DOMAIN_ID:-default}
@@ -90,8 +89,6 @@ test/ci/prepare_storperf_admin-rc.sh
   echo "OS_PASSWORD="$PASSWORD >> ~/storperf_admin-rc
   echo "OS_PROJECT_NAME="$PROJECT_NAME >> ~/storperf_admin-rc
   echo "OS_PROJECT_ID="$PROJECT_ID >> ~/storperf_admin-rc
-  echo "OS_TENANT_NAME="$TENANT_NAME >> ~/storperf_admin-rc
-  echo "OS_TENANT_ID="$TENANT_ID >> ~/storperf_admin-rc
   echo "OS_USER_DOMAIN_ID="$USER_DOMAIN_ID >> ~/storperf_admin-rc
 
 
index ff6e622..92fa408 100644 (file)
@@ -252,7 +252,6 @@ Example::
                 "OS_PASSWORD": "console",
                 "OS_PROJECT_DOMAIN_NAME": "default",
                 "OS_PROJECT_NAME": "admin",
-                "OS_TENANT_NAME": "admin",
                 "OS_USERNAME": "admin",
                 "OS_USER_DOMAIN_NAME": "default"
             },
index ceec83f..dc5c326 100644 (file)
@@ -107,7 +107,7 @@ angular.module('yardStickGui2App')
             $scope.envInfo = [
                 { name: 'OS_USERNAME', value: '' },
                 { name: 'OS_PASSWORD', value: '' },
-                { name: 'OS_TENANT_NAME', value: '' },
+                { name: 'OS_PROJECT_NAME', value: '' },
                 { name: 'EXTERNAL_NETWORK', value: '' }
             ];
 
@@ -298,7 +298,7 @@ angular.module('yardStickGui2App')
                 $scope.envInfo = [
                     { name: 'OS_USERNAME', value: '' },
                     { name: 'OS_PASSWORD', value: '' },
-                    { name: 'OS_TENANT_NAME', value: '' },
+                    { name: 'OS_PROJECT_NAME', value: '' },
                     { name: 'EXTERNAL_NETWORK', value: '' }
                 ];
                 $scope.displayOpenrcFile = null;
index 558375e..ef7c229 100755 (executable)
@@ -15,8 +15,9 @@ AUTH_URL=${OS_AUTH_URL}
 USERNAME=${OS_USERNAME:-admin}
 PASSWORD=${OS_PASSWORD:-console}
 
+# OS_TENANT_NAME is still present to keep backward compatibility with legacy
+# deployments, but should be replaced by OS_PROJECT_NAME.
 TENANT_NAME=${OS_TENANT_NAME:-admin}
-TENANT_ID=`openstack project show admin|grep '\bid\b' |awk -F '|' '{print $3}'|sed -e 's/^[[:space:]]*//'`
 PROJECT_NAME=${OS_PROJECT_NAME:-$TENANT_NAME}
 PROJECT_ID=`openstack project show admin|grep '\bid\b' |awk -F '|' '{print $3}'|sed -e 's/^[[:space:]]*//'`
 
@@ -30,8 +31,6 @@ echo "OS_USERNAME="$USERNAME >> ~/storperf_admin-rc
 echo "OS_PASSWORD="$PASSWORD >> ~/storperf_admin-rc
 echo "OS_PROJECT_NAME="$PROJECT_NAME >> ~/storperf_admin-rc
 echo "OS_PROJECT_ID="$PROJECT_ID >> ~/storperf_admin-rc
-echo "OS_TENANT_NAME="$TENANT_NAME >> ~/storperf_admin-rc
-echo "OS_TENANT_ID="$TENANT_ID >> ~/storperf_admin-rc
 echo "OS_USER_DOMAIN_ID="$USER_DOMAIN_ID >> ~/storperf_admin-rc
 echo "OS_PROJECT_DOMAIN_NAME="$OS_PROJECT_DOMAIN_NAME >> ~/storperf_admin-rc
 echo "OS_USER_DOMAIN_NAME="$OS_USER_DOMAIN_NAME >> ~/storperf_admin-rc
index d5feabb..aaab213 100644 (file)
@@ -34,11 +34,13 @@ def get_credentials(service):  # pragma: no cover
 
     # The most common way to pass these info to the script is to do it through
     # environment variables.
+    # NOTE(ralonsoh): OS_TENANT_NAME is deprecated.
+    project_name = os.environ.get('OS_PROJECT_NAME', 'admin')
     creds.update({
         "username": os.environ.get('OS_USERNAME', "admin"),
         password: os.environ.get("OS_PASSWORD", 'admin'),
         "auth_url": os.environ.get("OS_AUTH_URL"),
-        tenant: os.environ.get("OS_TENANT_NAME", "admin"),
+        tenant: os.environ.get("OS_TENANT_NAME", project_name),
     })
     cacert = os.environ.get("OS_CACERT")
     if cacert is not None:
@@ -59,7 +61,7 @@ def get_instances(nova_client):  # pragma: no cover
     try:
         instances = nova_client.servers.list(search_opts={'all_tenants': 1})
         return instances
-    except Exception as e:
+    except Exception as e:  # pylint: disable=broad-except
         print("Error [get_instances(nova_client)]:", e)
         return None
 
@@ -72,7 +74,7 @@ def get_SFs(nova_client):  # pragma: no cover
             if "sfc_test" not in instance.name:
                 SFs.append(instance)
         return SFs
-    except Exception as e:
+    except Exception as e:  # pylint: disable=broad-except
         print("Error [get_SFs(nova_client)]:", e)
         return None
 
@@ -93,7 +95,7 @@ def create_floating_ips(neutron_client):  # pragma: no cover
             ip_json = neutron_client.create_floatingip({'floatingip': props})
             fip_addr = ip_json['floatingip']['floating_ip_address']
             ips.append(fip_addr)
-    except Exception as e:
+    except Exception as e:  # pylint: disable=broad-except
         print("Error [create_floating_ip(neutron_client)]:", e)
         return None
     return ips
@@ -106,7 +108,7 @@ def floatIPtoSFs(SFs, floatips):  # pragma: no cover
             SF.add_floating_ip(floatips[i])
             i = i + 1
         return True
-    except Exception as e:
+    except Exception as e:  # pylint: disable=broad-except
         print(("Error [add_floating_ip(nova_client, '%s', '%s')]:" %
                (SF, floatips[i]), e))
         return False
@@ -122,7 +124,3 @@ def get_an_IP():  # pragma: no cover
     floatips = create_floating_ips(neutron_client)
     floatIPtoSFs(SFs, floatips)
     return floatips
-
-
-if __name__ == '__main__':  # pragma: no cover
-    get_an_IP()
index 8f666e2..e3f67ba 100644 (file)
@@ -33,38 +33,22 @@ DEFAULT_API_VERSION = '2'
 #   CREDENTIALS
 # *********************************************
 def get_credentials():
-    """Returns a creds dictionary filled with parsed from env"""
-    creds = {}
-
-    keystone_api_version = os.getenv('OS_IDENTITY_API_VERSION')
-
-    if keystone_api_version is None or keystone_api_version == '2':
-        keystone_v3 = False
-        tenant_env = 'OS_TENANT_NAME'
-        tenant = 'tenant_name'
-    else:
-        keystone_v3 = True
-        tenant_env = 'OS_PROJECT_NAME'
-        tenant = 'project_name'
-
-    # The most common way to pass these info to the script is to do it
-    # through environment variables.
-    creds.update({
-        "username": os.environ.get("OS_USERNAME"),
-        "password": os.environ.get("OS_PASSWORD"),
-        "auth_url": os.environ.get("OS_AUTH_URL"),
-        tenant: os.environ.get(tenant_env)
-    })
-
-    if keystone_v3:
-        if os.getenv('OS_USER_DOMAIN_NAME') is not None:
-            creds.update({
-                "user_domain_name": os.getenv('OS_USER_DOMAIN_NAME')
-            })
-        if os.getenv('OS_PROJECT_DOMAIN_NAME') is not None:
-            creds.update({
-                "project_domain_name": os.getenv('OS_PROJECT_DOMAIN_NAME')
-            })
+    """Returns a creds dictionary filled with parsed from env
+
+    Keystone API version used is 3; v2 was deprecated in 2014 (Icehouse). Along
+    with this deprecation, environment variable 'OS_TENANT_NAME' is replaced by
+    'OS_PROJECT_NAME'.
+    """
+    creds = {'username': os.environ.get('OS_USERNAME'),
+             'password': os.environ.get('OS_PASSWORD'),
+             'auth_url': os.environ.get('OS_AUTH_URL'),
+             'project_name': os.environ.get('OS_PROJECT_NAME')
+             }
+
+    if os.getenv('OS_USER_DOMAIN_NAME'):
+        creds['user_domain_name'] = os.getenv('OS_USER_DOMAIN_NAME')
+    if os.getenv('OS_PROJECT_DOMAIN_NAME'):
+        creds['project_domain_name'] = os.getenv('OS_PROJECT_DOMAIN_NAME')
 
     return creds
 
@@ -294,8 +278,7 @@ def create_instance_and_wait_for_active(json_body):    # pragma: no cover
     VM_BOOT_TIMEOUT = 180
     nova_client = get_nova_client()
     instance = create_instance(json_body)
-    count = VM_BOOT_TIMEOUT / SLEEP
-    for _ in range(count, -1, -1):
+    for _ in range(int(VM_BOOT_TIMEOUT / SLEEP)):
         status = get_instance_status(nova_client, instance)
         if status.lower() == "active":
             return instance