Bug #14179
closedInterface/NIC compute attributes in API host creation overwritten with compute profile attributes
Description
Since #6342, compute attributes specified inside a NIC/interface via the host create API are overwritten with compute attributes from associated compute profiles. This has the same symptoms as ticket #11124, which fixed it before #6342 reintroduced it.
POST to /api/v2/hosts with the following parameters:
{ "host": { "name": "niccrattrs", "hostgroup_name": "libvirt", "compute_resource_name": "localhost", "compute_attributes": { "cpus": 3 }, "interfaces_attributes": { "0": { "primary": "true", "compute_attributes": { "model": "e1000" } } } } }
... results in a VM with the NIC model set in the compute profile assigned to the host group, rather than e1000 as per the NIC compute attributes.
In HostsController#create, the host compute attrs after ComputeAttributeMerge contains the nic_attributes from the profile:
[1] pry(#<Api::V2::HostsController>)> @host.compute_attributes => {"cpus"=>3, "memory"=>"1073741824", "nics_attributes"=>{"0"=>{"type"=>"network", "network"=>"default", "model"=>"virtio"}}, "volumes_attributes"=>{"0"=>{"pool_name"=>"default", "capacity"=>"10G", "allocation"=>"0G", "format_type"=>"qcow2"}}}
Prior to #6342, these compute attributes wouldn't have been filled in - it changed the API behaviour to merge compute profile attributes into host.compute_attributes.
But the NIC's compute_attributes does contain the merged compute attributes from the compute profile plus the user's parameters, due to InterfaceMerge and #11124:
[2] pry(#<Api::V2::HostsController>)> @host.interfaces => [#<Nic::Managed id: nil, mac: nil, ip: nil, type: "Nic::Managed", name: "test13982a", host_id: nil, subnet_id: nil, domain_id: nil, attrs: {}, created_at: nil, updated_at: nil, provider: nil, username: nil, password: nil, virtual: false, link: true, identifier: nil, tag: "", attached_to: "", managed: true, mode: "balance-rr", attached_devices: "", bond_options: "", primary: true, provision: true, compute_attributes: {"type"=>"network", "network"=>"default", "model"=>"e1000", "from_profile"=>"libvirt"}>]
Later in Orchestration::Compute#add_interfaces_to_compute_attrs, the per-NIC compute attributes should be merged back into the host compute attributes, but the step is skipped (the return unless
in this method) as the host compute attributes already contains nics_attributes:
[1] pry(#<Host::Managed>)> compute_attributes[attrs_name] => {"0"=>{"type"=>"network", "network"=>"default", "model"=>"virtio"}} [2] pry(#<Host::Managed>)> compute_attributes => {"cpus"=>3, "memory"=>"1073741824", "nics_attributes"=>{"0"=>{"type"=>"network", "network"=>"default", "model"=>"virtio"}}, "volumes_attributes"=>{"0"=>{"pool_name"=>"default", "capacity"=>"10G", "allocation"=>"0G", "format_type"=>"qcow2"}}}