Esempio n. 1
0
 def test_get_portgroup_and_datacenter_id_by_name(self):
     dvs_name = "test_dvs"
     port_group_name = fake_vmware_api.Constants.PORTGROUP_NAME
     dvs = fake_vmware_api.DataObject()
     dvs_config = fake_vmware_api.DataObject()
     folder_mor = fake_vmware_api.create_folder()
     port_group_mors = []
     pg1 = fake_vmware_api.create_network()
     pg1.set("summary.name", "pg1")
     pg1.set("parent", folder_mor)
     port_group_mors.append(pg1)
     pg2 = fake_vmware_api.create_network()
     pg2.set("summary.name", port_group_name)
     pg2.set("parent", folder_mor)
     port_group_mors.append(pg2)
     dvs_config.ManagedObjectReference = port_group_mors
     with contextlib.nested(
         mock.patch.object(vim_util,
                           'get_properties_for_a_collection_of_objects',
                           return_value=port_group_mors),
         mock.patch.object(network_util, "get_dvs_mor_by_name",
                           return_value=dvs),
         mock.patch.object(vim_util, "get_dynamic_property",
                           return_value=dvs_config)):
             port_groupid, datacenter_id = network_util.\
                 get_portgroup_and_datacenter_id_by_name(self.session,
                                                         dvs_name,
                                                         port_group_name
                                                         )
             self.assertEqual(port_groupid, pg2.value)
             self.assertEqual(datacenter_id, datacenter_id)
Esempio n. 2
0
 def test_get_portgroup_mor_by_name_not_found(self):
     dvs_name = "test_dvs"
     port_group_name = fake_vmware_api.Constants.PORTGROUP_NAME
     dvs = fake_vmware_api.DataObject()
     dvs_config = fake_vmware_api.DataObject()
     port_group_mors = []
     pg1 = fake_vmware_api.create_network()
     pg1.set("summary.name", "pg1")
     port_group_mors.append(pg1)
     dvs_config.ManagedObjectReference = port_group_mors
     with contextlib.nested(
         mock.patch.object(vim_util,
                           'get_properties_for_a_collection_of_objects',
                           return_value=port_group_mors),
         mock.patch.object(network_util, "get_dvs_mor_by_name",
                           return_value=dvs),
         mock.patch.object(vim_util, "get_dynamic_property",
                           return_value=dvs_config)):
             port_group = network_util.get_portgroup_mor_by_name(
                 self.session, dvs_name, port_group_name)
             self.assertIsNone(port_group)