| mirabal | 126e787 | 2017-07-06 05:54:49 -0500 | [diff] [blame] | 1 | import pytest |
| 2 | import time |
| 3 | from ...lib.test_utils import * |
| 4 | |
| 5 | |
| 6 | @pytest.fixture(autouse=True) |
| 7 | def post_install_service(): |
| 8 | """ |
| 9 | Fixture to be executed before test |
| 10 | :param request: argument for a fixture... can be a list, dict, etc |
| 11 | :param request: |
| 12 | :return: |
| 13 | """ |
| 14 | yield post_install_service |
| 15 | print "Stoping service openvim " |
| 16 | service_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'scripts', 'service-openvim') |
| 17 | execute_local("{} stop".format(service_path)) |
| 18 | |
| 19 | |
| 20 | @pytest.fixture() |
| 21 | def post_delete_server(request): |
| 22 | """ |
| 23 | Fixture to be executed before test |
| 24 | :param request: argument for a fixture... can be a list, dict, etc |
| 25 | :param request: |
| 26 | :return: |
| 27 | """ |
| 28 | |
| 29 | yield post_delete_server |
| 30 | |
| 31 | if hasattr(request, 'config'): |
| 32 | config_path = request.config.getoption('config') |
| 33 | config = get_config(config_path) |
| 34 | |
| 35 | if config['create_inf']: |
| 36 | vm_id = os.environ['OPENVIM_VM'] |
| 37 | openvim_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'openvim') |
| 38 | execute_local("{} vm-delete {}".format(openvim_path, vm_id)) |
| 39 | |
| 40 | |
| 41 | @pytest.fixture() |
| 42 | def post_delete_net(request): |
| 43 | """ |
| 44 | Fixture to be executed before test |
| 45 | :param request: argument for a fixture... can be a list, dict, etc |
| 46 | :param request: |
| 47 | :return: |
| 48 | """ |
| 49 | |
| 50 | yield post_delete_net |
| 51 | |
| 52 | if hasattr(request, 'config'): |
| 53 | config_path = request.config.getoption('config') |
| 54 | config = get_config(config_path) |
| 55 | if config['create_inf']: |
| 56 | net_id = os.environ['OPENVIM_TEST_MGMT_NET'] |
| 57 | openvim_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'openvim') |
| 58 | execute_local("{} net-delete -f {}".format(openvim_path, net_id)) |
| 59 | |
| 60 | |
| 61 | @pytest.fixture() |
| 62 | def post_delete_vm(): |
| 63 | """ |
| 64 | Fixture to be executed after test |
| 65 | :return: |
| 66 | """ |
| 67 | yield post_delete_vm |
| 68 | # destroy vm |
| 69 | openvim_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'openvim') |
| 70 | out = execute_local('{} vm-delete -f'.format(openvim_path)) |
| 71 | |
| 72 | |
| 73 | @pytest.fixture() |
| 74 | def post_delete_flavor(): |
| 75 | """ |
| 76 | Fixture to be executed before test |
| 77 | :param request: argument for a fixture... can be a list, dict, etc |
| 78 | :param request: |
| 79 | :return: |
| 80 | """ |
| 81 | |
| 82 | yield post_delete_flavor |
| 83 | |
| 84 | flavor_id = os.environ['OPENVIM_TEST_FLAVOR'] |
| 85 | openvim_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'openvim') |
| 86 | execute_local("{} flavor-delete -f {}".format(openvim_path, flavor_id)) |
| 87 | |
| 88 | |
| 89 | @pytest.fixture() |
| 90 | def post_delete_image(): |
| 91 | """ |
| 92 | Fixture to be executed before test |
| 93 | :param request: argument for a fixture... can be a list, dict, etc |
| 94 | :param request: |
| 95 | :return: |
| 96 | """ |
| 97 | |
| 98 | yield post_delete_image |
| 99 | |
| 100 | img_id = os.environ['OPENVIM_TEST_IMAGE'] |
| 101 | openvim_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'openvim') |
| 102 | execute_local("{} image-delete -f {}".format(openvim_path, img_id)) |
| 103 | |
| 104 | |
| 105 | @pytest.fixture() |
| 106 | def post_delete_host(request): |
| 107 | """ |
| 108 | Fixture to be executed before test |
| 109 | :param request: argument for a fixture... can be a list, dict, etc |
| 110 | :param request: |
| 111 | :return: |
| 112 | """ |
| 113 | |
| 114 | yield post_delete_host |
| 115 | |
| 116 | if hasattr(request, 'config'): |
| 117 | config_path = request.config.getoption('config') |
| 118 | config = get_config(config_path) |
| 119 | if config['create_inf']: |
| 120 | host_ids = search_host_in_env_var() |
| 121 | for host_ids in host_ids: |
| 122 | openvim_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'openvim') |
| 123 | execute_local("{} host-remove -f {}".format(openvim_path, os.environ[host_ids])) |
| 124 | time.sleep(30) |
| 125 | |
| 126 | |