update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b second try
[osm/SO.git] / rwlaunchpad / ra / pytest / test_start_standby.py
1 """
2 #
3 # Copyright 2016 RIFT.IO Inc
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain 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,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 @file test_start_standby.py
19 @brief This test starts the launchpad on a remote VM
20 """
21 import argparse
22 import sys
23 import time
24 import os
25 import glob
26 import subprocess
27 import shlex
28 import multiprocessing
29
30 import rift.auto.session
31 import rift.vcs.vcs
32
33 def get_manifest_file():
34 artifacts_path = os.environ["RIFT_ARTIFACTS"]
35 manifest_files = glob.glob(artifacts_path + "/manifest*xml")
36 manifest_files.sort(key=lambda x: os.stat(x).st_mtime)
37 return manifest_files[0]
38
39 def copy_manifest_to_remote(remote_ip, manifest_file):
40 print ("Copying manifest file {} to remote".format(manifest_file))
41 cmd = "scp {0} {1}:/tmp/manifest.xml".format(manifest_file, remote_ip)
42 print ("Running command: {}".format(cmd))
43 subprocess.check_call(cmd, shell=True)
44
45
46 def test_start_lp_remote(remote_ip):
47 rift_root = os.environ.get('HOME_RIFT', os.environ.get('RIFT_ROOT'))
48 rift_install = os.environ.get('RIFT_INSTALL')
49
50 copy_manifest_to_remote(remote_ip, get_manifest_file())
51
52 cmd_template = ("ssh_root {remote_ip} -q -o BatchMode=yes -o "
53 " UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -- "
54 " \"rm -rf /tmp/corosync; cd {rift_install}; {rift_root}/rift-shell -- {rift_install}/usr/bin/rwmain -m /tmp/manifest.xml\"").format(
55 remote_ip=remote_ip,
56 rift_root=rift_root,
57 rift_install=rift_install)
58
59 def start_lp(cmd):
60 print ("Running cmd: {}".format(cmd))
61 subprocess.call(shlex.split(cmd))
62
63 print ("Starting launchpad on remote VM: {}".format(cmd_template))
64 p = multiprocessing.Process(target=start_lp, args=(cmd_template,))
65 p.daemon = True
66 p.start()
67 print ("Standby system started")
68 time.sleep(60)
69 pass
70
71
72 if __name__ == "__main__":
73 parser = argparse.ArgumentParser(description='Start standby LP')
74 parser.add_argument("--remote-ip", action="store", dest="remote_ip")
75
76 args = parser.parse_args()
77
78 test_start_lp_remote(args.remote_ip)