xcat2 / xcat-inventory

An inventory tool for xcat cluster
8 stars 16 forks source link

Implement Osimage restful APIs #189

Closed bybai closed 5 years ago

bybai commented 5 years ago

Implement Osimage restful APIs for: https://github.ibm.com/xcat2/task_management/issues/142

Changes summaries:

  1. Implement a general validate method validate_resource_input_data in invmanager.py.
  2. Osimage restful APIs includes:
    1. inventory/osimages POST/GET
    2. inventory/osimages/{name} GET/PUT/DELETE/PATCH

UT results:

  1. inventory/osimages/{name} DELETE OK
    ]# lsdef -t osimage
    rhels7.6  (osimage)
    rhels7.6-test  (osimage)
    ]# curl -X DELETE "http://10.4.41.7:5000/api/v2/inventory/osimages/rhels7.6" -H  "accept: application/json"
    null
    ]# lsdef -t osimage
    rhels7.6-test  (osimage)
  2. inventory/osimages/{name} DELETE Not Found
    ]# curl -X DELETE "http://10.4.41.7:5000/api/v2/inventory/osimages/rh" -H  "accept: application/json"
    {
    "message": "Could not find an object named 'rh' of type 'osimage'."
    }
  3. inventory/osimages/{name} GET OK
    ]# curl -X GET "http://10.4.41.7:5000/api/v2/inventory/osimages/rhels7.6-x86_64-install-compute" -H  "accept: application/json"
    {
    "meta": {
        "name": "rhels7.6-x86_64-install-compute"
    },
    "spec": {
        "basic_attributes": {
            "osdistro": "rhels7.6-x86_64",
            "osname": "Linux",
            "distribution": "rhels7.6",
            "arch": "x86_64"
        },
        "role": "compute",
        "package_selection": {
            "pkglist": [
                "/opt/xcat/share/xcat/install/rh/compute.rhels7.pkglist"
            ],
            "otherpkgdir": [
                "/install/post/otherpkgs/rhels7.6/x86_64"
            ],
            "pkgdir": [
                "/install/rhels7.6/x86_64"
            ]
        },
        "template": "/opt/xcat/share/xcat/install/rh/compute.rhels7.tmpl",
        "imagetype": "linux",
        "provision_mode": "install"
    }
    }
  4. inventory/osimages/{name} GET failed
    ]# curl -X GET "http://10.4.41.7:5000/api/v2/inventory/osimages/rhels7.6-x86_64" -H  "accept: application/json"
    {
    "message": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. You have requested this URI [/api/v2/inventory/osimages/rhels7.6-x86_64] but did you mean /api/v2/inventory/osimages/<string:name> or /api/v2/inventory/osimages or /api/v2/inventory/routes/<string:name> ?"
    }
  5. inventory/osimages/{name} PUT created OK.
    
    ]# lsdef -t osimage rhels7.6-test
    Object name: rhels7.6-test
    imagetype=linux
    osarch=x86_64
    osdistroname=rhels7.6-x86_64
    osname=Linux
    osvers=rhels7.6
    otherpkgdir=/install/post/otherpkgs/rhels7.6/x86_64
    pkgdir=/install/rhels7.6/x86_64
    pkglist=/opt/xcat/share/xcat/install/rh/compute.rhels7.pkglist
    profile=compute
    provmethod=install
    template=/opt/xcat/share/xcat/install/rh/compute.rhels7.tmpl

]#curl -X PUT "http://10.4.41.7:5000/api/v2/inventory/osimages/rhels7.6-test" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"meta\": { \"name\": \"rhels7.6-test\" }, \"spec\": { \"basic_attributes\": { \"osdistro\": \"rhels7.6-x86_64\", \"osname\": \"Linux\", \"distribution\": \"rhels7.6\", \"arch\": \"ppc64\" }, \"role\": \"service\", \"imagetype\": \"linux\", \"provision_mode\": \"netboot\" }}"

]# lsdef -t osimage rhels7.6-test Object name: rhels7.6-test environvar=OBJNAME=rhels7.6-x86_64-install-compute imagetype=linux osarch=ppc64 osdistroname=rhels7.6-x86_64 osname=Linux osvers=rhels7.6 profile=service provmethod=netboot

6. Validate PUT

curl -X PUT "http://10.4.41.7:5000/api/v2/inventory/osimages/rhels7.6-x86_64-install-compute" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"meta\": { \"name\": \"rhels7.6-\" }, \"spec\": { \"basic_attributes\": { \"osdistro\": \"rhels7.6-x86_64\", \"osname\": \"Linux\", \"distribution\": \"rhels7.6\", \"arch\": \"ppc64\" }, \"role\": \"service\", \"imagetype\": \"linux\", \"provision_mode\": \"netboot\" }}"

{ "message": "meta name rhels7.6- is not the same with resource name rhels7.6-x86_64-install-compute." }

7. empty PATCH input data:

curl -X PATCH "http://10.4.41.7:5000/api/v2/inventory/osimages/rhels7.6-test" -H "accept: application/json" -H "Content-Type: application/json" -d "{}" { "message": "Input data should not be None." }

8. valid PATCH input data:

curl -X PATCH "http://10.4.41.7:5000/api/v2/inventory/osimages/rhels7.6-test" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"modify\": { \"osdistro\": \"rhels7.6-x86_64\", \"osname\": \"Linux\", \"osarch\": \"ppc\" }}"