Added possibility to deploy Drivetrain separately from other services

Change-Id: I0deab9a27fd8fbd3e2c6e4b726a387513f9574c1
diff --git a/tcp_tests/fixtures/drivetrain_fixtures.py b/tcp_tests/fixtures/drivetrain_fixtures.py
new file mode 100644
index 0000000..e0e709b
--- /dev/null
+++ b/tcp_tests/fixtures/drivetrain_fixtures.py
@@ -0,0 +1,81 @@
+#    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
+
+from tcp_tests import logger
+from tcp_tests.helpers import ext
+from tcp_tests.managers import drivetrain_manager
+
+LOG = logger.logger
+
+
+@pytest.fixture(scope='function')
+def drivetrain_actions(config, underlay, salt_actions):
+    """Fixture that provides various actions for Drivetrain
+
+    :param config: fixture provides oslo.config
+    :param underlay: fixture provides underlay manager
+    :rtype: DrivetrainManager
+    """
+    return drivetrain_manager.DrivetrainManager(config, underlay, salt_actions)
+
+
+@pytest.mark.revert_snapshot(ext.SNAPSHOT.drivetrain_deployed)
+@pytest.fixture(scope='function')
+def drivetrain_deployed(revert_snapshot, request, config,
+                        hardware, underlay, salt_deployed,
+                        drivetrain_actions):
+    """Fixture to get or install Drivetrain on the environment
+
+    :param revert_snapshot: fixture that reverts snapshot that is specified
+                            in test with @pytest.mark.revert_snapshot(<name>)
+    :param request: fixture provides pytest data
+    :param config: fixture provides oslo.config
+    :param hardware: fixture provides enviromnet manager
+    :param underlay: fixture provides underlay manager
+    :param drivetrain_actions: fixture provides OSSManager instance
+    :rtype: DrivetrainManager
+
+    If config.drivetrain.drivetrain_installed is not set, this
+    fixture assumes that the Drivetrain were not installed
+    , and do the following:
+    - install Drivetrain
+    - make snapshot with name 'drivetrain_deployed'
+    - return DrivetrainManager
+
+    If config.drivetrain.drivetrain_installed was set, this fixture
+    assumes that the Drivetrain were already installed, and do
+    the following:
+    - return DrivetrainManager instance
+
+    If you want to revert 'drivetrain_deployed' snapshot, please use mark:
+    @pytest.mark.revert_snapshot("drivetrain_deployed")
+    """
+    if not config.drivetrain.drivetrain_installed:
+        steps_path = config.drivetrain_deploy.drivetrain_steps_path
+        commands = underlay.read_template(steps_path)
+        drivetrain_actions.install(commands)
+        hardware.create_snapshot(ext.SNAPSHOT.drivetrain_deployed)
+        salt_deployed.sync_time()
+
+    else:
+        # 1. hardware environment created and powered on
+        # 2. config.underlay.ssh contains SSH access to provisioned nodes
+        #    (can be passed from external config with TESTS_CONFIGS variable)
+        # 3. config.tcp.* options contain access credentials to the already
+        #    installed TCP API endpoint
+        pass
+
+    return drivetrain_actions
diff --git a/tcp_tests/helpers/ext.py b/tcp_tests/helpers/ext.py
index 804d110..8dbf832 100644
--- a/tcp_tests/helpers/ext.py
+++ b/tcp_tests/helpers/ext.py
@@ -45,6 +45,7 @@
     'salt_deployed',
     'common_services_deployed',
     'oss_deployed',
+    'drivetrain_deployed'
     'openstack_deployed',
     'sl_deployed',
     'virtlet_deployed',
diff --git a/tcp_tests/managers/drivetrain_manager.py b/tcp_tests/managers/drivetrain_manager.py
new file mode 100644
index 0000000..6e2fbda
--- /dev/null
+++ b/tcp_tests/managers/drivetrain_manager.py
@@ -0,0 +1,34 @@
+#    Copyright 2017 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.
+
+from tcp_tests.managers.execute_commands import ExecuteCommandsMixin
+
+
+class DrivetrainManager(ExecuteCommandsMixin):
+    """docstring for DrivetrainManager"""
+
+    __config = None
+    __underlay = None
+
+    def __init__(self, config, underlay, salt=None):
+        self.__config = config
+        self.__underlay = underlay
+        self._salt = salt
+        super(DrivetrainManager, self).__init__(
+            config=config, underlay=underlay)
+
+    def install(self, commands):
+        self.execute_commands(commands,
+                              label='Install Drivetrain Tools')
+        self.__config.drivetrain.drivetrain_installed = True
diff --git a/tcp_tests/settings_oslo.py b/tcp_tests/settings_oslo.py
index ad4cce3..96e5483 100644
--- a/tcp_tests/settings_oslo.py
+++ b/tcp_tests/settings_oslo.py
@@ -42,6 +42,10 @@
     __name__,
     'templates/{0}/oss.yaml'.format(
         settings.LAB_CONFIG_NAME))
+_default_drivetrain_steps = pkg_resources.resource_filename(
+    __name__,
+    'templates/{0}/drivetrain.yaml'.format(
+        settings.LAB_CONFIG_NAME))
 _default_decapod_steps = pkg_resources.resource_filename(
     __name__,
     'templates/{0}/decapod.yaml'.format(
@@ -159,6 +163,17 @@
            help="", default=False),
 ]
 
+drivetrain_deploy_opts = [
+    ct.Cfg('drivetrain_steps_path', ct.String(),
+           help="Path to YAML with steps to deploy Drivetrain",
+           default=_default_drivetrain_steps),
+]
+
+drivetrain_opts = [
+    ct.Cfg('drivetrain_installed', ct.Boolean(),
+           help="", default=False),
+]
+
 decapod_deploy_opts = [
     ct.Cfg('decapod_steps_path', ct.String(),
            help="Path to YAML with steps to deploy Ceph with Decapod",
@@ -332,6 +347,8 @@
     ('common_services', common_services_opts),
     ('oss_deploy', oss_deploy_opts),
     ('oss', oss_opts),
+    ('drivetrain_deploy', drivetrain_deploy_opts),
+    ('drivetrain', drivetrain_opts),
     ('decapod_deploy', decapod_deploy_opts),
     ('decapod', decapod_opts),
     ('openstack_deploy', openstack_deploy_opts),
@@ -383,6 +400,15 @@
     config.register_opts(group='oss_deploy',
                          opts=oss_deploy_opts)
 
+    config.register_group(cfg.OptGroup(name='drivetrain',
+                          title="Drivetrain Tools", help=""))
+    config.register_opts(group='drivetrain', opts=drivetrain_opts)
+
+    config.register_group(cfg.OptGroup(name='drivetrain_deploy',
+                          title="Drivetrain deploy config", help=""))
+    config.register_opts(group='drivetrain_deploy',
+                         opts=drivetrain_deploy_opts)
+
     config.register_group(cfg.OptGroup(name='decapod',
                           title="Decapod options for Ceph", help=""))
     config.register_opts(group='decapod', opts=decapod_opts)
diff --git a/tcp_tests/tests/system/conftest.py b/tcp_tests/tests/system/conftest.py
index 64288ab..754e0d7 100644
--- a/tcp_tests/tests/system/conftest.py
+++ b/tcp_tests/tests/system/conftest.py
@@ -25,7 +25,7 @@
 from tcp_tests.fixtures.decapod_fixtures import *  # noqa
 from tcp_tests.fixtures.stacklight_fixtures import *  # noqa
 from tcp_tests.fixtures.k8s_fixtures import *  # noqa
-
+from tcp_tests.fixtures.drivetrain_fixtures import *  # noqa
 
 __all__ = sorted([  # sort for documentation
     # common_fixtures
@@ -53,6 +53,9 @@
     'oss_actions',
     'oss_deployed',
     'oss_sl_os_deployed',
+    # drivetrain_fixtures
+    'drivetrain_actions'
+    'drivetrain_deployed'
     # decapod_fixtures
     'decapod_actions',
     'decapod_deployed',