def test_get_unit_name_from_host_name(self): unit_mock1 = mock.MagicMock() unit_mock1.data = {'machine-id': 12} unit_mock1.entity_id = 'myapp/2' unit_mock2 = mock.MagicMock() unit_mock2.data = {'machine-id': 15} unit_mock2.entity_id = 'myapp/5' self.model.get_units.return_value = [unit_mock1, unit_mock2] self.assertEqual( juju_utils.get_unit_name_from_host_name('juju-model-12', 'myapp'), 'myapp/2')
def get_guests_compute_info(self, vm_name): """Return the hostname & juju unit of compute host hosting vm. :param vm_name: Name of guest to lookup :type vm_name: str :returns: Hypervisor name and juju unit name :rtype: (str, str) """ current_hypervisor = openstack_utils.get_hypervisor_for_guest( self.nova_client, vm_name) unit_name = juju_utils.get_unit_name_from_host_name( current_hypervisor, 'nova-compute') return current_hypervisor, unit_name