1 # Copyright 2017 Sandvine
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
20 from osmclient
.common
import utils
23 class TestClass(object):
25 @pytest.fixture(scope
='function')
26 def cleanup_test_vnf(self
,osm
,request
):
27 vnfd_file_list
= osm
.vnfd_descriptors_list
28 nsd_file_list
= osm
.nsd_descriptors_list
30 # cleanup all ns/packages that might have been left around
33 # first delete all nsd's
34 for file in nsd_file_list
:
36 desc
= osm
.get_api().package
.get_descriptor_type_from_pkg(file)
37 ns_name
=osm
.ns_name_prefix
+nsd_desc
['name']
38 osm
.get_api().ns
.delete(ns_name
)
42 # delete all nsd packages
43 for file in nsd_file_list
:
45 desc
= osm
.get_api().package
.get_descriptor_type_from_pkg(file)
46 osm
.get_api().nsd
.delete(desc
['name'])
50 # delete all vnfd packages
51 for file in vnfd_file_list
:
53 desc
= osm
.get_api().package
.get_descriptor_type_from_pkg(file)
54 osm
.get_api().vnfd
.delete(desc
['name'])
58 request
.addfinalizer(teardown
)
60 def vnf_test(self
,osm
, openstack
, vim
, vnfd_file_list
, nsd_file_list
):
62 for file in vnfd_file_list
:
63 assert not osm
.get_api().package
.upload(file)
64 assert not osm
.get_api().package
.wait_for_upload(file)
65 desc
= osm
.get_api().package
.get_descriptor_type_from_pkg(file)
67 vnfd_descriptors
.append(desc
)
70 for file in nsd_file_list
:
71 assert not osm
.get_api().package
.upload(file)
72 assert not osm
.get_api().package
.wait_for_upload(file)
73 desc
= osm
.get_api().package
.get_descriptor_type_from_pkg(file)
75 nsd_descriptors
.append(desc
)
77 # TODO/HACK: need to figure out why this is necessary.
78 # vnfd/nsd is there (seen on ping_pong), but the ns fails that nsd is not there,
79 # another way to check if the nsd is really ready via API?
82 for nsd_desc
in nsd_descriptors
:
83 ns_name
=osm
.ns_name_prefix
+nsd_desc
['name']
85 assert not osm
.get_api().ns
.create(nsd_desc
['name'],ns_name
,vim
.vim_name
)
87 assert utils
.wait_for_value(lambda: osm
.get_api().ns
.get_field(ns_name
,'operational-status'),result
='init')
89 # make sure ns is running
90 assert utils
.wait_for_value(lambda: osm
.get_api().ns
.get_field(ns_name
,'operational-status'),result
='running',wait_time
=120)
92 assert not osm
.get_api().ns
.delete(ns_name
)
94 assert not osm
.get_api().nsd
.delete(nsd_desc
['name'])
96 for vnfd_desc
in vnfd_descriptors
:
98 assert not osm
.get_api().vnfd
.delete(vnfd_desc
['name'])
100 @pytest.mark
.openstack
102 def test_vnf(self
,osm
, vim
, openstack
, cleanup_test_vnf
):
103 vnfd_file_list
= osm
.vnfd_descriptors_list
104 nsd_file_list
= osm
.nsd_descriptors_list
106 self
.vnf_test(osm
,openstack
, vim
, vnfd_file_list
, nsd_file_list
)