def test_get_subnet_not_found(self, m_get_net): m_net = mock.Mock() m_get_net.return_value = m_net m_net.subnets.return_value = iter(()) filters = {'name': 'foo', 'tags': 'bar'} sub = utils.get_subnet_id(**filters) m_net.subnets.assert_called_with(**filters) self.assertIsNone(sub)
def test_get_subnet_id(self, m_get_net): m_net = mock.Mock() m_get_net.return_value = m_net subnets = (mock.Mock(id=mock.sentinel.subnet1), mock.Mock(id=mock.sentinel.subnet2)) m_net.subnets.return_value = iter(subnets) filters = {'name': 'foo', 'tags': 'bar'} sub = utils.get_subnet_id(**filters) m_net.subnets.assert_called_with(**filters) self.assertEqual(mock.sentinel.subnet1, sub)
def _get_subnet_from_machine(self, machine): networks = machine['spec'].get('providerSpec', {}).get('value', {}).get('networks') if not networks: LOG.warning('No `networks` in Machine `providerSpec`') return None subnets = networks[0].get('subnets') if not subnets: LOG.warning('No `subnets` in Machine `providerSpec.values.' 'networks`.') return None primary_subnet = subnets[0] if primary_subnet.get('uuid'): return primary_subnet['uuid'] else: subnet_filter = primary_subnet['filter'] subnet_id = utils.get_subnet_id(**subnet_filter) return subnet_id