Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | # Copyright (C) 2017-2018 Wind River Systems, Inc. |
| 2 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 3 | # SPDX-License-Identifier: GPL-2.0-only |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 4 | # |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 5 | |
| 6 | import unittest |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 7 | import os |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 8 | |
| 9 | import layerindexlib |
| 10 | from layerindexlib.tests.common import LayersTest |
| 11 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 12 | |
| 13 | def skipIfNoNetwork(): |
| 14 | if os.environ.get("BB_SKIP_NETTESTS") == "yes": |
| 15 | return unittest.skip("Network tests being skipped") |
| 16 | return lambda f: f |
| 17 | |
| 18 | class 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) |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 25 | self.layerindex.load_layerindex('https://layers.openembedded.org/layerindex/api/;branch=sumo', load=['layerDependencies']) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 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 Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 60 | self.logger.debug("type %s" % (type)) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 61 | |
| 62 | self.assertTrue(id in getattr(reload.indexes[0], type), msg="Id number not in reloaded index") |
| 63 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 64 | self.logger.debug("%s ? %s" % (getattr(self.layerindex.indexes[0], type)[id], getattr(reload.indexes[0], type)[id])) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 65 | |
| 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 Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 83 | self.logger.debug("type %s" % (type)) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 84 | |
| 85 | self.assertTrue(id in getattr(reload.indexes[0], type), msg="Id number missing from reloaded data") |
| 86 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 87 | self.logger.debug("%s ? %s" % (getattr(self.layerindex.indexes[0] ,type)[id], getattr(reload.indexes[0], type)[id])) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 88 | |
| 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 Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 114 | self.logger.debug("meta-python was not found") |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 115 | raise self.failureException |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 116 | |
| 117 | # Only check the first element... |
| 118 | break |
| 119 | else: |
| 120 | # Empty list, this is bad. |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 121 | self.logger.debug("Empty list of dependencies") |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 122 | 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 Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 131 | self.logger.debug("Looking for collection %s..." % collection) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 132 | 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 Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 151 | self.logger.debug("Looking for layerbranch %s..." % name) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 152 | |
| 153 | for index in self.layerindex.indexes: |
| 154 | for layerbranchid in index.layerBranches: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 155 | self.logger.debug("Present: %s" % index.layerBranches[layerbranchid].layer.name) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 156 | 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 | |