Merge "Added scenario which updates Ceph"
diff --git a/tcp_tests/templates/bm-cicd-pike-ovs-maas/salt.yaml b/tcp_tests/templates/bm-cicd-pike-ovs-maas/salt.yaml
index 4e66daa..706e8ab 100644
--- a/tcp_tests/templates/bm-cicd-pike-ovs-maas/salt.yaml
+++ b/tcp_tests/templates/bm-cicd-pike-ovs-maas/salt.yaml
@@ -3,6 +3,7 @@
 {% set DOMAIN_NAME='bm-cicd-pike-ovs-maas.local' %}
 
 {% import 'shared-salt.yaml' as SHARED with context %}
+{% import 'shared-test-tools.yaml' as SHARED_TEST_TOOLS with context %}
 
 - description: Wait for salt-master is ready after configdrive user-data
   cmd: |
@@ -76,3 +77,5 @@
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 6, delay: 5}
   skip_fail: false
+
+{{SHARED_TEST_TOOLS.MACRO_INSTALL_RECLASS_TOOLS()}}
\ No newline at end of file
diff --git a/tcp_tests/templates/bm-cicd-queens-ovs-maas/salt.yaml b/tcp_tests/templates/bm-cicd-queens-ovs-maas/salt.yaml
index 5f7d480..3d1dbfe 100644
--- a/tcp_tests/templates/bm-cicd-queens-ovs-maas/salt.yaml
+++ b/tcp_tests/templates/bm-cicd-queens-ovs-maas/salt.yaml
@@ -3,6 +3,7 @@
 {% set DOMAIN_NAME='bm-cicd-queens-ovs-maas.local' %}
 
 {% import 'shared-salt.yaml' as SHARED with context %}
+{% import 'shared-test-tools.yaml' as SHARED_TEST_TOOLS with context %}
 
 - description: Wait for salt-master is ready after configdrive user-data
   cmd: |
@@ -76,3 +77,5 @@
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 6, delay: 5}
   skip_fail: false
+
+{{SHARED_TEST_TOOLS.MACRO_INSTALL_RECLASS_TOOLS()}}
\ No newline at end of file
diff --git a/tcp_tests/templates/heat-bm-cicd-pike-contrail-sl/salt.yaml b/tcp_tests/templates/heat-bm-cicd-pike-contrail-sl/salt.yaml
index eb65ef0..f8368a3 100644
--- a/tcp_tests/templates/heat-bm-cicd-pike-contrail-sl/salt.yaml
+++ b/tcp_tests/templates/heat-bm-cicd-pike-contrail-sl/salt.yaml
@@ -5,6 +5,7 @@
 # Other salt model repository parameters see in shared-salt.yaml
 
 {% import 'shared-salt.yaml' as SHARED with context %}
+{% import 'shared-test-tools.yaml' as SHARED_TEST_TOOLS with context %}
 
 - description: Wait for salt-master is ready after configdrive user-data
   cmd: |
@@ -73,3 +74,4 @@
   retry: {count: 6, delay: 5}
   skip_fail: false
 
+{{SHARED_TEST_TOOLS.MACRO_INSTALL_RECLASS_TOOLS()}}
diff --git a/tcp_tests/templates/heat-bm-cicd-queens-contrail-sl/salt.yaml b/tcp_tests/templates/heat-bm-cicd-queens-contrail-sl/salt.yaml
index fa3aa30..0e1931f 100644
--- a/tcp_tests/templates/heat-bm-cicd-queens-contrail-sl/salt.yaml
+++ b/tcp_tests/templates/heat-bm-cicd-queens-contrail-sl/salt.yaml
@@ -5,6 +5,7 @@
 # Other salt model repository parameters see in shared-salt.yaml
 
 {% import 'shared-salt.yaml' as SHARED with context %}
+{% import 'shared-test-tools.yaml' as SHARED_TEST_TOOLS with context %}
 
 - description: Wait for salt-master is ready after configdrive user-data
   cmd: |
@@ -73,3 +74,4 @@
   retry: {count: 6, delay: 5}
   skip_fail: false
 
+{{SHARED_TEST_TOOLS.MACRO_INSTALL_RECLASS_TOOLS()}}
\ No newline at end of file
diff --git a/tcp_tests/tests/system/test_backup_restore_galera.py b/tcp_tests/tests/system/test_backup_restore_galera.py
index 96ea98a..ee4043b 100644
--- a/tcp_tests/tests/system/test_backup_restore_galera.py
+++ b/tcp_tests/tests/system/test_backup_restore_galera.py
@@ -29,7 +29,7 @@
         dt = drivetrain_actions
 
         # ################## Run backup job #########################
-        show_step(2)
+        show_step(1)
         job_name = 'galera_backup_database'
         job_parameters = {
             'ASK_CONFIRMATION': False
@@ -41,7 +41,7 @@
         assert backup_galera_pipeline == 'SUCCESS'
 
         # ######################## Run CPV ###########################
-        show_step(3)
+        show_step(2)
         job_name = 'cvp-sanity'
         job_cvp_sanity_parameters = {
             'EXTRA_PARAMS': '''
@@ -65,7 +65,7 @@
         assert run_cvp_sanity == 'SUCCESS'
 
         # ######################## Run Tempest ###########################
-        show_step(4)
+        show_step(3)
         job_name = 'cvp-tempest'
         job_parameters = {
              'TEMPEST_ENDPOINT_TYPE': 'internalURL'
@@ -76,7 +76,7 @@
 
         assert run_cvp_tempest == 'SUCCESS'
         # ######################## Run Restore ###########################
-        show_step(5)
+        show_step(4)
         job_name = 'galera_verify_restore'
         job_parameters = {
              'RESTORE_TYPE': 'ONLY_RESTORE',
@@ -88,7 +88,7 @@
 
         assert run_galera_verify_restore == 'SUCCESS'
         # ######################## Run CPV ###########################
-        show_step(6)
+        show_step(5)
         job_name = 'cvp-sanity'
         run_cvp_sanity = dt.start_job_on_cid_jenkins(
             job_name=job_name,
@@ -96,7 +96,7 @@
 
         assert run_cvp_sanity == 'SUCCESS'
         # ######################## Run Tempest ###########################
-        show_step(7)
+        show_step(6)
         job_name = 'cvp-tempest'
         job_parameters = {
              'TEMPEST_ENDPOINT_TYPE': 'internalURL'
diff --git a/tcp_tests/tests/system/test_upgrade_pike_queens.py b/tcp_tests/tests/system/test_upgrade_pike_queens.py
new file mode 100644
index 0000000..0f2082c
--- /dev/null
+++ b/tcp_tests/tests/system/test_upgrade_pike_queens.py
@@ -0,0 +1,199 @@
+#    Copyright 2016 Mirantis, Inc.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+import pytest
+import json
+
+from tcp_tests import logger
+
+
+LOG = logger.logger
+
+
+class TestUpdatePikeToQueens(object):
+    """
+    Created by https://mirantis.jira.com/browse/PROD-32683
+    """
+    def execute_pre_post_steps(self, underlay_actions,
+                               cfg_node, verbose, type):
+        ret = underlay_actions.check_call(
+            node_name=cfg_node, verbose=verbose,
+            cmd="salt 'cfg01*' config.get"
+                " orchestration:upgrade:applications --out=json")
+        cfg_nodes_list = json.loads(ret['stdout_str'])
+        services_for_upgrade = []
+        for i in cfg_nodes_list:
+            for j in cfg_nodes_list[i]:
+                services_for_upgrade.append(j)
+        LOG.info(services_for_upgrade)
+        list_nodes = underlay_actions.check_call(
+            node_name=cfg_node, verbose=verbose,
+            cmd="salt-key -l accepted | grep -v cfg01 | "
+                "grep -v Accepted")['stdout_str'].splitlines()
+        LOG.info(list_nodes)
+        for node in list_nodes:
+            salt_pillars = underlay_actions.check_call(
+                node_name=cfg_node, verbose=verbose,
+                cmd="salt {} pillar.items __reclass__:applications"
+                    " --out=json".format(node))
+            node_app_output = json.loads(salt_pillars['stdout_str'])
+            need_output = '__reclass__:applications'
+            LOG.info(node_app_output)
+            if need_output in node_app_output[node]:
+                node_applications = node_app_output[node][need_output]
+                LOG.info(node_applications)
+                for service in services_for_upgrade:
+                    if service in node_applications:
+                        underlay_actions.check_call(
+                            node_name=cfg_node, verbose=verbose,
+                            cmd="salt {} state.apply "
+                                "{}.upgrade.{}".format(node, service, type))
+
+    @pytest.mark.day1_underlay
+    def test_upgrade_pike_queens(self,
+                                 show_step,
+                                 underlay_actions,
+                                 drivetrain_actions,
+                                 reclass_actions,
+                                 salt_actions):
+        """Execute upgrade from Pike to Queens
+
+        Scenario:
+            1. Perform the pre-upgrade activities
+            2. Upgrade control VMs
+            3. Upgrade gatewey nodes
+            4. Upgrade compute nodes
+            5. Perform the post-upgrade activities
+            6. If jobs are passed then start tests with cvp-sanity job
+            7. Run tests with cvp-tempest job
+        """
+        cfg_node = underlay_actions.get_target_node_names(target='cfg')[0]
+        LOG.info('cfg node is {}'.format(cfg_node))
+        verbose = True
+        dt = drivetrain_actions
+        infra_init_yaml = "cluster/*/infra/init.yml"
+        # ########## Perform the pre-upgrade activities ##########
+        show_step(1)
+        LOG.info('Add parameters to {}'.format(infra_init_yaml))
+        reclass_actions.add_bool_key(
+            'parameters._param.openstack_upgrade_enabled',
+            'true',
+            infra_init_yaml)
+        LOG.info('Add openstack_version: queens')
+        reclass_actions.add_key(
+            'parameters._param.openstack_version',
+            'queens',
+            infra_init_yaml)
+        LOG.info('Add openstack_old_version: pike')
+        reclass_actions.add_key(
+            'parameters._param.openstack_old_version',
+            'pike',
+            infra_init_yaml)
+        underlay_actions.check_call(
+            node_name=cfg_node, verbose=verbose,
+            cmd="cd /srv/salt/reclass; git add -u && "
+                "git commit --allow-empty -m 'Cluster model update'")
+        LOG.info('Perform refresh_pillar')
+        salt_actions.run_state("*", "saltutil.refresh_pillar")
+        self.execute_pre_post_steps(underlay_actions, cfg_node,
+                                    verbose, 'pre')
+        LOG.info('Perform refresh_pillar')
+        salt_actions.run_state("*", "saltutil.refresh_pillar")
+        # ########## Upgrade control VMs #########
+        show_step(2)
+        LOG.info('Upgrade control VMs')
+        job_name = 'deploy-upgrade-control'
+        job_parameters = {
+            'INTERACTIVE': False,
+            'OS_DIST_UPGRADE': False,
+            'OS_UPGRADE': False
+        }
+        update_control_vms = dt.start_job_on_cid_jenkins(
+            job_name=job_name,
+            job_parameters=job_parameters)
+        assert update_control_vms == 'SUCCESS'
+        # ########## Upgrade gatewey nodes  ###########
+        show_step(3)
+        LOG.info('Upgrade gateway')
+        job_name = 'deploy-upgrade-ovs-gateway'
+        job_parameters = {
+            'INTERACTIVE': False,
+            'OS_DIST_UPGRADE': False,
+            'OS_UPGRADE': False
+        }
+        update_gateway = dt.start_job_on_cid_jenkins(
+            job_name=job_name,
+            job_parameters=job_parameters)
+        assert update_gateway == 'SUCCESS'
+        # ############ Upgrade compute nodes  ############
+        show_step(4)
+        LOG.info('Upgrade compute nodes')
+        job_name = 'deploy-upgrade-compute'
+        job_parameters = {
+            'INTERACTIVE': False,
+            'OS_DIST_UPGRADE': False,
+            'OS_UPGRADE': False
+        }
+        update_computes = dt.start_job_on_cid_jenkins(
+            job_name=job_name,
+            job_parameters=job_parameters)
+        assert update_computes == 'SUCCESS'
+        # ############ Perform the post-upgrade activities ##########
+        show_step(5)
+        LOG.info('Add parameters._param.openstack_upgrade_enabled false'
+                 'to {}'.format(infra_init_yaml))
+        reclass_actions.add_bool_key(
+            'parameters._param.openstack_upgrade_enabled',
+            'false',
+            infra_init_yaml)
+        underlay_actions.check_call(
+            node_name=cfg_node, verbose=verbose,
+            cmd="cd /srv/salt/reclass; git add -u && "
+                "git commit --allow-empty -m 'Cluster model update'")
+        LOG.info('Perform refresh_pillar')
+        salt_actions.run_state("*", "saltutil.refresh_pillar")
+        self.execute_pre_post_steps(underlay_actions, cfg_node,
+                                    verbose, 'post')
+        LOG.info('Perform refresh_pillar')
+        salt_actions.run_state("*", "saltutil.refresh_pillar")
+        # ######################## Run CPV ##########################
+        show_step(6)
+        job_name = 'cvp-sanity'
+        job_parameters = {
+            'EXTRA_PARAMS': '''
+                envs:
+                  - skipped_packages='{},{},{},{},{},{}'
+                  - skipped_modules='xunitmerge,setuptools'
+                  - skipped_services='docker,containerd'
+                  - ntp_skipped_nodes=''
+                  - tests_set=-k "not {} and not {} and not {}"
+            '''.format('python-setuptools', 'python-pkg-resources',
+                       'xunitmerge', 'python-gnocchiclient',
+                       'python-ujson', 'python-octaviaclient',
+                       'test_ceph_status', 'test_prometheus_alert_count',
+                       'test_uncommited_changes')
+        }
+        run_cvp_sanity = dt.start_job_on_cid_jenkins(
+            job_name=job_name,
+            job_parameters=job_parameters)
+        assert run_cvp_sanity == 'SUCCESS'
+        # ######################## Run Tempest #######################
+        show_step(7)
+        job_name = 'cvp-tempest'
+        job_parameters = {
+             'TEMPEST_ENDPOINT_TYPE': 'internalURL'
+        }
+        run_cvp_tempest = dt.start_job_on_cid_jenkins(
+            job_name=job_name,
+            job_parameters=job_parameters)
+        assert run_cvp_tempest == 'SUCCESS'