From 14026861cae3ce164051ac40c49eb73b94d57c6d Mon Sep 17 00:00:00 2001
From: Simon Dodsley <simondodsley@gmail.com>
Date: Thu, 21 Dec 2023 10:42:13 -0500
Subject: [PATCH] Pure Storage - bump version numbers for 2024.1 (Caracal)

Pure uses the version number of the driver to identify which
customers are using which versions of OpenStack.

This will help granular analysis of which driver is being
used in each OpenStack version.

Additionally, change ``user_agent`` string to report
operating system name and version, rather than the kernel
version.

Change-Id: I26e01621d3de5eb4edc647f82f0582a4de6744dc
---
 cinder/tests/unit/volume/drivers/test_pure.py          |  8 ++++----
 cinder/volume/drivers/pure.py                          | 10 +++++-----
 driver-requirements.txt                                |  1 +
 .../notes/pure_version_bump-4877df33faa27efa.yaml      |  5 +++++
 requirements.txt                                       |  1 +
 test-requirements.txt                                  |  1 +
 6 files changed, 17 insertions(+), 9 deletions(-)
 create mode 100644 releasenotes/notes/pure_version_bump-4877df33faa27efa.yaml

diff --git a/cinder/tests/unit/volume/drivers/test_pure.py b/cinder/tests/unit/volume/drivers/test_pure.py
index af73bf46cba..a047513669c 100644
--- a/cinder/tests/unit/volume/drivers/test_pure.py
+++ b/cinder/tests/unit/volume/drivers/test_pure.py
@@ -737,11 +737,11 @@ class PureDriverTestCase(test.TestCase):
                               func, *args, **kwargs)
             mock_func.side_effect = original_side_effect
 
-    @mock.patch('platform.platform')
-    def test_for_user_agent(self, mock_platform):
-        mock_platform.return_value = 'MyFavoritePlatform'
+    @mock.patch('distro.name')
+    def test_for_user_agent(self, mock_distro):
+        mock_distro.return_value = 'MyFavouriteDistro'
         driver = pure.PureBaseVolumeDriver(configuration=self.mock_config)
-        expected_agent = "OpenStack Cinder %s/%s (MyFavoritePlatform)" % (
+        expected_agent = "OpenStack Cinder %s/%s (MyFavouriteDistro)" % (
             driver.__class__.__name__,
             driver.VERSION
         )
diff --git a/cinder/volume/drivers/pure.py b/cinder/volume/drivers/pure.py
index a6998fe917d..23574c3def4 100644
--- a/cinder/volume/drivers/pure.py
+++ b/cinder/volume/drivers/pure.py
@@ -20,10 +20,10 @@ This driver requires Purity version 4.0.0 or later.
 import functools
 import ipaddress
 import math
-import platform
 import re
 import uuid
 
+import distro
 from os_brick import constants as brick_constants
 from oslo_config import cfg
 from oslo_log import log as logging
@@ -257,7 +257,7 @@ class PureBaseVolumeDriver(san.SanDriver):
             'base': USER_AGENT_BASE,
             'class': self.__class__.__name__,
             'version': self.VERSION,
-            'platform': platform.platform()
+            'platform': distro.name(pretty=True)
         }
 
     @classmethod
@@ -2895,7 +2895,7 @@ class PureISCSIDriver(PureBaseVolumeDriver, san.SanISCSIDriver):
     the underlying storage connectivity with the FlashArray.
     """
 
-    VERSION = "17.0.iscsi"
+    VERSION = "18.0.iscsi"
 
     def __init__(self, *args, **kwargs):
         execute = kwargs.pop("execute", utils.execute)
@@ -3120,7 +3120,7 @@ class PureFCDriver(PureBaseVolumeDriver, driver.FibreChannelDriver):
     supports the Cinder Fibre Channel Zone Manager.
     """
 
-    VERSION = "17.0.fc"
+    VERSION = "18.0.fc"
 
     def __init__(self, *args, **kwargs):
         execute = kwargs.pop("execute", utils.execute)
@@ -3318,7 +3318,7 @@ class PureNVMEDriver(PureBaseVolumeDriver, driver.BaseVD):
     FlashArray.
     """
 
-    VERSION = "17.0.nvme"
+    VERSION = "18.0.nvme"
 
     def __init__(self, *args, **kwargs):
         execute = kwargs.pop("execute", utils.execute)
diff --git a/driver-requirements.txt b/driver-requirements.txt
index 2f05bc94e35..8cff370ed5e 100644
--- a/driver-requirements.txt
+++ b/driver-requirements.txt
@@ -11,6 +11,7 @@ krest>=1.3.0 # Apache-2.0
 
 # Pure Storage
 purestorage>=1.17.0 # BSD
+distro # Apache-2.0
 
 # Dell EMC VMAX, IBM DS8K
 pyOpenSSL>=1.0.0 # Apache-2.0
diff --git a/releasenotes/notes/pure_version_bump-4877df33faa27efa.yaml b/releasenotes/notes/pure_version_bump-4877df33faa27efa.yaml
new file mode 100644
index 00000000000..941a3508077
--- /dev/null
+++ b/releasenotes/notes/pure_version_bump-4877df33faa27efa.yaml
@@ -0,0 +1,5 @@
+---
+other:
+  - |
+    [Pure Storage] ``user_agent`` string changed from reporting kernel
+    version to operating system distro and version.
diff --git a/requirements.txt b/requirements.txt
index f0bd467b87c..95bbf3387d0 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -63,3 +63,4 @@ cryptography>=3.1 # BSD/Apache-2.0
 cursive>=0.2.2 # Apache-2.0
 zstd>=1.4.5.1 # BSD
 boto3>=1.18.49 # Apache-2.0
+distro>=1.8.0 # Apache-2.0
diff --git a/test-requirements.txt b/test-requirements.txt
index 31485921405..4d276181cf8 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -20,3 +20,4 @@ testtools>=2.4.0 # MIT
 doc8>=0.8.1 # Apache-2.0
 mypy>=1.2.0 # MIT
 moto>=2.2.5 # Apache-2.0
+distro>=1.8.0 # Apache-2.0