forked from azavea/ansible-scala
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_scala.py
93 lines (67 loc) · 2.7 KB
/
test_scala.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import pytest
@pytest.fixture()
def AnsibleDefaults(Ansible):
""" Load default variables into dictionary.
Args:
Ansible - Requires the ansible connection backend.
"""
return Ansible("include_vars", "./defaults/main.yml")["ansible_facts"]
@pytest.fixture()
def AnsibleFacts(Ansible):
""" Load ansible facts into a dictionary.
Args:
Ansible - Requires ansible connection backend.
"""
return Ansible("setup")["ansible_facts"]
def test_java_exists(AnsibleFacts, Package):
""" Ensure that the proper java version has been installed
Args:
AnsibleFacts - Dictionary of Ansible facts.
Package - Module that gives information about package install status
and version.
Raises:
AssertionError if the wrong java version is installed.
"""
# Ubuntu 16.04 and above only support openjdk 8
os_version = AnsibleFacts["ansible_distribution_version"]
if float(os_version) >= 16.04:
java_major_version = "8"
else:
java_major_version = "7"
assert Package("openjdk-{}-jdk".format(java_major_version)).is_installed
def test_scala_exists(Command):
""" Attempt to run the scala binary to ensure it exists.
Args:
Command - module to run commands in a remote shell.
Raises:
AssertionError if the command's return code is not zero.
"""
Command.run_test(
"scala -e \"println(util.Properties.versionNumberString)\"")
def test_scala_version(Command, AnsibleDefaults):
""" Check that Ansible installed the proper version of scala
Args:
Command - module to run commands in a remote shell.
AnsibleDefaults - Dictionary of default ansible variable values.
Raises:
AssertionError if the command's return code is not zero.
"""
# Extract target scala version from ansible facts
target_scala_version = AnsibleDefaults["scala_version"]
# Ensure that the running version of scala is the target version
Command.run_test(
"scala -e \"println(util.Properties.versionNumberString)\" |"
" grep {}".format(target_scala_version))
def test_sbt(Package, AnsibleDefaults):
""" Check to see if the proper version of SBT is installed.
Args:
Package: module that verifies package install and version
AnsibleDefaults - Dictionary of default ansible variable values.
Raises:
AssertionError if the proper version of SBT isn't installed, or SBT
is installed at the wrong version.
"""
target_sbt_version = AnsibleDefaults["scala_sbt_version"]
installed_version = Package("sbt").version
assert Package("sbt").is_installed
assert installed_version.startswith(target_sbt_version)