Update Openstack, add missed steps to upgrade computes

Additional changes:
 * Refactored switch_to_proposed_pipelines to avoid multiply executions

Change-Id: If9b0c460bdbf41b8248dc3cb5f0d2f486b47e954
diff --git a/tcp_tests/fixtures/reclass_fixtures.py b/tcp_tests/fixtures/reclass_fixtures.py
index a2d84cb..c28de1d 100644
--- a/tcp_tests/fixtures/reclass_fixtures.py
+++ b/tcp_tests/fixtures/reclass_fixtures.py
@@ -6,7 +6,7 @@
 LOG = logger.logger
 
 
-@pytest.fixture(scope='function')
+@pytest.fixture(scope='session')
 def reclass_actions(config, underlay_actions):
     """Fixture that provides various actions for salt
 
diff --git a/tcp_tests/fixtures/salt_fixtures.py b/tcp_tests/fixtures/salt_fixtures.py
index 226ab22..d662180 100644
--- a/tcp_tests/fixtures/salt_fixtures.py
+++ b/tcp_tests/fixtures/salt_fixtures.py
@@ -21,7 +21,7 @@
 LOG = logger.logger
 
 
-@pytest.fixture(scope='function')
+@pytest.fixture(scope='session')
 def salt_actions(config, underlay_actions):
     """Fixture that provides various actions for salt
 
diff --git a/tcp_tests/fixtures/underlay_fixtures.py b/tcp_tests/fixtures/underlay_fixtures.py
index a8856d6..1cfae51 100644
--- a/tcp_tests/fixtures/underlay_fixtures.py
+++ b/tcp_tests/fixtures/underlay_fixtures.py
@@ -158,7 +158,7 @@
     request.addfinalizer(test_fin)
 
 
-@pytest.fixture(scope="function")
+@pytest.fixture(scope="session")
 def underlay_actions(config):
     """Fixture that provides SSH access to underlay objects.
 
diff --git a/tcp_tests/managers/reclass_manager.py b/tcp_tests/managers/reclass_manager.py
index 8448169..f8895c6 100644
--- a/tcp_tests/managers/reclass_manager.py
+++ b/tcp_tests/managers/reclass_manager.py
@@ -11,7 +11,6 @@
 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 #    License for the specific language governing permissions and limitations
 #    under the License.
-
 from tcp_tests import logger
 from tcp_tests.managers.execute_commands import ExecuteCommandsMixin
 
@@ -69,18 +68,40 @@
                 path=short_path
             ))
 
-    def get_key(self, key, short_path):
+    def get_key(self, key, file_name):
         """Find a key in a YAML
 
         :param key: string, parameter to add
-        :param short_path: path to reclass yaml file.
-            It takes into account default path where the reclass is located.
-            May look like cluster/*/cicd/control/leader.yml
+        :param file_name: name of YAML file to find a key
         :return: str, key if found
         """
-        return self.ssh.check_call(
-            "{reclass_tools} get-key {key} /srv/salt/reclass/classes".format(
-                reclass_tools=self.reclass_tools_cmd, key=key))
+        request_key = self.ssh.check_call(
+            "{reclass_tools} get-key {key} /srv/salt/reclass/*/{file_name}".
+            format(reclass_tools=self.reclass_tools_cmd,
+                   key=key,
+                   file_name=file_name))['stdout']
+
+        # Reclass-tools returns result to stdout, so we get it as
+        #     ['\n',
+        #      '---\n',
+        #      '# Found parameters._param.jenkins_pipelines_branch in \
+        #          /srv/salt/reclass/classes/cluster/../infra/init.yml\n',
+        #      'release/proposed/2019.2.0\n',
+        #      '...\n',
+        #      '\n']
+        # So we have no chance to get value without dirty code like `stdout[3]`
+
+        LOG.info("From reclass.get_key {}".format(request_key))
+        if len(request_key) < 4:
+            assert "Can't find {key} in {file_name}. Got stdout {stdout}".\
+                format(
+                    key=key,
+                    file_name=file_name,
+                    stdout=request_key
+                )
+        value = request_key[3].strip('\n')
+        LOG.info("From reclass.get_key {}".format(value))
+        return value
 
     def add_bool_key(self, key, value, short_path):
         """
diff --git a/tcp_tests/tests/system/test_mcp_update.py b/tcp_tests/tests/system/test_mcp_update.py
index 4a1cfa2..5078439 100644
--- a/tcp_tests/tests/system/test_mcp_update.py
+++ b/tcp_tests/tests/system/test_mcp_update.py
@@ -54,29 +54,49 @@
     return targets
 
 
-@pytest.fixture
+@pytest.fixture(scope='class')
 def switch_to_proposed_pipelines(reclass_actions, salt_actions):
-    reclass_actions.add_key(
-        "parameters._param.jenkins_pipelines_branch",
-        "release/proposed/2019.2.0",
-        "cluster/*/infra/init.yml"
-    )
+    reclass = reclass_actions
+    proposed_repo = "http://mirror.mirantis.com/update/proposed/"
+    repo_param = "parameters._param.linux_system_repo_update_url"
 
-    proposed_branch = "http://mirror.mirantis.com/update/proposed/"
-    url_param = "parameters._param.linux_system_repo_update_url"
-    reclass_actions.add_key(url_param, proposed_branch,
-                            "cluster/*/infra/init.yml")
-    reclass_actions.add_key(url_param, proposed_branch,
-                            "cluster/*/openstack/init.yml")
-    reclass_actions.add_key(url_param, proposed_branch,
-                            "cluster/*/stacklight/init.yml")
-    reclass_actions.add_key(url_param, proposed_branch,
-                            "cluster/*/ceph/init.yml")
+    proposed_pipeline_branch = "release/proposed/2019.2.0"
+    pipeline_branch_param = "parameters._param.jenkins_pipelines_branch"
+    infra_yml = "cluster/*/infra/init.yml"
+
+    LOG.info("Check reclass has release/proposed/2019.2.0 branches")
+    if reclass.get_key(pipeline_branch_param,
+                       infra_yml) == proposed_pipeline_branch \
+            and reclass.get_key(repo_param, infra_yml) == proposed_repo:
+        return True
+
+    LOG.info("Switch to release/proposed/2019.2.0 branches")
+    reclass.add_key(pipeline_branch_param, proposed_pipeline_branch, infra_yml)
+
+    reclass.add_key(repo_param, proposed_repo, infra_yml)
+    reclass.add_key(repo_param, proposed_repo, "cluster/*/openstack/init.yml")
+    reclass.add_key(repo_param, proposed_repo, "cluster/*/stacklight/init.yml")
+    reclass.add_key(repo_param, proposed_repo, "cluster/*/ceph/init.yml")
 
     salt_actions.run_state("*", "saltutil.refresh_pillar")
     salt_actions.enforce_state("I@jenkins:client", "jenkins.client")
 
 
+@pytest.fixture(scope='class')
+def enable_openstack_update(reclass_actions, salt_actions):
+    param = "parameters._param.openstack_upgrade_enabled"
+    context_file = "cluster/*/infra/init.yml"
+
+    LOG.info("Enable openstack_upgrade_enabled in reclass")
+    reclass_actions.add_bool_key(param, "True", context_file)
+    salt_actions.run_state("*", "saltutil.refresh_pillar")
+    yield True
+    LOG.info("Disable openstack_upgrade_enabled in reclass")
+    reclass_actions.add_bool_key(param, "False", context_file)
+    salt_actions.run_state("*", "saltutil.refresh_pillar")
+
+
+@pytest.mark.usefixtures("switch_to_proposed_pipelines")
 class TestUpdateMcpCluster(object):
     """
     Following the steps in
@@ -87,7 +107,7 @@
     @pytest.mark.parametrize("_", [settings.ENV_NAME])
     @pytest.mark.run_mcp_update
     def test_update_drivetrain(self, salt_actions, drivetrain_actions,
-                               show_step, _, switch_to_proposed_pipelines):
+                               show_step, _):
         """Updating DriveTrain component to release/proposed/2019.2.0 version
 
         Scenario:
@@ -144,7 +164,7 @@
         update_drivetrain = dt.start_job_on_cid_jenkins(
             job_name=job_name,
             job_parameters=job_parameters,
-            build_timeout=90*60)
+            build_timeout=90 * 60)
 
         assert update_drivetrain == 'SUCCESS'
 
@@ -193,7 +213,7 @@
             "I@glusterfs:server",
             "glusterd --version|head -n1")[0]
 
-        assert has_only_similar(gluster_server_versions_by_nodes),\
+        assert has_only_similar(gluster_server_versions_by_nodes), \
             gluster_server_versions_by_nodes
 
         # ################ Check GlusterFS version for clients ##############
@@ -266,6 +286,7 @@
         On each OpenStack controller node, modify the neutron.conf file
         Restart the neutron-server service
         """
+
         def comment_line(node, file_name, word):
             """
             Adds '#' before the specific line in specific file
@@ -290,8 +311,8 @@
             :return: None
             """
             salt_actions.cmd_run(node, "echo {line} >> {file}".format(
-                    line=line,
-                    file=file_name))
+                line=line,
+                file=file_name))
 
         neutron_conf = '/etc/neutron/neutron.conf'
         neutron_server = "I@neutron:server"
@@ -302,7 +323,7 @@
 
         # ## Change parameters in neutron.conf'
         comment_line(neutron_server, neutron_conf,
-                     "allow_automatic_l3agent_failover",)
+                     "allow_automatic_l3agent_failover", )
         comment_line(neutron_server, neutron_conf,
                      "allow_automatic_dhcp_failover")
         add_line(neutron_server, neutron_conf,
@@ -427,12 +448,14 @@
         show_step(3)
 
         ceph_version_by_nodes = salt.cmd_run(
-          "I@ceph:* and not I@ceph:monitoring and not I@ceph:backup:server",
-          "ceph version")[0]
+            "I@ceph:* and not I@ceph:monitoring and not I@ceph:backup:server",
+            "ceph version")[0]
 
         assert has_only_similar(ceph_version_by_nodes), ceph_version_by_nodes
 
 
+@pytest.mark.usefixtures("switch_to_proposed_pipelines",
+                         "enable_openstack_update")
 class TestOpenstackUpdate(object):
 
     @pytest.mark.grab_versions
@@ -468,8 +491,7 @@
     @pytest.mark.grab_versions
     @pytest.mark.parametrize('target', get_control_plane_targets())
     @pytest.mark.run_mcp_update
-    def test__update__control_plane(self, drivetrain_actions,
-                                    switch_to_proposed_pipelines, target):
+    def test__update__control_plane(self, drivetrain_actions, target):
         """Start 'Deploy - upgrade control VMs' for specific node
         """
         job_parameters = {
@@ -493,3 +515,16 @@
             job_parameters=job_parameters)
 
         assert upgrade_data_pipeline == 'SUCCESS'
+
+    @pytest.mark.grab_versions
+    @pytest.mark.run_mcp_update
+    def test__update__computes(self, drivetrain_actions):
+        """Start 'Deploy - upgrade computes'
+        """
+        job_parameters = {
+            "INTERACTIVE": False}
+        upgrade_compute_pipeline = drivetrain_actions.start_job_on_cid_jenkins(
+            job_name="deploy-upgrade-compute",
+            job_parameters=job_parameters)
+
+        assert upgrade_compute_pipeline == 'SUCCESS'