~nskaggs/juju-ci-tools/add-assess-terms

997.2.2 by Aaron Bentley
convert test-win-client to python.
1
#!/usr/bin/env python
997.2.1 by Aaron Bentley
Convert the majority of test-win-client to Python.
2
from argparse import ArgumentParser
3
import os
1142.1.1 by Aaron Bentley
Enable parallel streams for assess_win_client.
4
import re
997.2.1 by Aaron Bentley
Convert the majority of test-win-client to Python.
5
import subprocess
6
from textwrap import dedent
1142.1.1 by Aaron Bentley
Enable parallel streams for assess_win_client.
7
from utility import s3_cmd
997.2.1 by Aaron Bentley
Convert the majority of test-win-client to Python.
8
import yaml
9
997.2.2 by Aaron Bentley
convert test-win-client to python.
10
1142.1.1 by Aaron Bentley
Enable parallel streams for assess_win_client.
11
def win_test(script_dir, address, juju_home, revision_build):
997.2.1 by Aaron Bentley
Convert the majority of test-win-client to Python.
12
    host = 'Administrator@{}'.format(address)
13
    private_key = os.path.join(juju_home, 'staging-juju-rsa')
1142.1.1 by Aaron Bentley
Enable parallel streams for assess_win_client.
14
    revision_build_url = (
15
        's3://juju-qa-data/juju-ci/products/version-{}'.format(revision_build))
16
    win_client_url = '{}/build-win-client/'.format(revision_build_url)
17
    output = s3_cmd(['ls', '-r', win_client_url])
18
    urls = sorted(l.split()[3] for l in output.splitlines())
19
    installer = [u for u in urls if re.search('juju-setup-.*\.exe', u)][-1]
20
    s3_cmd(['sync', installer, '.'])
21
    install_file = installer.split('/')[-1]
1842.1.1 by Aaron Bentley
Use the existing juju-ci-tools rather than copying some of it.
22
    deploy_job = (
23
        'c:\\\\Users\\\\Administrator\\\\juju-ci-tools\\\\deploy_job.py')
997.2.1 by Aaron Bentley
Convert the majority of test-win-client to Python.
24
    with open('run-file', 'w') as run_file:
25
        run_file.write(dedent("""
26
            ci/$1 /verysilent
27
            juju version
1044.1.1 by Aaron Bentley
Use the deploy_job script everywhere, fix windows weirdness.
28
            juju destroy-environment --force -y win-client-deploy
29
            mkdir logs
1842.1.1 by Aaron Bentley
Use the existing juju-ci-tools rather than copying some of it.
30
            python {deploy_job} parallel-win-client \
1044.1.1 by Aaron Bentley
Use the deploy_job script everywhere, fix windows weirdness.
31
                'c:\\Program Files (x86)\\Juju\\juju.exe' \
1808 by Martin Packman
Add missing --use-charmstore flag to assess_win_client
32
                logs win-client-deploy --series xenial --use-charmstore \
1142.1.1 by Aaron Bentley
Enable parallel streams for assess_win_client.
33
                --agent-stream revision-build-{revision_build}
1842.1.1 by Aaron Bentley
Use the existing juju-ci-tools rather than copying some of it.
34
            """.format(revision_build=revision_build, deploy_job=deploy_job)))
997.2.1 by Aaron Bentley
Convert the majority of test-win-client to Python.
35
1842.1.2 by Aaron Bentley
Removen unneeded parens.
36
    ci = [install_file, 'run-file']
997.2.1 by Aaron Bentley
Convert the majority of test-win-client to Python.
37
    with open('foo.yaml', 'w') as config:
38
        yaml.dump({
39
            'install': {'ci': ci},
40
            'command': ['ci/run-file', install_file],
41
            }, config)
997.2.4 by Aaron Bentley
Use verbose workspace mode.
42
    subprocess.check_call(['workspace-run', '-v', 'foo.yaml', host, '-i',
997.2.1 by Aaron Bentley
Convert the majority of test-win-client to Python.
43
                           private_key])
44
45
997.2.2 by Aaron Bentley
convert test-win-client to python.
46
def main():
47
    parser = ArgumentParser()
48
    parser.add_argument('address',
49
                        help='The IP or DNS address the windows test machine.')
1142.1.1 by Aaron Bentley
Enable parallel streams for assess_win_client.
50
    parser.add_argument('revision_build',
51
                        help='Revision-build to test.')
997.2.2 by Aaron Bentley
convert test-win-client to python.
52
    parser.add_argument(
53
        '--juju-home', default=os.environ.get('JUJU_HOME'),
54
        help='The location of cloud-city and staging-juju-rsa.')
55
    script_dir = os.path.dirname(__file__)
56
    win_test(script_dir=script_dir, **parser.parse_args().__dict__)
57
58
59
if __name__ == '__main__':
60
    main()