2
from __future__ import print_function
12
from deploy_stack import BootstrapManager
14
add_basic_testing_arguments,
23
log = logging.getLogger("assess_version")
26
class JujuAssertionError(AssertionError):
27
"""Exception for juju assertion failures."""
30
def assert_fail(client, charm, ver, cur, name):
32
client.deploy(charm, service=name)
33
except subprocess.CalledProcessError:
35
raise JujuAssertionError(
36
'assert_fail failed min: {} cur: {}'.format(ver, cur))
39
def assert_pass(client, charm, ver, cur, name):
41
client.deploy(charm, service=name)
42
client.wait_for_started()
43
except subprocess.CalledProcessError:
44
raise JujuAssertionError(
45
'assert_pass failed min: {} cur: {}'.format(ver, cur))
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]
62
return '-'.join(current)
65
def assess_deploy(client, assertion, ver, current, name):
66
with temp_dir() as charm_dir:
67
log.info("Testing min version {}".format(ver))
68
make_charm(charm_dir, ver)
69
assertion(client, charm_dir, ver, current, name)
72
def assess_min_version(client, args):
73
current = get_current_version(client, args.juju_bin)
74
tests = [['1.25.0', 'name1250', assert_pass],
75
['99.9.9', 'name9999', assert_fail],
76
['99.9-alpha1', 'name999alpha1', assert_fail],
77
['1.2-beta1', 'name12beta1', assert_pass],
78
['1.25.5.1', 'name12551', assert_pass],
79
['2.0-alpha1', 'name20alpha1', assert_pass],
80
[current, 'current', assert_pass]]
81
for ver, name, assertion in tests:
82
assess_deploy(client, assertion, ver, current, name)
86
"""Parse all arguments."""
87
parser = argparse.ArgumentParser(description="Juju min version")
88
add_basic_testing_arguments(parser)
89
return parser.parse_args(argv)
93
args = parse_args(argv)
94
configure_logging(args.verbose)
95
bs_manager = BootstrapManager.from_args(args)
96
with bs_manager.booted_context(args.upload_tools):
97
assess_min_version(bs_manager.client, args)
101
if __name__ == '__main__':