vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 1 | # Copyright 2017 Mirantis, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 15 | import pytest |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 16 | |
| 17 | from tcp_tests import logger |
| 18 | from tcp_tests.helpers import ext |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 19 | from tcp_tests.managers import virtlet_manager |
| 20 | |
| 21 | LOG = logger.logger |
| 22 | |
| 23 | |
| 24 | @pytest.fixture(scope='function') |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 25 | def virtlet_actions(config, underlay): |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 26 | """Fixture that provides various actions for Virtlet project |
| 27 | |
| 28 | :param config: fixture provides oslo.config |
| 29 | :param underlay: fixture provides underlay manager |
| 30 | :rtype: VirtletManager |
| 31 | """ |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 32 | return virtlet_manager.VirtletManager(config, underlay) |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 33 | |
| 34 | |
| 35 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.virtlet_deployed) |
| 36 | @pytest.fixture(scope='function') |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 37 | def virtlet_deployed(revert_snapshot, config, hardware, underlay, |
| 38 | k8s_deployed, virtlet_actions): |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 39 | """Fixture to get or install Virtlet project on the environment |
| 40 | |
| 41 | :param revert_snapshot: fixture that reverts snapshot that is specified |
| 42 | in test with @pytest.mark.revert_snapshot(<name>) |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 43 | :param config: fixture provides oslo.config |
| 44 | :param hardware: fixture provides enviromnet manager |
| 45 | :param underlay: fixture provides underlay manager |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 46 | :param k8s_deployed: fixture provides K8SManager instance |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 47 | :param virtlet_actions: fixture provides VirtletManager instance |
| 48 | :rtype: VirtletManager |
| 49 | |
| 50 | If config.virtlet.virtlet_installed is not set, this |
| 51 | fixture assumes that the Virtlet project was not installed, |
| 52 | and do the following: |
| 53 | - install Virtlet project |
| 54 | - make snapshot with name 'virtlet_deployed' |
| 55 | - return VirtletManager |
| 56 | |
| 57 | If config.virtlet.virtlet_installed was set, this fixture assumes that |
| 58 | the Virtlet project was already installed, and do the following: |
| 59 | - return VirtletManager instance |
| 60 | |
| 61 | If you want to revert 'virtlet_deployed' snapshot, please use mark: |
| 62 | @pytest.mark.revert_snapshot("virtlet_deployed") |
| 63 | """ |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 64 | # Deploy Virtlet for Kubernetes |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 65 | if not config.virtlet.virtlet_installed: |
| 66 | steps_path = config.virtlet_deploy.virtlet_steps_path |
| 67 | commands = underlay.read_template(steps_path) |
| 68 | virtlet_actions.install(commands) |
| 69 | hardware.create_snapshot(ext.SNAPSHOT.virtlet_deployed) |
| 70 | |
| 71 | else: |
| 72 | # 1. hardware environment created and powered on |
| 73 | # 2. config.underlay.ssh contains SSH access to provisioned nodes |
| 74 | # (can be passed from external config with TESTS_CONFIGS variable) |
| 75 | # 3. config.tcp.* options contain access credentials to the already |
| 76 | # installed TCP API endpoint |
| 77 | pass |
| 78 | |
| 79 | return virtlet_actions |