blob: 6d8dc0058e42728bcbba3eacc00605e6a11321a6 [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
7import tempfile
8import os
9import bb
10
11import layerindexlib
12from layerindexlib.tests.common import LayersTest
13
14import logging
15
16def skipIfNoNetwork():
17 if os.environ.get("BB_SKIP_NETTESTS") == "yes":
18 return unittest.skip("Network tests being skipped")
19 return lambda f: f
20
21class LayerIndexWebRestApiTest(LayersTest):
22
23 @skipIfNoNetwork()
24 def setUp(self):
25 self.assertFalse(os.environ.get("BB_SKIP_NETTESTS") == "yes", msg="BB_SKIP_NETTESTS set, but we tried to test anyway")
26 LayersTest.setUp(self)
27 self.layerindex = layerindexlib.LayerIndex(self.d)
28 self.layerindex.load_layerindex('http://layers.openembedded.org/layerindex/api/;branch=sumo', load=['layerDependencies'])
29
30 @skipIfNoNetwork()
31 def test_layerindex_is_empty(self):
32 self.assertFalse(self.layerindex.is_empty(), msg="Layerindex is empty")
33
34 @skipIfNoNetwork()
35 def test_layerindex_store_file(self):
36 self.layerindex.store_layerindex('file://%s/file.json' % self.tempdir, self.layerindex.indexes[0])
37
38 self.assertTrue(os.path.isfile('%s/file.json' % self.tempdir), msg="Temporary file was not created by store_layerindex")
39
40 reload = layerindexlib.LayerIndex(self.d)
41 reload.load_layerindex('file://%s/file.json' % self.tempdir)
42
43 self.assertFalse(reload.is_empty(), msg="Layerindex is empty")
44
45 # Calculate layerItems in original index that should NOT be in reload
46 layerItemNames = []
47 for itemId in self.layerindex.indexes[0].layerItems:
48 layerItemNames.append(self.layerindex.indexes[0].layerItems[itemId].name)
49
50 for layerBranchId in self.layerindex.indexes[0].layerBranches:
51 layerItemNames.remove(self.layerindex.indexes[0].layerBranches[layerBranchId].layer.name)
52
53 for itemId in reload.indexes[0].layerItems:
54 self.assertFalse(reload.indexes[0].layerItems[itemId].name in layerItemNames, msg="Item reloaded when it shouldn't have been")
55
56 # Compare the original to what we wrote...
57 for type in self.layerindex.indexes[0]._index:
58 if type == 'apilinks' or \
59 type == 'layerItems' or \
60 type in self.layerindex.indexes[0].config['local']:
61 continue
62 for id in getattr(self.layerindex.indexes[0], type):
63 self.logger.debug(1, "type %s" % (type))
64
65 self.assertTrue(id in getattr(reload.indexes[0], type), msg="Id number not in reloaded index")
66
67 self.logger.debug(1, "%s ? %s" % (getattr(self.layerindex.indexes[0], type)[id], getattr(reload.indexes[0], type)[id]))
68
69 self.assertEqual(getattr(self.layerindex.indexes[0], type)[id], getattr(reload.indexes[0], type)[id], msg="Reloaded contents different")
70
71 @skipIfNoNetwork()
72 def test_layerindex_store_split(self):
73 self.layerindex.store_layerindex('file://%s' % self.tempdir, self.layerindex.indexes[0])
74
75 reload = layerindexlib.LayerIndex(self.d)
76 reload.load_layerindex('file://%s' % self.tempdir)
77
78 self.assertFalse(reload.is_empty(), msg="Layer index is empty")
79
80 for type in self.layerindex.indexes[0]._index:
81 if type == 'apilinks' or \
82 type == 'layerItems' or \
83 type in self.layerindex.indexes[0].config['local']:
84 continue
85 for id in getattr(self.layerindex.indexes[0] ,type):
86 self.logger.debug(1, "type %s" % (type))
87
88 self.assertTrue(id in getattr(reload.indexes[0], type), msg="Id number missing from reloaded data")
89
90 self.logger.debug(1, "%s ? %s" % (getattr(self.layerindex.indexes[0] ,type)[id], getattr(reload.indexes[0], type)[id]))
91
92 self.assertEqual(getattr(self.layerindex.indexes[0] ,type)[id], getattr(reload.indexes[0], type)[id], msg="reloaded data does not match original")
93
94 @skipIfNoNetwork()
95 def test_dependency_resolution(self):
96 # Verify depth first searching...
97 (dependencies, invalidnames) = self.layerindex.find_dependencies(names=['meta-python'])
98
99 first = True
100 for deplayerbranch in dependencies:
101 layerBranch = dependencies[deplayerbranch][0]
102 layerDeps = dependencies[deplayerbranch][1:]
103
104 if not first:
105 continue
106
107 first = False
108
109 # Top of the deps should be openembedded-core, since everything depends on it.
110 self.assertEqual(layerBranch.layer.name, "openembedded-core", msg='OpenEmbedded-Core is no the first dependency')
111
112 # meta-python should cause an openembedded-core dependency, if not assert!
113 for dep in layerDeps:
114 if dep.layer.name == 'meta-python':
115 break
116 else:
117 self.logger.debug(1, "meta-python was not found")
118 self.assetTrue(False)
119
120 # Only check the first element...
121 break
122 else:
123 # Empty list, this is bad.
124 self.logger.debug(1, "Empty list of dependencies")
125 self.assertIsNotNone(first, msg="Empty list of dependencies")
126
127 # Last dep should be the requested item
128 layerBranch = dependencies[deplayerbranch][0]
129 self.assertEqual(layerBranch.layer.name, "meta-python", msg="Last dependency not meta-python")
130
131 @skipIfNoNetwork()
132 def test_find_collection(self):
133 def _check(collection, expected):
134 self.logger.debug(1, "Looking for collection %s..." % collection)
135 result = self.layerindex.find_collection(collection)
136 if expected:
137 self.assertIsNotNone(result, msg="Did not find %s when it should be there" % collection)
138 else:
139 self.assertIsNone(result, msg="Found %s when it shouldn't be there" % collection)
140
141 tests = [ ('core', True),
142 ('openembedded-core', False),
143 ('networking-layer', True),
144 ('meta-python', True),
145 ('openembedded-layer', True),
146 ('notpresent', False) ]
147
148 for collection,result in tests:
149 _check(collection, result)
150
151 @skipIfNoNetwork()
152 def test_find_layerbranch(self):
153 def _check(name, expected):
154 self.logger.debug(1, "Looking for layerbranch %s..." % name)
155
156 for index in self.layerindex.indexes:
157 for layerbranchid in index.layerBranches:
158 self.logger.debug(1, "Present: %s" % index.layerBranches[layerbranchid].layer.name)
159 result = self.layerindex.find_layerbranch(name)
160 if expected:
161 self.assertIsNotNone(result, msg="Did not find %s when it should be there" % collection)
162 else:
163 self.assertIsNone(result, msg="Found %s when it shouldn't be there" % collection)
164
165 tests = [ ('openembedded-core', True),
166 ('core', False),
167 ('meta-networking', True),
168 ('meta-python', True),
169 ('meta-oe', True),
170 ('notpresent', False) ]
171
172 for collection,result in tests:
173 _check(collection, result)
174