def test_get_traits_filter_by_prefix_and_suffix(self):
        traits = ot.get_traits(prefix='HW_NIC', suffix='RSA')
        self.assertIn("HW_NIC_ACCEL_RSA", traits)
        self.assertNotIn(ot.HW_NIC_ACCEL_TLS, traits)
        self.assertEqual(1, len(traits))

        traits = ot.get_traits(prefix='HW_NIC', suffix='TX')
        self.assertIn("HW_NIC_SRIOV_QOS_TX", traits)
        self.assertIn("HW_NIC_OFFLOAD_TX", traits)
        self.assertEqual(2, len(traits))
Exemplo n.º 2
0
def _trait_sync(ctx):
    """Sync the os_traits symbols to the database.

    Reads all symbols from the os_traits library, checks if any of them do
    not exist in the database and bulk-inserts those that are not. This is
    done once per web-service process, at startup.

    :param ctx: `placement.context.RequestContext` that may be used to grab a
                 DB connection.
    """
    # Create a set of all traits in the os_traits library.
    std_traits = set(os_traits.get_traits())
    sel = sa.select([_TRAIT_TBL.c.name])
    res = ctx.session.execute(sel).fetchall()
    # Create a set of all traits in the db that are not custom
    # traits.
    db_traits = set(
        r[0] for r in res
        if not os_traits.is_custom(r[0])
    )
    # Determine those traits which are in os_traits but not
    # currently in the database, and insert them.
    need_sync = std_traits - db_traits
    ins = _TRAIT_TBL.insert()
    batch_args = [
        {'name': six.text_type(trait)}
        for trait in need_sync
    ]
    if batch_args:
        try:
            ctx.session.execute(ins, batch_args)
            LOG.debug("Synced traits from os_traits into API DB: %s",
                      need_sync)
        except db_exc.DBDuplicateEntry:
            pass  # some other process sync'd, just ignore
Exemplo n.º 3
0
def _trait_sync(context):
    """Sync the os_traits symbols to the database.

    Reads all symbols from the os_traits library, checks if any of them do
    not exist in the database and bulk-inserts those that are not. This is
    done once per web-service process, at startup.

    :param context: `placement.context.RequestContext` that may be used to grab
                    a DB connection.
    """
    # Create a set of all traits in the os_traits library.
    std_traits = set(os_traits.get_traits())
    # Get the traits in the database
    trait_names = Trait.get_all_names(context)
    db_traits = set(name for name in trait_names
                    if not os_traits.is_custom(name))
    # Determine those traits which are in os_traits but not
    # currently in the database, and insert them.
    need_sync = std_traits - db_traits
    if not need_sync:
        return
    qlines = []
    for num, trait_name in enumerate(need_sync):
        qline = """
                CREATE (t%s:TRAIT {name: '%s', created_at: timestamp(),
                    updated_at: timestamp()})
        """ % (num, trait_name)
        qlines.append(qline)
    query = "\n".join(qlines) + "\nRETURN t0"

    try:
        result = context.tx.run(query).data()
    except db.ClientError:
        pass  # some other process sync'd, just ignore
 def test_trait_names_match_regex(self):
     traits = ot.get_traits()
     valid_name = re.compile("^[A-Z][A-Z0-9_]*$")
     for t in traits:
         match = valid_name.match(t)
         if not match:
             self.fail("Trait %s does not validate name regex." % t)
 def test_dunderinit_and_nondunderinit(self):
     """Make sure we can have both dunderinit'd traits and submodules
     co-exist in the same namespace.
     """
     traits = ot.get_traits('COMPUTE')
     self.assertIn("COMPUTE_DEVICE_TAGGING", traits)
     self.assertIn(ot.COMPUTE_DEVICE_TAGGING, traits)
     self.assertIn("COMPUTE_VOLUME_EXTEND", traits)
     self.assertIn(ot.COMPUTE_NET_ATTACH_INTERFACE, traits)
 def test_get_traits_filter_by_prefix(self):
     traits = ot.get_traits('HW_CPU')
     self.assertIn("HW_CPU_X86_SSE42", traits)
     self.assertIn("HW_CPU_HYPERTHREADING", traits)
     self.assertIn(ot.HW_CPU_X86_AVX2, traits)
     self.assertNotIn(ot.STORAGE_DISK_SSD, traits)
     self.assertNotIn(ot.HW_NIC_SRIOV, traits)
     self.assertNotIn('CUSTOM_NAMESPACE', traits)
     self.assertNotIn('os_traits', traits)
Exemplo n.º 7
0
def _generate_trait_list():
    yield 'Available Traits'
    yield '================'
    yield ''
    yield 'Below is a list of all traits currently available.'
    yield ''

    for trait in os_traits.get_traits():
        yield f'- ``{trait}``'

    yield ''
Exemplo n.º 8
0
    states.VERBS['rescue']: versions.MINOR_38_RESCUE_INTERFACE,
    states.VERBS['unrescue']: versions.MINOR_38_RESCUE_INTERFACE,
}

V31_FIELDS = [
    'boot_interface',
    'console_interface',
    'deploy_interface',
    'inspect_interface',
    'management_interface',
    'power_interface',
    'raid_interface',
    'vendor_interface',
]

STANDARD_TRAITS = os_traits.get_traits()
CUSTOM_TRAIT_REGEX = re.compile("^%s[A-Z0-9_]+$" % os_traits.CUSTOM_NAMESPACE)


def validate_limit(limit):
    if limit is None:
        return CONF.api.max_limit

    if limit <= 0:
        raise wsme.exc.ClientSideError(_("Limit must be positive"))

    return min(CONF.api.max_limit, limit)


def validate_sort_dir(sort_dir):
    if sort_dir not in ['asc', 'desc']:
Exemplo n.º 9
0
    states.VERBS['rescue']: versions.MINOR_38_RESCUE_INTERFACE,
    states.VERBS['unrescue']: versions.MINOR_38_RESCUE_INTERFACE,
}

V31_FIELDS = [
    'boot_interface',
    'console_interface',
    'deploy_interface',
    'inspect_interface',
    'management_interface',
    'power_interface',
    'raid_interface',
    'vendor_interface',
]

STANDARD_TRAITS = os_traits.get_traits()
CUSTOM_TRAIT_REGEX = re.compile("^%s[A-Z0-9_]+$" % os_traits.CUSTOM_NAMESPACE)


def validate_limit(limit):
    if limit is None:
        return CONF.api.max_limit

    if limit <= 0:
        raise wsme.exc.ClientSideError(_("Limit must be positive"))

    return min(CONF.api.max_limit, limit)


def validate_sort_dir(sort_dir):
    if sort_dir not in ['asc', 'desc']:
Exemplo n.º 10
0
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Validators for ``traits`` namespaced extra specs."""

import os_traits

from nova.api.validation.extra_specs import base

EXTRA_SPEC_VALIDATORS = []

for trait in os_traits.get_traits():
    EXTRA_SPEC_VALIDATORS.append(
        base.ExtraSpecValidator(
            name=f'trait{{group}}:{trait}',
            description=f'Require or forbid trait {trait}.',
            value={
                'type': str,
                'enum': [
                    'required',
                    'forbidden',
                ],
            },
            parameters=[
                {
                    'name': 'group',
                    'pattern': r'([a-zA-Z0-9_-]{1,64})?',
Exemplo n.º 11
0
 def test_get_traits(self):
     traits = ot.get_traits(ot.NAMESPACES['x86'])
     self.assertIn("hw:cpu:x86:sse42", traits)
     self.assertEqual(35, len(traits))
 def test_get_traits_filter_by_suffix(self):
     traits = ot.get_traits(suffix='SSE42')
     self.assertIn("HW_CPU_X86_SSE42", traits)
     self.assertEqual(1, len(traits))