maas returning error 500 when querying raid by name not id

Bug #1776526 reported by Michał Ajduk
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MAAS
Invalid
Undecided
Unassigned

Bug Description

MAAS version: 2.3.3

Issue:
Querying node raid by name does not work in MAAS. The command should return either 404 (there is no id md0, it's a name) or return the data in the same way as when querying by database id.

According to MAAS CLI help:

ubuntu@infra1:~$ maas root raid read -h
usage: maas root raid read [--help] [-d] [-k] system_id id [data [data ...]]

Read RAID device on a machine.

Positional arguments:
 system_id
 id

Returns 404 if the machine or RAID is not found.

Common command-line options:
    --help, -h
 Show this help message and exit.
    -d, --debug
 Display more information about API responses.
    -k, --insecure
 Disable SSL certificate check

This command works correctly when querying the MAAS for raid using the database ID of the raid (321 in the example below):

ubuntu@infra1:~$ maas root raid read bypknn 321
Success.
Machine-readable output follows:
{
    "size": 1996488704,
    "system_id": "bypknn",
    "devices": [
        {
            "size": 1996488704,
            "uuid": "7f1eacad-f4dc-479b-bd7a-6aaa09d1288a",
            "bootable": false,
            "device_id": 3213,
            "used_for": "Active raid-1 device for md0",
            "system_id": "bypknn",
            "id": 1850,
            "type": "partition",
            "path": "/dev/disk/by-dname/sda-part2",
            "resource_uri": "/MAAS/api/2.0/nodes/bypknn/blockdevices/3213/partition/1850",
            "filesystem": {
                "fstype": "raid",
                "label": null,
                "mount_point": null,
                "mount_options": null,
                "uuid": "a4f5f2b6-e16b-4e0b-8cbf-d7210770a14b"
            }
        },
        {
            "size": 1996488704,
            "uuid": "b31b808c-5502-4efb-ad0c-2c35bf24282b",
            "bootable": false,
            "device_id": 3214,
            "used_for": "Active raid-1 device for md0",
            "system_id": "bypknn",
            "id": 1851,
            "type": "partition",
            "path": "/dev/disk/by-dname/sdb-part2",
            "resource_uri": "/MAAS/api/2.0/nodes/bypknn/blockdevices/3214/partition/1851",
            "filesystem": {
                "fstype": "raid",
                "label": null,
                "mount_point": null,
                "mount_options": null,
                "uuid": "00b3731c-f225-413d-8607-6277472a36ba"
            }
        }
    ],
    "virtual_device": {
        "size": 1996488704,
        "tags": [],
        "path": "/dev/disk/by-dname/md0",
        "used_for": "ext4 formatted filesystem mounted at /boot",
        "serial": null,
        "partition_table_type": null,
        "id_path": null,
        "partitions": [],
        "name": "md0",
        "block_size": 512,
        "resource_uri": "/MAAS/api/2.0/nodes/bypknn/blockdevices/3539/",
        "used_size": 1996488704,
        "system_id": "bypknn",
        "uuid": "7688584d-ed09-4ab5-8bd4-e63dd812b4ea",
        "available_size": 0,
        "id": 3539,
        "type": "virtual",
        "filesystem": {
            "fstype": "ext4",
            "label": "boot",
            "mount_point": "/boot",
            "mount_options": "",
            "uuid": "d1fa733a-8642-455e-96b8-d2f0af15b1b4"
        },
        "model": null
    },
    "spare_devices": [],
    "id": 321,
    "uuid": "10ceec5b-6985-49ef-bd41-ab7d0fcce8f4",
    "name": "md0",
    "human_size": "2.0 GB",
    "resource_uri": "/MAAS/api/2.0/nodes/bypknn/raid/321/",
    "level": "raid-1"
}

The command fails with 500 (system internal error) when querying using the raid name (md0 in this example):

ubuntu@infra1:~$ maas root raid read bypknn md0 -d
500 INTERNAL SERVER ERROR

       Content-Type: text/plain; charset=utf-8
               Date: Tue, 12 Jun 2018 16:43:40 GMT
             Server: TwistedWeb/16.0.0
             Status: 500
  Transfer-Encoding: chunked
               Vary: Cookie
    X-Frame-Options: SAMEORIGIN

get() returned more than one RAID -- it returned 41!

The exception thrown:
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: 2018-06-12 16:43:40 maasserver: [error] ################################ Exception: get() returned more than one RAID -- it returned 41! ################################
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: 2018-06-12 16:43:40 maasserver: [error] Traceback (most recent call last):
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: File "/usr/lib/python3/dist-packages/django/core/handlers/base.py", line 132, in get_response
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: File "/usr/lib/python3/dist-packages/maasserver/utils/views.py", line 185, in view_atomic_with_post_commit_savepoint
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: return view_atomic(*args, **kwargs)
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: File "/usr/lib/python3.5/contextlib.py", line 30, in inner
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: return func(*args, **kwds)
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: File "/usr/lib/python3/dist-packages/maasserver/api/support.py", line 59, in __call__
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: response = upcall(request, *args, **kwargs)
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: File "/usr/lib/python3/dist-packages/django/views/decorators/vary.py", line 21, in inner_func
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: response = func(*args, **kwargs)
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: File "/usr/lib/python3/dist-packages/piston3/resource.py", line 190, in __call__
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: result = self.error_handler(e, request, meth, em_format)
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: File "/usr/lib/python3/dist-packages/piston3/resource.py", line 188, in __call__
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: result = meth(request, *args, **kwargs)
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: File "/usr/lib/python3/dist-packages/maasserver/api/support.py", line 298, in dispatch
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: return function(self, request, *args, **kwargs)
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: File "/usr/lib/python3/dist-packages/maasserver/api/raid.py", line 156, in read
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: system_id, id, request.user, NODE_PERMISSION.VIEW)
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: File "/usr/lib/python3/dist-packages/maasserver/models/filesystemgroup.py", line 86, in get_object_or_404
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: filesystem_group = get_object_or_404(self.model, **params)
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: File "/usr/lib/python3/dist-packages/django/shortcuts.py", line 155, in get_object_or_404
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: return queryset.get(*args, **kwargs)
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: File "/usr/lib/python3/dist-packages/django/db/models/query.py", line 338, in get
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: (self.model._meta.object_name, num)
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: maasserver.models.filesystemgroup.MultipleObjectsReturned: get() returned more than one RAID -- it returned 41!
Jun 12 16:43:40 ic-skbrat2-infra1 sh[3708]: 2018-06-12 16:43:40 regiond: [info] 100.80.0.1 GET /MAAS/api/2.0/nodes/bypknn/raid/md0/ HTTP/1.1 --> 500 INTERNAL_SERVER_ERROR (referrer: -; agent: Python-httplib2/0.9.1 (gzip))

Note 41 is a cound of md0 devices on all nodes in MAAS. Looks like the querying by name is only partially implemented or there is some filtering issue.

MAAS version:
ubuntu@ic-skbrat2-infra1:~$ dpkg -l '*maas*'|cat
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===============================-====================================-============-=============================================
un maas <none> <none> (no description available)
ii maas-cli 2.3.3-6498-ge4db91d-0ubuntu1~16.04.1 all MAAS client and command-line interface
un maas-cluster-controller <none> <none> (no description available)
ii maas-common 2.3.3-6498-ge4db91d-0ubuntu1~16.04.1 all MAAS server common files
ii maas-dhcp 2.3.3-6498-ge4db91d-0ubuntu1~16.04.1 all MAAS DHCP server
ii maas-dns 2.3.3-6498-ge4db91d-0ubuntu1~16.04.1 all MAAS DNS server
ii maas-proxy 2.3.3-6498-ge4db91d-0ubuntu1~16.04.1 all MAAS Caching Proxy
ii maas-rack-controller 2.3.3-6498-ge4db91d-0ubuntu1~16.04.1 all Rack Controller for MAAS
ii maas-region-api 2.3.3-6498-ge4db91d-0ubuntu1~16.04.1 all Region controller API service for MAAS
ii maas-region-controller 2.3.3-6498-ge4db91d-0ubuntu1~16.04.1 all Region Controller for MAAS
un maas-region-controller-min <none> <none> (no description available)
un python-django-maas <none> <none> (no description available)
un python-maas-client <none> <none> (no description available)
un python-maas-provisioningserver <none> <none> (no description available)
ii python3-django-maas 2.3.3-6498-ge4db91d-0ubuntu1~16.04.1 all MAAS server Django web framework (Python 3)
ii python3-maas-client 2.3.3-6498-ge4db91d-0ubuntu1~16.04.1 all MAAS python API client (Python 3)
ii python3-maas-provisioningserver 2.3.3-6498-ge4db91d-0ubuntu1~16.04.1 all MAAS server provisioning libraries (Python 3)

Tags: 4010
Revision history for this message
Gábor Mészáros (gabor.meszaros) wrote :

I think using raid name is the way.
This is the case for 2.2.0 maas version as well:
$ maas maas version read
Success.
Machine-readable output follows:
{"version": "2.2.0", "subversion": "bzr6054-0ubuntu1~16.04.1", "capabilities": ["networks-management", "static-ipaddresses", "ipv6-deployment-ubuntu", "devices-management", "storage-deployment-ubuntu", "network-deployment-ubuntu", "bridging-interface-ubuntu", "bridging-automatic-ubuntu", "authenticate-api"]}

$ maas maas raid read gaey8h md0
get() returned more than one RAID -- it returned 49!

$ maas maas raid read gaey8h 7
Success.
Machine-readable output follows:
{
    "id": 7,
    "resource_uri": "/MAAS/api/2.0/nodes/gaey8h/raid/7/",
    "human_size": "51.2 GB",
    "system_id": "gaey8h",
    "size": 51170508800,
    "virtual_device": {
        "block_size": 512,
        "id": 15,
        "filesystem": {
            "label": "",
            "mount_point": "/",
            "fstype": "ext4",
...

Michał Ajduk (majduk)
Changed in maas:
status: New → Invalid
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.