~juju-qa/juju-ci-tools/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
"""This test will test the juju sla command. Currently, testing budget or
supported sla models requires a functioning omnibus. As such, the current
test merely checks to ensure unsupported models appear as unsupported"""

from __future__ import print_function

import argparse
import logging
import sys

from deploy_stack import (
    BootstrapManager,
)
from jujucharm import (
    local_charm_path,
)
from utility import (
    add_basic_testing_arguments,
    configure_logging,
    JujuAssertionError,
)

__metaclass__ = type


log = logging.getLogger("assess_sla")


def list_sla(client):
    """Return output of the sla command.

    This will return the support level for a model"""
    return client.get_juju_output('sla', include_e=False).strip()


def assert_sla_state(client, expected_state):
    sla_state = list_sla(client)
    if sla_state != expected_state:
        raise JujuAssertionError(
            'Found: {}\nExpected: {}'.format(sla_state, expected_state))


def assess_sla(client, series='xenial'):
    client.wait_for_started()
    dummy_source = local_charm_path(charm='dummy-source',
                                    juju_ver=client.version,
                                    series=series)
    client.deploy(charm=dummy_source)
    client.wait_for_workloads()
    # As we are unable to test supported models, for now, we only can assert
    # on the model shows correctly as unsupported
    assert_sla_state(client, 'unsupported')


def parse_args(argv):
    """Parse all arguments."""
    parser = argparse.ArgumentParser(description="Test the juju sla command")
    add_basic_testing_arguments(parser)
    return parser.parse_args(argv)


def main(argv=None):
    args = parse_args(argv)
    configure_logging(args.verbose)
    bs_manager = BootstrapManager.from_args(args)
    with bs_manager.booted_context(args.upload_tools):
        assess_sla(bs_manager.client, args.series)
    return 0


if __name__ == '__main__':
    sys.exit(main())