45407db83f27c159cd0102b9f74ec45236e881e2
[osm/SO.git] / rwlaunchpad / ra / pytest / ns / pingpong / test_mro_pingpong.py
1 #!/usr/bin/env python3
2 """
3 #
4 # Copyright 2017 RIFT.IO Inc
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18
19 @file test_mro_pingpong.py
20 @author Paul Laidler (Paul.Laidler@riftio.com)
21 @date 06/21/2017
22 @brief Multi-RO test that instantiates two ping pong instances on seperate ROs
23 """
24
25 import gi
26 import logging
27 import os
28 import pytest
29 import random
30 import re
31 import subprocess
32 import sys
33 import time
34 import uuid
35
36 from contextlib import contextmanager
37
38 import rift.auto.mano
39 import rift.auto.session
40 import rift.auto.descriptor
41
42 gi.require_version('RwVnfrYang', '1.0')
43 from gi.repository import (
44 NsrYang,
45 RwProjectNsdYang,
46 VnfrYang,
47 RwNsrYang,
48 RwVnfrYang,
49 RwBaseYang,
50 )
51
52 gi.require_version('RwKeyspec', '1.0')
53 from gi.repository.RwKeyspec import quoted_key
54
55 logging.basicConfig(level=logging.DEBUG)
56 logger = logging.getLogger(__name__)
57
58 @pytest.mark.setup('pingpong')
59 @pytest.mark.depends('launchpad')
60 @pytest.mark.incremental
61 class TestSetupPingpong(object):
62 def test_onboard(self, mgmt_session, descriptors):
63 for descriptor in descriptors:
64 rift.auto.descriptor.onboard(mgmt_session, descriptor)
65
66 def test_instantiate(self, mgmt_session, ro_account_info):
67 catalog = mgmt_session.proxy(RwProjectNsdYang).get_config("/rw-project:project[rw-project:name='default']/nsd-catalog")
68 nsd = catalog.nsd[0]
69 instance_id = 0
70 for resource_orchestrator, account_info in ro_account_info.items():
71 for datacenter in account_info['datacenters']:
72 nsr = rift.auto.descriptor.create_nsr(
73 datacenter,
74 "pingpong_{}".format(instance_id),
75 nsd,
76 resource_orchestrator=resource_orchestrator
77 )
78 mgmt_session.proxy(RwNsrYang).create_config("/rw-project:project[rw-project:name='default']/ns-instance-config/nsr", nsr)
79 instance_id += 1
80
81
82 @pytest.mark.depends('pingpong')
83 @pytest.mark.incremental
84 class TestPingpong:
85 def test_service_started(self, mgmt_session):
86 nsr_opdata = mgmt_session.proxy(RwNsrYang).get("/rw-project:project[rw-project:name='default']/ns-instance-opdata")
87 nsrs = nsr_opdata.nsr
88
89 for nsr in nsrs:
90 xpath = (
91 "/rw-project:project[rw-project:name='default']/ns-instance-opdata/nsr[ns-instance-config-ref={ns_instance_config_ref}]/operational-status"
92 ).format(
93 ns_instance_config_ref=quoted_key(nsr.ns_instance_config_ref)
94 )
95 mgmt_session.proxy(RwNsrYang).wait_for(xpath, "running", fail_on=['failed'], timeout=300)
96
97 def test_service_configured(self, mgmt_session):
98 nsr_opdata = mgmt_session.proxy(RwNsrYang).get("/rw-project:project[rw-project:name='default']/ns-instance-opdata")
99 nsrs = nsr_opdata.nsr
100
101 for nsr in nsrs:
102 xpath = (
103 "/rw-project:project[rw-project:name='default']/ns-instance-opdata/nsr[ns-instance-config-ref={}]/config-status"
104 ).format(
105 quoted_key(nsr.ns_instance_config_ref)
106 )
107 mgmt_session.proxy(RwNsrYang).wait_for(xpath, "configured", fail_on=['failed'], timeout=300)
108
109 @pytest.mark.depends('pingpong')
110 @pytest.mark.teardown('pingpong')
111 @pytest.mark.incremental
112 class TestTeardownPingpong(object):
113 def test_teardown(self, mgmt_session):
114 ns_instance_config = mgmt_session.proxy(RwNsrYang).get_config("/rw-project:project[rw-project:name='default']/ns-instance-config")
115 for nsr in ns_instance_config.nsr:
116 mgmt_session.proxy(RwNsrYang).delete_config("/rw-project:project[rw-project:name='default']/ns-instance-config/nsr[id={}]".format(quoted_key(nsr.id)))
117
118 time.sleep(60)
119 vnfr_catalog = mgmt_session.proxy(RwVnfrYang).get("/rw-project:project[rw-project:name='default']/vnfr-catalog")
120 assert vnfr_catalog is None or len(vnfr_catalog.vnfr) == 0
121