def test_get_hypervisor_by_host(self, make_client): expected_hostname = 'expected-host' hosts = [ self._make_hypervisor(expected_hostname), self._make_hypervisor(), self._make_hypervisor() ] make_client.return_value = client = mock.Mock() client.hypervisors.list.return_value = hosts actual = compute_util.get_hypervisors_by_host(self.config, expected_hostname) self.assertEqual(hosts[0], actual)
def _port_belongs_to_vmware(self, context): port = context.current try: try: host = port['binding:host_id'] except KeyError: raise exceptions.HypervisorNotFound hypervisor = compute_util.get_hypervisors_by_host(CONF, host) # value for field hypervisor_type collected from VMWare itself, # need to make research, about all possible and suitable values if hypervisor.hypervisor_type != dvs_const.VMWARE_HYPERVISOR_TYPE: raise exceptions.HypervisorNotFound except exceptions.ResourceNotFond: return False return func(self, context)
def _port_belongs_to_vmware(self, context): port = context.current try: try: host = port['binding:host_id'] except KeyError: raise exceptions.HypervisorNotFound hypervisor = compute_util.get_hypervisors_by_host( CONF, host) # value for field hypervisor_type collected from VMWare itself, # need to make research, about all possible and suitable values if hypervisor.hypervisor_type != dvs_const.VMWARE_HYPERVISOR_TYPE: raise exceptions.HypervisorNotFound except exceptions.ResourceNotFound: return False return func(self, context)