22
23
log = logging.getLogger("assess_version")
26
class JujuAssertionError(AssertionError):
27
"""Exception for juju assertion failures."""
25
30
def assert_fail(client, charm, ver, cur, name):
27
32
client.deploy(charm, service=name)
40
45
'assert_pass failed min: {} cur: {}'.format(ver, cur))
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')
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)
60
def get_current_version(client, juju_path):
61
current = client.get_version(juju_path=juju_path).split('-')[:-2]
45
62
return '-'.join(current)
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)
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)
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)