| mirabal | 126e787 | 2017-07-06 05:54:49 -0500 | [diff] [blame] | 1 | import pytest |
| 2 | import os |
| 3 | from ...lib.ssh import * |
| 4 | from ...lib.test_utils import * |
| 5 | |
| 6 | |
| 7 | @pytest.fixture(autouse=True) |
| 8 | def pre_launch_openvim_service(): |
| 9 | """ |
| 10 | Fixture to be executed before test |
| 11 | :param request: argument for a fixture... can be a list, dict, etc |
| 12 | :param request: |
| 13 | :return: |
| 14 | """ |
| 15 | service_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'scripts', 'service-openvim') |
| 16 | |
| 17 | execute_local('{} stop'.format(service_path)) |
| 18 | print "launching service openvim" |
| 19 | execute_local('{} start'.format(service_path)) |
| 20 | out = execute_local('{} -h '.format(service_path)) |
| 21 | assert out |
| 22 | |
| 23 | @pytest.fixture() |
| 24 | def pre_create_flavor(request): |
| 25 | """ |
| 26 | Fixture to be executed before test |
| 27 | :param request: argument for a fixture... can be a list, dict, etc |
| 28 | :param request: |
| 29 | :return: |
| 30 | """ |
| 31 | if hasattr(request, 'config'): |
| 32 | config_path = request.config.getoption('config') |
| 33 | config = get_config(config_path) |
| 34 | flavor = config['flavor'] |
| 35 | |
| 36 | openvim_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'openvim') |
| 37 | |
| 38 | flavor_id = execute_local("{} flavor-create {}".format(openvim_path, flavor)) |
| 39 | flavor_id = parse_uuid(flavor_id) |
| 40 | assert flavor_id |
| 41 | os.environ['OPENVIM_TEST_FLAVOR'] = flavor_id |
| 42 | |
| 43 | |
| 44 | @pytest.fixture() |
| 45 | def pre_create_host(request): |
| 46 | """ |
| 47 | Fixture to be executed before test |
| 48 | :param request: argument for a fixture... can be a list, dict, etc |
| 49 | :param request: |
| 50 | :return: |
| 51 | """ |
| 52 | if hasattr(request, 'config'): |
| 53 | config_path = request.config.getoption('config') |
| 54 | config = get_config(config_path) |
| 55 | |
| 56 | if config['create_inf']: |
| 57 | hosts = config['host'] |
| 58 | counter = 0 |
| 59 | for key, value in hosts.iteritems(): |
| 60 | openvim_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'openvim') |
| 61 | |
| 62 | host_id = execute_local("{} host-add {}".format(openvim_path, value)) |
| 63 | host_id = parse_uuid(host_id) |
| 64 | assert host_id |
| 65 | os.environ['OPENVIM_TEST_HOST_' + str(counter)] = host_id |
| 66 | counter += 1 |
| 67 | |
| 68 | |
| 69 | @pytest.fixture() |
| 70 | def pre_create_image(request): |
| 71 | """ |
| 72 | Fixture to be executed before test |
| 73 | :param request: argument for a fixture... can be a list, dict, etc |
| 74 | :param request: |
| 75 | :return: |
| 76 | """ |
| 77 | if hasattr(request, 'config'): |
| 78 | config_path = request.config.getoption('config') |
| 79 | config = get_config(config_path) |
| 80 | img = config['image'] |
| 81 | |
| 82 | openvim_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'openvim') |
| 83 | image_id = execute_local("{} image-create {}".format(openvim_path, img)) |
| 84 | image_id = parse_uuid(image_id) |
| 85 | assert image_id |
| 86 | os.environ['OPENVIM_TEST_IMAGE'] = image_id |
| 87 | |
| 88 | |
| 89 | @pytest.fixture() |
| 90 | def pre_create_image(request): |
| 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 | if hasattr(request, 'config'): |
| 98 | config_path = request.config.getoption('config') |
| 99 | config = get_config(config_path) |
| 100 | img = config['image'] |
| 101 | openvim_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'openvim') |
| 102 | image_id = execute_local("{} image-create {}".format(openvim_path, img)) |
| 103 | image_id = parse_uuid(image_id) |
| 104 | assert image_id |
| 105 | os.environ['OPENVIM_TEST_IMAGE'] = image_id |
| 106 | |
| 107 | |
| 108 | @pytest.fixture() |
| 109 | def pre_create_net(request): |
| 110 | """ |
| 111 | Fixture to be executed before test |
| 112 | :param request: argument for a fixture... can be a list, dict, etc |
| 113 | :return: |
| 114 | """ |
| 115 | if hasattr(request, 'config'): |
| 116 | config_path = request.config.getoption('config') |
| 117 | config = get_config(config_path) |
| 118 | if config['create_inf']: |
| 119 | net_yaml = config['net'] |
| 120 | openvim_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'openvim') |
| 121 | net_id = execute_local("{} net-create {}".format(openvim_path, net_yaml)) |
| 122 | net_id = parse_uuid(net_id) |
| 123 | assert net_id |
| 124 | |
| 125 | vlan = execute_local("{} net-list {} -vvv | grep provider:vlan:".format(openvim_path, net_id)) |
| 126 | vlan = vlan.replace('provider:vlan:','') |
| 127 | vlan = vlan.replace(' ', '') |
| 128 | vlan = vlan.replace('\n', '') |
| 129 | |
| 130 | os.environ['OPENVIM_TEST_MGMT_NET'] = net_id |
| 131 | os.environ['OPENVIM_TEST_MGMT_NET_VLAN'] = vlan |
| 132 | |
| 133 | |
| 134 | @pytest.fixture() |
| 135 | def pre_create_tenant(request): |
| 136 | """ |
| 137 | Fixture to be executed before test |
| 138 | :param request: argument for a fixture... can be a list, dict, etc |
| 139 | :param monkeypatch: |
| 140 | :return: |
| 141 | """ |
| 142 | |
| 143 | if hasattr(request, 'config'): |
| 144 | config_path = request.config.getoption('config') |
| 145 | config = get_config(config_path) |
| 146 | tenant_yaml = config['tenant'] |
| 147 | openvim_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'openvim') |
| 148 | |
| 149 | tenant_id = execute_local("{} tenant-create {}".format(openvim_path, tenant_yaml)) |
| 150 | tenant_id = parse_uuid(tenant_id) |
| 151 | assert tenant_id |
| 152 | os.environ['OPENVIM_TENANT'] = tenant_id |
| 153 | |
| 154 | |
| 155 | @pytest.fixture() |
| 156 | def pre_init_db(request): |
| 157 | """ |
| 158 | Fixture to be executed before test |
| 159 | :param request: argument for a fixture... can be a list, dict, etc |
| 160 | :param request: |
| 161 | :return: |
| 162 | """ |
| 163 | if hasattr(request, 'config'): |
| 164 | config_path = request.config.getoption('config') |
| 165 | config = get_config(config_path) |
| 166 | if config['create_inf']: |
| 167 | init_db_path = os.path.join(os.environ['OPENVIM_ROOT_FOLDER'], 'database_utils', 'init_vim_db.sh') |
| 168 | execute_local('{}'.format(init_db_path)) |