From 531843819b65e9232e3524be9515355435b5da6b Mon Sep 17 00:00:00 2001 From: ashoksingh Date: Fri, 30 Jan 2015 16:23:10 +0530 Subject: [PATCH] In VM UVE we have interface list and for each of these interfaces we send the VM Name. This name is populated by Nova msg. For Non-nova VMIs this field has empty string in agent. While sending UVE for such VMIs we need to pick VM name from VM object instead of VMI. Closes-Bug: #1416345 Change-Id: I28adcf98f97ba4c736fa388571969fd218f30b65 --- src/vnsw/agent/uve/test/test_vm_uve.cc | 64 +++++++++++++++++++++++++ src/vnsw/agent/uve/vm_uve_entry_base.cc | 11 ++++- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/vnsw/agent/uve/test/test_vm_uve.cc b/src/vnsw/agent/uve/test/test_vm_uve.cc index 2ba5f49c575..696bb58ca5b 100644 --- a/src/vnsw/agent/uve/test/test_vm_uve.cc +++ b/src/vnsw/agent/uve/test/test_vm_uve.cc @@ -1263,6 +1263,70 @@ TEST_F(UveVmUveTest, VmChangeOnVMI) { vmut->ClearCount(); } +/* Verify that VM name is not NULL-string in the interface list sent as part of + * VM UVE */ +TEST_F(UveVmUveTest, VmNameInInterfaceList) { + VmUveTableTest *vmut = static_cast + (Agent::GetInstance()->uve()->vm_uve_table()); + struct PortInfo input[] = { + {"vmi1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1} + }; + + //Add physical-device and physical-interface and add their association + util_.VmAdd(input[0].vm_id); + AddPhysicalDevice("prouter1", 1); + AddPhysicalInterface("pi1", 1, "pid1"); + AddLogicalInterface("li1", 1, "lid1"); + AddPort("vmi1", 1); + AddLink("physical-router", "prouter1", "physical-interface", "pi1"); + AddLink("physical-interface", "pi1", "logical-interface", "li1"); + AddLink("virtual-machine-interface", "vmi1", "logical-interface", "li1"); + AddLink("virtual-machine-interface", "vmi1", "virtual-machine", "vm1"); + client->WaitForIdle(); + WAIT_FOR(1000, 500, (PhysicalDeviceGet(1) != NULL)); + WAIT_FOR(1000, 500, (PhysicalInterfaceGet("pi1") != NULL)); + WAIT_FOR(1000, 500, (LogicalInterfaceGet(1, "li1") != NULL)); + WAIT_FOR(1000, 500, (VmInterfaceGet(1) != NULL)); + + //Verify UVE + VmEntry *vm = VmGet(input[0].vm_id); + EXPECT_TRUE(vm != NULL); + UveVirtualMachineAgent *uve1 = vmut->VmUveObject(vm); + EXPECT_TRUE(uve1 != NULL); + EXPECT_EQ(1U, uve1->get_interface_list().size()); + + //Verify that VMI does not have VM Name set + VmInterface *vmi = VmInterfaceGet(input[0].intf_id); + EXPECT_TRUE((vmi->vm_name() == agent_->NullString())); + + //Verify that UVE has sent VM name for VMI + VmInterfaceAgent intf_entry = uve1->get_interface_list().front(); + EXPECT_TRUE((intf_entry.get_vm_name() == vm->GetCfgName())); + + //cleanup + DelLink("virtual-machine-interface", "vmi1", "virtual-machine", "vm1"); + DelNode("virtual-machine", "vm1"); + //Disassociate VMI from logical-interface + DelLink("virtual-machine-interface", "vmi1", "logical-interface", "li1"); + //Disassociate logical-interface from physical_interface + DelLink("physical-interface", "pi1", "logical-interface", "li1"); + //Disassociate physical-device from physical-interface + DelLink("physical-router", "prouter1", "physical-interface", "pi1"); + //Delete physical-device and physical-interface + DelPort("vmi1"); + DeleteLogicalInterface("li1"); + DeletePhysicalInterface("pi1"); + DeletePhysicalDevice("prouter1"); + client->WaitForIdle(); + WAIT_FOR(1000, 500, (PhysicalInterfaceGet("pi1") == NULL)); + WAIT_FOR(1000, 500, (PhysicalDeviceGet(1) == NULL)); + WAIT_FOR(1000, 500, (LogicalInterfaceGet(1, "li1") == NULL)); + + //clear counters at the end of test case + client->Reset(); + vmut->ClearCount(); +} + int main(int argc, char **argv) { GETUSERARGS(); client = TestInit(init_file, ksync_init, true, false, true, diff --git a/src/vnsw/agent/uve/vm_uve_entry_base.cc b/src/vnsw/agent/uve/vm_uve_entry_base.cc index 1a5735b0d90..eeeb3172628 100644 --- a/src/vnsw/agent/uve/vm_uve_entry_base.cc +++ b/src/vnsw/agent/uve/vm_uve_entry_base.cc @@ -82,7 +82,16 @@ bool VmUveEntryBase::FrameInterfaceMsg(const VmInterface *vm_intf, return false; } s_intf->set_name(vm_intf->cfg_name()); - s_intf->set_vm_name(vm_intf->vm_name()); + /* VM interfaces which are not created by Nova will not have VM name set. + * In that case pick VM name from VM object instead of VMI object */ + if (vm_intf->vm_name() != agent_->NullString()) { + s_intf->set_vm_name(vm_intf->vm_name()); + } else { + const VmEntry *vm = vm_intf->vm(); + if (vm) { + s_intf->set_vm_name(vm->GetCfgName()); + } + } if (vm_intf->vn() != NULL) { s_intf->set_virtual_network(vm_intf->vn()->GetName()); } else {