Merge lp:~sinzui/juju-ci-tools/check-subet-resources into lp:juju-ci-tools

Proposed by Curtis Hovey
Status: Merged
Merged at revision: 1990
Proposed branch: lp:~sinzui/juju-ci-tools/check-subet-resources
Merge into: lp:juju-ci-tools
Diff against target: 200 lines (+45/-47)
6 files modified
assess_resources.py (+3/-8)
assess_storage.py (+1/-13)
tests/test_assess_resources.py (+2/-2)
tests/test_assess_storage.py (+0/-24)
tests/test_utility.py (+27/-0)
utility.py (+12/-0)
To merge this branch: bzr merge lp:~sinzui/juju-ci-tools/check-subet-resources
Reviewer Review Type Date Requested Status
Juju Release Engineering Pending
Review via email: mp+322294@code.launchpad.net

Description of the change

Check the subset of resource data that is interesting.

The resource tests are failing because Juju 2.2 now includes combinedrevision and combinedorigin keys in the resource data. The first is a time stamp we cannot predict, the second is a value we already test for.

This branch moved assert_dict_is_subset from assess_storage to assess_resources, then replaces the resources checks with the safer function. This also reduced the code we maintain.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'assess_resources.py'
2--- assess_resources.py 2016-10-06 01:28:20 +0000
3+++ assess_resources.py 2017-04-10 14:35:59 +0000
4@@ -16,6 +16,7 @@
5 )
6 from utility import (
7 add_basic_testing_arguments,
8+ assert_dict_is_subset,
9 configure_logging,
10 JujuAssertionError,
11 )
12@@ -51,14 +52,8 @@
13 service_app_id = 'applicationId'
14 expected_values = _resource_info(name, fingerprint,
15 size, service_app_id)
16- if resource['expected'] != expected_values:
17- raise JujuAssertionError(
18- 'Unexpected resource list values: {} Expected: {}'.format(
19- resource['expected'], expected_values))
20- if resource['unit'] != expected_values:
21- raise JujuAssertionError(
22- 'Unexpected unit resource list values: {} Expected: '
23- '{}'.format(resource['unit'], expected_values))
24+ assert_dict_is_subset(expected_values, resource['expected'])
25+ assert_dict_is_subset(expected_values, resource['unit'])
26 break
27 else:
28 raise JujuAssertionError('Resource id not found.')
29
30=== modified file 'assess_storage.py'
31--- assess_storage.py 2017-03-07 19:22:24 +0000
32+++ assess_storage.py 2017-04-10 14:35:59 +0000
33@@ -19,8 +19,8 @@
34 )
35 from utility import (
36 add_basic_testing_arguments,
37+ assert_dict_is_subset,
38 configure_logging,
39- JujuAssertionError,
40 temp_dir,
41 )
42 from jujupy.version_client import ModelClient2_1
43@@ -247,18 +247,6 @@
44 client.wait_for_started()
45
46
47-def assert_dict_is_subset(sub_dict, super_dict):
48- """Assert that every item in the sub_dict is in the super_dict.
49-
50- :raises JujuAssertionError: when sub_dict items are missing.
51- :return: True when when sub_dict is a subset of super_dict
52- """
53- if not all(item in super_dict.items() for item in sub_dict.items()):
54- raise JujuAssertionError(
55- 'Found: {} \nExpected: {}'.format(super_dict, sub_dict))
56- return True
57-
58-
59 def check_storage_list(client, expected):
60 storage_list_derived = storage_list(client)
61 assert_dict_is_subset(expected, storage_list_derived)
62
63=== modified file 'tests/test_assess_resources.py'
64--- tests/test_assess_resources.py 2017-03-10 16:17:23 +0000
65+++ tests/test_assess_resources.py 2017-04-10 14:35:59 +0000
66@@ -86,14 +86,14 @@
67 status = make_resource_list()
68 status['resources'][0]['expected']['origin'] = 'charmstore'
69 with self.assertRaisesRegexp(
70- JujuAssertionError, 'Unexpected resource list values'):
71+ JujuAssertionError, 'Found:.*\nExpected:'):
72 verify_status(status, 'dummy-resource/foo', 'foo', '1234', 27)
73
74 def test_verify_status_unit_exception(self):
75 status = make_resource_list()
76 status['resources'][0]['unit']['origin'] = 'charmstore'
77 with self.assertRaisesRegexp(
78- JujuAssertionError, 'Unexpected unit resource list values'):
79+ JujuAssertionError, 'Found:.*\nExpected:'):
80 verify_status(status, 'dummy-resource/foo', 'foo', '1234', 27)
81
82 def test_verify_status_no_resoruce_id_exception(self):
83
84=== modified file 'tests/test_assess_storage.py'
85--- tests/test_assess_storage.py 2017-03-07 17:26:23 +0000
86+++ tests/test_assess_storage.py 2017-04-10 14:35:59 +0000
87@@ -8,7 +8,6 @@
88
89 from assess_storage import (
90 AWS_DEFAULT_STORAGE_POOL_DETAILS,
91- assert_dict_is_subset,
92 assess_storage,
93 parse_args,
94 make_expected_disk,
95@@ -30,7 +29,6 @@
96 parse_error,
97 TestCase,
98 )
99-from utility import JujuAssertionError
100
101
102 class TestParseArgs(TestCase):
103@@ -75,28 +73,6 @@
104
105 class TestAssess(TestCase):
106
107- def test_assert_dict_is_subset(self):
108- # Identical dicts.
109- self.assertIsTrue(
110- assert_dict_is_subset(
111- {'a': 1, 'b': 2},
112- {'a': 1, 'b': 2}))
113- # super dict has an extra item.
114- self.assertIsTrue(
115- assert_dict_is_subset(
116- {'a': 1, 'b': 2},
117- {'a': 1, 'b': 2, 'c': 3}))
118- # A key is missing.
119- with self.assertRaises(JujuAssertionError):
120- assert_dict_is_subset(
121- {'a': 1, 'b': 2},
122- {'a': 1, 'c': 2})
123- # A value is different.
124- with self.assertRaises(JujuAssertionError):
125- assert_dict_is_subset(
126- {'a': 1, 'b': 2},
127- {'a': 1, 'b': 4})
128-
129 def test_make_expected_ls(self):
130 client = fake_juju_client()
131 data = make_expected_ls(client, 'data/0', 'foo/0')
132
133=== modified file 'tests/test_utility.py'
134--- tests/test_utility.py 2017-03-01 19:02:24 +0000
135+++ tests/test_utility.py 2017-04-10 14:35:59 +0000
136@@ -28,6 +28,7 @@
137 )
138 from utility import (
139 add_basic_testing_arguments,
140+ assert_dict_is_subset,
141 as_literal_address,
142 extract_deb,
143 _find_candidates,
144@@ -36,6 +37,7 @@
145 get_candidates_path,
146 get_deb_arch,
147 get_winrm_certs,
148+ JujuAssertionError,
149 log_and_wrap_exception,
150 logged_exception,
151 LoggedException,
152@@ -582,3 +584,28 @@
153 mock_logger.info.assert_called_once_with(
154 'Output from exception:\nstdout:\n%s\nstderr:\n%s', 'some output',
155 None)
156+
157+
158+class TestAssertDictIsSubset(TestCase):
159+
160+ def test_assert_dict_is_subset(self):
161+ # Identical dicts.
162+ self.assertIsTrue(
163+ assert_dict_is_subset(
164+ {'a': 1, 'b': 2},
165+ {'a': 1, 'b': 2}))
166+ # super dict has an extra item.
167+ self.assertIsTrue(
168+ assert_dict_is_subset(
169+ {'a': 1, 'b': 2},
170+ {'a': 1, 'b': 2, 'c': 3}))
171+ # A key is missing.
172+ with self.assertRaises(JujuAssertionError):
173+ assert_dict_is_subset(
174+ {'a': 1, 'b': 2},
175+ {'a': 1, 'c': 2})
176+ # A value is different.
177+ with self.assertRaises(JujuAssertionError):
178+ assert_dict_is_subset(
179+ {'a': 1, 'b': 2},
180+ {'a': 1, 'b': 4})
181
182=== modified file 'utility.py'
183--- utility.py 2017-03-01 20:34:01 +0000
184+++ utility.py 2017-04-10 14:35:59 +0000
185@@ -426,3 +426,15 @@
186 yield
187 except (Exception, KeyboardInterrupt) as e:
188 raise log_and_wrap_exception(logger, e)
189+
190+
191+def assert_dict_is_subset(sub_dict, super_dict):
192+ """Assert that every item in the sub_dict is in the super_dict.
193+
194+ :raises JujuAssertionError: when sub_dict items are missing.
195+ :return: True when when sub_dict is a subset of super_dict
196+ """
197+ if not all(item in super_dict.items() for item in sub_dict.items()):
198+ raise JujuAssertionError(
199+ 'Found: {} \nExpected: {}'.format(super_dict, sub_dict))
200+ return True

Subscribers

People subscribed via source and target branches