Add tag support to boostrap-verify-perf
[csit.git] / resources / tools / topo_installation.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2016 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 """This script provides copy and installation of VPP build deb packages.
17    As destinations are used all DUT nodes from the topology file."""
18
19 import sys
20 import argparse
21 from yaml import load
22
23 from resources.libraries.python.ssh import SSH
24
25 def main():
26     """Copy and installation of VPP packages."""
27
28     parser = argparse.ArgumentParser()
29     parser.add_argument("-t", "--topo", required=True,
30                         help="Topology file")
31     parser.add_argument("-d", "--directory", required=True,
32                         help="Installation directory")
33     parser.add_argument("-p", "--packages", required=True, nargs='+',
34                         help="Packages paths to copy")
35     args = parser.parse_args()
36     topology_file = args.topo
37     packages = args.packages
38     install_dir = args.directory
39
40     work_file = open(topology_file)
41     topology = load(work_file.read())['nodes']
42
43     for node in topology:
44         if topology[node]['type'] == "DUT":
45             ssh = SSH()
46             ssh.connect(topology[node])
47
48             # Copy packages from local path to installation dir
49             for deb in packages:
50                 ssh.scp(local_path=deb, remote_path=install_dir)
51
52             # Installation of VPP deb packages
53             ret, _, err = ssh.exec_command_sudo(
54                 "dpkg -i {}*.deb".format(install_dir))
55             if ret != 0:
56                 print "Installation unsuccessful:\n{}".format(err)
57                 return ret
58
59 if __name__ == "__main__":
60     sys.exit(main())