assorted novaclient CLI commands treat hostname as pattern

Bug #1667794 reported by Chris Friesen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-novaclient
Fix Released
Undecided
Sen Yang

Bug Description

There are a number of commands (host-servers-migrate, host-meta, host-evacuate and host-evacuate-live, and "hypervisor-list --matching <substring>") that treat the user-specified host name as the input to the HTTP /os-hypervisors/{hypervisor_hostname_pattern}/search API. Novaclient then loops over the returned hypervisors.

The end result of this is that you run "nova host-evacuate-live compute-1", it will apply to "compute-1", "compute-10", "compute-11", "compute-100", etc. This doesn't match up with the documentation or user expectations.

The discussion at the nova PTG session on Friday was that this behaviour was insane, and we should try to try to fix this in novaclient.

Tags: compute
Chris Friesen (cbf123)
Changed in python-novaclient:
assignee: nobody → Chris Friesen (cbf123)
Changed in python-novaclient:
assignee: Chris Friesen (cbf123) → NidhiMittalHada (nidhimittal19)
Revision history for this message
NidhiMittalHada (nidhimittal19) wrote :

working on this

Changed in python-novaclient:
status: New → In Progress
Revision history for this message
Matt Riedemann (mriedem) wrote :

The "hypervisor-list --matching" CLI is fine to use the hypervisors search API - if you don't want pattern matching, don't use the --matching option.

The bug is probably in the evacuate CLIs relying on this - that should be fixed in python-novaclient.

There was a patch proposed against nova for changing the API behavior in the server, which is the wrong way to fix this.

Revision history for this message
Chris Friesen (cbf123) wrote :

Agreed, the fix should be in novaclient.

The help text for "hypervisor-list --matching" reads, "List hypervisors matching the given <hostname>."

This is a bit confusing, since it does talk about hypervisors as plural, but it still talks about a singular hostname as opposed to a pattern being matched. We might want to tweak the help text for that one.

Revision history for this message
Chris Friesen (cbf123) wrote :

We should probably also ensure that openstackclient is sane as well.

Revision history for this message
NidhiMittalHada (nidhimittal19) wrote :

working on this

Revision history for this message
NidhiMittalHada (nidhimittal19) wrote :
Download full text (4.4 KiB)

Hello Matt,

Kindly see analysis below and suggest.

When we execute
stack@ubuntu14-OptiPlex-3020:~/openstack_install/devstack$ nova --debug host-evacuate wipro .
.
.
DEBUG (session:347) REQ: curl -g -i -X GET http://10.141.67.190:8774/v2.1/os-hypervisors/wipro/servers -H "OpenStack-API-Version: compute 2.46" -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-OpenStack-Nova-API-Version: 2.46" -H "X-Auth-Token: {SHA1}9e9230a54eff2444ac32fa054c6bab3dbe446df9" >>>>>>>>>>>>>>>>>>>>>>>>>>

nova api that's being called is this
https://developer.openstack.org/api-ref/compute/?expanded=search-hypervisor-detail,list-hypervisor-servers-detail#list-hypervisor-servers
Where it clearly states: "List all servers belong to each hypervisor whose host name is matching a given hypervisor host name or portion of it."

Another available api for hostname match is https://developer.openstack.org/api-ref/compute/?expanded=search-hypervisor-detail,list-hypervisor-servers-detail#search-hypervisor
which states: "Search hypervisor by a given hypervisor host name or portion of it."

There is no api available at present where hostname is matched not as a pattern. PCMIIW.

Hence it can't be just fixed in client as it is.

Solution: I thought we can fix it by changing only http://10.141.67.190:8774/v2.1/os-hypervisors/wipro/servers api to match hostname as exact so that https://developer.openstack.org/api-ref/compute/?expanded=search-hypervisor-detail,list-hypervisor-servers-detail#search-hypervisor remains unaffected.
This I still have to change in nova server code, I will use an additional function parameter to specify if exact match is desired or a pattern match is desired.

But then http://10.141.67.190:8774/v2.1/os-hypervisors/wipro/servers is being used by many other commands than just host-evacuate.
Which all will be affected.

Listing commands that will be affected are .

Function in novaclient from where we call api
   def search(self, hypervisor_match, servers=False): >>>>>>>>>>>>>>.servers is False by default
        """
        Get a list of matching hypervisors.
        :param servers: If True, server information is also retrieved.
        """
        target = 'servers' if servers else 'search'
        url = ('/os-hypervisors/%s/%s' %
               (parse.quote(hypervisor_match, safe=''), target)) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
        return self._list(url, 'hypervisors')

we are passing servers as true in these cli commands.

Servers = True
==============================================
1.
do_host_meta(cs, args):
    """Set or Delete metadata on all instances of a host."""
    hypervisors = cs.hypervisors.search(args.host, servers=True)

2.
@utils.arg(
    'hostname',
    metavar='<hostname>',
    help=_('The hypervisor hostname (or pattern) to search for.')) def do_hypervisor_servers(cs, args):
    """List servers belonging to specific hypervisors."""
    hypers = cs.hypervisors.search(args.hostname, servers=True)

3.
def do_host_evacuate(cs, args):
    """Evacuate all instances from failed host."""

    hypervisors = cs.hypervisors.search(args.host, servers=True)

4.
def do_host_evacuate_live(cs, args):
    """Live migrate al...

Read more...

Revision history for this message
NidhiMittalHada (nidhimittal19) wrote :

@Chris

I think OpenStack Client doesn't need a fix in helptext.

=======================================================================================================
stack@ubuntu14-OptiPlex-3020:~/openstack_install/devstack$ openstack --help hypervisor list
WARNING: openstackclient.common.utils is deprecated and will be removed after Jun 2017. Please use osc_lib.utils. This warning is caused by an out-of-date import in /usr/local/lib/python2.7/dist-packages/saharaclient/osc/plugin.py
Ignoring domain related config project_domain_id because identity API version is 2.0
Ignoring domain related config user_domain_id because identity API version is 2.0
Ignoring domain related config project_domain_id because identity API version is 2.0
Ignoring domain related config user_domain_id because identity API version is 2.0
Ignoring domain related config project_domain_id because identity API version is 2.0
Ignoring domain related config user_domain_id because identity API version is 2.0
Ignoring domain related config project_domain_id because identity API version is 2.0
Ignoring domain related config user_domain_id because identity API version is 2.0
usage: openstack hypervisor list [-h]
                                 [-f {csv,html,json,json,table,value,yaml,yaml}]
                                 [-c COLUMN] [--max-width <integer>]
                                 [--print-empty] [--noindent]
                                 [--quote {all,minimal,none,nonnumeric}]
                                 [--matching <hostname>] [--long]

List hypervisors

optional arguments:
  -h, --help show this help message and exit
  --matching <hostname>
                        Filter hypervisors using <hostname> substring
  --long List additional fields in output

output formatters:
  output formatter options

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-novaclient (master)

Fix proposed to branch: master
Review: https://review.openstack.org/487494

Changed in python-novaclient:
assignee: NidhiMittalHada (nidhimittal19) → Chris Friesen (cbf123)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Fix proposed to branch: master
Review: https://review.openstack.org/487513

Changed in python-novaclient:
assignee: Chris Friesen (cbf123) → Matt Riedemann (mriedem)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-novaclient (master)

Reviewed: https://review.openstack.org/487513
Committed: https://git.openstack.org/cgit/openstack/python-novaclient/commit/?id=7024d84e258199d51607e176bb4d8ad5e44f6991
Submitter: Jenkins
Branch: master

commit 7024d84e258199d51607e176bb4d8ad5e44f6991
Author: Matt Riedemann <email address hidden>
Date: Wed Jul 26 12:44:34 2017 -0400

    Be clear about hypevisors.search used in a few CLIs

    The following CLIs are doing a pattern match on the hypervisor
    hostname when getting servers:

    1. nova host-evacuate
    2. nova host-evacuate-live (terrible name)
    3. nova host-servers-migrate
    4. nova host-meta (terrible name)

    The fact that the hypervisor host(s) are looked up using
    a pattern match is not clear in the help string for the host
    argument.

    This makes the help more clear and adds a warning about being
    specific if you only want to target a specific host for these
    operations.

    In a later change we may modify the behavior in these CLIs which
    allow you to find hypervisors via pattern matching, but for now
    we should at least update the help text so we can backport it.

    Change-Id: Icec03326bb4d9f898c04e10199038167ce5e3cce
    Partial-Bug: #1667794

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-novaclient (master)

Fix proposed to branch: master
Review: https://review.openstack.org/520187

Changed in python-novaclient:
assignee: Matt Riedemann (mriedem) → Sen Yang (senyang)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-novaclient (master)

Reviewed: https://review.openstack.org/520187
Committed: https://git.openstack.org/cgit/openstack/python-novaclient/commit/?id=9213ec2d32fa173ec9943c28fb6c3ba5c196015d
Submitter: Zuul
Branch: master

commit 9213ec2d32fa173ec9943c28fb6c3ba5c196015d
Author: Sen Yang <email address hidden>
Date: Wed Nov 15 12:09:04 2017 -0600

    Implement hypervisor hostname exact pattern match

        When starting cold migration with nova command "nova host-
        servers-migrate compute-1", the migration started from all
        compute hosts starting with name "compute-1", not only from
        compute-1 host. The same thing happens to "nova host-meta",
        "nova host-evacuate", "nova host-evacuate-live" as well.

        With the "--strict" option added to these nova commands, the
        action will be applied to a single compute with the exact
        hostname string match, but not to the computes with hostname
        substring match. Error handling is also added to these nova
        commands such that when specified hostname name does not exist,
        "NotFound" will be returned.

    Closes-Bug: #1667794
    Change-Id: I5610efa160864b0d91cd67961883a6bec5bb8dd0

Changed in python-novaclient:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on python-novaclient (master)

Change abandoned by Chris Friesen (<email address hidden>) on branch: master
Review: https://review.openstack.org/487494
Reason: This has been superceded by https://review.openstack.org/#/c/520187/

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/python-novaclient 10.2.0

This issue was fixed in the openstack/python-novaclient 10.2.0 release.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.