From 14a8b0f931424d42543c100c9deb409eaded86d3 Mon Sep 17 00:00:00 2001
From: Andrey Kurilin <andr.kurilin@gmail.com>
Date: Tue, 14 May 2019 18:06:57 -0700
Subject: [PATCH] Release 1.5.1 with a fix for os deployment create from env

**rally deployment create* --fromenv* creates wrong spec for
rally-openstack<=1.4.0

Closes-Bug: #1829030
Change-Id: I61588eaa070b10b780c92d54d1b9439e8fd3f6b6
---
 CHANGELOG.rst                              | 12 ++++++++
 etc/docker/README.md                       |  8 +++---
 rally/cli/commands/deployment.py           | 16 +++++++++++
 tests/unit/cli/commands/test_deployment.py | 33 +++++++++++++++++++++-
 tests/unit/doc/test_docker_readme.py       |  4 +--
 upper-constraints.txt                      |  1 +
 6 files changed, 67 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index c0d371899..67800f0b2 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -17,6 +17,18 @@ Changelog
 .. Release notes for existing releases are MUTABLE! If there is something that
    was missed or can be improved, feel free to change it!
 
+[1.5.1] - 2019-05-15
+--------------------
+
+Fixed
+~~~~~
+
+**rally deployment create --fromenv** creates wrong spec for
+rally-openstack<=1.4.0 which doesn't pass **rally deployment check**.
+
+`Launchpad-bug #1829030 <https://launchpad.net/bugs/1829030>`_
+
+
 [1.5.0] - 2019-05-08
 --------------------
 
diff --git a/etc/docker/README.md b/etc/docker/README.md
index 026e2db15..10019dcba 100644
--- a/etc/docker/README.md
+++ b/etc/docker/README.md
@@ -17,7 +17,7 @@ additional plugins:
     #   for rally user is used.
     #
     # Tags of the image are the same as releases of xRally/Rally
-    FROM xrally/xrally:1.5.0
+    FROM xrally/xrally:1.5.1
     
     # "rally" user (which is selected by-default) is owner of "/rally" directory,
     #   so there is no need to call chown or switch the user
@@ -39,8 +39,8 @@ details)
 First of all, you need to pull the container. We suggest to use the last
 tagged version:
 
-    # pull the 1.5.0 image (the latest release at the point of writing the note)
-    $ docker pull xrally/xrally:1.5.0
+    # pull the 1.5.1 image (the latest release at the point of writing the note)
+    $ docker pull xrally/xrally:1.5.1
 
 **WARNING: never attach folders and volumes to `/rally` inside the container. It can break everything.**
 
@@ -56,7 +56,7 @@ docker volumes or mount the directory.
 * use docker volumes. It is the easiest way. You just need to do something like:
 
       $ docker volume create --name rally_volume
-      $ docker run -v rally_volume:/home/rally/.rally xrally/xrally:1.5.0 env create --name "foo"
+      $ docker run -v rally_volume:/home/rally/.rally xrally/xrally:1.5.1 env create --name "foo"
 
 
 * mount outer directory inside the container
diff --git a/rally/cli/commands/deployment.py b/rally/cli/commands/deployment.py
index dde68a0c6..be8f163b7 100644
--- a/rally/cli/commands/deployment.py
+++ b/rally/cli/commands/deployment.py
@@ -85,6 +85,22 @@ class DeploymentCommands(object):
         if fromenv:
             result = env_mgr.EnvManager.create_spec_from_sys_environ()
             config = result["spec"]
+            if "existing@openstack" in config:
+                # NOTE(andreykurilin): if we are are here it means that
+                #   rally-openstack package is installed
+                import rally_openstack
+                if rally_openstack.__version_tuple__ <= (1, 4, 0):
+                    print(rally_openstack.__version_tuple__)
+                    if config["existing@openstack"]["https_key"]:
+                        print("WARNING: OS_KEY is ignored due to old version "
+                              "of rally-openstack package.")
+                    # NOTE(andreykurilin): To support rally-openstack <=1.4.0
+                    #   we need to remove https_key, since OpenStackCredentials
+                    #   object doesn't support it.
+                    #   Latest rally-openstack fixed this issue with
+                    #   https://github.com/openstack/rally-openstack/commit/c7483386e6b59474c83e3ecd0c7ee0e77ff50c02
+
+                    config["existing@openstack"].pop("https_key")
         else:
             if not filename:
                 config = {}
diff --git a/tests/unit/cli/commands/test_deployment.py b/tests/unit/cli/commands/test_deployment.py
index 67354aa98..4d05d0449 100755
--- a/tests/unit/cli/commands/test_deployment.py
+++ b/tests/unit/cli/commands/test_deployment.py
@@ -54,13 +54,44 @@ class DeploymentCommandsTestCase(test.TestCase):
 
     @mock.patch("rally.env.env_mgr.EnvManager.create_spec_from_sys_environ",
                 return_value={"spec": {"auth_url": "http://fake"}})
-    def test_createfromenv(self, mock_create_spec_from_sys_environ):
+    def test_create_fromenv(self, mock_create_spec_from_sys_environ):
         self.deployment.create(self.fake_api, "from_env", True)
         self.fake_api.deployment.create.assert_called_once_with(
             config={"auth_url": "http://fake"},
             name="from_env"
         )
 
+    @mock.patch("rally.env.env_mgr.EnvManager.create_spec_from_sys_environ")
+    def test_create_fromenv_openstack(self, mock_create_spec_from_sys_environ):
+
+        mock_create_spec_from_sys_environ.side_effect = lambda: {
+            "spec": {
+                "existing@openstack": {
+                    "https_key": "some key",
+                    "another_key": "another"
+                }
+            }
+        }
+        mock_rally_os = mock.Mock()
+        mock_rally_os.__version_tuple__ = (1, 4, 0)
+
+        with mock.patch.dict("sys.modules",
+                             {"rally_openstack": mock_rally_os}):
+            self.deployment.create(self.fake_api, "from_env", True)
+            self.fake_api.deployment.create.assert_called_once_with(
+                config={"existing@openstack": {"another_key": "another"}},
+                name="from_env"
+            )
+
+            self.fake_api.deployment.create.reset_mock()
+            mock_rally_os.__version_tuple__ = (1, 5, 0)
+            self.deployment.create(self.fake_api, "from_env", True)
+            self.fake_api.deployment.create.assert_called_once_with(
+                config={"existing@openstack": {"another_key": "another",
+                                               "https_key": "some key"}},
+                name="from_env"
+            )
+
     @mock.patch("rally.cli.commands.deployment.DeploymentCommands.list")
     @mock.patch("rally.cli.commands.deployment.DeploymentCommands.use")
     @mock.patch("rally.cli.commands.deployment.open",
diff --git a/tests/unit/doc/test_docker_readme.py b/tests/unit/doc/test_docker_readme.py
index 9c5c5d437..16e50947e 100644
--- a/tests/unit/doc/test_docker_readme.py
+++ b/tests/unit/doc/test_docker_readme.py
@@ -27,7 +27,7 @@ DOCKER_DIR = os.path.join(ROOT_DIR, "etc", "docker")
 
 
 class DockerReadmeTestCase(test.TestCase):
-    RE_RELEASE = re.compile(r"\[(?P<version>[0-9]+\.[0-9]+.[0.9]+)\]")
+    RE_RELEASE = re.compile(r"\[(?P<version>[0-9]+\.[0-9]+.[0-9]+)\]")
 
     def get_rally_releases(self):
         full_path = os.path.join(ROOT_DIR, "CHANGELOG.rst")
@@ -58,7 +58,7 @@ class DockerReadmeTestCase(test.TestCase):
         rally_releases = self.get_rally_releases()
         latest_release = rally_releases[0]
         previous_release = rally_releases[1]
-        print(rally_releases)
+        print("All discovered releases: %s" % ",".join(rally_releases))
 
         found = False
         for i, line in enumerate(readme.split("\n"), 1):
diff --git a/upper-constraints.txt b/upper-constraints.txt
index 73e55bf9b..e04f74055 100644
--- a/upper-constraints.txt
+++ b/upper-constraints.txt
@@ -39,6 +39,7 @@ prettytable==0.7.2
 pyasn1==0.4.2
 pycparser==2.18
 pyinotify==0.9.6
+Pygments==2.3.1;python_version=='3.4'
 PyNaCl==1.2.1
 pyOpenSSL==18.0.0
 pyparsing==2.2.0
-- 
GitLab