|
1
|
+import pytest
|
|
2
|
+
|
|
3
|
+import itertools
|
|
4
|
+import os
|
|
5
|
+
|
|
6
|
+from buildstream import _yaml
|
|
7
|
+from buildstream._exceptions import ErrorDomain, LoadErrorReason
|
|
8
|
+
|
|
9
|
+from tests.testutils.runcli import cli
|
|
10
|
+
|
|
11
|
+DATA_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
12
|
+
|
|
13
|
+# Tests that we get a useful error message when supplying invalid
|
|
14
|
+# remote execution configurations.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+# Assert that if both 'url' (the old style) and 'exec-service' (the new style)
|
|
18
|
+# are used at once, a LoadError results.
|
|
19
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
20
|
+def test_old_and_new_configs(cli, datafiles):
|
|
21
|
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'missing-certs')
|
|
22
|
+
|
|
23
|
+ project_conf = {
|
|
24
|
+ 'name': 'test',
|
|
25
|
+
|
|
26
|
+ 'remote-execution': {
|
|
27
|
+ 'url': 'https://cache.example.com:12345',
|
|
28
|
+ 'exec-service': {
|
|
29
|
+ 'url': 'http://localhost:8088'
|
|
30
|
+ },
|
|
31
|
+ 'storage-service': {
|
|
32
|
+ 'url': 'http://charactron:11001',
|
|
33
|
+ }
|
|
34
|
+ }
|
|
35
|
+ }
|
|
36
|
+ project_conf_file = os.path.join(project, 'project.conf')
|
|
37
|
+ _yaml.dump(project_conf, project_conf_file)
|
|
38
|
+
|
|
39
|
+ # Use `pull` here to ensure we try to initialize the remotes, triggering the error
|
|
40
|
+ #
|
|
41
|
+ # This does not happen for a simple `bst show`.
|
|
42
|
+ result = cli.run(project=project, args=['pull', 'element.bst'])
|
|
43
|
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA, "specify one")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+# Assert that if either the client key or client cert is specified
|
|
47
|
+# without specifying its counterpart, we get a comprehensive LoadError
|
|
48
|
+# instead of an unhandled exception.
|
|
49
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
50
|
+@pytest.mark.parametrize('config_key, config_value', [
|
|
51
|
+ ('client-cert', 'client.crt'),
|
|
52
|
+ ('client-key', 'client.key')
|
|
53
|
+])
|
|
54
|
+def test_missing_certs(cli, datafiles, config_key, config_value):
|
|
55
|
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'missing-certs')
|
|
56
|
+
|
|
57
|
+ project_conf = {
|
|
58
|
+ 'name': 'test',
|
|
59
|
+
|
|
60
|
+ 'remote-execution': {
|
|
61
|
+ 'exec-service': {
|
|
62
|
+ 'url': 'http://localhost:8088'
|
|
63
|
+ },
|
|
64
|
+ 'storage-service': {
|
|
65
|
+ 'url': 'http://charactron:11001',
|
|
66
|
+ config_key: config_value,
|
|
67
|
+ }
|
|
68
|
+ }
|
|
69
|
+ }
|
|
70
|
+ project_conf_file = os.path.join(project, 'project.conf')
|
|
71
|
+ _yaml.dump(project_conf, project_conf_file)
|
|
72
|
+
|
|
73
|
+ # Use `pull` here to ensure we try to initialize the remotes, triggering the error
|
|
74
|
+ #
|
|
75
|
+ # This does not happen for a simple `bst show`.
|
|
76
|
+ result = cli.run(project=project, args=['show', 'element.bst'])
|
|
77
|
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA, "Your config is missing")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+# Assert that if incomplete information is supplied we get a sensible error message.
|
|
81
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
82
|
+def test_empty_config(cli, datafiles):
|
|
83
|
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'missing-certs')
|
|
84
|
+
|
|
85
|
+ project_conf = {
|
|
86
|
+ 'name': 'test',
|
|
87
|
+
|
|
88
|
+ 'remote-execution': {
|
|
89
|
+ }
|
|
90
|
+ }
|
|
91
|
+ project_conf_file = os.path.join(project, 'project.conf')
|
|
92
|
+ _yaml.dump(project_conf, project_conf_file)
|
|
93
|
+
|
|
94
|
+ # Use `pull` here to ensure we try to initialize the remotes, triggering the error
|
|
95
|
+ #
|
|
96
|
+ # This does not happen for a simple `bst show`.
|
|
97
|
+ result = cli.run(project=project, args=['pull', 'element.bst'])
|
|
98
|
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA, "specify one")
|