Merge "Work around version conflicts between Rift and Ubuntu archives"
[osm/devops.git] / systest / testcases / vnfs / test_vnfs.py
1 # Copyright 2017 Sandvine
2 #
3 # All Rights Reserved.
4 #
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
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, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
15 # under the License.
16
17 import pytest
18 import pprint
19 import time
20 from osmclient.common import utils
21
22
23 class TestClass(object):
24
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
29
30 # cleanup all ns/packages that might have been left around
31 def teardown():
32
33 # first delete all nsd's
34 for file in nsd_file_list:
35 try:
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)
39 except:
40 pass
41
42 # delete all nsd packages
43 for file in nsd_file_list:
44 try:
45 desc = osm.get_api().package.get_descriptor_type_from_pkg(file)
46 osm.get_api().nsd.delete(desc['name'])
47 except:
48 pass
49
50 # delete all vnfd packages
51 for file in vnfd_file_list:
52 try:
53 desc = osm.get_api().package.get_descriptor_type_from_pkg(file)
54 osm.get_api().vnfd.delete(desc['name'])
55 except:
56 pass
57
58 request.addfinalizer(teardown)
59
60 def vnf_test(self,osm, openstack, vim, vnfd_file_list, nsd_file_list):
61 vnfd_descriptors=[]
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)
66 assert desc
67 vnfd_descriptors.append(desc)
68
69 nsd_descriptors=[]
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)
74 assert desc
75 nsd_descriptors.append(desc)
76
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?
80 time.sleep(10)
81
82 for nsd_desc in nsd_descriptors:
83 ns_name=osm.ns_name_prefix+nsd_desc['name']
84
85 assert not osm.get_api().ns.create(nsd_desc['name'],ns_name,vim.vim_name)
86
87 assert utils.wait_for_value(lambda: osm.get_api().ns.get_field(ns_name,'operational-status'),result='init')
88
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)
91
92 assert not osm.get_api().ns.delete(ns_name)
93
94 assert not osm.get_api().nsd.delete(nsd_desc['name'])
95
96 for vnfd_desc in vnfd_descriptors:
97
98 assert not osm.get_api().vnfd.delete(vnfd_desc['name'])
99
100 @pytest.mark.openstack
101 @pytest.mark.vnf
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
105
106 self.vnf_test(osm,openstack, vim, vnfd_file_list, nsd_file_list)