blob: d24fbffab7a8498feab5b156f216617d33612d24 [file] [log] [blame]
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -04001#!/usr/bin/env python3
2"""
3#
4# Copyright 2016 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_failover.py
20@brief System test of stopping launchpad on master and
21validating configuration on standby
22"""
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040023import argparse
24import gi
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040025import os
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040026import subprocess
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040027import sys
28import time
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040029
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040030from gi.repository import RwProjectVnfdYang
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040031from gi.repository import RwVnfrYang
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040032gi.require_version('RwKeyspec', '1.0')
33from gi.repository.RwKeyspec import quoted_key
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040034
35import rift.auto.proxy
36from rift.auto.session import NetconfSession
37
38def yield_vnfd_vnfr_pairs(proxy, nsr=None):
39 """
40 Yields tuples of vnfd & vnfr entries.
41
42 Args:
43 proxy (callable): Launchpad proxy
44 nsr (optional): If specified, only the vnfr & vnfd records of the NSR
45 are returned
46
47 Yields:
48 Tuple: VNFD and its corresponding VNFR entry
49 """
50 def get_vnfd(vnfd_id):
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040051 xpath = "/rw-project:project[rw-project:name='default']/vnfd-catalog/vnfd[id={}]".format(quoted_key(vnfd_id))
52 return proxy(RwProjectVnfdYang).get(xpath)
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040053
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040054 vnfr = "/rw-project:project[rw-project:name='default']/vnfr-catalog/vnfr"
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040055 print ("START")
56 vnfrs = proxy(RwVnfrYang).get(vnfr, list_obj=True)
57 print ("STOP")
58 for vnfr in vnfrs.vnfr:
59
60 if nsr:
61 const_vnfr_ids = [const_vnfr.vnfr_id for const_vnfr in nsr.constituent_vnfr_ref]
62 if vnfr.id not in const_vnfr_ids:
63 continue
64
Ananda Baitharu2d3f1022016-11-24 05:23:39 -050065 vnfd = get_vnfd(vnfr.vnfd.id)
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040066 yield vnfd, vnfr
67
68def check_configuration_on_standby(standby_ip):
69 print ("Start- check_configuration_on_standby")
70 mgmt_session = NetconfSession(standby_ip)
71 mgmt_session.connect()
72 print ("Connected to proxy")
73
74 vnf_tuple = list(yield_vnfd_vnfr_pairs(mgmt_session.proxy))
75 assert len(vnf_tuple) == 2
76
77if __name__ == "__main__":
78 parser = argparse.ArgumentParser(description='Test launchpad failover')
79 parser.add_argument("--master-ip", action="store", dest="master_ip")
80 parser.add_argument("--standby-ip", action="store", dest="standby_ip")
81
82 args = parser.parse_args()
83
84 # 60 seconds should be more than enough time for Agent to be able
85 # to make confd as the new Master
86 time.sleep(60)
87 print ("Try fetching configuration from the old standby or the new Master\n")
88 check_configuration_on_standby(args.standby_ip)