blob: a3c565bb9c9f1bb031b028eadad68cbdd35f06f8 [file] [log] [blame]
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -04001
2#
3# Copyright 2016 RIFT.IO Inc
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18import gi
19import shlex
20import pytest
21import os
22import subprocess
23import tempfile
24
25from gi.repository import (
26 NsdYang,
27 NsrYang,
28 RwNsrYang,
29 RwVnfrYang,
30 VnfrYang,
31 VldYang,
32 RwVnfdYang,
33 RwLaunchpadYang,
34 RwBaseYang
35)
36
37@pytest.fixture(scope='session', autouse=True)
38def cloud_account_name(request):
39 '''fixture which returns the name used to identify the cloud account'''
40 return 'cloud-0'
41
42@pytest.fixture(scope='session')
43def launchpad_host(request, confd_host):
44 return confd_host
45
46@pytest.fixture(scope='session')
47def vnfd_proxy(request, mgmt_session):
48 return mgmt_session.proxy(RwVnfdYang)
49
50@pytest.fixture(scope='session')
51def vnfr_proxy(request, mgmt_session):
52 return mgmt_session.proxy(VnfrYang)
53
54@pytest.fixture(scope='session')
55def rwvnfr_proxy(request, mgmt_session):
56 return mgmt_session.proxy(RwVnfrYang)
57
58@pytest.fixture(scope='session')
59def vld_proxy(request, mgmt_session):
60 return mgmt_session.proxy(VldYang)
61
62@pytest.fixture(scope='session')
63def nsd_proxy(request, mgmt_session):
64 return mgmt_session.proxy(NsdYang)
65
66@pytest.fixture(scope='session')
67def nsr_proxy(request, mgmt_session):
68 return mgmt_session.proxy(NsrYang)
69
70@pytest.fixture(scope='session')
71def rwnsr_proxy(request, mgmt_session):
72 return mgmt_session.proxy(RwNsrYang)
73
74@pytest.fixture(scope='session')
75def base_proxy(request, mgmt_session):
76 return mgmt_session.proxy(RwBaseYang)
77
78@pytest.fixture(scope='session')
79def base_proxy(request, mgmt_session):
80 return mgmt_session.proxy(RwBaseYang)
81
82@pytest.fixture(scope='session')
83def mvv_descr_dir(request):
84 """root-directory of descriptors files used for Multi-VM VNF"""
85 return os.path.join(
86 os.environ["RIFT_INSTALL"],
87 "demos/tests/multivm_vnf"
88 )
89
90@pytest.fixture(scope='session')
91def package_dir(request):
92 return tempfile.mkdtemp(prefix="mvv_")
93
94@pytest.fixture(scope='session')
95def trafgen_vnfd_package_file(request, package_gen_script, mvv_descr_dir, package_dir):
96 pkg_cmd = "{pkg_scr} --descriptor-type='vnfd' --format='xml' --infile='{infile}' --outdir='{outdir}'".format(
97 pkg_scr=package_gen_script,
98 outdir=package_dir,
99 infile=os.path.join(mvv_descr_dir, 'vnfd/xml/multivm_trafgen_vnfd.xml'))
100 pkg_file = os.path.join(package_dir, 'multivm_trafgen_vnfd.tar.gz')
101 command = shlex.split(pkg_cmd)
102 print("Running the command arguments: %s" % command)
103 command = [package_gen_script,
104 "--descriptor-type", "vnfd",
105 "--format", "xml",
106 "--infile", "%s" % os.path.join(mvv_descr_dir, 'vnfd/xml/multivm_trafgen_vnfd.xml'),
107 "--outdir", "%s" % package_dir]
108 print("Running new command arguments: %s" % command)
109 subprocess.check_call(command)
110 return pkg_file
111
112@pytest.fixture(scope='session')
113def trafsink_vnfd_package_file(request, package_gen_script, mvv_descr_dir, package_dir):
114 pkg_cmd = "{pkg_scr} --descriptor-type='vnfd' --format='xml' --infile='{infile}' --outdir='{outdir}'".format(
115 pkg_scr=package_gen_script,
116 outdir=package_dir,
117 infile=os.path.join(mvv_descr_dir, 'vnfd/xml/multivm_trafsink_vnfd.xml'))
118 pkg_file = os.path.join(package_dir, 'multivm_trafsink_vnfd.tar.gz')
119 command = shlex.split(pkg_cmd)
120 print("Running the command arguments: %s" % command)
121 command = [package_gen_script,
122 "--descriptor-type", "vnfd",
123 "--format", "xml",
124 "--infile", "%s" % os.path.join(mvv_descr_dir, 'vnfd/xml/multivm_trafsink_vnfd.xml'),
125 "--outdir", "%s" % package_dir]
126 print("Running new command arguments: %s" % command)
127 subprocess.check_call(command)
128 return pkg_file
129
130@pytest.fixture(scope='session')
131def slb_vnfd_package_file(request, package_gen_script, mvv_descr_dir, package_dir):
132 pkg_cmd = "{pkg_scr} --outdir {outdir} --infile {infile} --descriptor-type vnfd --format xml".format(
133 pkg_scr=package_gen_script,
134 outdir=package_dir,
135 infile=os.path.join(mvv_descr_dir, 'vnfd/xml/multivm_slb_vnfd.xml'),
136 )
137 pkg_file = os.path.join(package_dir, 'multivm_slb_vnfd.tar.gz')
138 subprocess.check_call(shlex.split(pkg_cmd))
139 return pkg_file