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