Bootstrap verify performance fix
[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=False, nargs='+',
34                         help="Packages paths to copy")
35     parser.add_argument("-c", "--cancel", help="Cancel installation",
36                         action="store_true")
37     args = parser.parse_args()
38     topology_file = args.topo
39     packages = args.packages
40     install_dir = args.directory
41     cancel_installation = args.cancel
42
43     work_file = open(topology_file)
44     topology = load(work_file.read())['nodes']
45
46     for node in topology:
47         if topology[node]['type'] == "DUT":
48             ssh = SSH()
49             ssh.connect(topology[node])
50
51             if cancel_installation:
52                 ret, _, err = ssh.exec_command("rm -r {}".format(install_dir))
53                 if ret != 0:
54                     print "Cancel unsuccessful:\n{}".format(err)
55                     return ret
56             else:
57                 ret, _, err = ssh.exec_command("mkdir {}".format(install_dir))
58                 if ret != 0:
59                     print "Mkdir unsuccessful:\n{}".format(err)
60                     return ret
61
62                 # Copy packages from local path to installation dir
63                 for deb in packages:
64                     ssh.scp(local_path=deb, remote_path=install_dir)
65
66                 # Installation of VPP deb packages
67                 ret, _, err = ssh.exec_command_sudo(
68                     "dpkg -i {}/*.deb".format(install_dir))
69                 if ret != 0:
70                     print "Installation unsuccessful:\n{}".format(err)
71                     return ret
72
73 if __name__ == "__main__":
74     sys.exit(main())