~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to assess_min_version.py

  • Committer: Curtis Hovey
  • Date: 2016-04-10 15:23:18 UTC
  • Revision ID: curtis@canonical.com-20160410152318-ntfymsv9eiw63vt2
Addedd daily streams to get_amy.py get_ami.py tests/test_get_ami.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
import argparse
5
5
import logging
 
6
import os
 
7
import sys
6
8
import subprocess
7
 
import sys
8
 
 
9
 
from jujucharm import Charm
 
9
 
 
10
import yaml
 
11
 
10
12
from deploy_stack import BootstrapManager
11
13
from utility import (
12
14
    add_basic_testing_arguments,
13
15
    configure_logging,
14
 
    JujuAssertionError,
15
16
    temp_dir,
16
17
)
17
18
 
22
23
log = logging.getLogger("assess_version")
23
24
 
24
25
 
 
26
class JujuAssertionError(AssertionError):
 
27
    """Exception for juju assertion failures."""
 
28
 
 
29
 
25
30
def assert_fail(client, charm, ver, cur, name):
26
31
    try:
27
32
        client.deploy(charm, service=name)
40
45
            'assert_pass failed min: {} cur: {}'.format(ver, cur))
41
46
 
42
47
 
43
 
def get_current_version(client):
44
 
    current = client.version.split('-')[:-2]
 
48
def make_charm(charm_dir, ver, name='dummy'):
 
49
    metadata = os.path.join(charm_dir, 'metadata.yaml')
 
50
    content = {}
 
51
    content['name'] = name
 
52
    content['min-juju-version'] = ver
 
53
    content['summary'] = 'summary'
 
54
    content['description'] = 'description'
 
55
    content['series'] = ['trusty']
 
56
    with open(metadata, 'w') as f:
 
57
        yaml.dump(content, f, default_flow_style=False)
 
58
 
 
59
 
 
60
def get_current_version(client, juju_path):
 
61
    current = client.get_version(juju_path=juju_path).split('-')[:-2]
45
62
    return '-'.join(current)
46
63
 
47
64
 
48
 
def make_minver_charm(charm_dir, min_ver):
49
 
    charm = Charm('minver',
50
 
                  'Test charm for min-juju-version {}'.format(min_ver))
51
 
    charm.metadata['min-juju-version'] = min_ver
52
 
    charm.to_dir(charm_dir)
53
 
 
54
 
 
55
65
def assess_deploy(client, assertion, ver, current, name):
56
66
    with temp_dir() as charm_dir:
57
67
        log.info("Testing min version {}".format(ver))
58
 
        make_minver_charm(charm_dir, ver)
 
68
        make_charm(charm_dir, ver)
59
69
        assertion(client, charm_dir, ver, current, name)
60
70
 
61
71
 
62
 
def assess_min_version(client):
63
 
    current = get_current_version(client)
 
72
def assess_min_version(client, args):
 
73
    current = get_current_version(client, args.juju_bin)
64
74
    tests = [['1.25.0', 'name1250', assert_pass],
65
75
             ['99.9.9', 'name9999', assert_fail],
66
76
             ['99.9-alpha1', 'name999alpha1', assert_fail],
84
94
    configure_logging(args.verbose)
85
95
    bs_manager = BootstrapManager.from_args(args)
86
96
    with bs_manager.booted_context(args.upload_tools):
87
 
        assess_min_version(bs_manager.client)
 
97
        assess_min_version(bs_manager.client, args)
88
98
    return 0
89
99
 
90
100