Only one user here which is no longer needed in a Python 3 only world.
Change-Id: Iac33e324d07d67368a5b544030cd5414d0586955
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
On the theory that they aren't and shouldn't be used, the following
methods are removed from the public interface of the base os_traits
package:
- symbolize (deleted, unused internally)
- import_submodules (deleted, replaced with appropriate call to
_walk_submodules)
This commit also reorganizes the module to put private methods first,
public methods last; and alphabetize within those groupings.
Sem-Ver: api-break
Change-Id: Idb5613bc016743ba689c6996d39399aae774daa9
Add a print_tree method in the base os_traits package. This recursively
walks the repository and prints a formatted tree of short names of all
the namespaces and their traits. You can try it like this:
python -c 'import os_traits; os_traits.print_tree()'
Here's an abbreviated subset of the output:
COMPUTE:
DEVICE_TAGGING, TRUSTED_CERTS
GRAPHICS:
MODEL_CIRRUS, MODEL_GOP, MODEL_NONE, MODEL_QXL, MODEL_VGA, MODEL_VIRTIO, MODEL_VMVGA, MODEL_XEN
HW:
CPU:
HYPERTHREADING
AMD:
SEV
PPC64LE:
POWER8, POWER9
NUMA:
ROOT
MISC:
SHARES_VIA_AGGREGATE
STORAGE:
DISK:
HDD, SSD
Change-Id: I6309501f10544f468bb694361c845a393a9491cf
Names of traits in placement are restricted to certain characters and
lengths. Consumers (e.g. Nova virt driver implementations of
update_provider_tree) may wish to generate such names dynamically based
on inputs that don't necessarily know or follow those rules. Such
consumers could use a convenient way to sanitize generated names such
that they conform to what placement expects.
This change set introduces a normalize_name method into the base
os_traits namespace. It is functionally identical to
ResourceClass.normalize_name: it converts and squashes any sequences of
non-alphanumeric characters to an underscore, upcases, and prepends
CUSTOM_.
Change-Id: I0d83cb39abb417b337a3429d374e88942561d254
Related-Blueprint: update-provider-tree
Added a new optional parameter ``suffix`` to function ``get_traits``. This
new parameter allows filtering the list of traits returned by the ending
of the name.
Change-Id: Ifadb72a1b8b64971c0377eaef89522fe979c0c87
Added "prefix" parameter to "check_traits" function. Now it's
possible to check a list of strings with a subset of defined
traits.
Change-Id: Ie2e7a5a7a264f887673bd3855efde44da1324701
They are constants, after all.
In the process make sure that none of these constants are presented
as traits when get_traits is called.
Change-Id: I783e0a2e99823ff061303152def64db59f3c31de
When walk_packages is called, unless a prefix is provided, it is
easy to escape the os_traits package and start walking other
packages. If there is a top-level 'tests' package somewhere in the
python path, this can then lead to importing all sorts of things,
some which rely on the environment having certain characteristics
and fail the import without that, some which will change the
environment.
Neither of these things are good. Nor do we want to be walking
packages all over the place. By providing a prefix we stay within
the os_traits package as desired.
Change-Id: Icde41191e39317ff5a031fff9ece0f05f1e0b4bc
Closes-Bug: #1694792
The get_traits() function was erroneously including 'CUSTOM_NAMESPACE' and
'os_traits' in the list of returned traits because the matching expression in
the list comprehension wasn't filtering out these two module-level string
attributes.
Also removes the name.upper() in symbolize() because that's actually dangerous
-- it may make a symbol in os_traits that doesn't actually match the trait name
defined in the submodule. For instance, if someone creates an
os_traits/foo/bar.py module with::
TRAITS = [
'baz',
]
the name.upper() would make a symbol os_traits.foo.bar.BAZ and
os_traits.FOO_BAR_baz
Change-Id: I8633cb29649ad0ca67f7669fd2b405b55e16258e
The os_traits.get_symbol_names() function implementation was identical to the
os_traits.get_traits() function. Remove it.
Change-Id: I8656d98e51258b641190cfca1da71348ca7b6752
The previous patch broke apart the single monolithic declaration of
traits into a branching directory structure. That was great, but it
added a lot of repetitive code to get the subpackages and submodules
into the proper namespace. This patch automates that for any file in the
tree that contains a 'TRAITS' property.
Change-Id: I904789cbec76d83a14e213ce6bb474c9967d588b
Sean Mooney had a good idea that for future-proofing the os-traits library and
ensuring that we don't have to deal with one giant const.py file, that we break
the library into various modules corresponding to the higher-level namespaces.
This patch adds some symbol-registration foo into a utils module and allows the
os_traits module and "leaf modules" to be called in the following way:
import os_traits
from os_traits.hw.cpu import x86
assert os_traits.HW_CPU_X86_SSE42 == x86.SSE42
assert x86.SSE42 == 'HW_CPU_X86_SSE42'
Change-Id: I0e8f50822ab67cb3be85ed3b935dd6cdb4436dbf
Adds the CUSTOM_ trait namespace prefix, matching the CUSTOM_ prefix
from the resource classes in the placement API. Also adds a simple
is_custom() method to the library for testing whether a trait is
custom or not.
Change-Id: I37cd61516eb68c9bf07778fe6ad42bb34c19d4da
Changes the lowercased constants to uppercase and replaces the : with a
_ character. This aligns with the naming convention for resource classes
in the placement API.
Change-Id: Ic8e87ff8db5b1893d2060af01bf48adda712a27c