blob: 33b5c1c4c84286c4f5f301d181ae278935665c53 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001# Copyright (C) 2017-2018 Wind River Systems, Inc.
2#
Brad Bishopc342db32019-05-15 21:57:59 -04003# SPDX-License-Identifier: GPL-2.0-only
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08004#
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005
6import unittest
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08007import os
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08008
9import layerindexlib
10from layerindexlib.tests.common import LayersTest
11
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012
13def skipIfNoNetwork():
14 if os.environ.get("BB_SKIP_NETTESTS") == "yes":
15 return unittest.skip("Network tests being skipped")
16 return lambda f: f
17
18class LayerIndexWebRestApiTest(LayersTest):
19
20 @skipIfNoNetwork()
21 def setUp(self):
22 self.assertFalse(os.environ.get("BB_SKIP_NETTESTS") == "yes", msg="BB_SKIP_NETTESTS set, but we tried to test anyway")
23 LayersTest.setUp(self)
24 self.layerindex = layerindexlib.LayerIndex(self.d)
25 self.layerindex.load_layerindex('http://layers.openembedded.org/layerindex/api/;branch=sumo', load=['layerDependencies'])
26
27 @skipIfNoNetwork()
28 def test_layerindex_is_empty(self):
29 self.assertFalse(self.layerindex.is_empty(), msg="Layerindex is empty")
30
31 @skipIfNoNetwork()
32 def test_layerindex_store_file(self):
33 self.layerindex.store_layerindex('file://%s/file.json' % self.tempdir, self.layerindex.indexes[0])
34
35 self.assertTrue(os.path.isfile('%s/file.json' % self.tempdir), msg="Temporary file was not created by store_layerindex")
36
37 reload = layerindexlib.LayerIndex(self.d)
38 reload.load_layerindex('file://%s/file.json' % self.tempdir)
39
40 self.assertFalse(reload.is_empty(), msg="Layerindex is empty")
41
42 # Calculate layerItems in original index that should NOT be in reload
43 layerItemNames = []
44 for itemId in self.layerindex.indexes[0].layerItems:
45 layerItemNames.append(self.layerindex.indexes[0].layerItems[itemId].name)
46
47 for layerBranchId in self.layerindex.indexes[0].layerBranches:
48 layerItemNames.remove(self.layerindex.indexes[0].layerBranches[layerBranchId].layer.name)
49
50 for itemId in reload.indexes[0].layerItems:
51 self.assertFalse(reload.indexes[0].layerItems[itemId].name in layerItemNames, msg="Item reloaded when it shouldn't have been")
52
53 # Compare the original to what we wrote...
54 for type in self.layerindex.indexes[0]._index:
55 if type == 'apilinks' or \
56 type == 'layerItems' or \
57 type in self.layerindex.indexes[0].config['local']:
58 continue
59 for id in getattr(self.layerindex.indexes[0], type):
Andrew Geisslerd1e89492021-02-12 15:35:20 -060060 self.logger.debug("type %s" % (type))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080061
62 self.assertTrue(id in getattr(reload.indexes[0], type), msg="Id number not in reloaded index")
63
Andrew Geisslerd1e89492021-02-12 15:35:20 -060064 self.logger.debug("%s ? %s" % (getattr(self.layerindex.indexes[0], type)[id], getattr(reload.indexes[0], type)[id]))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080065
66 self.assertEqual(getattr(self.layerindex.indexes[0], type)[id], getattr(reload.indexes[0], type)[id], msg="Reloaded contents different")
67
68 @skipIfNoNetwork()
69 def test_layerindex_store_split(self):
70 self.layerindex.store_layerindex('file://%s' % self.tempdir, self.layerindex.indexes[0])
71
72 reload = layerindexlib.LayerIndex(self.d)
73 reload.load_layerindex('file://%s' % self.tempdir)
74
75 self.assertFalse(reload.is_empty(), msg="Layer index is empty")
76
77 for type in self.layerindex.indexes[0]._index:
78 if type == 'apilinks' or \
79 type == 'layerItems' or \
80 type in self.layerindex.indexes[0].config['local']:
81 continue
82 for id in getattr(self.layerindex.indexes[0] ,type):
Andrew Geisslerd1e89492021-02-12 15:35:20 -060083 self.logger.debug("type %s" % (type))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080084
85 self.assertTrue(id in getattr(reload.indexes[0], type), msg="Id number missing from reloaded data")
86
Andrew Geisslerd1e89492021-02-12 15:35:20 -060087 self.logger.debug("%s ? %s" % (getattr(self.layerindex.indexes[0] ,type)[id], getattr(reload.indexes[0], type)[id]))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080088
89 self.assertEqual(getattr(self.layerindex.indexes[0] ,type)[id], getattr(reload.indexes[0], type)[id], msg="reloaded data does not match original")
90
91 @skipIfNoNetwork()
92 def test_dependency_resolution(self):
93 # Verify depth first searching...
94 (dependencies, invalidnames) = self.layerindex.find_dependencies(names=['meta-python'])
95
96 first = True
97 for deplayerbranch in dependencies:
98 layerBranch = dependencies[deplayerbranch][0]
99 layerDeps = dependencies[deplayerbranch][1:]
100
101 if not first:
102 continue
103
104 first = False
105
106 # Top of the deps should be openembedded-core, since everything depends on it.
107 self.assertEqual(layerBranch.layer.name, "openembedded-core", msg='OpenEmbedded-Core is no the first dependency')
108
109 # meta-python should cause an openembedded-core dependency, if not assert!
110 for dep in layerDeps:
111 if dep.layer.name == 'meta-python':
112 break
113 else:
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600114 self.logger.debug("meta-python was not found")
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500115 raise self.failureException
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800116
117 # Only check the first element...
118 break
119 else:
120 # Empty list, this is bad.
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600121 self.logger.debug("Empty list of dependencies")
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800122 self.assertIsNotNone(first, msg="Empty list of dependencies")
123
124 # Last dep should be the requested item
125 layerBranch = dependencies[deplayerbranch][0]
126 self.assertEqual(layerBranch.layer.name, "meta-python", msg="Last dependency not meta-python")
127
128 @skipIfNoNetwork()
129 def test_find_collection(self):
130 def _check(collection, expected):
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600131 self.logger.debug("Looking for collection %s..." % collection)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800132 result = self.layerindex.find_collection(collection)
133 if expected:
134 self.assertIsNotNone(result, msg="Did not find %s when it should be there" % collection)
135 else:
136 self.assertIsNone(result, msg="Found %s when it shouldn't be there" % collection)
137
138 tests = [ ('core', True),
139 ('openembedded-core', False),
140 ('networking-layer', True),
141 ('meta-python', True),
142 ('openembedded-layer', True),
143 ('notpresent', False) ]
144
145 for collection,result in tests:
146 _check(collection, result)
147
148 @skipIfNoNetwork()
149 def test_find_layerbranch(self):
150 def _check(name, expected):
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600151 self.logger.debug("Looking for layerbranch %s..." % name)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800152
153 for index in self.layerindex.indexes:
154 for layerbranchid in index.layerBranches:
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600155 self.logger.debug("Present: %s" % index.layerBranches[layerbranchid].layer.name)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800156 result = self.layerindex.find_layerbranch(name)
157 if expected:
158 self.assertIsNotNone(result, msg="Did not find %s when it should be there" % collection)
159 else:
160 self.assertIsNone(result, msg="Found %s when it shouldn't be there" % collection)
161
162 tests = [ ('openembedded-core', True),
163 ('core', False),
164 ('meta-networking', True),
165 ('meta-python', True),
166 ('meta-oe', True),
167 ('notpresent', False) ]
168
169 for collection,result in tests:
170 _check(collection, result)
171