sonata-nfv / son-gkeeper

SONATA's Service Platform Gatekeeper
http://www.sonata-nfv.eu
Apache License 2.0
2 stars 18 forks source link

Fix records retrieval by uuid #801

Closed cgeoffroy closed 7 years ago

cgeoffroy commented 7 years ago

Existing records for services/functions cannot be queried using their uuids.

We can list the current running services/functions by listing the records with:

(venv3) tai@Sydney:~/Projects/Sonata/git/son-cli$ curl -H "Authorization: ${H}" http://sp.int3.sonata-nfv.eu:32001/api/v2/records/services | jq '.'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1101  100  1101    0     0   2084      0 --:--:-- --:--:-- --:--:--  2089
[
  {
    "uuid": "609b1b1d-b47f-4f25-942b-592689e8f4f3",
    "virtual_links": [
      {
        "connectivity_type": "E-LAN",
        "id": "mgmt",
        "connection_points_reference": [
          "vnf_vtc:mgmt",
          "mgmt"
        ]
      },
      {
        "connectivity_type": "E-Line",
        "id": "input-2-vtc",
        "connection_points_reference": [
          "input",
          "vnf_vtc:input"
        ]
      },
      {
        "connectivity_type": "E-Line",
        "id": "vtc-2-output",
        "connection_points_reference": [
          "vnf_vtc:output",
          "output"
        ]
      }
    ],
    "created_at": "2017-07-27T08:48:50.151+00:00",
    "descriptor_reference": "6b9367c0-c784-4b7a-baf7-2a8f9489950f",
    "descriptor_version": "nsr-schema-01",
    "forwarding_graphs": [
      {
        "number_of_endpoints": 2,
        "network_forwarding_paths": [
          {
            "fp_id": "ns:fg01:fp01",
            "policy": "none",
            "connection_points": [
              {
                "connection_point_ref": "input",
                "position": 1
              },
              {
                "connection_point_ref": "vnf_vtc:input",
                "position": 2
              },
              {
                "connection_point_ref": "vnf_vtc:output",
                "position": 3
              },
              {
                "connection_point_ref": "output",
                "position": 4
              }
            ]
          }
        ],
        "fg_id": "ns:fg01",
        "number_of_virtual_links": 2,
        "constituent_vnfs": [
          "vnf_vtc"
        ]
      }
    ],
    "network_functions": [
      {
        "vnfr_id": "7256ea39-375a-41fb-b868-c44cf91f69f5"
      }
    ],
    "status": "normal operation",
    "updated_at": "2017-07-27T08:48:50.151+00:00",
    "version": "1"
  }
]

But directly querying records by their uuid fails:

(venv3) tai@Sydney:~/Projects/Sonata/git/son-cli$ curl -H "Authorization: ${H}" http://sp.int3.sonata-nfv.eu:32001/api/v2/records/services/609b1b1d-b47f-4f25-942b-592689e8f4f3 | jq '.'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    95  100    95    0     0    276      0 --:--:-- --:--:-- --:--:--   276
{
  "error": {
    "message": "#<NoMethodError: undefined method `empty?' for nil:NilClass>",
    "code": 500
  }
}

Or for functions:

(venv3) tai@Sydney:~/Projects/Sonata/git/son-cli$ curl -H "Authorization: ${H}" http://sp.int3.sonata-nfv.eu:32001/api/v2/records/functions/7256ea39-375a-41fb-b868-c44cf91f69f5 | jq '.'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    91  100    91    0     0    341      0 --:--:-- --:--:-- --:--:--   340
{
  "error": {
    "message": "#<NoMethodError: undefined method `[]' for nil:NilClass>",
    "code": 500
  }
}

the admin logs contains this error:

D, [2017-07-27 09:35:04#6] DEBUG -- GtkRec GET /functions/:uuid: entered with :uuid=7256ea39-375a-41fb-b868-c44cf91f69f5
2017-07-27 09:35:04 - NoMethodError - undefined method `functions_catalogue' for GtkRec:Class:
    /app/routes/function.rb:75:in `block in <class:GtkRec>'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1611:in `call'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1611:in `block in compile!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:975:in `[]'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:975:in `block (3 levels) in route!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:994:in `route_eval'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:975:in `block (2 levels) in route!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1015:in `block in process_route'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1013:in `catch'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1013:in `process_route'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:973:in `block in route!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:972:in `each'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:972:in `route!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1085:in `block in dispatch!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `block in invoke'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `catch'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `invoke'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1082:in `dispatch!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:907:in `block in call!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `block in invoke'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `catch'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `invoke'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:907:in `call!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:895:in `call'
    /usr/local/bundle/gems/rack-1.6.8/lib/rack/session/abstract/id.rb:225:in `context'
    /usr/local/bundle/gems/rack-1.6.8/lib/rack/session/abstract/id.rb:220:in `call'
    /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
    /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
    /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
    /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
    /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
    /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
    /usr/local/bundle/gems/rack-1.6.8/lib/rack/logger.rb:15:in `call'
    /usr/local/bundle/gems/rack-1.6.8/lib/rack/commonlogger.rb:33:in `call'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:219:in `call'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:212:in `call'
    /usr/local/bundle/gems/rack-1.6.8/lib/rack/head.rb:13:in `call'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:182:in `call'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:2013:in `call'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1487:in `block in call'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1787:in `synchronize'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1487:in `call'
    /usr/local/bundle/gems/puma-3.6.2/lib/puma/configuration.rb:225:in `call'
    /usr/local/bundle/gems/puma-3.6.2/lib/puma/server.rb:578:in `handle_request'
    /usr/local/bundle/gems/puma-3.6.2/lib/puma/server.rb:415:in `process_client'
    /usr/local/bundle/gems/puma-3.6.2/lib/puma/server.rb:275:in `block in run'
    /usr/local/bundle/gems/puma-3.6.2/lib/puma/thread_pool.rb:116:in `call'
    /usr/local/bundle/gems/puma-3.6.2/lib/puma/thread_pool.rb:116:in `block in spawn_thread'
172.20.0.1 - - [27/Jul/2017:09:35:04 +0000] "GET /functions/7256ea39-375a-41fb-b868-c44cf91f69f5 HTTP/1.1" 500 30 0.0007
jbonnet commented 7 years ago

@cgeoffroy Can you please retry? Functions are fixed, services will take a little longer

cgeoffroy commented 7 years ago

I just tried and it works better now for functions and services

jbonnet commented 7 years ago

Hey, @cgeoffroy , only better? Not perfect? ;-)

cgeoffroy commented 7 years ago

Oups, i did my verification on the descriptor api (api/v2/services, api/v2/functions) :-1:

I need to make a new service instantiation to correctly check the records api.

jbonnet commented 7 years ago

Ok, no problem. I'm working on the service instantiation, as a side effect of the service termination

cgeoffroy commented 7 years ago

I just tested on the sonata bss in the testbed.

The function records is still broken:

(venv3) tai@Sydney:~/Projects/Sonata/git/son-cli$ curl -H "Authorization: ${H}" http://sp.int3.sonata-nfv.eu:32001/api/v2/records/functions/41868cde-98e8-461e-8ddc-7fe38b50f218 | jq '.'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    91  100    91    0     0    201      0 --:--:-- --:--:-- --:--:--   201
{
  "error": {
    "message": "#<NoMethodError: undefined method `[]' for nil:NilClass>",
    "code": 500
  }
}

The logs seems to indicate that the record was fetched correctly from the backend but it fails afterwards:

D, [2017-07-27 15:25:36#6] DEBUG -- GtkRec GET /functions/:uuid: entered with :uuid=41868cde-98e8-461e-8ddc-7fe38b50f218
D, [2017-07-27 15:25:36#6] DEBUG -- : VFunction.new(repository=#<Repository:0x00559e590b2078 @url="http://sp.int3.sonata-nfv.eu:4002/records/vnfr/vnf-instances", @logger=#<Logger:0x00559e590c6078 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x00559e590c6028 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0x00559e590c5fd8 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<File:log/integration.log>, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x00559e590c5fb0 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x00559e590c5f60>>>>>, logger#<Logger:0x00559e58a0de20 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x00559e58a0ddf8 @datetime_format="%Y-%m-%d %H:%M:%S">, @formatter=nil, @logdev=#<Logger::LogDevice:0x00559e58a0dda8 @shift_size=1048576, @shift_age=0, @filename="/app/log/integration.log", @dev=#<File:/app/log/integration.log>, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x00559e58a0dd80 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x00559e58a0dd30>>>>)
D, [2017-07-27 15:25:36#6] DEBUG -- : VFunction.find_by_uuid(41868cde-98e8-461e-8ddc-7fe38b50f218)
D, [2017-07-27T15:25:36.003161 #6] DEBUG -- Repository.find_by_uuid: entered with uuid 41868cde-98e8-461e-8ddc-7fe38b50f218
D, [2017-07-27T15:25:36.093103 #6] DEBUG -- Repository.find_by_uuid: response={"created_at":"2017-07-27T15:17:07.522+00:00","descriptor_reference":"83aeca1d-3ba7-4209-99af-a6134a7eac41","descriptor_version":"vnfr-schema-01","status":"normal operation","updated_at":"2017-07-27T15:17:07.522+00:00","version":"2","virtual_deployment_units":[{"monitoring_parameters":[{"name":"vm_cpu_perc","unit":"Percentage"},{"name":"vm_mem_perc","unit":"Percentage"},{"name":"vm_net_rx_bps","unit":"bps"},{"name":"vm_net_tx_bps","unit":"bps"}],"id":"vdu01","vm_image":"sonata-vtc","number_of_instances":1,"vdu_reference":"vtc-vnf:vdu01","resource_requirements":{"cpu":{"vcpus":1},"memory":{"size":2,"size_unit":"GB"},"storage":{"size":40,"size_unit":"GB"}},"vnfc_instance":[{"vc_id":"49526bf3-5a8c-48f3-9ff3-7f476b810807","vim_id":"1111-22222222-33333333-4444","id":"0","connection_points":[{"interface":{"address":"10.100.32.246","hardware_address":"fa:16:3e:bc:4a:26"},"id":"eth0","type":"management"},{"interface":{"address":"10.0.0.35","hardware_address":"fa:16:3e:68:17:93","netmask":"255.255.255.248"},"id":"eth1","type":"internal"},{"interface":{"address":"10.0.0.36","hardware_address":"fa:16:3e:b4:ab:b0","netmask":"255.255.255.248"},"id":"eth2","type":"internal"}]}]}],"virtual_links":[{"connection_points_reference":["vdu01:eth0","mgmt"],"id":"mgmt","connectivity_type":"E-LAN","dhcp":true},{"connection_points_reference":["vdu01:eth1","input"],"id":"input","connectivity_type":"E-Line","dhcp":true},{"connection_points_reference":["vdu01:eth2","output"],"id":"output","connectivity_type":"E-Line","dhcp":true}],"uuid":"41868cde-98e8-461e-8ddc-7fe38b50f218"}
2017-07-27 15:25:36 - NameError - undefined local variable or method `service' for #<VFunction:0x00559e58a0d8d0>:
    /app/models/v_function.rb:48:in `find_by_uuid'
    /app/routes/function.rb:75:in `block in <class:GtkRec>'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1611:in `call'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1611:in `block in compile!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:975:in `[]'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:975:in `block (3 levels) in route!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:994:in `route_eval'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:975:in `block (2 levels) in route!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1015:in `block in process_route'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1013:in `catch'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1013:in `process_route'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:973:in `block in route!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:972:in `each'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:972:in `route!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1085:in `block in dispatch!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `block in invoke'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `catch'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `invoke'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1082:in `dispatch!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:907:in `block in call!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `block in invoke'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `catch'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `invoke'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:907:in `call!'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:895:in `call'
    /usr/local/bundle/gems/rack-1.6.8/lib/rack/session/abstract/id.rb:225:in `context'
    /usr/local/bundle/gems/rack-1.6.8/lib/rack/session/abstract/id.rb:220:in `call'
    /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
    /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
    /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
    /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
    /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
    /usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
    /usr/local/bundle/gems/rack-1.6.8/lib/rack/logger.rb:15:in `call'
    /usr/local/bundle/gems/rack-1.6.8/lib/rack/commonlogger.rb:33:in `call'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:219:in `call'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:212:in `call'
    /usr/local/bundle/gems/rack-1.6.8/lib/rack/head.rb:13:in `call'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:182:in `call'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:2013:in `call'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1487:in `block in call'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1787:in `synchronize'
    /usr/local/bundle/gems/sinatra-1.4.7/lib/sinatra/base.rb:1487:in `call'
    /usr/local/bundle/gems/puma-3.6.2/lib/puma/configuration.rb:225:in `call'
    /usr/local/bundle/gems/puma-3.6.2/lib/puma/server.rb:578:in `handle_request'
    /usr/local/bundle/gems/puma-3.6.2/lib/puma/server.rb:415:in `process_client'
    /usr/local/bundle/gems/puma-3.6.2/lib/puma/server.rb:275:in `block in run'
    /usr/local/bundle/gems/puma-3.6.2/lib/puma/thread_pool.rb:116:in `call'
    /usr/local/bundle/gems/puma-3.6.2/lib/puma/thread_pool.rb:116:in `block in spawn_thread'
172.20.0.1 - - [27/Jul/2017:15:25:36 +0000] "GET /functions/41868cde-98e8-461e-8ddc-7fe38b50f218 HTTP/1.1" 500 30 0.0913

The service records are also broken:

(venv3) tai@Sydney:~/Projects/Sonata/git/son-cli$ curl -H "Authorization: ${H}" http://sp.int3.sonata-nfv.eu:32001/api/v2/records/services/c3468aac-f41b-42a7-9288-672fb2c5342a | jq '.'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    95  100    95    0     0    287      0 --:--:-- --:--:-- --:--:--   287
{
  "error": {
    "message": "#<NoMethodError: undefined method `empty?' for nil:NilClass>",
    "code": 500
  }
}

But no error shows up in the admin logs:

D, [2017-07-27 15:31:08#6] DEBUG -- GtkRec GET /services/:uuid: leaving with response={"created_at":"2017-07-27T15:17:07.615+00:00","descriptor_reference":"50664d77-bae2-4779-96e7-570cf24db07b","descriptor_version":"nsr-schema-01","forwarding_graphs":[{"fg_id":"ns:fg01","network_forwarding_paths":[{"connection_points":[{"position":1,"connection_point_ref":"input"},{"position":2,"connection_point_ref":"vnf_vtc:input"},{"position":3,"connection_point_ref":"vnf_vtc:output"},{"position":4,"connection_point_ref":"output"}],"fp_id":"ns:fg01:fp01","policy":"none"}],"constituent_vnfs":["vnf_vtc"],"number_of_endpoints":2,"number_of_virtual_links":2}],"network_functions":[{"vnfr_id":"41868cde-98e8-461e-8ddc-7fe38b50f218"}],"status":"normal operation","updated_at":"2017-07-27T15:17:07.615+00:00","version":"1","virtual_links":[{"connection_points_reference":["vnf_vtc:mgmt","mgmt"],"id":"mgmt","connectivity_type":"E-LAN"},{"connection_points_reference":["input","vnf_vtc:input"],"id":"input-2-vtc","connectivity_type":"E-Line"},{"connection_points_reference":["vnf_vtc:output","output"],"id":"vtc-2-output","connectivity_type":"E-Line"}],"uuid":"c3468aac-f41b-42a7-9288-672fb2c5342a"}
172.20.0.1 - - [27/Jul/2017:15:31:08 +0000] "GET /services/c3468aac-f41b-42a7-9288-672fb2c5342a HTTP/1.1" 200 1099 0.0839
jbonnet commented 7 years ago

Correct, just fixed the function wrong variable, service one is hiding deeper in the code, will need some time to find it

jbonnet commented 7 years ago

Hello, @cgeoffroy PR #825 hopefully solves this issue. Please check it and let me know. Thanks, and sorry for the time taken to solve it.

cgeoffroy commented 7 years ago

This issue seems resolved.