| |
@@ -234,75 +234,121 @@
|
| |
# messages.
|
| |
self.assertGreaterEqual(log.info.call_count, 2)
|
| |
|
| |
- def test_get_module_config_match_name_stream(self):
|
| |
- configs = [
|
| |
- {'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 10},
|
| |
- {'name': 'testmodule2', 'stream': 'rhel-8.0', 'priority': 20}
|
| |
- ]
|
| |
- message = self.load_json_from_file("testmodule_ready_message.json")
|
| |
- mock_mbs = mock.MagicMock()
|
| |
- fake_requires = {"platform": ["el8"]}
|
| |
- fake_mmd = self.make_mmd("testmodule", "rhel-8.0",
|
| |
- "20180409051516", "9e5fe74b",
|
| |
- requires=fake_requires)
|
| |
- mock_mbs.get_module_mmd.return_value = fake_mmd
|
| |
- modinfo = ModuleInfo.from_mbs_message(mock_mbs, message)
|
| |
- matched_config = AddTagHandler.get_module_config(configs, modinfo)
|
| |
- expected = {'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 10}
|
| |
- self.assertEqual(matched_config, expected)
|
| |
-
|
| |
- def test_get_module_config_match_requires(self):
|
| |
- configs = [
|
| |
- {'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 10,
|
| |
- 'requires': {'platform': 'el8'}},
|
| |
- {'name': 'testmodule2', 'stream': 'rhel-8.0', 'priority': 20}
|
| |
- ]
|
| |
+ def assert_get_module_config(self, fake_configs, expected_result):
|
| |
message_file = "testmodule_with_requires_ready_message.json"
|
| |
message = self.load_json_from_file(message_file)
|
| |
mock_mbs = mock.MagicMock()
|
| |
fake_requires = {"platform": ["el8"]}
|
| |
fake_mmd = self.make_mmd("testmodule", "rhel-8.0",
|
| |
"20180409051516", "9e5fe74b",
|
| |
- requires=fake_requires)
|
| |
- mock_mbs.get_module_mmd.return_value = fake_mmd
|
| |
- modinfo = ModuleInfo.from_mbs_message(mock_mbs, message)
|
| |
- matched_config = AddTagHandler.get_module_config(configs, modinfo)
|
| |
- expected = {'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 10,
|
| |
- 'requires': {'platform': 'el8'}}
|
| |
- self.assertEqual(matched_config, expected)
|
| |
-
|
| |
- def test_get_module_config_unmatch_stream(self):
|
| |
- configs = [
|
| |
- {'name': 'testmodule', 'stream': 'f28', 'priority': 10},
|
| |
- {'name': 'testmodule2', 'stream': 'rhel-8.0', 'priority': 20}
|
| |
- ]
|
| |
- message = self.load_json_from_file("testmodule_ready_message.json")
|
| |
- mock_mbs = mock.MagicMock()
|
| |
- fake_requires = {"platform": ["el8"]}
|
| |
- fake_mmd = self.make_mmd("testmodule", "rhel-8.0",
|
| |
- "20180409051516", "9e5fe74b",
|
| |
- requires=fake_requires)
|
| |
+ requires=fake_requires,
|
| |
+ buildrequires=fake_requires)
|
| |
mock_mbs.get_module_mmd.return_value = fake_mmd
|
| |
modinfo = ModuleInfo.from_mbs_message(mock_mbs, message)
|
| |
- matched_config = AddTagHandler.get_module_config(configs, modinfo)
|
| |
- self.assertEqual(matched_config, None)
|
| |
-
|
| |
- def test_get_module_config_unmatch_requires(self):
|
| |
- configs = [
|
| |
- {'name': 'testmodule', 'stream': 'f28', 'priority': 10,
|
| |
- 'requires': {'platform': 'el8'}},
|
| |
- {'name': 'testmodule2', 'stream': 'rhel-8.0', 'priority': 20}
|
| |
- ]
|
| |
- message = self.load_json_from_file("testmodule_ready_message.json")
|
| |
- mock_mbs = mock.MagicMock()
|
| |
- fake_requires = {"platform": ["el8"]}
|
| |
- fake_mmd = self.make_mmd("testmodule", "rhel-8.0",
|
| |
- "20180409051516", "9e5fe74b",
|
| |
- requires=fake_requires)
|
| |
- mock_mbs.get_module_mmd.return_value = fake_mmd
|
| |
- modinfo = ModuleInfo.from_mbs_message(mock_mbs, message)
|
| |
- matched_config = AddTagHandler.get_module_config(configs, modinfo)
|
| |
- self.assertEqual(matched_config, None)
|
| |
+ matched_config = AddTagHandler.get_module_config(fake_configs, modinfo)
|
| |
+ self.assertEqual(matched_config, expected_result)
|
| |
+
|
| |
+ def test_get_module_config_match_requires(self):
|
| |
+ # ((fake_module_configs, expected result), ...)
|
| |
+ test_matrix = (
|
| |
+ (
|
| |
+ [
|
| |
+ {
|
| |
+ 'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 10,
|
| |
+ 'requires': {'platform': 'el8'}
|
| |
+ },
|
| |
+ # This noisy config should not impact to choose the correct one.
|
| |
+ {
|
| |
+ 'name': 'testmodule2', 'stream': 'rhel-8.0', 'priority': 20,
|
| |
+ }
|
| |
+ ],
|
| |
+ {
|
| |
+ 'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 10,
|
| |
+ 'requires': {'platform': 'el8'}
|
| |
+ },
|
| |
+ ),
|
| |
+ (
|
| |
+ [
|
| |
+ # buildrequires could be specified in config as well.
|
| |
+ {
|
| |
+ 'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 10,
|
| |
+ 'buildrequires': {'platform': 'el8'}
|
| |
+ },
|
| |
+ ],
|
| |
+ {
|
| |
+ 'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 10,
|
| |
+ 'buildrequires': {'platform': 'el8'}
|
| |
+ },
|
| |
+ ),
|
| |
+ (
|
| |
+ [
|
| |
+ # Both requires and buildrequires are specified to match the
|
| |
+ # module metadata.
|
| |
+ {
|
| |
+ 'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 10,
|
| |
+ 'requires': {'platform': 'el8'},
|
| |
+ 'buildrequires': {'platform': 'el8'},
|
| |
+ },
|
| |
+ ],
|
| |
+ {
|
| |
+ 'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 10,
|
| |
+ 'requires': {'platform': 'el8'},
|
| |
+ 'buildrequires': {'platform': 'el8'},
|
| |
+ },
|
| |
+ ),
|
| |
+ # Either requires or buildrequires is not included in module metadata.
|
| |
+ (
|
| |
+ [
|
| |
+ {
|
| |
+ 'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 10,
|
| |
+ 'requires': {'platform': 'f30'},
|
| |
+ },
|
| |
+ ],
|
| |
+ None,
|
| |
+ ),
|
| |
+ (
|
| |
+ [
|
| |
+ # Both requires and buildrequires are specified to match the
|
| |
+ # module metadata.
|
| |
+ {
|
| |
+ 'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 10,
|
| |
+ 'buildrequires': {'platform': 'f30'},
|
| |
+ },
|
| |
+ ],
|
| |
+ None,
|
| |
+ ),
|
| |
+ (
|
| |
+ [
|
| |
+ {
|
| |
+ 'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 10,
|
| |
+ 'requires': {'platform': 'f30'},
|
| |
+ 'buildrequires': {'platform': 'f30'},
|
| |
+ },
|
| |
+ ],
|
| |
+ None,
|
| |
+ ),
|
| |
+ # Either name or stream is not matched module metadata.
|
| |
+ (
|
| |
+ # Module name is not matched in this config
|
| |
+ [{'name': 'module-xxxx', 'stream': 'rhel-8.0', 'priority': 20}],
|
| |
+ None,
|
| |
+ ),
|
| |
+ (
|
| |
+ # Module stream is not matched in this config
|
| |
+ [{'name': 'testmodule', 'stream': '100', 'priority': 20}],
|
| |
+ None,
|
| |
+ ),
|
| |
+ # Module name and stream are matched
|
| |
+ (
|
| |
+ [
|
| |
+ {'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 20},
|
| |
+ {'name': 'testmodule2', 'stream': 'rhel-8.0', 'priority': 20},
|
| |
+ ],
|
| |
+ {'name': 'testmodule', 'stream': 'rhel-8.0', 'priority': 20},
|
| |
+ ),
|
| |
+ )
|
| |
+ for config, expected_result in test_matrix:
|
| |
+ self.assert_get_module_config(config, expected_result)
|
| |
|
| |
@mock.patch('ursa_major.mbs.requests.get')
|
| |
def test_get_match_tags_in_inheritance(self, requests_get):
|
| |
With this patch, Ursa-Major could be configured to track modules by both
buildrequires and requires. There is an example in README. Meanwhile, just same
as the requires, buildrequires is optional as well.
Signed-off-by: Chenxiong Qi cqi@redhat.com